From c0d54ce7fc52a0565bcaf675fabb9dbd8043bd6c Mon Sep 17 00:00:00 2001 From: Nicholas Eveland <55118955+nme077@users.noreply.github.com> Date: Mon, 19 Jul 2021 15:29:23 -0600 Subject: [PATCH] Allow module block to start a member expression (#13573) * Accept module in primaryExpression * Add module blocks to primaryExpression * Fix package.json * Fix yarn.lock * Fix yarn.lock * Remove package.tgz file --- .../babel-parser/src/parser/expression.js | 14 +++---- .../options.json | 2 +- .../input.js | 1 + .../output.json | 39 +++++++++++++++++++ 4 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/experimental/module-blocks/module-block-in-member-expression/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/module-blocks/module-block-in-member-expression/output.json diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 854e64e03b6c..04801bbd75aa 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -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) { @@ -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(); diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json index 082c82b3aead..41eb0be83352 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json @@ -3,4 +3,4 @@ "plugins": [ "doExpressions" ] -} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-blocks/module-block-in-member-expression/input.js b/packages/babel-parser/test/fixtures/experimental/module-blocks/module-block-in-member-expression/input.js new file mode 100644 index 000000000000..70c24654eff9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-blocks/module-block-in-member-expression/input.js @@ -0,0 +1 @@ +module {}.foo \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-blocks/module-block-in-member-expression/output.json b/packages/babel-parser/test/fixtures/experimental/module-blocks/module-block-in-member-expression/output.json new file mode 100644 index 000000000000..e83d5467722f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-blocks/module-block-in-member-expression/output.json @@ -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": [] + } +} \ No newline at end of file