diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/class/input.js b/packages/babel-parser/test/fixtures/flow/multiple-declarations/class/input.js new file mode 100644 index 000000000000..fa5ff14cb9be --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/class/input.js @@ -0,0 +1,2 @@ +declare class C1 {} +class C1 {} diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/class/options.json b/packages/babel-parser/test/fixtures/flow/multiple-declarations/class/options.json new file mode 100644 index 000000000000..06ad6ded6032 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/class/options.json @@ -0,0 +1,8 @@ +{ + "sourceType": "module", + "plugins": [ + "jsx", + "flow" + ], + "throws": "Identifier 'C1' has already been declared (2:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-class/input.js b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-class/input.js new file mode 100644 index 000000000000..d9470b0fd596 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-class/input.js @@ -0,0 +1,6 @@ +declare class C1{} +declare class C1{} + +declare module M1 { + declare class C1 {} +} diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-class/output.json b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-class/output.json new file mode 100644 index 000000000000..149ca744eb22 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-class/output.json @@ -0,0 +1,253 @@ +{ + "type": "File", + "start": 0, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareClass", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "C1" + }, + "name": "C1" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "internalSlots": [], + "exact": false + } + }, + { + "type": "DeclareClass", + "start": 19, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "C1" + }, + "name": "C1" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 35, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "internalSlots": [], + "exact": false + } + }, + { + "type": "DeclareModule", + "start": 39, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 54, + "end": 56, + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 17 + }, + "identifierName": "M1" + }, + "name": "M1" + }, + "body": { + "type": "BlockStatement", + "start": 57, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [ + { + "type": "DeclareClass", + "start": 61, + "end": 80, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 75, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 18 + }, + "identifierName": "C1" + }, + "name": "C1" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 78, + "end": 80, + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "internalSlots": [], + "exact": false + } + } + ] + }, + "kind": "CommonJS" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/input.js b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/input.js new file mode 100644 index 000000000000..fb98eb970189 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/input.js @@ -0,0 +1,3 @@ +declare function F1(): void +declare function F1(): void +function F1() {} diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/output.json b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/output.json new file mode 100644 index 000000000000..ad507ae14079 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/output.json @@ -0,0 +1,249 @@ +{ + "type": "File", + "start": 0, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareFunction", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "F1" + }, + "name": "F1", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 19, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start": 19, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "typeParameters": null, + "params": [], + "rest": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 27 + } + } + } + } + } + }, + "predicate": null + }, + { + "type": "DeclareFunction", + "start": 28, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 45, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 27 + }, + "identifierName": "F1" + }, + "name": "F1", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 47, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start": 47, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "typeParameters": null, + "params": [], + "rest": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 51, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 27 + } + } + } + } + } + }, + "predicate": null + }, + { + "type": "FunctionDeclaration", + "start": 56, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 65, + "end": 67, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "F1" + }, + "name": "F1" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 70, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-var/input.js b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-var/input.js new file mode 100644 index 000000000000..21b4f11b204c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-var/input.js @@ -0,0 +1,3 @@ +declare var V1; +declare var V1; +var V1; diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-var/output.json b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-var/output.json new file mode 100644 index 000000000000..b96badb7fe54 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-var/output.json @@ -0,0 +1,150 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareVariable", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "V1" + }, + "name": "V1" + } + }, + { + "type": "DeclareVariable", + "start": 16, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "V1" + }, + "name": "V1" + } + }, + { + "type": "VariableDeclaration", + "start": 32, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "id": { + "type": "Identifier", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + }, + "identifierName": "V1" + }, + "name": "V1" + }, + "init": null + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/interface/input.js b/packages/babel-parser/test/fixtures/flow/multiple-declarations/interface/input.js new file mode 100644 index 000000000000..bca93948ce50 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/interface/input.js @@ -0,0 +1,2 @@ +interface I {}; +interface I {}; diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/interface/options.json b/packages/babel-parser/test/fixtures/flow/multiple-declarations/interface/options.json new file mode 100644 index 000000000000..5672ce1b6444 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/interface/options.json @@ -0,0 +1,8 @@ +{ + "sourceType": "module", + "plugins": [ + "jsx", + "flow" + ], + "throws": "Identifier 'I' has already been declared (2:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/type/input.js b/packages/babel-parser/test/fixtures/flow/multiple-declarations/type/input.js new file mode 100644 index 000000000000..273aa1c7176c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/type/input.js @@ -0,0 +1,2 @@ +type T1 = string; +type T1 = number; diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/type/options.json b/packages/babel-parser/test/fixtures/flow/multiple-declarations/type/options.json new file mode 100644 index 000000000000..946261f4e872 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/type/options.json @@ -0,0 +1,8 @@ +{ + "sourceType": "module", + "plugins": [ + "jsx", + "flow" + ], + "throws": "Identifier 'T1' has already been declared (2:5)" +} \ No newline at end of file