From e2a1a78dd30ea9f025b3990b73d68ecbb3eec160 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 2 Jun 2016 13:26:15 -0700 Subject: [PATCH] reuse the fixupParentReferences function --- src/compiler/parser.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e377f988d55..b24dd85f2f0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -444,19 +444,7 @@ namespace ts { if (result && result.jsDocComment) { // because the jsDocComment was parsed out of the source file, it might // not be covered by the fixupParentReferences. - let parentNode: Node = result.jsDocComment; - forEachChild(result.jsDocComment, visitNode); - - function visitNode(n: Node): void { - if (n.parent === undefined) { - n.parent = parentNode; - - const saveParent = parentNode; - parentNode = n; - forEachChild(n, visitNode); - parentNode = saveParent; - } - } + Parser.fixupParentReferences(result.jsDocComment); } return result; @@ -671,14 +659,14 @@ namespace ts { return node; } - export function fixupParentReferences(sourceFile: Node) { + export function fixupParentReferences(rootNode: Node) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary // overhead. This functions allows us to set all the parents, without all the expense of // binding. - let parent: Node = sourceFile; - forEachChild(sourceFile, visitNode); + let parent: Node = rootNode; + forEachChild(rootNode, visitNode); return; function visitNode(n: Node): void {