Skip to content

Commit 55b3804

Browse files
author
Andy
committed
Fix bug: In newFileChanges, setParentNodes in new source file (#24765)
1 parent b2ad86d commit 55b3804

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/services/textChanges.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ namespace ts.textChanges {
735735
export function newFileChanges(oldFile: SourceFile, fileName: string, statements: ReadonlyArray<Statement>, newLineCharacter: string, formatContext: formatting.FormatContext): FileTextChanges {
736736
// TODO: this emits the file, parses it back, then formats it that -- may be a less roundabout way to do this
737737
const nonFormattedText = statements.map(s => getNonformattedText(s, oldFile, newLineCharacter).text).join(newLineCharacter);
738-
const sourceFile = createSourceFile(fileName, nonFormattedText, ScriptTarget.ESNext);
738+
const sourceFile = createSourceFile(fileName, nonFormattedText, ScriptTarget.ESNext, /*setParentNodes*/ true);
739739
const changes = formatting.formatDocument(sourceFile, formatContext);
740740
const text = applyChanges(nonFormattedText, changes);
741741
return { fileName, textChanges: [createTextChange(createTextSpan(0, 0), text)], isNewFile: true };
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /a.tsx
4+
////[|<div>a</div>;|]
5+
6+
verify.moveToNewFile({
7+
newFileContents: {
8+
"/a.tsx":
9+
``,
10+
11+
"/newFile.tsx":
12+
`<div>a</div>;`,
13+
}
14+
});

0 commit comments

Comments
 (0)