From 950593d970bf50397be45bbc213b7374c4d98ad0 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Tue, 11 Jun 2019 23:37:47 +0800 Subject: [PATCH 1/6] flow - allow type parameter defaults in function declarations --- packages/babel-parser/src/plugins/flow.js | 20 +- .../default-invalid-1/input.js | 4 +- .../default-invalid-1/options.json | 4 +- .../default-invalid-2/input.js | 2 +- .../default-invalid-2/options.json | 4 +- .../default-invalid-3/input.js | 2 +- .../default-invalid-3/options.json | 4 +- .../default-invalid-4/input.js | 3 - .../default-invalid-4/options.json | 3 - .../default-invalid-5/input.js | 1 - .../default-invalid-5/options.json | 3 - .../default/input.js | 10 + .../default/output.json | 887 +++++++++++++++++- 13 files changed, 907 insertions(+), 40 deletions(-) delete mode 100644 packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/input.js delete mode 100644 packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/options.json delete mode 100644 packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/input.js delete mode 100644 packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/options.json diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index d6f3e06a906f..c6f33ba3a894 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -798,9 +798,7 @@ export default (superClass: Class): Class => node.typeParameters = null; if (this.isRelational("<")) { - node.typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + node.typeParameters = this.flowParseTypeParameterDeclaration(); } this.expect(tt.parenL); @@ -1287,9 +1285,7 @@ export default (superClass: Class): Class => case tt.relational: if (this.state.value === "<") { - node.typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + node.typeParameters = this.flowParseTypeParameterDeclaration(); this.expect(tt.parenL); tmp = this.flowParseFunctionTypeParams(); node.params = tmp.params; @@ -2092,9 +2088,7 @@ export default (superClass: Class): Class => } delete (method: $FlowFixMe).variance; if (this.isRelational("<")) { - method.typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + method.typeParameters = this.flowParseTypeParameterDeclaration(); } super.pushClassMethod( @@ -2176,9 +2170,7 @@ export default (superClass: Class): Class => // method shorthand if (this.isRelational("<")) { - typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + typeParameters = this.flowParseTypeParameterDeclaration(); if (!this.match(tt.parenL)) this.unexpected(); } @@ -2386,9 +2378,7 @@ export default (superClass: Class): Class => // $FlowFixMe const kind = node.kind; if (kind !== "get" && kind !== "set" && this.isRelational("<")) { - node.typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + node.typeParameters = this.flowParseTypeParameterDeclaration(); } super.parseFunctionParams(node, allowModifiers); } diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js index e85753f1bf25..018ada1c550e 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js @@ -1,3 +1 @@ -(class A { - foo() {} -}); +declare function foo() {} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json index ef2b7c682fba..161afd296dc4 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (2:8)" -} + "throws": "Unexpected token, expected \":\" (1:35)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js index 088051643fa2..646522dea3d9 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js @@ -1 +1 @@ -({ foo() {} }); +var x: Array diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json index 2a28555f76db..fbfad415eebf 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" -} + "throws": "Unexpected token, expected \",\" (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js index 742685c460ec..2b40a1ba03fc 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js @@ -1 +1 @@ -declare class A { foo(): void } +class A extends B {} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json index fa579aa83145..6f017e5a5919 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:24)" -} + "throws": "Unexpected token, expected \",\" (1:20)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/input.js deleted file mode 100644 index a35315333a49..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/input.js +++ /dev/null @@ -1,3 +0,0 @@ -class A { - foo() {} -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/options.json deleted file mode 100644 index ef2b7c682fba..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:8)" -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/input.js deleted file mode 100644 index 3223246d3979..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/input.js +++ /dev/null @@ -1 +0,0 @@ -function foo() {} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/options.json deleted file mode 100644 index 98d712379010..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:15)" -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/input.js index c434fce2a03d..4feffe1038d6 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/input.js @@ -20,3 +20,13 @@ interface A19 {} interface A20 {} interface A21 {} type A22 = T +function A26() {} +;({ A28() {} }); +class A29 { + foo() {} +} +;(class A30 { + foo() {} +}); +declare class A31 { foo(): void } +() => 123; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json index e97815d406f0..8b2db5858c66 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 803, + "end": 1009, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 22, + "line": 32, "column": 22 } }, "program": { "type": "Program", "start": 0, - "end": 803, + "end": 1009, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 22, + "line": 32, "column": 22 } }, @@ -3339,6 +3339,885 @@ "name": "T" } } + }, + { + "type": "FunctionDeclaration", + "start": 804, + "end": 833, + "loc": { + "start": { + "line": 23, + "column": 0 + }, + "end": { + "line": 23, + "column": 29 + } + }, + "id": { + "type": "Identifier", + "start": 813, + "end": 816, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 12 + }, + "identifierName": "A26" + }, + "name": "A26" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 816, + "end": 828, + "loc": { + "start": { + "line": 23, + "column": 12 + }, + "end": { + "line": 23, + "column": 24 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 817, + "end": 827, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 23 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 821, + "end": 827, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 23 + } + } + } + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start": 831, + "end": 833, + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 23, + "column": 29 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "EmptyStatement", + "start": 834, + "end": 835, + "loc": { + "start": { + "line": 24, + "column": 0 + }, + "end": { + "line": 24, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "start": 835, + "end": 862, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 28 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 836, + "end": 860, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 26 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 838, + "end": 858, + "loc": { + "start": { + "line": 24, + "column": 4 + }, + "end": { + "line": 24, + "column": 24 + } + }, + "method": true, + "key": { + "type": "Identifier", + "start": 838, + "end": 841, + "loc": { + "start": { + "line": 24, + "column": 4 + }, + "end": { + "line": 24, + "column": 7 + }, + "identifierName": "A28" + }, + "name": "A28" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 856, + "end": 858, + "loc": { + "start": { + "line": 24, + "column": 22 + }, + "end": { + "line": 24, + "column": 24 + } + }, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 841, + "end": 853, + "loc": { + "start": { + "line": 24, + "column": 7 + }, + "end": { + "line": 24, + "column": 19 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 842, + "end": 852, + "loc": { + "start": { + "line": 24, + "column": 8 + }, + "end": { + "line": 24, + "column": 18 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 846, + "end": 852, + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 18 + } + } + } + } + ] + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 835 + } + } + }, + { + "type": "ClassDeclaration", + "start": 863, + "end": 899, + "loc": { + "start": { + "line": 25, + "column": 0 + }, + "end": { + "line": 27, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 869, + "end": 872, + "loc": { + "start": { + "line": 25, + "column": 6 + }, + "end": { + "line": 25, + "column": 9 + }, + "identifierName": "A29" + }, + "name": "A29" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 873, + "end": 899, + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 27, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 877, + "end": 897, + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 22 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 877, + "end": 880, + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 880, + "end": 892, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 17 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 881, + "end": 891, + "loc": { + "start": { + "line": 26, + "column": 6 + }, + "end": { + "line": 26, + "column": 16 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 885, + "end": 891, + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 16 + } + } + } + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 895, + "end": 897, + "loc": { + "start": { + "line": 26, + "column": 20 + }, + "end": { + "line": 26, + "column": 22 + } + }, + "body": [], + "directives": [] + } + } + ] + } + }, + { + "type": "EmptyStatement", + "start": 900, + "end": 901, + "loc": { + "start": { + "line": 28, + "column": 0 + }, + "end": { + "line": 28, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "start": 901, + "end": 940, + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 30, + "column": 3 + } + }, + "expression": { + "type": "ClassExpression", + "start": 902, + "end": 938, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 30, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 908, + "end": 911, + "loc": { + "start": { + "line": 28, + "column": 8 + }, + "end": { + "line": 28, + "column": 11 + }, + "identifierName": "A30" + }, + "name": "A30" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 912, + "end": 938, + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 30, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 916, + "end": 936, + "loc": { + "start": { + "line": 29, + "column": 2 + }, + "end": { + "line": 29, + "column": 22 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 916, + "end": 919, + "loc": { + "start": { + "line": 29, + "column": 2 + }, + "end": { + "line": 29, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 919, + "end": 931, + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 17 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 920, + "end": 930, + "loc": { + "start": { + "line": 29, + "column": 6 + }, + "end": { + "line": 29, + "column": 16 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 924, + "end": 930, + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 16 + } + } + } + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 934, + "end": 936, + "loc": { + "start": { + "line": 29, + "column": 20 + }, + "end": { + "line": 29, + "column": 22 + } + }, + "body": [], + "directives": [] + } + } + ] + }, + "extra": { + "parenthesized": true, + "parenStart": 901 + } + } + }, + { + "type": "DeclareClass", + "start": 941, + "end": 986, + "loc": { + "start": { + "line": 31, + "column": 0 + }, + "end": { + "line": 31, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 955, + "end": 958, + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 31, + "column": 17 + }, + "identifierName": "A31" + }, + "name": "A31" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 959, + "end": 986, + "loc": { + "start": { + "line": 31, + "column": 18 + }, + "end": { + "line": 31, + "column": 45 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 961, + "end": 984, + "loc": { + "start": { + "line": 31, + "column": 20 + }, + "end": { + "line": 31, + "column": 43 + } + }, + "key": { + "type": "Identifier", + "start": 961, + "end": 964, + "loc": { + "start": { + "line": 31, + "column": 20 + }, + "end": { + "line": 31, + "column": 23 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start": 961, + "end": 984, + "loc": { + "start": { + "line": 31, + "column": 20 + }, + "end": { + "line": 31, + "column": 43 + } + }, + "params": [], + "rest": null, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 964, + "end": 976, + "loc": { + "start": { + "line": 31, + "column": 23 + }, + "end": { + "line": 31, + "column": 35 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 965, + "end": 975, + "loc": { + "start": { + "line": 31, + "column": 24 + }, + "end": { + "line": 31, + "column": 34 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 969, + "end": 975, + "loc": { + "start": { + "line": 31, + "column": 28 + }, + "end": { + "line": 31, + "column": 34 + } + } + } + } + ] + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 980, + "end": 984, + "loc": { + "start": { + "line": 31, + "column": 39 + }, + "end": { + "line": 31, + "column": 43 + } + } + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false + } + }, + { + "type": "ExpressionStatement", + "start": 987, + "end": 1009, + "loc": { + "start": { + "line": 32, + "column": 0 + }, + "end": { + "line": 32, + "column": 22 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 987, + "end": 1008, + "loc": { + "start": { + "line": 32, + "column": 0 + }, + "end": { + "line": 32, + "column": 21 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "NumericLiteral", + "start": 1005, + "end": 1008, + "loc": { + "start": { + "line": 32, + "column": 18 + }, + "end": { + "line": 32, + "column": 21 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 987, + "end": 999, + "loc": { + "start": { + "line": 32, + "column": 0 + }, + "end": { + "line": 32, + "column": 12 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 988, + "end": 998, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 32, + "column": 11 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 992, + "end": 998, + "loc": { + "start": { + "line": 32, + "column": 5 + }, + "end": { + "line": 32, + "column": 11 + } + } + } + } + ] + } + } } ], "directives": [] From ba1b9f7f66e8162b41cb6c00bf39c1a97fe261cb Mon Sep 17 00:00:00 2001 From: Li Hau Tan Date: Wed, 12 Jun 2019 11:45:44 +0800 Subject: [PATCH 2/6] fix flow test --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dc858ab2ee46..5fa5cb0cfdbf 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ MAKEFLAGS = -j1 -FLOW_COMMIT = 2ac56861e3ceff9ca406ae586fbafb3480c6c0b7 +FLOW_COMMIT = 09669846b7a7ca5a6c23c12d56bb3bebdafd67e9 TEST262_COMMIT = de567d3aa5de4eaa11e00131d26b9fe77997dfb0 # Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967 From 5a4bc721837957b8102d161aa54bc0e8db15ed52 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Wed, 12 Jun 2019 22:09:15 +0800 Subject: [PATCH 3/6] add intern_comments option --- scripts/tests/flow/run_babel_parser_flow_tests.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/tests/flow/run_babel_parser_flow_tests.js b/scripts/tests/flow/run_babel_parser_flow_tests.js index 0b75218968fa..f772ca0c82d0 100644 --- a/scripts/tests/flow/run_babel_parser_flow_tests.js +++ b/scripts/tests/flow/run_babel_parser_flow_tests.js @@ -127,6 +127,7 @@ const flowOptionsMapping = { esproposal_nullish_coalescing: "nullishCoalescingOperator", esproposal_optional_chaining: "optionalChaining", types: "flowComments", + intern_comments: false, }; const summary = { @@ -169,10 +170,12 @@ tests.forEach(section => { } return; } - if (!flowOptionsMapping[option]) { + if (!(option in flowOptionsMapping)) { throw new Error("Parser options not mapped " + option); } - babelParserOptions.plugins.push(flowOptionsMapping[option]); + if (flowOptionsMapping[option]) { + babelParserOptions.plugins.push(flowOptionsMapping[option]); + } }); } From 445cd2aaa6d2a8766b877314027a9cfdab4b279c Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 13 Jun 2019 23:13:23 +0800 Subject: [PATCH 4/6] fix flow parser test --- scripts/tests/flow/flow_tests_whitelist.txt | 19 ++++++++++++++----- .../tests/flow/run_babel_parser_flow_tests.js | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/tests/flow/flow_tests_whitelist.txt b/scripts/tests/flow/flow_tests_whitelist.txt index 60ee5e0e6e98..81758912b0f4 100644 --- a/scripts/tests/flow/flow_tests_whitelist.txt +++ b/scripts/tests/flow/flow_tests_whitelist.txt @@ -9,24 +9,33 @@ # Entries should be removed incrementally as the babel parser is improved. JSX_invalid/migrated_0000.js +arrow_function/tuple_return_type.js arrow_function_invalid/migrated_0002.js async_await/migrated_0007.js async_await/migrated_0020.js async_await/migrated_0024.js async_await/migrated_0027.js async_generators/migrated_0007.js -class_properties/migrated_0000.js -class_properties/migrated_0005.js -class_properties/migrated_0011.js -class_properties/migrated_0016.js class_properties/migrated_0021.js class_properties/migrated_0026.js decorators/migrated_0003.js decorators/migrated_0007.js private_class_properties/multiple.js private_class_properties/super.js +private_class_properties/getter_and_field.js +private_class_properties/getter_duplicate.js +private_class_properties/setter_and_field.js +private_class_properties/setter_duplicate.js types/member/reserved_words.js -types/parameter_defaults/migrated_0032.js +types/bigint_literal/migrated_0000.js +types/bigint_literal/migrated_0002.js +types/bigint_literal/migrated_0003.js +types/bigint_literal/migrated_0004.js +types/bigint_literal/migrated_0005.js +types/bigint_literal/migrated_0006.js +types/bigint_literal/migrated_0007.js +types/bigint_literal/migrated_0008.js +types/bigint_literal/migrated_0009.js class_method_kinds/polymorphic_getter.js numbers/underscored_bin.js numbers/underscored_float.js diff --git a/scripts/tests/flow/run_babel_parser_flow_tests.js b/scripts/tests/flow/run_babel_parser_flow_tests.js index f772ca0c82d0..ffad821ba1d5 100644 --- a/scripts/tests/flow/run_babel_parser_flow_tests.js +++ b/scripts/tests/flow/run_babel_parser_flow_tests.js @@ -113,7 +113,10 @@ const options = { ["flow", { all: true }], "flowComments", "jsx", + "classProperties", "classPrivateProperties", + "classPrivateMethods", + "bigInt", ], sourceType: "module", ranges: true, From cdbed6d57f0033a692776cb19fb39eb17ac9ec6f Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 14 Jun 2019 13:28:18 +0800 Subject: [PATCH 5/6] remove allowdefault from flowParseTypeParameterDeclaration --- packages/babel-parser/src/plugins/flow.js | 28 ++++------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index c6f33ba3a894..e9b4cc32c37f 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -588,16 +588,7 @@ export default (superClass: Class): Class => // Type annotations - flowParseTypeParameter( - allowDefault?: boolean = true, - requireDefault?: boolean = false, - ): N.TypeParameter { - if (!allowDefault && requireDefault) { - throw new Error( - "Cannot disallow a default value (`allowDefault`) while also requiring it (`requireDefault`).", - ); - } - + flowParseTypeParameter(requireDefault?: boolean = false): N.TypeParameter { const nodeStart = this.state.start; const node = this.startNode(); @@ -610,12 +601,8 @@ export default (superClass: Class): Class => node.bound = ident.typeAnnotation; if (this.match(tt.eq)) { - if (allowDefault) { - this.eat(tt.eq); - node.default = this.flowParseType(); - } else { - this.unexpected(); - } + this.eat(tt.eq); + node.default = this.flowParseType(); } else { if (requireDefault) { this.unexpected( @@ -629,9 +616,7 @@ export default (superClass: Class): Class => return this.finishNode(node, "TypeParameter"); } - flowParseTypeParameterDeclaration( - allowDefault?: boolean = true, - ): N.TypeParameterDeclaration { + flowParseTypeParameterDeclaration(): N.TypeParameterDeclaration { const oldInType = this.state.inType; const node = this.startNode(); node.params = []; @@ -648,10 +633,7 @@ export default (superClass: Class): Class => let defaultRequired = false; do { - const typeParameter = this.flowParseTypeParameter( - allowDefault, - defaultRequired, - ); + const typeParameter = this.flowParseTypeParameter(defaultRequired); node.params.push(typeParameter); From 4141c485774c74e00c0dfa833aa4b5c9b1299da0 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 15 Jun 2019 10:50:25 +0800 Subject: [PATCH 6/6] rename test cases --- .../{default-invalid-3 => default-invalid-class-extends}/input.js | 0 .../options.json | 0 .../{default-invalid-1 => default-invalid-declare-func}/input.js | 0 .../options.json | 0 .../{default-invalid-2 => default-invalid-var-type}/input.js | 0 .../{default-invalid-2 => default-invalid-var-type}/options.json | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename packages/babel-parser/test/fixtures/flow/type-parameter-declaration/{default-invalid-3 => default-invalid-class-extends}/input.js (100%) rename packages/babel-parser/test/fixtures/flow/type-parameter-declaration/{default-invalid-3 => default-invalid-class-extends}/options.json (100%) rename packages/babel-parser/test/fixtures/flow/type-parameter-declaration/{default-invalid-1 => default-invalid-declare-func}/input.js (100%) rename packages/babel-parser/test/fixtures/flow/type-parameter-declaration/{default-invalid-1 => default-invalid-declare-func}/options.json (100%) rename packages/babel-parser/test/fixtures/flow/type-parameter-declaration/{default-invalid-2 => default-invalid-var-type}/input.js (100%) rename packages/babel-parser/test/fixtures/flow/type-parameter-declaration/{default-invalid-2 => default-invalid-var-type}/options.json (100%) diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js rename to packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/input.js diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json rename to packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/options.json diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js rename to packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/input.js diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json rename to packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/options.json diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js rename to packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/input.js diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json rename to packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/options.json