Skip to content

Commit e9e1d0d

Browse files
author
Andy
authored
textChanges: Use InsertNodeOptions instead of ChangeNodeOptions where possible (microsoft#22903)
1 parent 85f11cc commit e9e1d0d

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

src/services/textChanges.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ namespace ts.textChanges {
374374
this.insertNodesAt(sourceFile, start, typeParameters, { prefix: "<", suffix: ">" });
375375
}
376376

377-
private getOptionsForInsertNodeBefore(before: Node, doubleNewlines: boolean): ChangeNodeOptions {
377+
private getOptionsForInsertNodeBefore(before: Node, doubleNewlines: boolean): InsertNodeOptions {
378378
if (isStatement(before) || isClassElement(before)) {
379379
return { suffix: doubleNewlines ? this.newLineCharacter + this.newLineCharacter : this.newLineCharacter };
380380
}
@@ -645,20 +645,17 @@ namespace ts.textChanges {
645645
}
646646

647647
/** Note: this may mutate `nodeIn`. */
648-
function getFormattedTextOfNode(nodeIn: Node, sourceFile: SourceFile, pos: number, options: InsertNodeOptions, newLineCharacter: string, formatContext: formatting.FormatContext, validate: ValidateNonFormattedText): string {
648+
function getFormattedTextOfNode(nodeIn: Node, sourceFile: SourceFile, pos: number, { indentation, prefix, delta }: InsertNodeOptions, newLineCharacter: string, formatContext: formatting.FormatContext, validate: ValidateNonFormattedText): string {
649649
const { node, text } = getNonformattedText(nodeIn, sourceFile, newLineCharacter);
650650
if (validate) validate(node, text);
651651
const { options: formatOptions } = formatContext;
652652
const initialIndentation =
653-
options.indentation !== undefined
654-
? options.indentation
655-
: formatting.SmartIndenter.getIndentation(pos, sourceFile, formatOptions, options.prefix === newLineCharacter || getLineStartPositionForPosition(pos, sourceFile) === pos);
656-
const delta =
657-
options.delta !== undefined
658-
? options.delta
659-
: formatting.SmartIndenter.shouldIndentChildNode(nodeIn)
660-
? (formatOptions.indentSize || 0)
661-
: 0;
653+
indentation !== undefined
654+
? indentation
655+
: formatting.SmartIndenter.getIndentation(pos, sourceFile, formatOptions, prefix === newLineCharacter || getLineStartPositionForPosition(pos, sourceFile) === pos);
656+
if (delta === undefined) {
657+
delta = formatting.SmartIndenter.shouldIndentChildNode(nodeIn) ? (formatOptions.indentSize || 0) : 0;
658+
}
662659
const file: SourceFileLike = { text, getLineAndCharacterOfPosition(pos) { return getLineAndCharacterOfPosition(this, pos); } };
663660
const changes = formatting.formatNodeGivenIndentation(node, file, sourceFile.languageVariant, initialIndentation, delta, formatContext);
664661
return applyChanges(text, changes);

0 commit comments

Comments
 (0)