diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 3914611406..c23fd5d3c6 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -1849,7 +1849,7 @@ export default (superClass: Class): Class => return this.finishNode(typeCastNode, "TSTypeCastExpression"); } - return node; + return this.finishNode(node, node.type); } parseExportDeclaration(node: N.ExportNamedDeclaration): ?N.Declaration { diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/optional-parameter/input.js b/packages/babel-parser/test/fixtures/typescript/arrow-function/optional-parameter/input.js index 4b8fea779c..f3019ef4b6 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/optional-parameter/input.js +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/optional-parameter/input.js @@ -1 +1,2 @@ -(x?: number): any => x; \ No newline at end of file +(x?: number): any => x; +((k?) => k + 1)(); diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/optional-parameter/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/optional-parameter/output.json index de4c8043c3..3a08e42c86 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/optional-parameter/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/optional-parameter/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 23, + "end": 42, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 23 + "line": 2, + "column": 18 } }, "program": { "type": "Program", "start": 0, - "end": 23, + "end": 42, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 23 + "line": 2, + "column": 18 } }, "sourceType": "module", @@ -158,6 +158,132 @@ "name": "x" } } + }, + { + "type": "ExpressionStatement", + "start": 24, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "expression": { + "type": "CallExpression", + "start": 24, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "callee": { + "type": "ArrowFunctionExpression", + "start": 25, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "k" + }, + "name": "k", + "optional": true + } + ], + "body": { + "type": "BinaryExpression", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "k" + }, + "name": "k" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "parenthesized": true, + "parenStart": 24 + } + }, + "arguments": [] + } } ], "directives": []