Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add isLiteralPropertyName to parser utils #11547

Merged
merged 5 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: allow bigint in TSLiteralType
  • Loading branch information
JLHwung committed May 13, 2020
commit 98df3481bbdd15ea47c807cc4c4411c1d7c8ff14
5 changes: 4 additions & 1 deletion packages/babel-parser/src/plugins/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
node.literal = (() => {
switch (this.state.type) {
case tt.num:
case tt.bigint:
case tt.string:
case tt._true:
case tt._false:
Expand Down Expand Up @@ -747,13 +748,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
case tt.string:
case tt.num:
case tt.bigint:
case tt._true:
case tt._false:
return this.tsParseLiteralTypeNode();
case tt.plusMin:
if (this.state.value === "-") {
const node: N.TsLiteralType = this.startNode();
if (this.lookahead().type !== tt.num) {
const nextToken = this.lookahead();
if (nextToken.type !== tt.num && nextToken.type !== tt.bigint) {
throw this.unexpected();
}
node.literal = this.parseMaybeUnary();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: -1n;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"type": "File",
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
"program": {
"type": "Program",
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
"declarations": [
{
"type": "VariableDeclarator",
"start":4,"end":10,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":10}},
"id": {
"type": "Identifier",
"start":4,"end":10,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":10},"identifierName":"x"},
"name": "x",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start":5,"end":10,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":10}},
"typeAnnotation": {
"type": "TSLiteralType",
"start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}},
"literal": {
"type": "UnaryExpression",
"start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}},
"operator": "-",
"prefix": true,
"argument": {
"type": "BigIntLiteral",
"start":8,"end":10,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":10}},
"extra": {
"rawValue": "1",
"raw": "1n"
},
"value": "1"
}
}
}
}
},
"init": null
}
],
"kind": "let"
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x: 0n;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"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": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
"declarations": [
{
"type": "VariableDeclarator",
"start":4,"end":9,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":9}},
"id": {
"type": "Identifier",
"start":4,"end":9,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":9},"identifierName":"x"},
"name": "x",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start":5,"end":9,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":9}},
"typeAnnotation": {
"type": "TSLiteralType",
"start":7,"end":9,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":9}},
"literal": {
"type": "BigIntLiteral",
"start":7,"end":9,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":9}},
"extra": {
"rawValue": "0",
"raw": "0n"
},
"value": "0"
}
}
}
},
"init": null
}
],
"kind": "let"
}
],
"directives": []
}
}
1 change: 1 addition & 0 deletions packages/babel-types/src/definitions/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ defineType("TSLiteralType", {
"NumericLiteral",
"StringLiteral",
"BooleanLiteral",
"BigIntLiteral",
]),
},
});
Expand Down