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

@ -245,15 +245,15 @@ class TypeWrapper implements Symbol {
return (symbol && symbol.name) || '<anonymous>';
}
get kind(): DeclarationKind { return 'type'; }
public readonly kind: DeclarationKind = 'type';
get language(): string { return 'typescript'; }
public readonly language: string = 'typescript';
get type(): Symbol|undefined { return undefined; }
public readonly type: Symbol|undefined = undefined;
get container(): Symbol|undefined { return undefined; }
public readonly container: Symbol|undefined = undefined;
get public(): boolean { return true; }
public readonly public: boolean = true;
get callable(): boolean { return typeCallable(this.tsType); }
@ -284,6 +284,9 @@ class SymbolWrapper implements Symbol {
private _tsType: ts.Type;
private _members: SymbolTable;
public readonly nullable: boolean = false;
public readonly language: string = 'typescript';
constructor(symbol: ts.Symbol, private context: TypeContext) {
this.symbol = symbol && context && (symbol.flags & ts.SymbolFlags.Alias) ?
context.checker.getAliasedSymbol(symbol) :
@ -294,8 +297,6 @@ class SymbolWrapper implements Symbol {
get kind(): DeclarationKind { return this.callable ? 'method' : 'property'; }
get language(): string { return 'typescript'; }
get type(): Symbol|undefined { return new TypeWrapper(this.tsType, this.context); }
get container(): Symbol|undefined { return getContainerOf(this.symbol, this.context); }
@ -307,8 +308,6 @@ class SymbolWrapper implements Symbol {
get callable(): boolean { return typeCallable(this.tsType); }
get nullable(): boolean { return false; }
get definition(): Definition { return definitionFromTsSymbol(this.symbol); }
members(): SymbolTable {
@ -343,23 +342,24 @@ class SymbolWrapper implements Symbol {
}
class DeclaredSymbol implements Symbol {
public readonly language: string = 'ng-template';
public readonly nullable: boolean = false;
public readonly public: boolean = true;
constructor(private declaration: SymbolDeclaration) {}
get name() { return this.declaration.name; }
get kind() { return this.declaration.kind; }
get language(): string { return 'ng-template'; }
get container(): Symbol|undefined { return undefined; }
get type() { return this.declaration.type; }
get callable(): boolean { return this.declaration.type.callable; }
get nullable(): boolean { return false; }
get public(): boolean { return true; }
get definition(): Definition { return this.declaration.definition; }
@ -512,25 +512,19 @@ class PipesTable implements SymbolTable {
class PipeSymbol implements Symbol {
private _tsType: ts.Type;
public readonly kind: DeclarationKind = 'pipe';
public readonly language: string = 'typescript';
public readonly container: Symbol|undefined = undefined;
public readonly callable: boolean = true;
public readonly nullable: boolean = false;
public readonly public: boolean = true;
constructor(private pipe: CompilePipeSummary, private context: TypeContext) {}
get name(): string { return this.pipe.name; }
get kind(): DeclarationKind { return 'pipe'; }
get language(): string { return 'typescript'; }
get type(): Symbol|undefined { return new TypeWrapper(this.tsType, this.context); }
get container(): Symbol|undefined { return undefined; }
get callable(): boolean { return true; }
get nullable(): boolean { return false; }
get public(): boolean { return true; }
get definition(): Definition|undefined {
const symbol = this.tsType.getSymbol();
return symbol ? definitionFromTsSymbol(symbol) : undefined;
@ -613,7 +607,7 @@ function findClassSymbolInContext(type: StaticSymbol, context: TypeContext): ts.
}
class EmptyTable implements SymbolTable {
get size(): number { return 0; }
public readonly size: number = 0;
get(key: string): Symbol|undefined { return undefined; }
has(key: string): boolean { return false; }
values(): Symbol[] { return []; }

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[]) {