From 1640f6463f10beaf69de133d95d38e0819045caa Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Sat, 12 Dec 2020 03:17:24 +0900 Subject: [PATCH] Enter new prodParam scope --- .../babel-parser/src/parser/expression.js | 6 +++ .../input.js | 1 + .../options.json | 4 ++ .../output.json | 40 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/output.json diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 5eb7ee2a618e..2a9ac7cceab4 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -2641,8 +2641,14 @@ export default class ExpressionParser extends LValParser { this.state.exportedIdentifiers = []; this.eat(tt.braceL); this.scope.enter(SCOPE_OTHER); + let paramFlags = PARAM; + if (this.hasPlugin("topLevelAwait")) { + paramFlags |= PARAM_AWAIT; + } + this.prodParam.enter(paramFlags); this.parseBlockOrModuleBlockBody(node.body, undefined, true, tt.braceR); this.scope.exit(); + this.prodParam.exit(); this.eat(tt.braceR); this.state.labels = oldLabels; this.state.exportedIdentifiers = oldExportedIdentifiers; diff --git a/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/input.js b/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/input.js new file mode 100644 index 000000000000..3eb8123ffe50 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/input.js @@ -0,0 +1 @@ +module { await 3 }; diff --git a/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/options.json b/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/options.json new file mode 100644 index 000000000000..92bd836fbbd2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "plugins": ["moduleBlocks", "topLevelAwait"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/output.json b/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/output.json new file mode 100644 index 000000000000..a89661c7df2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-blocks/valid-top-level-await-in-module-blocks/output.json @@ -0,0 +1,40 @@ +{ + "type": "File", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "program": { + "type": "Program", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, + "expression": { + "type": "ModuleExpression", + "start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, + "body": [ + { + "type": "ExpressionStatement", + "start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}}, + "expression": { + "type": "AwaitExpression", + "start":9,"end":16,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":16}}, + "argument": { + "type": "NumericLiteral", + "start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16}}, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file