Skip to content

Commit

Permalink
LiteralPropertyName should allow BigIntLiteral (#10955)
Browse files Browse the repository at this point in the history
* fix: property name should allow BigIntLiteral

* test: add non decimal test case

* add bigintIndex to whitelist
  • Loading branch information
JLHwung committed Jan 7, 2020
1 parent 3fa37d2 commit 8fd532d
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -1790,7 +1790,7 @@ export default class ExpressionParser extends LValParser {
this.state.inPropertyName = true;
// We check if it's valid for it to be a private name when we push it.
(prop: $FlowFixMe).key =
this.match(tt.num) || this.match(tt.string)
this.match(tt.num) || this.match(tt.string) || this.match(tt.bigint)
? this.parseExprAtom()
: this.parseMaybePrivateName();

Expand Down
@@ -0,0 +1 @@
({ 0n: 0 });
@@ -0,0 +1,129 @@
{
"type": "File",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"program": {
"type": "Program",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"expression": {
"type": "ObjectExpression",
"start": 1,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 3,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 8
}
},
"method": false,
"key": {
"type": "BigIntLiteral",
"start": 3,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 5
}
},
"extra": {
"rawValue": "0",
"raw": "0n"
},
"value": "0"
},
"computed": false,
"shorthand": false,
"value": {
"type": "NumericLiteral",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
],
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
({ 0xbeefban: 0 });
@@ -0,0 +1,129 @@
{
"type": "File",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"program": {
"type": "Program",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"expression": {
"type": "ObjectExpression",
"start": 1,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 17
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 3,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 15
}
},
"method": false,
"key": {
"type": "BigIntLiteral",
"start": 3,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 12
}
},
"extra": {
"rawValue": "0xbeefba",
"raw": "0xbeefban"
},
"value": "0xbeefba"
},
"computed": false,
"shorthand": false,
"value": {
"type": "NumericLiteral",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
],
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}
1 change: 1 addition & 0 deletions scripts/parser-tests/typescript/whitelist.txt
Expand Up @@ -61,6 +61,7 @@ augmentedTypesVar.ts
awaitInNonAsyncFunction.ts
awaitLiteralValues.ts
bigIntWithTargetES3.ts
bigintIndex.ts
bigintWithLib.ts
breakNotInIterationOrSwitchStatement1.ts
breakNotInIterationOrSwitchStatement2.ts
Expand Down

0 comments on commit 8fd532d

Please sign in to comment.