Skip to content

Commit b26783f

Browse files
ivanwonderjosmar-crwdstffng
authored andcommitted
fix(compiler-cli): Support resolve animation name from the DTS (angular#45107)
Before this, the compiler resolves the value in the DTS as dynamic. If the `trigger` is imported from `@angular/animations`, this PR will use FFR to simulate the actual implementation in JS and extracts the animation name. PR Close angular#45107
1 parent 4b77882 commit b26783f

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {ComponentAnalysisData, ComponentResolutionData} from './metadata';
3535
import {_extractTemplateStyleUrls, extractComponentStyleUrls, extractStyleResources, extractTemplate, makeResourceNotFoundError, ParsedTemplateWithSource, parseTemplateDeclaration, preloadAndParseTemplate, ResourceTypeForDiagnostics, StyleUrlMeta, transformDecoratorToInlineResources} from './resources';
3636
import {scopeTemplate} from './scope';
3737
import {ComponentSymbol} from './symbol';
38-
import {collectAnimationNames, validateAndFlattenComponentImports} from './util';
38+
import {animationTriggerResolver, collectAnimationNames, validateAndFlattenComponentImports} from './util';
3939

4040
const EMPTY_MAP = new Map<string, Expression>();
4141
const EMPTY_ARRAY: any[] = [];
@@ -210,8 +210,10 @@ export class ComponentDecoratorHandler implements
210210
let animations: Expression|null = null;
211211
let animationTriggerNames: AnimationTriggerNames|null = null;
212212
if (component.has('animations')) {
213-
animations = new WrappedNodeExpr(component.get('animations')!);
214-
const animationsValue = this.evaluator.evaluate(component.get('animations')!);
213+
const animationExpression = component.get('animations')!;
214+
animations = new WrappedNodeExpr(animationExpression);
215+
const animationsValue =
216+
this.evaluator.evaluate(animationExpression, animationTriggerResolver);
215217
animationTriggerNames = {includesDynamicAnimations: false, staticTriggerNames: []};
216218
collectAnimationNames(animationsValue, animationTriggerNames);
217219
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {AnimationTriggerNames} from '@angular/compiler';
1010
import ts from 'typescript';
1111

1212
import {Reference} from '../../../imports';
13-
import {ResolvedValue} from '../../../partial_evaluator';
13+
import {ForeignFunctionResolver, ResolvedValue} from '../../../partial_evaluator';
1414
import {ClassDeclaration, isNamedClassDeclaration} from '../../../reflection';
1515
import {createValueHasWrongTypeError} from '../../common';
1616

@@ -38,6 +38,28 @@ export function collectAnimationNames(
3838
}
3939
}
4040

41+
export function isAngularAnimationsReference(reference: Reference, symbolName: string): boolean {
42+
return reference.ownedByModuleGuess === '@angular/animations' &&
43+
reference.debugName === symbolName;
44+
}
45+
46+
export const animationTriggerResolver: ForeignFunctionResolver = (ref, args) => {
47+
const animationTriggerMethodName = 'trigger';
48+
if (!isAngularAnimationsReference(ref, animationTriggerMethodName)) {
49+
return null;
50+
}
51+
const triggerNameExpression = args[0];
52+
if (!triggerNameExpression) {
53+
return null;
54+
}
55+
const factory = ts.factory;
56+
return factory.createObjectLiteralExpression(
57+
[
58+
factory.createPropertyAssignment(factory.createIdentifier('name'), triggerNameExpression),
59+
],
60+
true);
61+
};
62+
4163
export function validateAndFlattenComponentImports(imports: ResolvedValue, expr: ts.Expression): {
4264
imports: Reference<ClassDeclaration>[],
4365
diagnostics: ts.Diagnostic[],

0 commit comments

Comments
 (0)