Skip to content

Commit e48a44b

Browse files
gkalpakfilipesilva
authored andcommitted
refactor(@schematics/angular): remove dead code paths from addSymbolToNgModuleMetadata()
(cherry picked from commit 515f042)
1 parent 45cdbc7 commit e48a44b

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,6 @@ export function addSymbolToNgModuleMetadata(
358358
metadataField,
359359
);
360360

361-
// Get the last node of the array literal.
362-
if (!matchingProperties) {
363-
return [];
364-
}
365361
if (matchingProperties.length == 0) {
366362
// We haven't found the field in the metadata declaration. Insert a new field.
367363
const expr = node as ts.ObjectLiteralExpression;
@@ -406,13 +402,6 @@ export function addSymbolToNgModuleMetadata(
406402
node = arrLiteral.elements;
407403
}
408404

409-
if (!node) {
410-
// tslint:disable-next-line: no-console
411-
console.error('No app module found. Please add your new class to your component.');
412-
413-
return [];
414-
}
415-
416405
if (Array.isArray(node)) {
417406
const nodeArray = node as {} as Array<ts.Node>;
418407
const symbolsArray = nodeArray.map(node => node.getText());
@@ -425,23 +414,7 @@ export function addSymbolToNgModuleMetadata(
425414

426415
let toInsert: string;
427416
let position = node.getEnd();
428-
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
429-
// We haven't found the field in the metadata declaration. Insert a new
430-
// field.
431-
const expr = node as ts.ObjectLiteralExpression;
432-
if (expr.properties.length == 0) {
433-
position = expr.getEnd() - 1;
434-
toInsert = ` ${symbolName}\n`;
435-
} else {
436-
// Get the indentation of the last element, if any.
437-
const text = node.getFullText(source);
438-
if (text.match(/^\r?\r?\n/)) {
439-
toInsert = `,${text.match(/^\r?\n\s*/)[0]}${symbolName}`;
440-
} else {
441-
toInsert = `, ${symbolName}`;
442-
}
443-
}
444-
} else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
417+
if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
445418
// We found the field but it's empty. Insert it just before the `]`.
446419
position--;
447420
toInsert = `${symbolName}`;

0 commit comments

Comments
 (0)