Skip to content

Commit

Permalink
fix(compiler): no longer uses assetCacheKey for token identity.
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckjaz authored and tbosch committed Aug 29, 2016
1 parent af63378 commit d8983d2
Show file tree
Hide file tree
Showing 27 changed files with 588 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export class StaticAndDynamicReflectionCapabilities {
setter(name: string) { return this.dynamicDelegate.setter(name); }
method(name: string) { return this.dynamicDelegate.method(name); }
importUri(type: any): string { return this.staticDelegate.importUri(type); }
resolveType(name: string, moduleUrl: string) {
return this.staticDelegate.resolveType(name, moduleUrl);
}
resolveEnum(enumType: any, name: string): any {
if (isStaticType(enumType)) {
return this.staticDelegate.resolveEnum(enumType, name);
} else {
return null;
}
}
}

function isStaticType(type: any): boolean {
Expand Down
10 changes: 10 additions & 0 deletions modules/@angular/compiler-cli/src/static_reflector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ export class StaticReflector implements ReflectorReader {
return staticSymbol ? staticSymbol.filePath : null;
}

resolveType(name: string, moduleUrl: string): any {
const result = this.host.findDeclaration(moduleUrl, name, '');
return result;
}

resolveEnum(enumType: any, name: string): any {
const staticSymbol: StaticSymbol = enumType;
return this.host.getStaticSymbol(staticSymbol.filePath, staticSymbol.name, [name]);
}

public annotations(type: StaticSymbol): any[] {
let annotations = this.annotationCache.get(type);
if (!annotations) {
Expand Down
61 changes: 34 additions & 27 deletions modules/@angular/compiler/src/animation/animation_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {ANY_STATE, AnimationOutput, DEFAULT_STATE, EMPTY_STATE} from '../../core
import {CompileDirectiveMetadata} from '../compile_metadata';
import {StringMapWrapper} from '../facade/collection';
import {isBlank, isPresent} from '../facade/lang';
import {Identifiers} from '../identifiers';
import {Identifiers, resolveIdentifier} from '../identifiers';
import * as o from '../output/output_ast';
import * as t from '../template_parser/template_ast';

Expand Down Expand Up @@ -114,16 +114,16 @@ class _AnimationBuilder implements AnimationAstVisitor {
o.literalMap(StringMapWrapper.keys(entry).map(key => [key, o.literal(entry[key])])));
});

return o.importExpr(Identifiers.AnimationStyles).instantiate([
o.importExpr(Identifiers.collectAndResolveStyles).callFn([
return o.importExpr(resolveIdentifier(Identifiers.AnimationStyles)).instantiate([
o.importExpr(resolveIdentifier(Identifiers.collectAndResolveStyles)).callFn([
_ANIMATION_COLLECTED_STYLES, o.literalArr(stylesArr)
])
]);
}

visitAnimationKeyframe(ast: AnimationKeyframeAst, context: _AnimationBuilderContext):
o.Expression {
return o.importExpr(Identifiers.AnimationKeyframe).instantiate([
return o.importExpr(resolveIdentifier(Identifiers.AnimationKeyframe)).instantiate([
o.literal(ast.offset), ast.styles.visit(this, context)
]);
}
Expand All @@ -144,10 +144,11 @@ class _AnimationBuilder implements AnimationAstVisitor {
_visitEndStateAnimation(ast: AnimationStepAst, context: _AnimationBuilderContext): o.Expression {
var startingStylesExpr = ast.startingStyles.visit(this, context);
var keyframeExpressions = ast.keyframes.map(keyframe => keyframe.visit(this, context));
var keyframesExpr = o.importExpr(Identifiers.balanceAnimationKeyframes).callFn([
_ANIMATION_COLLECTED_STYLES, _ANIMATION_END_STATE_STYLES_VAR,
o.literalArr(keyframeExpressions)
]);
var keyframesExpr =
o.importExpr(resolveIdentifier(Identifiers.balanceAnimationKeyframes)).callFn([
_ANIMATION_COLLECTED_STYLES, _ANIMATION_END_STATE_STYLES_VAR,
o.literalArr(keyframeExpressions)
]);

return this._callAnimateMethod(ast, startingStylesExpr, keyframesExpr, context);
}
Expand All @@ -166,13 +167,16 @@ class _AnimationBuilder implements AnimationAstVisitor {
visitAnimationSequence(ast: AnimationSequenceAst, context: _AnimationBuilderContext):
o.Expression {
var playerExprs = ast.steps.map(step => step.visit(this, context));
return o.importExpr(Identifiers.AnimationSequencePlayer).instantiate([o.literalArr(
playerExprs)]);
return o.importExpr(resolveIdentifier(Identifiers.AnimationSequencePlayer)).instantiate([
o.literalArr(playerExprs)
]);
}

visitAnimationGroup(ast: AnimationGroupAst, context: _AnimationBuilderContext): o.Expression {
var playerExprs = ast.steps.map(step => step.visit(this, context));
return o.importExpr(Identifiers.AnimationGroupPlayer).instantiate([o.literalArr(playerExprs)]);
return o.importExpr(resolveIdentifier(Identifiers.AnimationGroupPlayer)).instantiate([
o.literalArr(playerExprs)
]);
}

visitAnimationStateDeclaration(
Expand Down Expand Up @@ -265,26 +269,27 @@ class _AnimationBuilder implements AnimationAstVisitor {
_ANIMATION_END_STATE_STYLES_VAR.equals(o.NULL_EXPR),
[_ANIMATION_END_STATE_STYLES_VAR.set(_ANIMATION_DEFAULT_STATE_VAR).toStmt()]));

var RENDER_STYLES_FN = o.importExpr(Identifiers.renderStyles);
var RENDER_STYLES_FN = o.importExpr(resolveIdentifier(Identifiers.renderStyles));

// before we start any animation we want to clear out the starting
// styles from the element's style property (since they were placed
// there at the end of the last animation
statements.push(
RENDER_STYLES_FN
.callFn([
_ANIMATION_FACTORY_ELEMENT_VAR, _ANIMATION_FACTORY_RENDERER_VAR,
o.importExpr(Identifiers.clearStyles).callFn([_ANIMATION_START_STATE_STYLES_VAR])
])
.toStmt());
statements.push(RENDER_STYLES_FN
.callFn([
_ANIMATION_FACTORY_ELEMENT_VAR, _ANIMATION_FACTORY_RENDERER_VAR,
o.importExpr(resolveIdentifier(Identifiers.clearStyles))
.callFn([_ANIMATION_START_STATE_STYLES_VAR])
])
.toStmt());

ast.stateTransitions.forEach(transAst => statements.push(transAst.visit(this, context)));

// this check ensures that the animation factory always returns a player
// so that the onDone callback can be used for tracking
statements.push(new o.IfStmt(
_ANIMATION_PLAYER_VAR.equals(o.NULL_EXPR),
[_ANIMATION_PLAYER_VAR.set(o.importExpr(Identifiers.NoOpAnimationPlayer).instantiate([]))
[_ANIMATION_PLAYER_VAR
.set(o.importExpr(resolveIdentifier(Identifiers.NoOpAnimationPlayer)).instantiate([]))
.toStmt()]));

// once complete we want to apply the styles on the element
Expand All @@ -295,14 +300,16 @@ class _AnimationBuilder implements AnimationAstVisitor {
.callMethod(
'onDone',
[o.fn(
[], [RENDER_STYLES_FN
.callFn([
_ANIMATION_FACTORY_ELEMENT_VAR, _ANIMATION_FACTORY_RENDERER_VAR,
o.importExpr(Identifiers.prepareFinalAnimationStyles).callFn([
[],
[RENDER_STYLES_FN
.callFn([
_ANIMATION_FACTORY_ELEMENT_VAR, _ANIMATION_FACTORY_RENDERER_VAR,
o.importExpr(resolveIdentifier(Identifiers.prepareFinalAnimationStyles))
.callFn([
_ANIMATION_START_STATE_STYLES_VAR, _ANIMATION_END_STATE_STYLES_VAR
])
])
.toStmt()])])
])
.toStmt()])])
.toStmt());

statements.push(_ANIMATION_FACTORY_VIEW_VAR
Expand All @@ -319,7 +326,7 @@ class _AnimationBuilder implements AnimationAstVisitor {
[
new o.FnParam(
_ANIMATION_FACTORY_VIEW_VAR.name,
o.importType(Identifiers.AppView, [o.DYNAMIC_TYPE])),
o.importType(resolveIdentifier(Identifiers.AppView), [o.DYNAMIC_TYPE])),
new o.FnParam(_ANIMATION_FACTORY_ELEMENT_VAR.name, o.DYNAMIC_TYPE),
new o.FnParam(_ANIMATION_CURRENT_STATE_VAR.name, o.DYNAMIC_TYPE),
new o.FnParam(_ANIMATION_NEXT_STATE_VAR.name, o.DYNAMIC_TYPE)
Expand Down
51 changes: 6 additions & 45 deletions modules/@angular/compiler/src/compile_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export abstract class CompileMetadataWithIdentifier {

get runtimeCacheKey(): any { return unimplemented(); }

get assetCacheKey(): any { return unimplemented(); }

equalsTo(id2: CompileMetadataWithIdentifier): boolean { return unimplemented(); }
}

Expand Down Expand Up @@ -93,7 +91,6 @@ export class CompileIdentifierMetadata implements CompileMetadataWithIdentifier
prefix: string;
moduleUrl: string;
value: any;
private _assetCacheKey: any = UNDEFINED;

constructor(
{runtime, name, moduleUrl, prefix, value}:
Expand All @@ -109,23 +106,9 @@ export class CompileIdentifierMetadata implements CompileMetadataWithIdentifier

get runtimeCacheKey(): any { return this.identifier.runtime; }

get assetCacheKey(): any {
if (this._assetCacheKey === UNDEFINED) {
if (isPresent(this.moduleUrl) && isPresent(getUrlScheme(this.moduleUrl))) {
var uri = reflector.importUri({'filePath': this.moduleUrl, 'name': this.name});
this._assetCacheKey = `${this.name}|${uri}`;
} else {
this._assetCacheKey = null;
}
}
return this._assetCacheKey;
}

equalsTo(id2: CompileIdentifierMetadata): boolean {
var rk = this.runtimeCacheKey;
var ak = this.assetCacheKey;
return (isPresent(rk) && rk == id2.runtimeCacheKey) ||
(isPresent(ak) && ak == id2.assetCacheKey);
return isPresent(rk) && rk == id2.runtimeCacheKey;
}
}

Expand Down Expand Up @@ -233,19 +216,9 @@ export class CompileTokenMetadata implements CompileMetadataWithIdentifier {
}
}

get assetCacheKey(): any {
if (isPresent(this.identifier)) {
return this.identifier.assetCacheKey;
} else {
return this.value;
}
}

equalsTo(token2: CompileTokenMetadata): boolean {
var rk = this.runtimeCacheKey;
var ak = this.assetCacheKey;
return (isPresent(rk) && rk == token2.runtimeCacheKey) ||
(isPresent(ak) && ak == token2.assetCacheKey);
return isPresent(rk) && rk == token2.runtimeCacheKey;
}

get name(): string {
Expand Down Expand Up @@ -275,24 +248,17 @@ export class CompileIdentifierMap<KEY extends CompileMetadataWithIdentifier, VAL
this._tokens.push(token);
this._values.push(value);
var rk = token.runtimeCacheKey;
if (isPresent(rk)) {
this._valueMap.set(rk, value);
}
var ak = token.assetCacheKey;
if (isPresent(ak)) {
this._valueMap.set(ak, value);
if (!isPresent(rk)) {
throw new Error(`Cannot find a key for Token: ${token.identifier.name}`);
}
this._valueMap.set(rk, value);
}
get(token: KEY): VALUE {
var rk = token.runtimeCacheKey;
var ak = token.assetCacheKey;
var result: VALUE;
if (isPresent(rk)) {
result = this._valueMap.get(rk);
}
if (isBlank(result) && isPresent(ak)) {
result = this._valueMap.get(ak);
}
return result;
}
keys(): KEY[] { return this._tokens; }
Expand Down Expand Up @@ -547,8 +513,6 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {

get runtimeCacheKey(): any { return this.type.runtimeCacheKey; }

get assetCacheKey(): any { return this.type.assetCacheKey; }

equalsTo(other: CompileMetadataWithIdentifier): boolean {
return this.type.equalsTo(other.identifier);
}
Expand All @@ -568,6 +532,7 @@ export function createHostComponentMeta(compMeta: CompileDirectiveMetadata):
isHost: true
}),
template: new CompileTemplateMetadata({
encapsulation: ViewEncapsulation.None,
template: template,
templateUrl: '',
styles: [],
Expand Down Expand Up @@ -606,8 +571,6 @@ export class CompilePipeMetadata implements CompileMetadataWithIdentifier {
get identifier(): CompileIdentifierMetadata { return this.type; }
get runtimeCacheKey(): any { return this.type.runtimeCacheKey; }

get assetCacheKey(): any { return this.type.assetCacheKey; }

equalsTo(other: CompileMetadataWithIdentifier): boolean {
return this.type.equalsTo(other.identifier);
}
Expand Down Expand Up @@ -668,8 +631,6 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
get identifier(): CompileIdentifierMetadata { return this.type; }
get runtimeCacheKey(): any { return this.type.runtimeCacheKey; }

get assetCacheKey(): any { return this.type.assetCacheKey; }

equalsTo(other: CompileMetadataWithIdentifier): boolean {
return this.type.equalsTo(other.identifier);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/@angular/compiler/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {ViewEncapsulation, isDevMode} from '@angular/core';

import {CompileIdentifierMetadata} from './compile_metadata';
import {Identifiers} from './identifiers';
import {Identifiers, resolveIdentifier} from './identifiers';

function unimplemented(): any {
throw new Error('unimplemented');
Expand Down Expand Up @@ -61,7 +61,7 @@ export abstract class RenderTypes {
}

export class DefaultRenderTypes implements RenderTypes {
renderer = Identifiers.Renderer;
get renderer() { return resolveIdentifier(Identifiers.Renderer); };
renderText: any = null;
renderElement: any = null;
renderComment: any = null;
Expand Down
Loading

0 comments on commit d8983d2

Please sign in to comment.