-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
Spec: Module Expressionsgood first issueoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser
Description
💻
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
module {}.fooConfiguration file name
No response
Configuration
No response
Current and expected behavior
Current: Parsing fails
Expected: Parsing succeeds
According to the spec, InlineModuleExpression (module {}) is a primary expression, so it should be allowed before the . in a member expression.
Environment
- Babel versions: 7.14.5
Possible solution
The module block is parsed in Parser#parseMaybeUnary
babel/packages/babel-parser/src/parser/expression.js
Lines 511 to 517 in bc1b953
| if ( | |
| this.isContextual("module") && | |
| this.lookaheadCharCode() === charCodes.leftCurlyBrace && | |
| !this.hasFollowingLineBreak() | |
| ) { | |
| return this.parseModuleExpression(); | |
| } |
which aligns to the UnaryExpression in the spec. It should be moved to Parser#parseExprAtom, which handles PrimaryExpression.
| parseExprAtom(refExpressionErrors?: ?ExpressionErrors): N.Expression { |
Specifically we can extend the current logic for tt.name token and handle the module {} checks here:
| case tt.name: { |
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Spec: Module Expressionsgood first issueoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser