Skip to content

Commit 4b2b609

Browse files
committed
disallow surrogate in the end of contextual name
1 parent 4ee6a27 commit 4b2b609

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

  • packages/babel-parser

packages/babel-parser/src/parser/util.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,17 @@ export default class UtilParser extends Tokenizer {
7171

7272
isUnparsedContextual(nameStart: number, name: string): boolean {
7373
const nameEnd = nameStart + name.length;
74-
return (
75-
this.input.slice(nameStart, nameEnd) === name &&
76-
(nameEnd === this.input.length ||
77-
!isIdentifierChar(this.input.charCodeAt(nameEnd)))
78-
);
74+
if (this.input.slice(nameStart, nameEnd) === name) {
75+
const nextCh = this.input.charCodeAt(nameEnd);
76+
return !(
77+
isIdentifierChar(nextCh) ||
78+
// check if `nextCh is between 0xd800 - 0xdbff,
79+
// if `nextCh` is NaN, `NaN & 0xfc00` is 0, the function
80+
// returns true
81+
(nextCh & 0xfc00) === 0xd800
82+
);
83+
}
84+
return false;
7985
}
8086

8187
isLookaheadContextual(name: string): boolean {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
async function𝐬 f() {}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
4+
"errors": [
5+
"SyntaxError: Missing semicolon. (1:5)",
6+
"SyntaxError: Missing semicolon. (1:16)",
7+
"SyntaxError: Missing semicolon. (1:20)"
8+
],
9+
"program": {
10+
"type": "Program",
11+
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
12+
"sourceType": "script",
13+
"interpreter": null,
14+
"body": [
15+
{
16+
"type": "ExpressionStatement",
17+
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
18+
"expression": {
19+
"type": "Identifier",
20+
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"async"},
21+
"name": "async"
22+
}
23+
},
24+
{
25+
"type": "ExpressionStatement",
26+
"start":6,"end":16,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":16}},
27+
"expression": {
28+
"type": "Identifier",
29+
"start":6,"end":16,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":16},"identifierName":"function𝐬"},
30+
"name": "function𝐬"
31+
}
32+
},
33+
{
34+
"type": "ExpressionStatement",
35+
"start":17,"end":20,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":20}},
36+
"expression": {
37+
"type": "CallExpression",
38+
"start":17,"end":20,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":20}},
39+
"callee": {
40+
"type": "Identifier",
41+
"start":17,"end":18,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":18},"identifierName":"f"},
42+
"name": "f"
43+
},
44+
"arguments": []
45+
}
46+
},
47+
{
48+
"type": "BlockStatement",
49+
"start":21,"end":23,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":23}},
50+
"body": [],
51+
"directives": []
52+
}
53+
],
54+
"directives": []
55+
}
56+
}

0 commit comments

Comments
 (0)