Skip to content

Commit 48e1745

Browse files
dsherretsandersn
andauthored
Fix Node#getStart(sourceFile, true) throwing when node has a js doc and no parent (#37439)
* Fix missing source file argument. * Add test * fix lint Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent c600aa7 commit 48e1745

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ namespace ts {
510510
}
511511

512512
if (includeJsDoc && hasJSDocNodes(node)) {
513-
return getTokenPosOfNode(node.jsDoc![0]);
513+
return getTokenPosOfNode(node.jsDoc![0], sourceFile);
514514
}
515515

516516
// For a syntax list, it is possible that one of its children has JSDocComment nodes, while

src/testRunner/unittests/jsDocParsing.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,9 @@ namespace ts {
342342
assert.equal(last!.kind, SyntaxKind.EndOfFileToken);
343343
});
344344
});
345+
describe("getStart of node with JSDoc but no parent pointers", () => {
346+
const root = createSourceFile("foo.ts", "/** */var a = true;", ScriptTarget.ES5, /*setParentNodes*/ false);
347+
root.statements[0].getStart(root, /*includeJsdocComment*/ true);
348+
});
345349
});
346350
}

0 commit comments

Comments
 (0)