refactor(core): remove readonly getters in common, compiler (#19150)

PR Close #19150
This commit is contained in:
Yuan Gao
2017-09-11 15:10:19 -07:00
committed by Matias Niemelä
parent 996c7c2dde
commit 0c44e733ad
6 changed files with 56 additions and 52 deletions

View File

@ -51,9 +51,10 @@ export class ProviderElementContext {
private _seenProviders = new Map<any, boolean>();
private _allProviders: Map<any, ProviderAst>;
private _attrs: {[key: string]: string};
private _hasViewContainer: boolean = false;
private _queriedTokens = new Map<any, QueryMatch[]>();
public readonly transformedHasViewContainer: boolean = false;
constructor(
public viewContext: ProviderViewContext, private _parent: ProviderElementContext,
private _isViewRoot: boolean, private _directiveAsts: DirectiveAst[], attrs: AttrAst[],
@ -80,7 +81,7 @@ export class ProviderElementContext {
});
if (this._queriedTokens.get(
this.viewContext.reflector.resolveExternalReference(Identifiers.ViewContainerRef))) {
this._hasViewContainer = true;
this.transformedHasViewContainer = true;
}
// create the providers that we know are eager first
@ -122,8 +123,6 @@ export class ProviderElementContext {
return sortedDirectives;
}
get transformedHasViewContainer(): boolean { return this._hasViewContainer; }
get queryMatches(): QueryMatch[] {
const allMatches: QueryMatch[] = [];
this._queriedTokens.forEach((matches: QueryMatch[]) => { allMatches.push(...matches); });
@ -249,7 +248,7 @@ export class ProviderElementContext {
}
if (tokenReference(dep.token) ===
this.viewContext.reflector.resolveExternalReference(Identifiers.ViewContainerRef)) {
this._hasViewContainer = true;
(this as{transformedHasViewContainer: boolean}).transformedHasViewContainer = true;
}
}
// access the injector

View File

@ -36,13 +36,15 @@ export enum BoundPropertyType {
* Represents a parsed property.
*/
export class BoundProperty {
public readonly isLiteral: boolean;
public readonly isAnimation: boolean;
constructor(
public name: string, public expression: ASTWithSource, public type: BoundPropertyType,
public sourceSpan: ParseSourceSpan) {}
get isLiteral() { return this.type === BoundPropertyType.LITERAL_ATTR; }
get isAnimation() { return this.type === BoundPropertyType.ANIMATION; }
public sourceSpan: ParseSourceSpan) {
this.isLiteral = this.type === BoundPropertyType.LITERAL_ATTR;
this.isAnimation = this.type === BoundPropertyType.ANIMATION;
}
}
/**

View File

@ -63,14 +63,17 @@ export class AttrAst implements TemplateAst {
* `[@trigger]="stateExp"`)
*/
export class BoundElementPropertyAst implements TemplateAst {
public readonly isAnimation: boolean;
constructor(
public name: string, public type: PropertyBindingType,
public securityContext: SecurityContext, public value: AST, public unit: string|null,
public sourceSpan: ParseSourceSpan) {}
public sourceSpan: ParseSourceSpan) {
this.isAnimation = this.type === PropertyBindingType.Animation;
}
visit(visitor: TemplateAstVisitor, context: any): any {
return visitor.visitElementProperty(this, context);
}
get isAnimation(): boolean { return this.type === PropertyBindingType.Animation; }
}
/**
@ -88,14 +91,18 @@ export class BoundEventAst implements TemplateAst {
}
}
public readonly fullName: string;
public readonly isAnimation: boolean;
constructor(
public name: string, public target: string|null, public phase: string|null,
public handler: AST, public sourceSpan: ParseSourceSpan) {}
public handler: AST, public sourceSpan: ParseSourceSpan) {
this.fullName = BoundEventAst.calcFullName(this.name, this.target, this.phase);
this.isAnimation = !!this.phase;
}
visit(visitor: TemplateAstVisitor, context: any): any {
return visitor.visitEvent(this, context);
}
get fullName() { return BoundEventAst.calcFullName(this.name, this.target, this.phase); }
get isAnimation(): boolean { return !!this.phase; }
}
/**

View File

@ -207,13 +207,16 @@ export function isPromise(obj: any): obj is Promise<any> {
}
export class Version {
constructor(public full: string) {}
public readonly major: string;
public readonly minor: string;
public readonly patch: string;
get major(): string { return this.full.split('.')[0]; }
get minor(): string { return this.full.split('.')[1]; }
get patch(): string { return this.full.split('.').slice(2).join('.'); }
constructor(public full: string) {
const splits = full.split('.');
this.major = splits[0];
this.minor = splits[1];
this.patch = splits.slice(2).join('.');
}
}
export interface Console {

View File

@ -114,6 +114,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
private variables: VariableAst[] = [];
private children: ViewBuilder[] = [];
public readonly viewName: string;
constructor(
private reflector: CompileReflector, private outputCtx: OutputContext,
private parent: ViewBuilder|null, private component: CompileDirectiveMetadata,
@ -126,10 +128,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
this.compType = this.embeddedViewIndex > 0 ?
o.DYNAMIC_TYPE :
o.expressionType(outputCtx.importExpr(this.component.type.reference)) !;
}
get viewName(): string {
return viewClassName(this.component.type.reference, this.embeddedViewIndex);
this.viewName = viewClassName(this.component.type.reference, this.embeddedViewIndex);
}
visitAll(variables: VariableAst[], astNodes: TemplateAst[]) {