Skip to content

Commit

Permalink
TSTypeCastExpression should not be inside call parameters (#10939)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Dec 30, 2019
1 parent 197a8da commit 86245a8
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -2568,11 +2568,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
): $ReadOnlyArray<?N.Expression> {
for (let i = 0; i < exprList.length; i++) {
const expr = exprList[i];
if (
expr &&
expr._exprListItem &&
expr.type === "TsTypeCastExpression"
) {
if (expr && expr.type === "TSTypeCastExpression") {
this.raise(expr.start, "Did not expect a type annotation here.");
}
}
Expand Down
@@ -0,0 +1 @@
func(a: T);
@@ -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": []
}
}

0 comments on commit 86245a8

Please sign in to comment.