Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 6a612cd

Browse files
soda0289JamesHenry
authored andcommitted
Breaking: Include type annotation range for Identifiers (fixes #314) (#319)
1 parent 074a64f commit 6a612cd

File tree

4 files changed

+523
-73
lines changed

4 files changed

+523
-73
lines changed

lib/convert.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ module.exports = function convert(config) {
526526

527527
}
528528

529-
case SyntaxKind.VariableDeclaration:
529+
case SyntaxKind.VariableDeclaration: {
530530
Object.assign(result, {
531531
type: AST_NODE_TYPES.VariableDeclarator,
532532
id: convertChild(node.name),
@@ -535,8 +535,18 @@ module.exports = function convert(config) {
535535

536536
if (node.type) {
537537
result.id.typeAnnotation = convertTypeAnnotation(node.type);
538+
result.id.range[1] = node.type.getEnd();
539+
540+
const identifierEnd = node.name.getEnd();
541+
const numCharsBetweenTypeAndIdentifier = node.type.getStart() - (node.type.getFullStart() - identifierEnd - ":".length) - identifierEnd;
542+
543+
result.id.typeAnnotation.range = [
544+
result.id.typeAnnotation.range[0] - numCharsBetweenTypeAndIdentifier,
545+
result.id.typeAnnotation.range[1]
546+
];
538547
}
539548
break;
549+
}
540550

541551
case SyntaxKind.VariableStatement:
542552
Object.assign(result, {
@@ -1145,9 +1155,8 @@ module.exports = function convert(config) {
11451155
}
11461156

11471157
if (node.type) {
1148-
Object.assign(parameter, {
1149-
typeAnnotation: convertTypeAnnotation(node.type)
1150-
});
1158+
parameter.typeAnnotation = convertTypeAnnotation(node.type);
1159+
parameter.range[1] = node.type.getEnd();
11511160
}
11521161

11531162
if (node.questionToken) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
var name:string = "Nicholas";
2+
var foo: string = "Bar";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let x : string;

0 commit comments

Comments
 (0)