Skip to content

Commit 9b424d7

Browse files
crisbetoatscott
authored andcommitted
fix(compiler-cli): preserve original reference to non-deferrable dependency (#54759)
Fixes an issue where we were outputting the reference to non-deferrable dependencies as strings, rather than going through the reference emitter. This caused some issues internally because the reference wasn't maintained in the generated JS. PR Close #54759
1 parent 83932aa commit 9b424d7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ export class ComponentDecoratorHandler implements
12641264
for (const [_, deps] of resolution.deferBlockDependencies) {
12651265
for (const deferBlockDep of deps) {
12661266
const importDecl =
1267-
resolution.deferrableDeclToImportDecl.get(deferBlockDep.type.node) ?? null;
1267+
resolution.deferrableDeclToImportDecl.get(deferBlockDep.declaration.node) ?? null;
12681268
if (importDecl !== null && this.deferredSymbolTracker.canDefer(importDecl)) {
12691269
deferBlockDep.isDeferrable = true;
12701270
deferBlockDep.importPath = (importDecl.moduleSpecifier as ts.StringLiteral).text;
@@ -1375,11 +1375,12 @@ export class ComponentDecoratorHandler implements
13751375
// `isDeferrable`, `importPath` and `isDefaultImport` will be
13761376
// added later during the `compile` step.
13771377
deps.push({
1378-
type: decl.ref,
1378+
typeReference: decl.type,
13791379
symbolName: decl.ref.node.name.text,
13801380
isDeferrable: false,
13811381
importPath: null,
13821382
isDefaultImport: false,
1383+
declaration: decl.ref,
13831384
});
13841385
allDeferredDecls.add(decl.ref.node);
13851386
}
@@ -1502,8 +1503,10 @@ export class ComponentDecoratorHandler implements
15021503
(new o.DynamicImportExpr(dep.importPath!)).prop('then').callFn([innerFn]);
15031504
depExpressions.push(importExpr);
15041505
} else {
1505-
// Non-deferrable symbol, just use a reference to the type.
1506-
depExpressions.push(o.variable(dep.symbolName));
1506+
// Non-deferrable symbol, just use a reference to the type. Note that it's important to
1507+
// go through `typeReference`, rather than `symbolName` in order to preserve the
1508+
// original reference within the source file.
1509+
depExpressions.push(dep.typeReference);
15071510
}
15081511
}
15091512
blocks.set(

packages/compiler-cli/src/ngtsc/annotations/component/src/metadata.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {AnimationTriggerNames, DeclarationListEmitMode, DeferBlockDepsEmitMode, R3ClassDebugInfo, R3ClassMetadata, R3ComponentMetadata, R3TemplateDependencyMetadata, SchemaMetadata, TmplAstDeferredBlock} from '@angular/compiler';
9+
import {AnimationTriggerNames, DeclarationListEmitMode, DeferBlockDepsEmitMode, Expression, R3ClassDebugInfo, R3ClassMetadata, R3ComponentMetadata, R3TemplateDependencyMetadata, SchemaMetadata, TmplAstDeferredBlock} from '@angular/compiler';
1010
import ts from 'typescript';
1111

1212
import {Reference} from '../../../imports';
@@ -125,7 +125,7 @@ export interface DeferredComponentDependency {
125125
/**
126126
* Reference to a dependency.
127127
*/
128-
type: Reference<ClassDeclaration>;
128+
typeReference: Expression;
129129

130130
/**
131131
* Dependency class name.
@@ -146,4 +146,7 @@ export interface DeferredComponentDependency {
146146
* Whether the symbol is the default export.
147147
*/
148148
isDefaultImport: boolean;
149+
150+
/** Reference to the declaration that defines the dependency. */
151+
declaration: Reference<ClassDeclaration>;
149152
}

0 commit comments

Comments
 (0)