fix: disallow surrogate in the end of contextual name (#13377)

This commit is contained in:
Huáng Jùnliàng 2021-05-26 22:57:59 -04:00 committed by GitHub
parent dbfa87740c
commit 079f8cd5bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 5 deletions

View File

@ -71,12 +71,18 @@ export default class UtilParser extends Tokenizer {
isUnparsedContextual(nameStart: number, name: string): boolean { isUnparsedContextual(nameStart: number, name: string): boolean {
const nameEnd = nameStart + name.length; const nameEnd = nameStart + name.length;
return ( if (this.input.slice(nameStart, nameEnd) === name) {
this.input.slice(nameStart, nameEnd) === name && const nextCh = this.input.charCodeAt(nameEnd);
(nameEnd === this.input.length || return !(
!isIdentifierChar(this.input.charCodeAt(nameEnd))) isIdentifierChar(nextCh) ||
// check if `nextCh is between 0xd800 - 0xdbff,
// if `nextCh` is NaN, `NaN & 0xfc00` is 0, the function
// returns true
(nextCh & 0xfc00) === 0xd800
); );
} }
return false;
}
isLookaheadContextual(name: string): boolean { isLookaheadContextual(name: string): boolean {
const next = this.nextTokenStart(); const next = this.nextTokenStart();

View File

@ -0,0 +1 @@
async function𝐬 f() {}

View File

@ -0,0 +1,56 @@
{
"type": "File",
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
"errors": [
"SyntaxError: Missing semicolon. (1:5)",
"SyntaxError: Missing semicolon. (1:16)",
"SyntaxError: Missing semicolon. (1:20)"
],
"program": {
"type": "Program",
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
"expression": {
"type": "Identifier",
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"async"},
"name": "async"
}
},
{
"type": "ExpressionStatement",
"start":6,"end":16,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":16}},
"expression": {
"type": "Identifier",
"start":6,"end":16,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":16},"identifierName":"function𝐬"},
"name": "function𝐬"
}
},
{
"type": "ExpressionStatement",
"start":17,"end":20,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":20}},
"expression": {
"type": "CallExpression",
"start":17,"end":20,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":20}},
"callee": {
"type": "Identifier",
"start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18},"identifierName":"f"},
"name": "f"
},
"arguments": []
}
},
{
"type": "BlockStatement",
"start":21,"end":23,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":23}},
"body": [],
"directives": []
}
],
"directives": []
}
}