Flow enums parsing (#10344)
* Flow enums parsing * Parse exporting enums * Enums parsing remove lookahead, other improvements * Enums: add EnumBody and EnumMember aliases, change boolean members to use BooleaLiteral value * Fix enum member init flow type, now that boolean members have a BooleanLiteral value * Flow enums: use contextual utils, change members length checks to use logic operators, remove reserved word logic modification * Flow enums: remove unnecessary code in generator, fix error message
This commit is contained in:
committed by
Nicolò Ribaudo
parent
4b3a19ea9f
commit
ec3345bb57
4
packages/babel-parser/test/fixtures/flow/enum-declaration/boolean-explicit/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/boolean-explicit/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E of boolean {
|
||||
A = true,
|
||||
B = false,
|
||||
}
|
||||
181
packages/babel-parser/test/fixtures/flow/enum-declaration/boolean-explicit/output.json
vendored
Normal file
181
packages/babel-parser/test/fixtures/flow/enum-declaration/boolean-explicit/output.json
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 46,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 46,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 46,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumBooleanBody",
|
||||
"start": 22,
|
||||
"end": 44,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"explicitType": true,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumBooleanMember",
|
||||
"start": 22,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 22,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"init": {
|
||||
"type": "BooleanLiteral",
|
||||
"start": 26,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"value": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumBooleanMember",
|
||||
"start": 34,
|
||||
"end": 43,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 34,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"init": {
|
||||
"type": "BooleanLiteral",
|
||||
"start": 38,
|
||||
"end": 43,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"value": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/boolean-implicit/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/boolean-implicit/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
A = true,
|
||||
B = false,
|
||||
}
|
||||
181
packages/babel-parser/test/fixtures/flow/enum-declaration/boolean-implicit/output.json
vendored
Normal file
181
packages/babel-parser/test/fixtures/flow/enum-declaration/boolean-implicit/output.json
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumBooleanBody",
|
||||
"start": 11,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumBooleanMember",
|
||||
"start": 11,
|
||||
"end": 19,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 11,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"init": {
|
||||
"type": "BooleanLiteral",
|
||||
"start": 15,
|
||||
"end": 19,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"value": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumBooleanMember",
|
||||
"start": 23,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 23,
|
||||
"end": 24,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"init": {
|
||||
"type": "BooleanLiteral",
|
||||
"start": 27,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"value": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of boolean {
|
||||
A,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Boolean enum members need to be initialized. Use either `A = true,` or `A = false,` in enum `E`. (2:2)"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
A,
|
||||
B = true,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Boolean enum members need to be initialized. Use either `A = true,` or `A = false,` in enum `E`. (2:2)"
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/duplicate-member-name/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/duplicate-member-name/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
A,
|
||||
A,
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/duplicate-member-name/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/duplicate-member-name/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum member names need to be unique, but the name `A` has already been used before in enum `E`. (3:2)"
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/flow/enum-declaration/empty/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/flow/enum-declaration/empty/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
enum E { }
|
||||
84
packages/babel-parser/test/fixtures/flow/enum-declaration/empty/output.json
vendored
Normal file
84
packages/babel-parser/test/fixtures/flow/enum-declaration/empty/output.json
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 10,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 10,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 10,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 9,
|
||||
"end": 8,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/flow/enum-declaration/end-of-file/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/flow/enum-declaration/end-of-file/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
enum
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/end-of-file/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/end-of-file/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Unexpected token (1:4)"
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/flow/enum-declaration/enum-name/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/flow/enum-declaration/enum-name/input.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
enum type {
|
||||
}
|
||||
84
packages/babel-parser/test/fixtures/flow/enum-declaration/enum-name/output.json
vendored
Normal file
84
packages/babel-parser/test/fixtures/flow/enum-declaration/enum-name/output.json
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 9,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"identifierName": "type"
|
||||
},
|
||||
"name": "type"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 12,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/flow/enum-declaration/export/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/flow/enum-declaration/export/input.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export enum A {}
|
||||
|
||||
export default enum B {}
|
||||
11
packages/babel-parser/test/fixtures/flow/enum-declaration/export/options.json
vendored
Normal file
11
packages/babel-parser/test/fixtures/flow/enum-declaration/export/options.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"plugins": [
|
||||
[
|
||||
"flow",
|
||||
{
|
||||
"enums": true
|
||||
}
|
||||
]
|
||||
],
|
||||
"sourceType": "module"
|
||||
}
|
||||
166
packages/babel-parser/test/fixtures/flow/enum-declaration/export/output.json
vendored
Normal file
166
packages/babel-parser/test/fixtures/flow/enum-declaration/export/output.json
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 42,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 24
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 42,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 24
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start": 0,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
"exportKind": "value",
|
||||
"declaration": {
|
||||
"type": "EnumDeclaration",
|
||||
"start": 7,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 12,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 13
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 15,
|
||||
"end": 15,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start": 18,
|
||||
"end": 42,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 24
|
||||
}
|
||||
},
|
||||
"declaration": {
|
||||
"type": "EnumDeclaration",
|
||||
"start": 33,
|
||||
"end": 42,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 24
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 38,
|
||||
"end": 39,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 20
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 21
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 41,
|
||||
"end": 41,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 23
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
enum E {
|
||||
A,
|
||||
B,
|
||||
C = 3,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers. (1:5)"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
A = 1,
|
||||
B = true,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers. (1:5)"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
enum E of [] {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Supplied enum type is not valid. Use one of `boolean`, `number`, `string`, or `symbol` in enum `E`. (1:10)"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
enum E of xxx {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum type `xxx` is not valid. Use one of `boolean`, `number`, `string`, or `symbol` in enum `E`. (1:10)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of string {
|
||||
A = true,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has type `string`, so the initializer of `A` needs to be a string literal. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of boolean {
|
||||
A = 1 + 2,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has type `boolean`, so the initializer of `A` needs to be a boolean literal. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of number {
|
||||
A = 1 + 2,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has type `number`, so the initializer of `A` needs to be a number literal. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of string {
|
||||
A = 1 + 2,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has type `string`, so the initializer of `A` needs to be a string literal. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of symbol {
|
||||
A = 1 + 2,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Symbol enum members cannot be initialized. Use `A,` in enum `E`. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E {
|
||||
A = 1 + 2,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "The enum member initializer for `A` needs to be a literal (either a boolean, number, or string) in enum `E`. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of symbol {
|
||||
A = 1,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Symbol enum members cannot be initialized. Use `A,` in enum `E`. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of boolean {
|
||||
A = 1,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has type `boolean`, so the initializer of `A` needs to be a boolean literal. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of string {
|
||||
A = 1,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has type `string`, so the initializer of `A` needs to be a string literal. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E {
|
||||
A = (1),
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "The enum member initializer for `A` needs to be a literal (either a boolean, number, or string) in enum `E`. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of boolean {
|
||||
A = "hi",
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has type `boolean`, so the initializer of `A` needs to be a boolean literal. (2:6)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of number {
|
||||
A = "hi",
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum `E` has type `number`, so the initializer of `A` needs to be a number literal. (2:6)"
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/invalid-member-name/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/invalid-member-name/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
foo,
|
||||
bar,
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/invalid-member-name/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/invalid-member-name/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Enum member names cannot start with lowercase 'a' through 'z'. Instead of using `foo`, consider using `Foo`, in enum `E`. (2:2)"
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/flow/enum-declaration/no-trailing-comma/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/flow/enum-declaration/no-trailing-comma/input.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
enum E {
|
||||
A
|
||||
}
|
||||
117
packages/babel-parser/test/fixtures/flow/enum-declaration/no-trailing-comma/output.json
vendored
Normal file
117
packages/babel-parser/test/fixtures/flow/enum-declaration/no-trailing-comma/output.json
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 14,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 14,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 14,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 11,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumDefaultedMember",
|
||||
"start": 11,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 11,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/number-explicit/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/number-explicit/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E of number {
|
||||
A = 1,
|
||||
B = 2,
|
||||
}
|
||||
189
packages/babel-parser/test/fixtures/flow/enum-declaration/number-explicit/output.json
vendored
Normal file
189
packages/babel-parser/test/fixtures/flow/enum-declaration/number-explicit/output.json
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 38,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 38,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 38,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumNumberBody",
|
||||
"start": 21,
|
||||
"end": 36,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 8
|
||||
}
|
||||
},
|
||||
"explicitType": true,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumNumberMember",
|
||||
"start": 21,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 21,
|
||||
"end": 22,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"init": {
|
||||
"type": "NumericLiteral",
|
||||
"start": 25,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": 1,
|
||||
"raw": "1"
|
||||
},
|
||||
"value": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumNumberMember",
|
||||
"start": 30,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 30,
|
||||
"end": 31,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"init": {
|
||||
"type": "NumericLiteral",
|
||||
"start": 34,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": 2,
|
||||
"raw": "2"
|
||||
},
|
||||
"value": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/number-implicit/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/number-implicit/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
A = 1,
|
||||
B = 2,
|
||||
}
|
||||
189
packages/babel-parser/test/fixtures/flow/enum-declaration/number-implicit/output.json
vendored
Normal file
189
packages/babel-parser/test/fixtures/flow/enum-declaration/number-implicit/output.json
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumNumberBody",
|
||||
"start": 11,
|
||||
"end": 26,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 8
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumNumberMember",
|
||||
"start": 11,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 11,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"init": {
|
||||
"type": "NumericLiteral",
|
||||
"start": 15,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": 1,
|
||||
"raw": "1"
|
||||
},
|
||||
"value": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumNumberMember",
|
||||
"start": 20,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 20,
|
||||
"end": 21,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"init": {
|
||||
"type": "NumericLiteral",
|
||||
"start": 24,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": 2,
|
||||
"raw": "2"
|
||||
},
|
||||
"value": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
enum E of number {
|
||||
A,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Number enum members need to be initialized, e.g. `A = 1` in enum `E`. (2:2)"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
A,
|
||||
B = 1,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Number enum members need to be initialized, e.g. `A = 1` in enum `E`. (2:2)"
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/flow/enum-declaration/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/flow/enum-declaration/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]]
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/flow/enum-declaration/reserved-word-enum-name/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/flow/enum-declaration/reserved-word-enum-name/input.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
enum class {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "Unexpected keyword 'class' (1:5)"
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/string-explicit-defaulted/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/string-explicit-defaulted/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E of string {
|
||||
A,
|
||||
B,
|
||||
}
|
||||
149
packages/babel-parser/test/fixtures/flow/enum-declaration/string-explicit-defaulted/output.json
vendored
Normal file
149
packages/babel-parser/test/fixtures/flow/enum-declaration/string-explicit-defaulted/output.json
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 21,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 4
|
||||
}
|
||||
},
|
||||
"explicitType": true,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumDefaultedMember",
|
||||
"start": 21,
|
||||
"end": 22,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 21,
|
||||
"end": 22,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumDefaultedMember",
|
||||
"start": 26,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 26,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum E of string {
|
||||
A = "a",
|
||||
B = "b",
|
||||
}
|
||||
189
packages/babel-parser/test/fixtures/flow/enum-declaration/string-explicit-initialized/output.json
vendored
Normal file
189
packages/babel-parser/test/fixtures/flow/enum-declaration/string-explicit-initialized/output.json
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 42,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 42,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 42,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 21,
|
||||
"end": 40,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"explicitType": true,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumStringMember",
|
||||
"start": 21,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 21,
|
||||
"end": 22,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"init": {
|
||||
"type": "StringLiteral",
|
||||
"start": 25,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": "a",
|
||||
"raw": "\"a\""
|
||||
},
|
||||
"value": "a"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumStringMember",
|
||||
"start": 32,
|
||||
"end": 39,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 32,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"init": {
|
||||
"type": "StringLiteral",
|
||||
"start": 36,
|
||||
"end": 39,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": "b",
|
||||
"raw": "\"b\""
|
||||
},
|
||||
"value": "b"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/string-implicit-defaulted/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/string-implicit-defaulted/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
A,
|
||||
B,
|
||||
}
|
||||
149
packages/babel-parser/test/fixtures/flow/enum-declaration/string-implicit-defaulted/output.json
vendored
Normal file
149
packages/babel-parser/test/fixtures/flow/enum-declaration/string-implicit-defaulted/output.json
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 20,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 20,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 20,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 11,
|
||||
"end": 18,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 4
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumDefaultedMember",
|
||||
"start": 11,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 11,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumDefaultedMember",
|
||||
"start": 16,
|
||||
"end": 17,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 16,
|
||||
"end": 17,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
enum E {
|
||||
A = "a",
|
||||
B = "b",
|
||||
}
|
||||
189
packages/babel-parser/test/fixtures/flow/enum-declaration/string-implicit-initialized/output.json
vendored
Normal file
189
packages/babel-parser/test/fixtures/flow/enum-declaration/string-implicit-initialized/output.json
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 32,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumStringBody",
|
||||
"start": 11,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 10
|
||||
}
|
||||
},
|
||||
"explicitType": false,
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumStringMember",
|
||||
"start": 11,
|
||||
"end": 18,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 11,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"init": {
|
||||
"type": "StringLiteral",
|
||||
"start": 15,
|
||||
"end": 18,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": "a",
|
||||
"raw": "\"a\""
|
||||
},
|
||||
"value": "a"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumStringMember",
|
||||
"start": 22,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 22,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"init": {
|
||||
"type": "StringLiteral",
|
||||
"start": 26,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": "b",
|
||||
"raw": "\"b\""
|
||||
},
|
||||
"value": "b"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
enum E of string {
|
||||
A = "a",
|
||||
B,
|
||||
C,
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "String enum members need to consistently either all use initializers, or use no initializers, in enum `E`. (2:2)"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
enum E of string {
|
||||
A,
|
||||
B = "b",
|
||||
C = "c",
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["flow", { "enums": true }]],
|
||||
"throws": "String enum members need to consistently either all use initializers, or use no initializers, in enum `E`. (2:2)"
|
||||
}
|
||||
4
packages/babel-parser/test/fixtures/flow/enum-declaration/symbol/input.js
vendored
Normal file
4
packages/babel-parser/test/fixtures/flow/enum-declaration/symbol/input.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
enum E of symbol {
|
||||
A,
|
||||
B,
|
||||
}
|
||||
148
packages/babel-parser/test/fixtures/flow/enum-declaration/symbol/output.json
vendored
Normal file
148
packages/babel-parser/test/fixtures/flow/enum-declaration/symbol/output.json
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "EnumDeclaration",
|
||||
"start": 0,
|
||||
"end": 30,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 5,
|
||||
"end": 6,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"identifierName": "E"
|
||||
},
|
||||
"name": "E"
|
||||
},
|
||||
"body": {
|
||||
"type": "EnumSymbolBody",
|
||||
"start": 21,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 4
|
||||
}
|
||||
},
|
||||
"members": [
|
||||
{
|
||||
"type": "EnumDefaultedMember",
|
||||
"start": 21,
|
||||
"end": 22,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 21,
|
||||
"end": 22,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "EnumDefaultedMember",
|
||||
"start": 26,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 26,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user