Skip to content

Commit

Permalink
Fix ES6 Unicode escape not recognized in identifier name.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Jul 11, 2015
1 parent 495b298 commit 1ee0f6c
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 6 deletions.
22 changes: 16 additions & 6 deletions esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,14 @@
throwUnexpectedToken();
}
++index;
ch = scanHexEscape('u');
if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {
throwUnexpectedToken();
if (source[index] === '{') {
++index;
ch = scanUnicodeCodePointEscape();
} else {
ch = scanHexEscape('u');
if (!ch || ch === '\\' || !isIdentifierStart(ch.charCodeAt(0))) {
throwUnexpectedToken();
}
}
id = ch;
}
Expand All @@ -647,9 +652,14 @@
throwUnexpectedToken();
}
++index;
ch = scanHexEscape('u');
if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {
throwUnexpectedToken();
if (source[index] === '{') {
++index;
ch = scanUnicodeCodePointEscape();
} else {
ch = scanHexEscape('u');
if (!ch || ch === '\\' || !isIdentifierPart(ch.charCodeAt(0))) {
throwUnexpectedToken();
}
}
id += ch;
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/escaped_all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var \u{41}\u{42}\u{43};
75 changes: 75 additions & 0 deletions test/fixtures/ES6/identifier/escaped_all.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"range": [
0,
23
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"type": "Program",
"body": [
{
"range": [
0,
23
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"type": "VariableDeclaration",
"declarations": [
{
"range": [
4,
22
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 22
}
},
"type": "VariableDeclarator",
"id": {
"range": [
4,
22
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 22
}
},
"type": "Identifier",
"name": "ABC"
},
"init": null
}
],
"kind": "var"
}
]
}
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/escaped_part.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var A\u{42}C;
75 changes: 75 additions & 0 deletions test/fixtures/ES6/identifier/escaped_part.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"range": [
0,
13
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"type": "Program",
"body": [
{
"range": [
0,
13
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"type": "VariableDeclaration",
"declarations": [
{
"range": [
4,
12
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 12
}
},
"type": "VariableDeclarator",
"id": {
"range": [
4,
12
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 12
}
},
"type": "Identifier",
"name": "ABC"
},
"init": null
}
],
"kind": "var"
}
]
}
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/escaped_start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var \u{41}BC;
75 changes: 75 additions & 0 deletions test/fixtures/ES6/identifier/escaped_start.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"range": [
0,
13
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"type": "Program",
"body": [
{
"range": [
0,
13
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"type": "VariableDeclaration",
"declarations": [
{
"range": [
4,
12
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 12
}
},
"type": "VariableDeclarator",
"id": {
"range": [
4,
12
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 12
}
},
"type": "Identifier",
"name": "ABC"
},
"init": null
}
],
"kind": "var"
}
]
}

0 comments on commit 1ee0f6c

Please sign in to comment.