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:
George Zahariev
2019-10-29 14:55:12 -07:00
committed by Nicolò Ribaudo
parent 4b3a19ea9f
commit ec3345bb57
92 changed files with 3213 additions and 5 deletions

View File

@@ -0,0 +1,4 @@
enum E of boolean {
A = true,
B = false,
}

View 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": []
}
}

View File

@@ -0,0 +1,4 @@
enum E {
A = true,
B = false,
}

View 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": []
}
}

View File

@@ -0,0 +1,3 @@
enum E of boolean {
A,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,4 @@
enum E {
A,
B = true,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,4 @@
enum E {
A,
A,
}

View 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)"
}

View File

@@ -0,0 +1 @@
enum E { }

View 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": []
}
}

View File

@@ -0,0 +1 @@
enum

View File

@@ -0,0 +1,4 @@
{
"plugins": [["flow", { "enums": true }]],
"throws": "Unexpected token (1:4)"
}

View File

@@ -0,0 +1,2 @@
enum type {
}

View 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": []
}
}

View File

@@ -0,0 +1,3 @@
export enum A {}
export default enum B {}

View File

@@ -0,0 +1,11 @@
{
"plugins": [
[
"flow",
{
"enums": true
}
]
],
"sourceType": "module"
}

View 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": []
}
}

View File

@@ -0,0 +1,5 @@
enum E {
A,
B,
C = 3,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,4 @@
enum E {
A = 1,
B = true,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,2 @@
enum E of [] {
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,2 @@
enum E of xxx {
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of string {
A = true,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of boolean {
A = 1 + 2,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of number {
A = 1 + 2,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of string {
A = 1 + 2,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of symbol {
A = 1 + 2,
}

View File

@@ -0,0 +1,4 @@
{
"plugins": [["flow", { "enums": true }]],
"throws": "Symbol enum members cannot be initialized. Use `A,` in enum `E`. (2:6)"
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of symbol {
A = 1,
}

View File

@@ -0,0 +1,4 @@
{
"plugins": [["flow", { "enums": true }]],
"throws": "Symbol enum members cannot be initialized. Use `A,` in enum `E`. (2:6)"
}

View File

@@ -0,0 +1,3 @@
enum E of boolean {
A = 1,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of string {
A = 1,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E {
A = (1),
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of boolean {
A = "hi",
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
enum E of number {
A = "hi",
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,4 @@
enum E {
foo,
bar,
}

View 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)"
}

View File

@@ -0,0 +1,3 @@
enum E {
A
}

View 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": []
}
}

View File

@@ -0,0 +1,4 @@
enum E of number {
A = 1,
B = 2,
}

View 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": []
}
}

View File

@@ -0,0 +1,4 @@
enum E {
A = 1,
B = 2,
}

View 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": []
}
}

View File

@@ -0,0 +1,3 @@
enum E of number {
A,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,4 @@
enum E {
A,
B = 1,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,3 @@
{
"plugins": [["flow", { "enums": true }]]
}

View File

@@ -0,0 +1,2 @@
enum class {
}

View File

@@ -0,0 +1,4 @@
{
"plugins": [["flow", { "enums": true }]],
"throws": "Unexpected keyword 'class' (1:5)"
}

View File

@@ -0,0 +1,4 @@
enum E of string {
A,
B,
}

View 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": []
}
}

View File

@@ -0,0 +1,4 @@
enum E of string {
A = "a",
B = "b",
}

View 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": []
}
}

View File

@@ -0,0 +1,4 @@
enum E {
A,
B,
}

View 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": []
}
}

View File

@@ -0,0 +1,4 @@
enum E {
A = "a",
B = "b",
}

View 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": []
}
}

View File

@@ -0,0 +1,5 @@
enum E of string {
A = "a",
B,
C,
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,5 @@
enum E of string {
A,
B = "b",
C = "c",
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,4 @@
enum E of symbol {
A,
B,
}

View 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": []
}
}