Alow regex after "of" in for(...of...) (#579)

Fixes #456
This commit is contained in:
Nicolò Ribaudo 2017-08-03 16:11:31 +02:00 committed by Brian Ng
parent 880fa582c3
commit eee1a3854e
3 changed files with 309 additions and 0 deletions

View File

@ -61,6 +61,11 @@ tt.parenR.updateContext = tt.braceR.updateContext = function() {
};
tt.name.updateContext = function(prevType) {
if (this.state.value === "of" && this.curContext() === types.parenStatement) {
this.state.exprAllowed = !prevType.beforeExpr;
return;
}
this.state.exprAllowed = false;
if (prevType === tt._let || prevType === tt._const || prevType === tt._var) {

View File

@ -0,0 +1,3 @@
for (var x of /foo/g);
for (var x = of /foo/g;;);

View File

@ -0,0 +1,301 @@
{
"type": "File",
"start": 0,
"end": 50,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 26
}
},
"program": {
"type": "Program",
"start": 0,
"end": 50,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 26
}
},
"sourceType": "script",
"body": [
{
"type": "ForOfStatement",
"start": 0,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 22
}
},
"await": false,
"left": {
"type": "VariableDeclaration",
"start": 5,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 10
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
},
"identifierName": "x"
},
"name": "x"
},
"init": null
}
],
"kind": "var"
},
"right": {
"type": "RegExpLiteral",
"start": 14,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 20
}
},
"extra": {
"raw": "/foo/g"
},
"pattern": "foo",
"flags": "g"
},
"body": {
"type": "EmptyStatement",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 22
}
}
}
},
{
"type": "ForStatement",
"start": 24,
"end": 50,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 26
}
},
"init": {
"type": "VariableDeclaration",
"start": 29,
"end": 46,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 22
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 33,
"end": 46,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 22
}
},
"id": {
"type": "Identifier",
"start": 33,
"end": 34,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 10
},
"identifierName": "x"
},
"name": "x"
},
"init": {
"type": "BinaryExpression",
"start": 37,
"end": 46,
"loc": {
"start": {
"line": 3,
"column": 13
},
"end": {
"line": 3,
"column": 22
}
},
"left": {
"type": "BinaryExpression",
"start": 37,
"end": 44,
"loc": {
"start": {
"line": 3,
"column": 13
},
"end": {
"line": 3,
"column": 20
}
},
"left": {
"type": "Identifier",
"start": 37,
"end": 39,
"loc": {
"start": {
"line": 3,
"column": 13
},
"end": {
"line": 3,
"column": 15
},
"identifierName": "of"
},
"name": "of"
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 41,
"end": 44,
"loc": {
"start": {
"line": 3,
"column": 17
},
"end": {
"line": 3,
"column": 20
},
"identifierName": "foo"
},
"name": "foo"
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 45,
"end": 46,
"loc": {
"start": {
"line": 3,
"column": 21
},
"end": {
"line": 3,
"column": 22
},
"identifierName": "g"
},
"name": "g"
}
}
}
],
"kind": "var"
},
"test": null,
"update": null,
"body": {
"type": "EmptyStatement",
"start": 49,
"end": 50,
"loc": {
"start": {
"line": 3,
"column": 25
},
"end": {
"line": 3,
"column": 26
}
}
}
}
],
"directives": []
}
}