Fix parsing of slash after class expression (#8804)

This commit is contained in:
Brian Ng 2018-10-02 20:45:53 -05:00 committed by GitHub
parent a5b5ed928d
commit 2575312d1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 571 additions and 1 deletions

View File

@ -106,7 +106,7 @@ tt.incDec.updateContext = function() {
// tokExprAllowed stays unchanged // tokExprAllowed stays unchanged
}; };
tt._function.updateContext = function(prevType) { tt._function.updateContext = tt._class.updateContext = function(prevType) {
if (this.state.exprAllowed && !this.braceIsBlock(prevType)) { if (this.state.exprAllowed && !this.braceIsBlock(prevType)) {
this.state.context.push(types.functionExpression); this.state.context.push(types.functionExpression);
} }

View File

@ -0,0 +1,9 @@
x = class{} / foo
x = class{}
/ foo / g
(x = class{} / foo)
(x = class{}
/ foo / g)

View File

@ -0,0 +1,561 @@
{
"type": "File",
"start": 0,
"end": 86,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 10
}
},
"program": {
"type": "Program",
"start": 0,
"end": 86,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 10
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"expression": {
"type": "AssignmentExpression",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "BinaryExpression",
"start": 4,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 17
}
},
"left": {
"type": "ClassExpression",
"start": 4,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 11
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 9,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 11
}
},
"body": []
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 14,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "foo"
},
"name": "foo"
}
}
}
},
{
"type": "ExpressionStatement",
"start": 19,
"end": 86,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 9,
"column": 10
}
},
"expression": {
"type": "AssignmentExpression",
"start": 19,
"end": 86,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 9,
"column": 10
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 1
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "BinaryExpression",
"start": 23,
"end": 86,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 9,
"column": 10
}
},
"left": {
"type": "BinaryExpression",
"start": 23,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 4,
"column": 5
}
},
"left": {
"type": "ClassExpression",
"start": 23,
"end": 30,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 11
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 28,
"end": 30,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 11
}
},
"body": []
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 33,
"end": 36,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 5
},
"identifierName": "foo"
},
"name": "foo"
}
},
"operator": "/",
"right": {
"type": "CallExpression",
"start": 39,
"end": 86,
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 9,
"column": 10
}
},
"callee": {
"type": "CallExpression",
"start": 39,
"end": 61,
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 6,
"column": 19
}
},
"callee": {
"type": "Identifier",
"start": 39,
"end": 40,
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 4,
"column": 9
},
"identifierName": "g"
},
"name": "g"
},
"arguments": [
{
"type": "AssignmentExpression",
"start": 43,
"end": 60,
"loc": {
"start": {
"line": 6,
"column": 1
},
"end": {
"line": 6,
"column": 18
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 43,
"end": 44,
"loc": {
"start": {
"line": 6,
"column": 1
},
"end": {
"line": 6,
"column": 2
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "BinaryExpression",
"start": 47,
"end": 60,
"loc": {
"start": {
"line": 6,
"column": 5
},
"end": {
"line": 6,
"column": 18
}
},
"left": {
"type": "ClassExpression",
"start": 47,
"end": 54,
"loc": {
"start": {
"line": 6,
"column": 5
},
"end": {
"line": 6,
"column": 12
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 52,
"end": 54,
"loc": {
"start": {
"line": 6,
"column": 10
},
"end": {
"line": 6,
"column": 12
}
},
"body": []
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 57,
"end": 60,
"loc": {
"start": {
"line": 6,
"column": 15
},
"end": {
"line": 6,
"column": 18
},
"identifierName": "foo"
},
"name": "foo"
}
}
}
]
},
"arguments": [
{
"type": "AssignmentExpression",
"start": 64,
"end": 85,
"loc": {
"start": {
"line": 8,
"column": 1
},
"end": {
"line": 9,
"column": 9
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 64,
"end": 65,
"loc": {
"start": {
"line": 8,
"column": 1
},
"end": {
"line": 8,
"column": 2
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "BinaryExpression",
"start": 68,
"end": 85,
"loc": {
"start": {
"line": 8,
"column": 5
},
"end": {
"line": 9,
"column": 9
}
},
"left": {
"type": "BinaryExpression",
"start": 68,
"end": 81,
"loc": {
"start": {
"line": 8,
"column": 5
},
"end": {
"line": 9,
"column": 5
}
},
"left": {
"type": "ClassExpression",
"start": 68,
"end": 75,
"loc": {
"start": {
"line": 8,
"column": 5
},
"end": {
"line": 8,
"column": 12
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 73,
"end": 75,
"loc": {
"start": {
"line": 8,
"column": 10
},
"end": {
"line": 8,
"column": 12
}
},
"body": []
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 78,
"end": 81,
"loc": {
"start": {
"line": 9,
"column": 2
},
"end": {
"line": 9,
"column": 5
},
"identifierName": "foo"
},
"name": "foo"
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 84,
"end": 85,
"loc": {
"start": {
"line": 9,
"column": 8
},
"end": {
"line": 9,
"column": 9
},
"identifierName": "g"
},
"name": "g"
}
}
}
]
}
}
}
}
],
"directives": []
}
}