From af88e63dff5a549507bb91593386ef21da9f9fef Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Mon, 21 Jan 2019 22:25:37 -0800 Subject: [PATCH] fix new keyword broken by recent refactoring (#9377) --- packages/babel-parser/src/tokenizer/types.js | 2 +- .../fixtures/core/regression/9374/input.js | 3 + .../fixtures/core/regression/9374/output.json | 152 ++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 packages/babel-parser/test/fixtures/core/regression/9374/input.js create mode 100644 packages/babel-parser/test/fixtures/core/regression/9374/output.json diff --git a/packages/babel-parser/src/tokenizer/types.js b/packages/babel-parser/src/tokenizer/types.js index 6775ee5375..4d88ed0e11 100644 --- a/packages/babel-parser/src/tokenizer/types.js +++ b/packages/babel-parser/src/tokenizer/types.js @@ -184,7 +184,7 @@ export const keywords = Object.create(null, { const: makeKeywordProps("const"), while: makeKeywordProps("while", { isLoop }), with: makeKeywordProps("with"), - new: makeKeywordProps("new"), + new: makeKeywordProps("new", { beforeExpr, startsExpr }), this: makeKeywordProps("this", { startsExpr }), super: makeKeywordProps("super", { startsExpr }), class: makeKeywordProps("class", { startsExpr }), diff --git a/packages/babel-parser/test/fixtures/core/regression/9374/input.js b/packages/babel-parser/test/fixtures/core/regression/9374/input.js new file mode 100644 index 0000000000..bce5ddf8e1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/9374/input.js @@ -0,0 +1,3 @@ +function* test() { + yield new Foo(); +} diff --git a/packages/babel-parser/test/fixtures/core/regression/9374/output.json b/packages/babel-parser/test/fixtures/core/regression/9374/output.json new file mode 100644 index 0000000000..c32f37d64b --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/9374/output.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "test" + }, + "name": "test" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 21, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "expression": { + "type": "YieldExpression", + "start": 21, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "delegate": false, + "argument": { + "type": "NewExpression", + "start": 27, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "callee": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "arguments": [] + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file