fix: allow bigInt in method name and TSLiteralType (#11547)

* refactor: add isLiteralPropertyName to parser utils

* address review comments [skip-ci]

* refactor: keyword is valid identifierName

* fix: allow bigint in TSLiteralType

* update typescript test whitelist
This commit is contained in:
Huáng Jùnliàng
2020-05-14 18:40:52 -04:00
committed by GitHub
parent de8264c8a7
commit 2f31ecf85d
11 changed files with 270 additions and 18 deletions

View File

@@ -1553,11 +1553,8 @@ export default class ExpressionParser extends LValParser {
!prop.computed &&
prop.key.type === "Identifier" &&
prop.key.name === "async" &&
(this.match(tt.name) ||
this.match(tt.num) ||
this.match(tt.string) ||
(this.isLiteralPropertyName() ||
this.match(tt.bracketL) ||
this.state.type.keyword ||
this.match(tt.star)) &&
!this.hasPrecedingLineBreak()
);
@@ -1646,11 +1643,8 @@ export default class ExpressionParser extends LValParser {
!prop.computed &&
prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set") &&
(this.match(tt.string) || // get "string"() {}
this.match(tt.num) || // get 1() {}
this.match(tt.bracketL) || // get ["string"]() {}
this.match(tt.name) || // get foo() {}
!!this.state.type.keyword) // get debugger() {}
(this.isLiteralPropertyName() || // get foo() {}
this.match(tt.bracketL)) // get ["string"]() {}
);
}

View File

@@ -259,6 +259,25 @@ export default class UtilParser extends Tokenizer {
this.raise(doubleProto, Errors.DuplicateProto);
}
}
/**
* Test if current token is a literal property name
* https://tc39.es/ecma262/#prod-LiteralPropertyName
* LiteralPropertyName:
* IdentifierName
* StringLiteral
* NumericLiteral
* BigIntLiteral
*/
isLiteralPropertyName(): boolean {
return (
this.match(tt.name) ||
!!this.state.type.keyword ||
this.match(tt.string) ||
this.match(tt.num) ||
this.match(tt.bigint)
);
}
}
/**

View File

@@ -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:
@@ -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();