From fde6f22408881bd3e0008938cbed2ddf5be9766d Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 7 Jun 2018 14:28:06 -0700 Subject: [PATCH] Fix bug: In newFileChanges, setParentNodes in new source file (#24765) --- src/services/textChanges.ts | 2 +- tests/cases/fourslash/moveToNewFile_jsx.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/moveToNewFile_jsx.ts diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 02c29b0568..c37969f19c 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 0000000000..b969794af3 --- /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
;`, + } +});