[parser] Report escapes in kws only if they won't be used as i… (#10455)

We can do it by tokenizing escaped keywords as normal identifiers, so that they won't
be accidentally used as real keywords.
This commit is contained in:
Nicolò Ribaudo
2019-09-18 00:13:51 +02:00
committed by GitHub
parent 45a484f0a2
commit cb881e6b3f
9 changed files with 172 additions and 447 deletions

View File

@@ -0,0 +1,3 @@
var a = {
br\u{65}ak
};

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected keyword 'break' (2:2)"
}

View File

@@ -0,0 +1,3 @@
var a = {
br\u{65}ak: 2
};

View File

@@ -0,0 +1,157 @@
{
"type": "File",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 2
}
},
"program": {
"type": "Program",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 2
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 2
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 5
},
"identifierName": "a"
},
"name": "a"
},
"init": {
"type": "ObjectExpression",
"start": 8,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 3,
"column": 1
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 12,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 15
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 12,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "break"
},
"name": "break"
},
"computed": false,
"shorthand": false,
"value": {
"type": "NumericLiteral",
"start": 24,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 14
},
"end": {
"line": 2,
"column": 15
}
},
"extra": {
"rawValue": 2,
"raw": "2"
},
"value": 2
}
}
]
}
}
],
"kind": "var"
}
],
"directives": []
}
}