mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-07 17:29:36 -05:00
Don't copy trivia when implementing an interface (#23343)
* Don't copy trivia when implementing an interface * Use an `includeTrivia` flag instead of a separate function
This commit is contained in:
@@ -25,8 +25,7 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
const declaration = declarations[0];
|
||||
// Clone name to remove leading trivia.
|
||||
const name = getSynthesizedDeepClone(getNameOfDeclaration(declaration)) as PropertyName;
|
||||
const name = getSynthesizedDeepClone(getNameOfDeclaration(declaration), /*includeTrivia*/ false) as PropertyName;
|
||||
const visibilityModifier = createVisibilityModifier(getModifierFlags(declaration));
|
||||
const modifiers = visibilityModifier ? createNodeArray([visibilityModifier]) : undefined;
|
||||
const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
|
||||
@@ -69,7 +68,7 @@ namespace ts.codefix {
|
||||
|
||||
for (const signature of signatures) {
|
||||
// Need to ensure nodes are fresh each time so they can have different positions.
|
||||
outputMethod(signature, getSynthesizedDeepClones(modifiers), getSynthesizedDeepClone(name));
|
||||
outputMethod(signature, getSynthesizedDeepClones(modifiers, /*includeTrivia*/ false), getSynthesizedDeepClone(name, /*includeTrivia*/ false));
|
||||
}
|
||||
|
||||
if (declarations.length > signatures.length) {
|
||||
@@ -103,10 +102,6 @@ namespace ts.codefix {
|
||||
return signatureDeclaration;
|
||||
}
|
||||
|
||||
function getSynthesizedDeepClones<T extends Node>(nodes: NodeArray<T> | undefined): NodeArray<T> | undefined {
|
||||
return nodes && createNodeArray(nodes.map(getSynthesizedDeepClone));
|
||||
}
|
||||
|
||||
export function createMethodFromCallExpression(
|
||||
{ typeArguments, arguments: args }: CallExpression,
|
||||
methodName: string,
|
||||
|
||||
@@ -1459,11 +1459,13 @@ namespace ts {
|
||||
* WARNING: This is an expensive operation and is only intended to be used in refactorings
|
||||
* and code fixes (because those are triggered by explicit user actions).
|
||||
*/
|
||||
export function getSynthesizedDeepClone<T extends Node>(node: T | undefined): T | undefined {
|
||||
if (node === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
export function getSynthesizedDeepClone<T extends Node>(node: T | undefined, includeTrivia = true): T | undefined {
|
||||
const clone = node && getSynthesizedDeepCloneWorker(node);
|
||||
if (clone && !includeTrivia) suppressLeadingAndTrailingTrivia(clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
function getSynthesizedDeepCloneWorker<T extends Node>(node: T): T | undefined {
|
||||
const visited = visitEachChild(node, getSynthesizedDeepClone, nullTransformationContext);
|
||||
if (visited === node) {
|
||||
// This only happens for leaf nodes - internal nodes always see their children change.
|
||||
@@ -1474,22 +1476,18 @@ namespace ts {
|
||||
else if (isNumericLiteral(clone)) {
|
||||
clone.numericLiteralFlags = (node as any).numericLiteralFlags;
|
||||
}
|
||||
clone.pos = node.pos;
|
||||
clone.end = node.end;
|
||||
return clone;
|
||||
return setTextRange(clone, node);
|
||||
}
|
||||
|
||||
// PERF: As an optimization, rather than calling getSynthesizedClone, we'll update
|
||||
// the new node created by visitEachChild with the extra changes getSynthesizedClone
|
||||
// would have made.
|
||||
|
||||
visited.parent = undefined;
|
||||
|
||||
return visited;
|
||||
}
|
||||
|
||||
export function getSynthesizedDeepClones<T extends Node>(nodes: NodeArray<T> | undefined): NodeArray<T> | undefined {
|
||||
return nodes && createNodeArray(nodes.map(getSynthesizedDeepClone), nodes.hasTrailingComma);
|
||||
export function getSynthesizedDeepClones<T extends Node>(nodes: NodeArray<T> | undefined, includeTrivia = true): NodeArray<T> | undefined {
|
||||
return nodes && createNodeArray(nodes.map(n => getSynthesizedDeepClone(n, includeTrivia)), nodes.hasTrailingComma);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user