Fix parsing arrow with existential return type (#6726)

This commit is contained in:
Raja Sekar 2017-11-02 21:26:27 +05:30 committed by Brian Ng
parent 3b540e3f5a
commit 2d0211a085
6 changed files with 323 additions and 1 deletions

View File

@ -437,6 +437,7 @@ export default class Tokenizer extends LocationParser {
let type = code === 42 ? tt.star : tt.modulo;
let width = 1;
let next = this.input.charCodeAt(this.state.pos + 1);
const exprAllowed = this.state.exprAllowed;
// Exponentiation operator **
if (code === 42 && next === 42) {
@ -445,7 +446,7 @@ export default class Tokenizer extends LocationParser {
type = tt.exponent;
}
if (next === 61) {
if (next === 61 && !exprAllowed) {
width++;
type = tt.assign;
}

View File

@ -0,0 +1 @@
const x = ():*=>{}

View File

@ -0,0 +1,152 @@
{
"type": "File",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 18
}
},
"program": {
"type": "Program",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 18
}
},
"sourceType": "module",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 18
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 18
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "x"
},
"name": "x"
},
"init": {
"type": "ArrowFunctionExpression",
"start": 10,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 18
}
},
"predicate": null,
"returnType": {
"type": "TypeAnnotation",
"start": 12,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 14
}
},
"typeAnnotation": {
"type": "ExistsTypeAnnotation",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
}
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 16,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 18
}
},
"body": [],
"directives": []
}
}
}
],
"kind": "const"
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
class C { field:*=null }

View File

@ -0,0 +1,164 @@
{
"type": "File",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"program": {
"type": "Program",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 24
}
},
"body": [
{
"type": "ClassProperty",
"start": 10,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 22
}
},
"static": false,
"key": {
"type": "Identifier",
"start": 10,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "field"
},
"name": "field"
},
"computed": false,
"variance": null,
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 15,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 17
}
},
"typeAnnotation": {
"type": "ExistsTypeAnnotation",
"start": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 17
}
}
}
},
"value": {
"type": "NullLiteral",
"start": 18,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 22
}
}
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["flow", "classProperties"]
}