Fix location/range on TypeScript ExportNamedDeclarations (#9406)
This commit is contained in:
@@ -91,12 +91,16 @@ export class NodeUtils extends UtilParser {
|
||||
return node;
|
||||
}
|
||||
|
||||
resetStartLocation(node: NodeBase, start: number, startLoc: Position): void {
|
||||
node.start = start;
|
||||
node.loc.start = startLoc;
|
||||
if (this.options.ranges) node.range[0] = start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the start location of node to the start location of locationNode
|
||||
*/
|
||||
resetStartLocationFromNode(node: NodeBase, locationNode: NodeBase): void {
|
||||
node.start = locationNode.start;
|
||||
node.loc.start = locationNode.loc.start;
|
||||
if (this.options.ranges) node.range[0] = locationNode.range[0];
|
||||
this.resetStartLocation(node, locationNode.start, locationNode.loc.start);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1853,10 +1853,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
|
||||
parseExportDeclaration(node: N.ExportNamedDeclaration): ?N.Declaration {
|
||||
// Store original location/position
|
||||
const startPos = this.state.start;
|
||||
const startLoc = this.state.startLoc;
|
||||
|
||||
// "export declare" is equivalent to just "export".
|
||||
const isDeclare = this.eatContextual("declare");
|
||||
|
||||
let declaration: ?N.Declaration;
|
||||
|
||||
if (this.match(tt.name)) {
|
||||
declaration = this.tsTryParseExportDeclaration();
|
||||
}
|
||||
@@ -1865,6 +1870,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
|
||||
if (declaration && isDeclare) {
|
||||
// Reset location to include `declare` in range
|
||||
this.resetStartLocation(declaration, startPos, startLoc);
|
||||
|
||||
declaration.declare = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user