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

This commit is contained in:
Andy 2018-06-07 15:09:44 -07:00 committed by GitHub
parent 59134dc2bd
commit b05e916824
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>;`,
}
});