Skip to content

[Bug]: Module block should be allowed in member expression #13533

@JLHwung

Description

@JLHwung

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

module {}.foo

AST Explorer

Configuration 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

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:

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions