Disallow escape sequences in contextual keywords (#9618)

* Disallow escape sequences in async

* Disallow escape sequences in get, set and async in class

* invalid escape tests

* Update whitelist

* tests for async in parens

* Add test for invalid newline between params and arrow

* Move canInsertSemilcolon() into shouldPArseAsyncArrow
This commit is contained in:
Daniel Tschinder
2019-03-05 17:20:36 -08:00
committed by GitHub
parent 349c0d4836
commit 29999007f6
58 changed files with 530 additions and 22 deletions

View File

@@ -0,0 +1 @@
({ ge\u0074 x() {} })

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \",\" (1:12)"
}

View File

@@ -0,0 +1 @@
(\u0061sync ())

View File

@@ -0,0 +1,87 @@
{
"type": "File",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"program": {
"type": "Program",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"expression": {
"type": "CallExpression",
"start": 1,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 14
}
},
"callee": {
"type": "Identifier",
"start": 1,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "async"
},
"name": "async"
},
"arguments": [],
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
class X { ge\u0074 x() {} }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:19)"
}

View File

@@ -0,0 +1 @@
class X { se\u0074 x(value) {} }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:19)"
}

View File

@@ -0,0 +1 @@
class X { st\u0061tic y() {} }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:22)"
}

View File

@@ -0,0 +1 @@
for (x \u006ff y) {}

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \";\" (1:7)"
}

View File

@@ -0,0 +1 @@
(function* () { y\u0069eld 10 })

View File

@@ -0,0 +1,3 @@
{
"throws": "Can not use 'yield' as identifier inside a generator (1:16)"
}

View File

@@ -0,0 +1 @@
le\u0074 x = 5

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \";\" (1:9)"
}

View File

@@ -0,0 +1 @@
function f() { new.ta\u0072get; }

View File

@@ -0,0 +1,3 @@
{
"throws": "The only valid meta property for new is new.target (1:19)"
}

View File

@@ -0,0 +1 @@
export { X \u0061s Y }

View File

@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "Unexpected token, expected \",\" (1:11)"
}

View File

@@ -0,0 +1 @@
import X fro\u006d 'x'

View File

@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "Unexpected token (1:9)"
}

View File

@@ -0,0 +1 @@
class X { \u0061sync x() { await x } }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:21)"
}

View File

@@ -0,0 +1 @@
({ \u0061sync x() { await x } })

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \",\" (1:14)"
}

View File

@@ -0,0 +1 @@
class X { static \u0061sync x() { await x } }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:28)"
}

View File

@@ -0,0 +1 @@
(async function() { aw\u0061it x })

View File

@@ -0,0 +1,3 @@
{
"throws": "Can not use 'await' as identifier inside an async function (1:20)"
}

View File

@@ -0,0 +1 @@
export \u0061sync function y() { await x }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \"{\" (1:7)"
}

View File

@@ -0,0 +1 @@
export default \u0061sync function y() { await x }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \";\" (1:26)"
}

View File

@@ -0,0 +1 @@
(\u0061sync x => { await x })

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \",\" (1:12)"
}

View File

@@ -0,0 +1 @@
\u0061sync x => { await x }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \";\" (1:11)"
}

View File

@@ -0,0 +1 @@
(\u0061sync function() { await x })

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \",\" (1:12)"
}

View File

@@ -0,0 +1 @@
\u0061sync function() { await x }

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \";\" (1:11)"
}

View File

@@ -0,0 +1,2 @@
async (x)
=> {}

View File

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

View File

@@ -0,0 +1 @@
(async)(a) => {}

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \";\" (1:11)"
}

View File

@@ -0,0 +1 @@
(async) function x (a) {}

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \";\" (1:8)"
}

View File

@@ -0,0 +1,2 @@
async (f)
: t => { }

View File

@@ -0,0 +1,152 @@
{
"type": "File",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"program": {
"type": "Program",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"returnType": {
"type": "TypeAnnotation",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 3
}
},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
}
},
"typeParameters": null,
"id": {
"type": "Identifier",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "t"
},
"name": "t"
}
}
},
"id": null,
"generator": false,
"async": true,
"params": [
{
"type": "Identifier",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
},
"identifierName": "f"
},
"name": "f"
}
],
"body": {
"type": "BlockStatement",
"start": 17,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 10
}
},
"body": [],
"directives": []
}
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1,2 @@
async (f)
: t => { }

View File

@@ -0,0 +1,151 @@
{
"type": "File",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"program": {
"type": "Program",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"returnType": {
"type": "TSTypeAnnotation",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 3
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
}
},
"typeName": {
"type": "Identifier",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "t"
},
"name": "t"
}
}
},
"id": null,
"generator": false,
"async": true,
"params": [
{
"type": "Identifier",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
},
"identifierName": "f"
},
"name": "f"
}
],
"body": {
"type": "BlockStatement",
"start": 17,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 10
}
},
"body": [],
"directives": []
}
}
}
],
"directives": []
}
}