feat: anonymous default exports - #801
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Summary by CodeRabbit
WalkthroughThe parser supports anonymous default export forms, consumes generator indicators, standardizes synthesized export identifiers, recognizes additional keywords, and updates function and class export expectations. ChangesExport parsing enhancements
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
packages/analysis/src/static/Parser.tspackages/analysis/src/static/definitions/Keyword.ts
| 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)); |
There was a problem hiding this comment.
🎯 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.
| 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.
|



Fixes #799
Changes proposed in this pull request:
@MaskingTechnology/jitar