Skip to content

Commit ba01d63

Browse files
committed
fixup! refactor(ng-update): handle namespaced angular decorators in update-tool
Address feedback
1 parent 57cc00d commit ba01d63

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/cdk/schematics/update-tool/utils/imports.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ export interface Import {
2020
/** Resolves the import of the specified identifier. */
2121
export function getImportOfIdentifier(node: ts.Identifier, typeChecker: ts.TypeChecker): Import|
2222
null {
23+
// Free standing identifiers which resolve to an import will be handled
24+
// as direct imports. e.g. "@Component()" where "Component" is an identifier
25+
// referring to an import specifier.
2326
const directImport = getSpecificImportOfIdentifier(node, typeChecker);
2427
if (directImport !== null) {
2528
return directImport;
2629
} else if (ts.isQualifiedName(node.parent) && node.parent.right === node) {
30+
// Determines the import of a qualified name. e.g. "let t: core.Component". In that
31+
// case, the import of the most left identifier will be determined ("core").
2732
const qualifierRoot = getQualifiedNameRoot(node.parent);
2833
if (qualifierRoot) {
2934
const moduleName = getImportOfNamespacedIdentifier(qualifierRoot, typeChecker);
@@ -32,6 +37,8 @@ export function getImportOfIdentifier(node: ts.Identifier, typeChecker: ts.TypeC
3237
}
3338
}
3439
} else if (ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) {
40+
// Determines the import of a property expression. e.g. "@core.Component". In that
41+
// case, the import of the most left identifier will be determined ("core").
3542
const rootIdentifier = getPropertyAccessRoot(node.parent);
3643
if (rootIdentifier) {
3744
const moduleName = getImportOfNamespacedIdentifier(rootIdentifier, typeChecker);
@@ -57,6 +64,8 @@ function getSpecificImportOfIdentifier(node: ts.Identifier, typeChecker: ts.Type
5764
if (!ts.isImportSpecifier(declaration)) {
5865
return null;
5966
}
67+
// Since the declaration is an import specifier, we can walk up three times to get a reference
68+
// to the import declaration node (NamedImports -> ImportClause -> ImportDeclaration).
6069
const importDecl = declaration.parent.parent.parent;
6170
if (!ts.isStringLiteral(importDecl.moduleSpecifier)) {
6271
return null;
@@ -81,6 +90,8 @@ function getImportOfNamespacedIdentifier(node: ts.Identifier, typeChecker: ts.Ty
8190
if (!ts.isNamespaceImport(declaration)) {
8291
return null;
8392
}
93+
// Since the declaration is a namespace import, we can walk up three times to get a reference
94+
// to the import declaration node (NamespaceImport -> ImportClause -> ImportDeclaration).
8495
const importDecl = declaration.parent.parent;
8596
if (!ts.isStringLiteral(importDecl.moduleSpecifier)) {
8697
return null;

0 commit comments

Comments
 (0)