Skip to content

Commit 3bf4f2a

Browse files
committed
PR feedback, removed now-redundant getUniqueClone
1 parent 4db1448 commit 3bf4f2a

4 files changed

Lines changed: 12 additions & 26 deletions

File tree

src/compiler/comments.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,9 @@ namespace ts {
8282
function getLeadingComments(range: TextRange): CommentRange[];
8383
function getLeadingComments(range: TextRange, contextNode: Node, ignoreNodeCallback: (contextNode: Node) => boolean, getTextRangeCallback: (contextNode: Node) => TextRange): CommentRange[];
8484
function getLeadingComments(range: TextRange, contextNode?: Node, ignoreNodeCallback?: (contextNode: Node) => boolean, getTextRangeCallback?: (contextNode: Node) => TextRange) {
85-
let comments: CommentRange[] = [];
86-
let ignored = false;
8785
if (contextNode) {
8886
range = getTextRangeCallback(contextNode) || range;
8987
if (ignoreNodeCallback(contextNode)) {
90-
ignored = true;
9188
// If the node will not be emitted in JS, remove all the comments (normal,
9289
// pinned and `///`) associated with the node, unless it is a triple slash
9390
// comment at the top of the file.
@@ -101,16 +98,14 @@ namespace ts {
10198
// The first `///` will NOT be removed while the second one will be removed
10299
// even though both nodes will not be emitted.
103100
if (range.pos === 0) {
104-
comments = filter(getLeadingCommentsOfPosition(0), isTripleSlashComment);
101+
return filter(getLeadingCommentsOfPosition(0), isTripleSlashComment);
105102
}
106-
}
107-
}
108103

109-
if (!ignored) {
110-
comments = getLeadingCommentsOfPosition(range.pos);
104+
return;
105+
}
111106
}
112107

113-
return comments;
108+
return getLeadingCommentsOfPosition(range.pos);
114109
}
115110

116111
/**

src/compiler/factory.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,6 @@ namespace ts {
9191
return clone;
9292
}
9393

94-
/**
95-
* Gets a clone of a node with a unique node ID.
96-
*/
97-
export function getUniqueClone<T extends Node>(node: T): T {
98-
const clone = getMutableClone(node);
99-
clone.id = 0;
100-
getNodeId(clone);
101-
return clone;
102-
}
103-
10494
// Literals
10595

10696
export function createLiteral(textSource: StringLiteral | Identifier, location?: TextRange): StringLiteral;
@@ -821,8 +811,9 @@ namespace ts {
821811
}
822812

823813
function createReactNamespace(reactNamespace: string, parent: JsxOpeningLikeElement) {
824-
// Create an identifier and give it a parent. This allows us to resolve the react
825-
// namespace during emit.
814+
// To ensure the emit resolver can properly resolve the namespace, we need to
815+
// treat this identifier as if it were a source tree node by clearing the `Synthesized`
816+
// flag and setting a parent node.
826817
const react = createIdentifier(reactNamespace || "React");
827818
react.flags &= ~NodeFlags.Synthesized;
828819
react.parent = parent;

src/compiler/transformers/es6.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ namespace ts {
10031003
}
10041004

10051005
// `declarationName` is the name of the local declaration for the parameter.
1006-
const declarationName = getUniqueClone(<Identifier>parameter.name);
1006+
const declarationName = getMutableClone(<Identifier>parameter.name);
10071007
setNodeEmitFlags(declarationName, NodeEmitFlags.NoSourceMap);
10081008

10091009
// `expressionName` is the name of the parameter used in expressions.
@@ -2916,7 +2916,7 @@ namespace ts {
29162916
*/
29172917
function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: NodeEmitFlags) {
29182918
if (node.name && !isGeneratedIdentifier(node.name)) {
2919-
const name = getUniqueClone(node.name);
2919+
const name = getMutableClone(node.name);
29202920
emitFlags |= getNodeEmitFlags(node.name);
29212921
if (!allowSourceMaps) {
29222922
emitFlags |= NodeEmitFlags.NoSourceMap;

src/compiler/transformers/ts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,10 +928,10 @@ namespace ts {
928928
function transformParameterWithPropertyAssignment(node: ParameterDeclaration) {
929929
Debug.assert(isIdentifier(node.name));
930930
const name = node.name as Identifier;
931-
const propertyName = getUniqueClone(name);
931+
const propertyName = getMutableClone(name);
932932
setNodeEmitFlags(propertyName, NodeEmitFlags.NoComments | NodeEmitFlags.NoSourceMap);
933933

934-
const localName = getUniqueClone(name);
934+
const localName = getMutableClone(name);
935935
setNodeEmitFlags(localName, NodeEmitFlags.NoComments);
936936

937937
return startOnNewLine(
@@ -2922,7 +2922,7 @@ namespace ts {
29222922
*/
29232923
function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: NodeEmitFlags) {
29242924
if (node.name) {
2925-
const name = getUniqueClone(node.name);
2925+
const name = getMutableClone(node.name);
29262926
emitFlags |= getNodeEmitFlags(node.name);
29272927
if (!allowSourceMaps) {
29282928
emitFlags |= NodeEmitFlags.NoSourceMap;

0 commit comments

Comments
 (0)