Skip to content

Commit f3dea42

Browse files
authored
Use ts.getParseTreeNode before getSourceFile to handle transformer output (#1010)
* Use getParseTreeNode before getSourceFile * npm audit fix
1 parent c09f98c commit f3dea42

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

package-lock.json

Lines changed: 16 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LuaAST.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ export function setNodeOriginal<T extends Node>(node: T | undefined, tsOriginal:
174174
}
175175

176176
function getSourcePosition(sourceNode: ts.Node): TextRange | undefined {
177-
if (sourceNode.getSourceFile() !== undefined && sourceNode.pos >= 0) {
177+
const parseTreeNode = ts.getParseTreeNode(sourceNode) ?? sourceNode;
178+
const sourceFile = parseTreeNode.getSourceFile();
179+
if (sourceFile !== undefined && parseTreeNode.pos >= 0) {
178180
const { line, character } = ts.getLineAndCharacterOfPosition(
179-
sourceNode.getSourceFile(),
180-
sourceNode.pos + sourceNode.getLeadingTriviaWidth()
181+
sourceFile,
182+
parseTreeNode.pos + parseTreeNode.getLeadingTriviaWidth()
181183
);
182184

183185
return { line, column: character };

src/transformation/utils/typescript/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export function getFirstDeclarationInFile(symbol: ts.Symbol, sourceFile: ts.Sour
3232
}
3333

3434
function isStandardLibraryDeclaration(context: TransformationContext, declaration: ts.Declaration): boolean {
35-
const sourceFile = declaration.getSourceFile();
35+
const parseTreeNode = ts.getParseTreeNode(declaration) ?? declaration;
36+
const sourceFile = parseTreeNode.getSourceFile();
3637
if (!sourceFile) {
3738
return false;
3839
}

0 commit comments

Comments
 (0)