Skip to content

Commit

Permalink
Allow module block to start a member expression (babel#13573)
Browse files Browse the repository at this point in the history
* Accept module in primaryExpression

* Add module blocks to primaryExpression

* Fix package.json

* Fix yarn.lock

* Fix yarn.lock

* Remove package.tgz file
  • Loading branch information
nme077 authored and nicolo-ribaudo committed Jul 30, 2021
1 parent d6950ed commit c0d54ce
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -512,13 +512,6 @@ export default class ExpressionParser extends LValParser {
if (!sawUnary) this.checkExponentialAfterUnary(expr);
return expr;
}
if (
this.isContextual("module") &&
this.lookaheadCharCode() === charCodes.leftCurlyBrace &&
!this.hasFollowingLineBreak()
) {
return this.parseModuleExpression();
}
const update = this.match(tt.incDec);
const node = this.startNode();
if (this.state.type.prefix) {
Expand Down Expand Up @@ -1002,6 +995,13 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(node, "ThisExpression");

case tt.name: {
if (
this.isContextual("module") &&
this.lookaheadCharCode() === charCodes.leftCurlyBrace &&
!this.hasFollowingLineBreak()
) {
return this.parseModuleExpression();
}
const canBeArrow = this.state.potentialArrowAt === this.state.start;
const containsEsc = this.state.containsEsc;
const id = this.parseIdentifier();
Expand Down
Expand Up @@ -3,4 +3,4 @@
"plugins": [
"doExpressions"
]
}
}
@@ -0,0 +1 @@
module {}.foo
@@ -0,0 +1,39 @@
{
"type": "File",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"program": {
"type": "Program",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"expression": {
"type": "MemberExpression",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"object": {
"type": "ModuleExpression",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}},
"body": {
"type": "Program",
"start":8,"end":9,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":9}},
"sourceType": "module",
"interpreter": null,
"body": [],
"directives": []
}
},
"computed": false,
"property": {
"type": "Identifier",
"start":10,"end":13,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":13},"identifierName":"foo"},
"name": "foo"
}
}
}
],
"directives": []
}
}

0 comments on commit c0d54ce

Please sign in to comment.