diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 02c29b0568dd9..c37969f19c245 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -735,7 +735,7 @@ namespace ts.textChanges { export function newFileChanges(oldFile: SourceFile, fileName: string, statements: ReadonlyArray, newLineCharacter: string, formatContext: formatting.FormatContext): FileTextChanges { // TODO: this emits the file, parses it back, then formats it that -- may be a less roundabout way to do this const nonFormattedText = statements.map(s => getNonformattedText(s, oldFile, newLineCharacter).text).join(newLineCharacter); - const sourceFile = createSourceFile(fileName, nonFormattedText, ScriptTarget.ESNext); + const sourceFile = createSourceFile(fileName, nonFormattedText, ScriptTarget.ESNext, /*setParentNodes*/ true); const changes = formatting.formatDocument(sourceFile, formatContext); const text = applyChanges(nonFormattedText, changes); return { fileName, textChanges: [createTextChange(createTextSpan(0, 0), text)], isNewFile: true }; diff --git a/tests/cases/fourslash/moveToNewFile_jsx.ts b/tests/cases/fourslash/moveToNewFile_jsx.ts new file mode 100644 index 0000000000000..b969794af3057 --- /dev/null +++ b/tests/cases/fourslash/moveToNewFile_jsx.ts @@ -0,0 +1,14 @@ +/// + +// @Filename: /a.tsx +////[|
a
;|] + +verify.moveToNewFile({ + newFileContents: { + "/a.tsx": +``, + + "/newFile.tsx": +`
a
;`, + } +});