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

Fix: Location data for methods and constructors #357

Merged
merged 1 commit into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,9 @@ module.exports = function convert(config) {
case SyntaxKind.SetAccessor:
case SyntaxKind.MethodDeclaration: {

// TODO: double-check that these positions are correct
const methodLoc = ast.getLineAndCharacterOfPosition(node.name.end + 1),
const openingParen = nodeUtils.findNextToken(node.name, ast);

const methodLoc = ast.getLineAndCharacterOfPosition(openingParen.getStart()),
nodeIsMethod = (node.kind === SyntaxKind.MethodDeclaration),
method = {
type: AST_NODE_TYPES.FunctionExpression,
Expand All @@ -758,7 +759,7 @@ module.exports = function convert(config) {
loc: {
start: {
line: methodLoc.line + 1,
column: methodLoc.character - 1
column: methodLoc.character
},
end: result.loc.end
}
Expand Down Expand Up @@ -865,7 +866,8 @@ module.exports = function convert(config) {
}
};

const constructorIdentifierLoc = ast.getLineAndCharacterOfPosition(firstConstructorToken.getStart()),
const constructorIdentifierLocStart = ast.getLineAndCharacterOfPosition(firstConstructorToken.getStart()),
constructorIdentifierLocEnd = ast.getLineAndCharacterOfPosition(firstConstructorToken.getEnd()),
constructorIsComputed = !!node.name && nodeUtils.isComputedProperty(node.name);

let constructorKey;
Expand All @@ -878,12 +880,12 @@ module.exports = function convert(config) {
range: [firstConstructorToken.getStart(), firstConstructorToken.end],
loc: {
start: {
line: constructorIdentifierLoc.line + 1,
column: constructorIdentifierLoc.character
line: constructorIdentifierLocStart.line + 1,
column: constructorIdentifierLocStart.character
},
end: {
line: constructor.loc.start.line,
column: constructor.loc.start.column
line: constructorIdentifierLocEnd.line + 1,
column: constructorIdentifierLocEnd.character
}
}
};
Expand All @@ -894,12 +896,12 @@ module.exports = function convert(config) {
range: [firstConstructorToken.getStart(), firstConstructorToken.end],
loc: {
start: {
line: constructorIdentifierLoc.line + 1,
column: constructorIdentifierLoc.character
line: constructorIdentifierLocStart.line + 1,
column: constructorIdentifierLocStart.character
},
end: {
line: constructor.loc.start.line,
column: constructor.loc.start.column
line: constructorIdentifierLocEnd.line + 1,
column: constructorIdentifierLocEnd.character
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/__snapshots__/ecma-features.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10441,7 +10441,7 @@ Object {
"line": 1,
},
"start": Object {
"column": 18,
"column": 19,
"line": 1,
},
},
Expand Down Expand Up @@ -18360,7 +18360,7 @@ Object {
"key": Object {
"loc": Object {
"end": Object {
"column": 21,
"column": 20,
"line": 1,
},
"start": Object {
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/__snapshots__/typescript.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ Object {
"key": Object {
"loc": Object {
"end": Object {
"column": 24,
"column": 12,
"line": 2,
},
"start": Object {
Expand Down Expand Up @@ -4744,7 +4744,7 @@ Object {
"line": 6,
},
"start": Object {
"column": 15,
"column": 16,
"line": 4,
},
},
Expand Down Expand Up @@ -4931,7 +4931,7 @@ Object {
"line": 9,
},
"start": Object {
"column": 18,
"column": 19,
"line": 7,
},
},
Expand Down