diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 7ad380f06af..79bb795efe5 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -82,12 +82,9 @@ namespace ts { function getLeadingComments(range: TextRange): CommentRange[]; function getLeadingComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean, getTextRangeCallback: (contextNode: Node) => TextRange): CommentRange[]; function getLeadingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange) { - let comments: CommentRange[] = []; - let ignored = false; if (contextNode) { range = getTextRangeCallback(contextNode) || range; if (ignoreNodeCallback(contextNode)) { - ignored = true; // If the node will not be emitted in JS, remove all the comments (normal, // pinned and `///`) associated with the node, unless it is a triple slash // comment at the top of the file. @@ -101,16 +98,14 @@ namespace ts { // The first `///` will NOT be removed while the second one will be removed // even though both nodes will not be emitted. if (range.pos === 0) { - comments = filter(getLeadingCommentsOfPosition(0), isTripleSlashComment); + return filter(getLeadingCommentsOfPosition(0), isTripleSlashComment); } + + return; } } - if (!ignored) { - comments = getLeadingCommentsOfPosition(range.pos); - } - - return comments; + return getLeadingCommentsOfPosition(range.pos); } /** diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 2fc5a437565..d04d7f0fd0d 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -91,16 +91,6 @@ namespace ts { return clone; } - /** - * Gets a clone of a node with a unique node ID. - */ - export function getUniqueClone(node: T): T { - const clone = getMutableClone(node); - clone.id = 0; - getNodeId(clone); - return clone; - } - // Literals export function createLiteral(textSource: StringLiteral | Identifier, location?: TextRange): StringLiteral; @@ -821,8 +811,9 @@ namespace ts { } function createReactNamespace(reactNamespace: string, parent: JsxOpeningLikeElement) { - // Create an identifier and give it a parent. This allows us to resolve the react - // namespace during emit. + // To ensure the emit resolver can properly resolve the namespace, we need to + // treat this identifier as if it were a source tree node by clearing the `Synthesized` + // flag and setting a parent node. const react = createIdentifier(reactNamespace || "React"); react.flags &= ~NodeFlags.Synthesized; react.parent = parent; diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index e2d41783982..1c412f98af7 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -1003,7 +1003,7 @@ namespace ts { } // `declarationName` is the name of the local declaration for the parameter. - const declarationName = getUniqueClone(parameter.name); + const declarationName = getMutableClone(parameter.name); setNodeEmitFlags(declarationName, NodeEmitFlags.NoSourceMap); // `expressionName` is the name of the parameter used in expressions. @@ -2916,7 +2916,7 @@ namespace ts { */ function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: NodeEmitFlags) { if (node.name && !isGeneratedIdentifier(node.name)) { - const name = getUniqueClone(node.name); + const name = getMutableClone(node.name); emitFlags |= getNodeEmitFlags(node.name); if (!allowSourceMaps) { emitFlags |= NodeEmitFlags.NoSourceMap; diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 488b76cc469..d4f7ea020cb 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -928,10 +928,10 @@ namespace ts { function transformParameterWithPropertyAssignment(node: ParameterDeclaration) { Debug.assert(isIdentifier(node.name)); const name = node.name as Identifier; - const propertyName = getUniqueClone(name); + const propertyName = getMutableClone(name); setNodeEmitFlags(propertyName, NodeEmitFlags.NoComments | NodeEmitFlags.NoSourceMap); - const localName = getUniqueClone(name); + const localName = getMutableClone(name); setNodeEmitFlags(localName, NodeEmitFlags.NoComments); return startOnNewLine( @@ -2922,7 +2922,7 @@ namespace ts { */ function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: NodeEmitFlags) { if (node.name) { - const name = getUniqueClone(node.name); + const name = getMutableClone(node.name); emitFlags |= getNodeEmitFlags(node.name); if (!allowSourceMaps) { emitFlags |= NodeEmitFlags.NoSourceMap;