diff --git a/packages/babel-parser/src/tokenizer/context.js b/packages/babel-parser/src/tokenizer/context.js index 11fe53d2d2..bb0f7b8a20 100644 --- a/packages/babel-parser/src/tokenizer/context.js +++ b/packages/babel-parser/src/tokenizer/context.js @@ -106,7 +106,7 @@ tt.incDec.updateContext = function() { // tokExprAllowed stays unchanged }; -tt._function.updateContext = function(prevType) { +tt._function.updateContext = tt._class.updateContext = function(prevType) { if (this.state.exprAllowed && !this.braceIsBlock(prevType)) { this.state.context.push(types.functionExpression); } diff --git a/packages/babel-parser/test/fixtures/es2015/class/division/input.js b/packages/babel-parser/test/fixtures/es2015/class/division/input.js new file mode 100644 index 0000000000..590fe776ec --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/division/input.js @@ -0,0 +1,9 @@ +x = class{} / foo + +x = class{} +/ foo / g + +(x = class{} / foo) + +(x = class{} +/ foo / g) diff --git a/packages/babel-parser/test/fixtures/es2015/class/division/output.json b/packages/babel-parser/test/fixtures/es2015/class/division/output.json new file mode 100644 index 0000000000..0a4a21ad4d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/division/output.json @@ -0,0 +1,561 @@ +{ + "type": "File", + "start": 0, + "end": 86, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 86, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 4, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "left": { + "type": "ClassExpression", + "start": 4, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "body": [] + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + } + }, + { + "type": "ExpressionStatement", + "start": 19, + "end": 86, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 19, + "end": 86, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 23, + "end": 86, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "left": { + "type": "BinaryExpression", + "start": 23, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "left": { + "type": "ClassExpression", + "start": 23, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "body": [] + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + } + }, + "operator": "/", + "right": { + "type": "CallExpression", + "start": 39, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "callee": { + "type": "CallExpression", + "start": 39, + "end": 61, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "callee": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + }, + "identifierName": "g" + }, + "name": "g" + }, + "arguments": [ + { + "type": "AssignmentExpression", + "start": 43, + "end": 60, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 47, + "end": 60, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "left": { + "type": "ClassExpression", + "start": 47, + "end": 54, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 52, + "end": 54, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "body": [] + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 57, + "end": 60, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 18 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + } + ] + }, + "arguments": [ + { + "type": "AssignmentExpression", + "start": 64, + "end": 85, + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 68, + "end": 85, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "left": { + "type": "BinaryExpression", + "start": 68, + "end": 81, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "left": { + "type": "ClassExpression", + "start": 68, + "end": 75, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 73, + "end": 75, + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "body": [] + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 78, + "end": 81, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 84, + "end": 85, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + }, + "identifierName": "g" + }, + "name": "g" + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file