From 48e1745d6d5cbec06dbacb926bd4e4f3fe4936f2 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 17 Mar 2020 19:08:57 -0400 Subject: [PATCH] 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> --- src/compiler/utilities.ts | 2 +- src/testRunner/unittests/jsDocParsing.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8f0cabdfc44..2acaa3200fb 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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 diff --git a/src/testRunner/unittests/jsDocParsing.ts b/src/testRunner/unittests/jsDocParsing.ts index 117e8b51a66..0af076df762 100644 --- a/src/testRunner/unittests/jsDocParsing.ts +++ b/src/testRunner/unittests/jsDocParsing.ts @@ -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); + }); }); }