Skip to content

Commit 8c81571

Browse files
committed
fix(@schematics/angular): retain existing EOL when adding imports
This commit updates the AST utility to retain the existing EOF when adding imports (cherry picked from commit dfde275)
1 parent 7f395be commit 8c81571

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/schematics/angular/utility/ast-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { tags } from '@angular-devkit/core';
1010
import * as ts from '../third_party/github.com/Microsoft/TypeScript/lib/typescript';
1111
import { Change, InsertChange, NoopChange } from './change';
12+
import { getEOL } from './eol';
1213

1314
/**
1415
* Add Import `import { symbolName } from fileName` if the import doesn't exit
@@ -73,12 +74,13 @@ export function insertImport(
7374
}
7475
const open = isDefault ? '' : '{ ';
7576
const close = isDefault ? '' : ' }';
77+
const eol = getEOL(rootNode.getText());
7678
// if there are no imports or 'use strict' statement, insert import at beginning of file
7779
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
78-
const separator = insertAtBeginning ? '' : ';\n';
80+
const separator = insertAtBeginning ? '' : `;${eol}`;
7981
const toInsert =
8082
`${separator}import ${open}${importExpression}${close}` +
81-
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
83+
` from '${fileName}'${insertAtBeginning ? `;${eol}` : ''}`;
8284

8385
return insertAfterLastOccurrence(
8486
allImports,

0 commit comments

Comments
 (0)