Fix bug: In newFileChanges, setParentNodes in new source file (#24765)
This commit is contained in:
parent
eab5b5105c
commit
fde6f22408
|
@ -735,7 +735,7 @@ namespace ts.textChanges {
|
||||||
export function newFileChanges(oldFile: SourceFile, fileName: string, statements: ReadonlyArray<Statement>, newLineCharacter: string, formatContext: formatting.FormatContext): FileTextChanges {
|
export function newFileChanges(oldFile: SourceFile, fileName: string, statements: ReadonlyArray<Statement>, 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
|
// 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 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 changes = formatting.formatDocument(sourceFile, formatContext);
|
||||||
const text = applyChanges(nonFormattedText, changes);
|
const text = applyChanges(nonFormattedText, changes);
|
||||||
return { fileName, textChanges: [createTextChange(createTextSpan(0, 0), text)], isNewFile: true };
|
return { fileName, textChanges: [createTextChange(createTextSpan(0, 0), text)], isNewFile: true };
|
||||||
|
|
14
tests/cases/fourslash/moveToNewFile_jsx.ts
Normal file
14
tests/cases/fourslash/moveToNewFile_jsx.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/// <reference path='fourslash.ts' />
|
||||||
|
|
||||||
|
// @Filename: /a.tsx
|
||||||
|
////[|<div>a</div>;|]
|
||||||
|
|
||||||
|
verify.moveToNewFile({
|
||||||
|
newFileContents: {
|
||||||
|
"/a.tsx":
|
||||||
|
``,
|
||||||
|
|
||||||
|
"/newFile.tsx":
|
||||||
|
`<div>a</div>;`,
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue