mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 14:02:43 +08:00
fix(@schematics/angular): linting errors in AST utils spec
This commit is contained in:
parent
86f1884e65
commit
94ca819656
@ -16,8 +16,8 @@ import {
|
||||
addExportToModule,
|
||||
addProviderToModule,
|
||||
addSymbolToNgModuleMetadata,
|
||||
insertAfterLastOccurrence,
|
||||
findNodes,
|
||||
insertAfterLastOccurrence,
|
||||
} from './ast-utils';
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@ function applyChanges(path: string, content: string, changes: Change[]): string
|
||||
return getFileContent(tree, path);
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-big-function
|
||||
describe('ast utils', () => {
|
||||
let modulePath: string;
|
||||
let moduleContent: string;
|
||||
@ -209,20 +210,23 @@ describe('ast utils', () => {
|
||||
});
|
||||
|
||||
describe('insertAfterLastOccurrence', () => {
|
||||
const filePath: string = './src/foo.ts';
|
||||
const filePath = './src/foo.ts';
|
||||
|
||||
it('should work for the default scenario', () => {
|
||||
const fileContent = `const arr = ['foo'];`;
|
||||
const source = getTsSource(filePath, fileContent);
|
||||
const arrayNode = findNodes(source.getChildren().shift() as ts.Node, ts.SyntaxKind.ArrayLiteralExpression);
|
||||
const arrayNode = findNodes(
|
||||
source.getChildren().shift() as ts.Node,
|
||||
ts.SyntaxKind.ArrayLiteralExpression,
|
||||
);
|
||||
const elements = (arrayNode.pop() as ts.ArrayLiteralExpression).elements;
|
||||
|
||||
const change = insertAfterLastOccurrence(
|
||||
elements as any as ts.Node[],
|
||||
elements as unknown as ts.Node[],
|
||||
`, 'bar'`,
|
||||
filePath,
|
||||
elements.pos,
|
||||
ts.SyntaxKind.StringLiteral
|
||||
ts.SyntaxKind.StringLiteral,
|
||||
);
|
||||
const output = applyChanges(filePath, fileContent, [change]);
|
||||
|
||||
@ -233,15 +237,18 @@ describe('ast utils', () => {
|
||||
it('should work without occurrences', () => {
|
||||
const fileContent = `const arr = [];`;
|
||||
const source = getTsSource(filePath, fileContent);
|
||||
const arrayNode = findNodes(source.getChildren().shift() as ts.Node, ts.SyntaxKind.ArrayLiteralExpression);
|
||||
const arrayNode = findNodes(
|
||||
source.getChildren().shift() as ts.Node,
|
||||
ts.SyntaxKind.ArrayLiteralExpression,
|
||||
);
|
||||
const elements = (arrayNode.pop() as ts.ArrayLiteralExpression).elements;
|
||||
|
||||
const change = insertAfterLastOccurrence(
|
||||
elements as any as ts.Node[],
|
||||
elements as unknown as ts.Node[],
|
||||
`'bar'`,
|
||||
filePath,
|
||||
elements.pos,
|
||||
ts.SyntaxKind.StringLiteral
|
||||
ts.SyntaxKind.StringLiteral,
|
||||
);
|
||||
const output = applyChanges(filePath, fileContent, [change]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user