TSTypeCastExpression should not be inside call parameters (#10939)

This commit is contained in:
Huáng Jùnliàng 2019-12-30 16:10:19 -05:00 committed by GitHub
parent 197a8da04d
commit 86245a83a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 168 additions and 5 deletions

View File

@ -2568,11 +2568,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
): $ReadOnlyArray<?N.Expression> { ): $ReadOnlyArray<?N.Expression> {
for (let i = 0; i < exprList.length; i++) { for (let i = 0; i < exprList.length; i++) {
const expr = exprList[i]; const expr = exprList[i];
if ( if (expr && expr.type === "TSTypeCastExpression") {
expr &&
expr._exprListItem &&
expr.type === "TsTypeCastExpression"
) {
this.raise(expr.start, "Did not expect a type annotation here."); this.raise(expr.start, "Did not expect a type annotation here.");
} }
} }

View File

@ -0,0 +1 @@
func(a: T);

View File

@ -0,0 +1,166 @@
{
"type": "File",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"errors": [
"SyntaxError: Did not expect a type annotation here. (1:5)"
],
"program": {
"type": "Program",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"expression": {
"type": "CallExpression",
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"callee": {
"type": "Identifier",
"start": 0,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "func"
},
"name": "func"
},
"arguments": [
{
"type": "TSTypeCastExpression",
"start": 5,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 9
}
},
"expression": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "a"
},
"name": "a"
},
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start": 6,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 9
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
},
"typeName": {
"type": "Identifier",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
},
"identifierName": "T"
},
"name": "T"
}
}
}
}
]
}
}
],
"directives": []
}
}