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