From 34c9890f41c84436940e0dbc9ba894c2b8281c6d Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Tue, 15 Jan 2019 06:52:33 -0600 Subject: [PATCH] Fix range on TypeScript index signature parameters (#9335) --- packages/babel-parser/src/plugins/typescript.js | 5 +++-- .../typescript/class/declare/output.json | 8 ++++---- .../typescript/class/index-signature/output.json | 16 ++++++++-------- .../interface/index-signature/output.json | 8 ++++---- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 0aa6211748..1f382db90f 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -398,8 +398,9 @@ export default (superClass: Class): Class => this.expect(tt.bracketL); const id = this.parseIdentifier(); - this.expect(tt.colon); - id.typeAnnotation = this.tsParseTypeAnnotation(/* eatColon */ false); + id.typeAnnotation = this.tsParseTypeAnnotation(); + this.finishNode(id, "Identifier"); // set end position to end of type + this.expect(tt.bracketR); node.parameters = [id]; diff --git a/packages/babel-parser/test/fixtures/typescript/class/declare/output.json b/packages/babel-parser/test/fixtures/typescript/class/declare/output.json index 9c183f96b8..f52b40639e 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/declare/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/declare/output.json @@ -94,7 +94,7 @@ { "type": "Identifier", "start": 23, - "end": 24, + "end": 32, "loc": { "start": { "line": 2, @@ -102,19 +102,19 @@ }, "end": { "line": 2, - "column": 6 + "column": 14 }, "identifierName": "x" }, "name": "x", "typeAnnotation": { "type": "TSTypeAnnotation", - "start": 26, + "start": 24, "end": 32, "loc": { "start": { "line": 2, - "column": 8 + "column": 6 }, "end": { "line": 2, diff --git a/packages/babel-parser/test/fixtures/typescript/class/index-signature/output.json b/packages/babel-parser/test/fixtures/typescript/class/index-signature/output.json index 64364c1015..b1b3fd1a35 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/index-signature/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/index-signature/output.json @@ -94,7 +94,7 @@ { "type": "Identifier", "start": 15, - "end": 16, + "end": 24, "loc": { "start": { "line": 2, @@ -102,19 +102,19 @@ }, "end": { "line": 2, - "column": 6 + "column": 14 }, "identifierName": "x" }, "name": "x", "typeAnnotation": { "type": "TSTypeAnnotation", - "start": 18, + "start": 16, "end": 24, "loc": { "start": { "line": 2, - "column": 8 + "column": 6 }, "end": { "line": 2, @@ -189,7 +189,7 @@ { "type": "Identifier", "start": 46, - "end": 47, + "end": 55, "loc": { "start": { "line": 3, @@ -197,19 +197,19 @@ }, "end": { "line": 3, - "column": 15 + "column": 23 }, "identifierName": "x" }, "name": "x", "typeAnnotation": { "type": "TSTypeAnnotation", - "start": 49, + "start": 47, "end": 55, "loc": { "start": { "line": 3, - "column": 17 + "column": 15 }, "end": { "line": 3, diff --git a/packages/babel-parser/test/fixtures/typescript/interface/index-signature/output.json b/packages/babel-parser/test/fixtures/typescript/interface/index-signature/output.json index e34dff90a1..6a4a98afb5 100644 --- a/packages/babel-parser/test/fixtures/typescript/interface/index-signature/output.json +++ b/packages/babel-parser/test/fixtures/typescript/interface/index-signature/output.json @@ -93,7 +93,7 @@ { "type": "Identifier", "start": 19, - "end": 20, + "end": 28, "loc": { "start": { "line": 2, @@ -101,19 +101,19 @@ }, "end": { "line": 2, - "column": 6 + "column": 14 }, "identifierName": "s" }, "name": "s", "typeAnnotation": { "type": "TSTypeAnnotation", - "start": 22, + "start": 20, "end": 28, "loc": { "start": { "line": 2, - "column": 8 + "column": 6 }, "end": { "line": 2,