From 46e3f6df1f010ec1276eb6e0f961c51fca5affcb Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 8 Jan 2019 14:19:55 +0100 Subject: [PATCH] @babel/parser: include leading character into range of generic ArrowFunctionExpression (#9295) --- packages/babel-parser/src/plugins/typescript.js | 5 +---- .../typescript/arrow-function/generic-tsx/output.json | 6 +++--- .../fixtures/typescript/arrow-function/generic/output.json | 6 +++--- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 07e57b9914..c25eaec0a3 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -2001,10 +2001,7 @@ export default (superClass: Class): Class => // Correct TypeScript code should have at least 1 type parameter, but don't crash on bad code. if (typeParameters && typeParameters.params.length !== 0) { - this.resetStartLocationFromNode( - arrowExpression, - typeParameters.params[0], - ); + this.resetStartLocationFromNode(arrowExpression, typeParameters); } arrowExpression.typeParameters = typeParameters; return arrowExpression; diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/output.json index ee5c663d37..58c3d96721 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx/output.json @@ -45,12 +45,12 @@ }, "expression": { "type": "ArrowFunctionExpression", - "start": 62, + "start": 61, "end": 78, "loc": { "start": { "line": 2, - "column": 1 + "column": 0 }, "end": { "line": 2, @@ -264,4 +264,4 @@ } } ] -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/output.json index 5b7f66c90e..1f99918b7a 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/generic/output.json @@ -45,12 +45,12 @@ }, "expression": { "type": "ArrowFunctionExpression", - "start": 1, + "start": 0, "end": 17, "loc": { "start": { "line": 1, - "column": 1 + "column": 0 }, "end": { "line": 1, @@ -228,4 +228,4 @@ ], "directives": [] } -} \ No newline at end of file +}