Fix bug: In newFileChanges, setParentNodes in new source file (#24765)

This commit is contained in:
Andy 2018-06-07 14:28:06 -07:00 committed by GitHub
parent eab5b5105c
commit fde6f22408
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -735,7 +735,7 @@ namespace ts.textChanges {
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
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 };

View 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>;`,
}
});