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>
This commit is contained in:
David Sherret 2020-03-17 19:08:57 -04:00 committed by GitHub
parent c600aa7411
commit 48e1745d6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -510,7 +510,7 @@ namespace ts {
}
if (includeJsDoc && hasJSDocNodes(node)) {
return getTokenPosOfNode(node.jsDoc![0]);
return getTokenPosOfNode(node.jsDoc![0], sourceFile);
}
// For a syntax list, it is possible that one of its children has JSDocComment nodes, while

View File

@ -342,5 +342,9 @@ namespace ts {
assert.equal(last!.kind, SyntaxKind.EndOfFileToken);
});
});
describe("getStart of node with JSDoc but no parent pointers", () => {
const root = createSourceFile("foo.ts", "/** */var a = true;", ScriptTarget.ES5, /*setParentNodes*/ false);
root.statements[0].getStart(root, /*includeJsdocComment*/ true);
});
});
}