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

Commit 92fab2e

Browse files
committed
Fix inner vs outer typeAnnotation ranges
1 parent a60bd85 commit 92fab2e

File tree

3 files changed

+911
-5334
lines changed

3 files changed

+911
-5334
lines changed

lib/convert.js

Lines changed: 10 additions & 1 deletion
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),
@@ -536,8 +536,17 @@ module.exports = function convert(config) {
536536
if (node.type) {
537537
result.id.typeAnnotation = convertTypeAnnotation(node.type);
538538
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+
];
539547
}
540548
break;
549+
}
541550

542551
case SyntaxKind.VariableStatement:
543552
Object.assign(result, {
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)