diff --git a/packages/babylon/src/tokenizer/index.js b/packages/babylon/src/tokenizer/index.js index fa484ed017..26d003094f 100644 --- a/packages/babylon/src/tokenizer/index.js +++ b/packages/babylon/src/tokenizer/index.js @@ -437,6 +437,7 @@ export default class Tokenizer extends LocationParser { let type = code === 42 ? tt.star : tt.modulo; let width = 1; let next = this.input.charCodeAt(this.state.pos + 1); + const exprAllowed = this.state.exprAllowed; // Exponentiation operator ** if (code === 42 && next === 42) { @@ -445,7 +446,7 @@ export default class Tokenizer extends LocationParser { type = tt.exponent; } - if (next === 61) { + if (next === 61 && !exprAllowed) { width++; type = tt.assign; } diff --git a/packages/babylon/test/fixtures/flow/anonymous-function-no-parens-types/good_13/actual.js b/packages/babylon/test/fixtures/flow/anonymous-function-no-parens-types/good_13/actual.js new file mode 100644 index 0000000000..feb53f2b4b --- /dev/null +++ b/packages/babylon/test/fixtures/flow/anonymous-function-no-parens-types/good_13/actual.js @@ -0,0 +1 @@ +const x = ():*=>{} diff --git a/packages/babylon/test/fixtures/flow/anonymous-function-no-parens-types/good_13/expected.json b/packages/babylon/test/fixtures/flow/anonymous-function-no-parens-types/good_13/expected.json new file mode 100644 index 0000000000..ad9ad5c630 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/anonymous-function-no-parens-types/good_13/expected.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "predicate": null, + "returnType": { + "type": "TypeAnnotation", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "typeAnnotation": { + "type": "ExistsTypeAnnotation", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} diff --git a/packages/babylon/test/fixtures/flow/classes/good_01/actual.js b/packages/babylon/test/fixtures/flow/classes/good_01/actual.js new file mode 100644 index 0000000000..aabb328bdf --- /dev/null +++ b/packages/babylon/test/fixtures/flow/classes/good_01/actual.js @@ -0,0 +1 @@ +class C { field:*=null } diff --git a/packages/babylon/test/fixtures/flow/classes/good_01/expected.json b/packages/babylon/test/fixtures/flow/classes/good_01/expected.json new file mode 100644 index 0000000000..85cf0ca075 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/classes/good_01/expected.json @@ -0,0 +1,164 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "C" + }, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 10, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "field" + }, + "name": "field" + }, + "computed": false, + "variance": null, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "typeAnnotation": { + "type": "ExistsTypeAnnotation", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + } + }, + "value": { + "type": "NullLiteral", + "start": 18, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 22 + } + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/classes/good_01/options.json b/packages/babylon/test/fixtures/flow/classes/good_01/options.json new file mode 100644 index 0000000000..65c79d81c7 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/classes/good_01/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["flow", "classProperties"] +}