Skip to content

feat: anonymous default exports - #801

Merged
basmasking merged 3 commits into
mainfrom
799-add-support-for-default-exports-of-anonymous-functions-and-classes
Jul 25, 2026
Merged

feat: anonymous default exports#801
basmasking merged 3 commits into
mainfrom
799-add-support-for-default-exports-of-anonymous-functions-and-classes

Conversation

@petermasking

Copy link
Copy Markdown
Member

Fixes #799

Changes proposed in this pull request:

  • Support for anonymous default exports of functions and classes
  • Boyscout: addition of keywords

@MaskingTechnology/jitar

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: da940c27-67ad-4f3b-ae26-5a441a40ae84

📥 Commits

Reviewing files that changed from the base of the PR and between 90772b5 and 5c31b73.

📒 Files selected for processing (2)
  • packages/analysis/src/static/Parser.ts
  • packages/analysis/test/static/Parser.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/analysis/src/static/Parser.ts

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of anonymous and default exports, ensuring synthesized identifiers are generated consistently for exports involving extends, grouped (...), and scoped {...} declarations.
    • Improved processing of generated export forms.
    • Expanded keyword recognition to include typeof and instanceof (type-checking keywords).
  • Tests
    • Updated export parsing test expectations for default function/class synthesized identifiers.

Walkthrough

The parser supports anonymous default export forms, consumes generator indicators, standardizes synthesized export identifiers, recognizes additional keywords, and updates function and class export expectations.

Changes

Export parsing enhancements

Layer / File(s) Summary
Keyword recognition
packages/analysis/src/static/definitions/Keyword.ts
The Keyword map includes FINALLY, TYPEOF, and INSTANCEOF.
Anonymous export handling
packages/analysis/src/static/Parser.ts, packages/analysis/test/static/Parser.spec.ts
Single-export parsing consumes generator indicators, inserts identifiers for anonymous export targets, uses EXPORTED_PREFIX for synthesized names, and expects synthesized identifiers for default function and class exports.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: basmasking

Poem

I’m a rabbit with exports to name,
Anonymous classes join the game.
Tokens hop, keywords gleam,
Prefixes guide the parsing stream—
Hop hop through the syntax frame!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The keyword additions in Keyword.ts are unrelated to #799 and go beyond anonymous default-export support. Move the keyword updates to a separate PR or remove them unless they are required for the linked issue.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: support for anonymous default exports.
Description check ✅ Passed The description follows the template with a fix reference, change bullets, and the required ownership tag.
Linked Issues check ✅ Passed The parser changes and tests align with #799 by supporting anonymous default exports for functions and classes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/analysis/src/static/Parser.ts`:
- Around line 417-425: Restrict the synthetic identifier insertion in the
export-handling branch to cases where the parser has consumed a function or
class declaration. Ensure expression exports such as object literals and arrow
functions bypass this branch and use the existing value-rehoming path, while
preserving synthetic names for anonymous function and class declarations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 138fce5c-ea82-44b6-beb6-a95531716a4a

📥 Commits

Reviewing files that changed from the base of the PR and between 165d785 and 90772b5.

📒 Files selected for processing (2)
  • packages/analysis/src/static/Parser.ts
  • packages/analysis/src/static/definitions/Keyword.ts

Comment on lines +417 to +425
if (token.hasValue(Keyword.EXTENDS)
|| token.hasValue(Group.OPEN)
|| token.hasValue(Scope.OPEN))
{
// Anonymous functions and class need an identifier

const identifier = `${EXPORTED_PREFIX}_${token.start}_${token.end}`;

tokenList.insert(new Token(TokenType.IDENTIFIER, identifier, 0, 0));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Restrict synthetic names to declaration exports.

Lines 417-425 also match non-declaration expressions such as export default { value: 1 } and export default async () => 1. They receive an exported $_EXPORT_* name, but no corresponding declaration is inserted, leaving resolution with a nonexistent FQN. Gate this branch on having consumed a function or class declaration; route expression forms through the value-rehoming path instead.

Proposed fix
+        let hasDeclarationKeyword = false;
+
         if (isDeclaration(token.value))
         {
+            hasDeclarationKeyword = true;
             token = tokenList.step(); // Read away the declaration keyword
             stepSize++;
         }

-        if (token.hasValue(Keyword.EXTENDS)
+        if (hasDeclarationKeyword
+         && (token.hasValue(Keyword.EXTENDS)
          || token.hasValue(Group.OPEN)
-         || token.hasValue(Scope.OPEN))
+         || token.hasValue(Scope.OPEN)))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (token.hasValue(Keyword.EXTENDS)
|| token.hasValue(Group.OPEN)
|| token.hasValue(Scope.OPEN))
{
// Anonymous functions and class need an identifier
const identifier = `${EXPORTED_PREFIX}_${token.start}_${token.end}`;
tokenList.insert(new Token(TokenType.IDENTIFIER, identifier, 0, 0));
let hasDeclarationKeyword = false;
if (isDeclaration(token.value))
{
hasDeclarationKeyword = true;
token = tokenList.step(); // Read away the declaration keyword
stepSize++;
}
if (hasDeclarationKeyword
&& (token.hasValue(Keyword.EXTENDS)
|| token.hasValue(Group.OPEN)
|| token.hasValue(Scope.OPEN)))
{
// Anonymous functions and class need an identifier
const identifier = `${EXPORTED_PREFIX}_${token.start}_${token.end}`;
tokenList.insert(new Token(TokenType.IDENTIFIER, identifier, 0, 0));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/analysis/src/static/Parser.ts` around lines 417 - 425, Restrict the
synthetic identifier insertion in the export-handling branch to cases where the
parser has consumed a function or class declaration. Ensure expression exports
such as object literals and arrow functions bypass this branch and use the
existing value-rehoming path, while preserving synthetic names for anonymous
function and class declarations.

@sonarqubecloud

Copy link
Copy Markdown

@basmasking
basmasking merged commit 30bbebb into main Jul 25, 2026
24 checks passed
@basmasking
basmasking deleted the 799-add-support-for-default-exports-of-anonymous-functions-and-classes branch July 25, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for default exports of anonymous functions and classes

2 participants