refactor(compiler): remove unused constructor query support

This commit is contained in:
Tobias Bosch 2016-10-31 15:46:24 -07:00 committed by vsavkin
parent f6710fefeb
commit 234c5599f1
9 changed files with 19 additions and 83 deletions

View File

@ -105,33 +105,27 @@ export class CompileDiDependencyMetadata {
isSkipSelf: boolean; isSkipSelf: boolean;
isOptional: boolean; isOptional: boolean;
isValue: boolean; isValue: boolean;
query: CompileQueryMetadata;
viewQuery: CompileQueryMetadata;
token: CompileTokenMetadata; token: CompileTokenMetadata;
value: any; value: any;
constructor( constructor({isAttribute, isSelf, isHost, isSkipSelf, isOptional, isValue, token, value}: {
{isAttribute, isSelf, isHost, isSkipSelf, isOptional, isValue, query, viewQuery, token, isAttribute?: boolean,
value}: { isSelf?: boolean,
isAttribute?: boolean, isHost?: boolean,
isSelf?: boolean, isSkipSelf?: boolean,
isHost?: boolean, isOptional?: boolean,
isSkipSelf?: boolean, isValue?: boolean,
isOptional?: boolean, query?: CompileQueryMetadata,
isValue?: boolean, viewQuery?: CompileQueryMetadata,
query?: CompileQueryMetadata, token?: CompileTokenMetadata,
viewQuery?: CompileQueryMetadata, value?: any
token?: CompileTokenMetadata, } = {}) {
value?: any
} = {}) {
this.isAttribute = !!isAttribute; this.isAttribute = !!isAttribute;
this.isSelf = !!isSelf; this.isSelf = !!isSelf;
this.isHost = !!isHost; this.isHost = !!isHost;
this.isSkipSelf = !!isSkipSelf; this.isSkipSelf = !!isSkipSelf;
this.isOptional = !!isOptional; this.isOptional = !!isOptional;
this.isValue = !!isValue; this.isValue = !!isValue;
this.query = query;
this.viewQuery = viewQuery;
this.token = token; this.token = token;
this.value = value; this.value = value;
} }

View File

@ -506,8 +506,6 @@ export class CompileMetadataResolver {
let isSelf = false; let isSelf = false;
let isSkipSelf = false; let isSkipSelf = false;
let isOptional = false; let isOptional = false;
let query: Query = null;
let viewQuery: Query = null;
let token: any = null; let token: any = null;
if (Array.isArray(param)) { if (Array.isArray(param)) {
param.forEach((paramEntry) => { param.forEach((paramEntry) => {
@ -522,12 +520,6 @@ export class CompileMetadataResolver {
} else if (paramEntry instanceof Attribute) { } else if (paramEntry instanceof Attribute) {
isAttribute = true; isAttribute = true;
token = paramEntry.attributeName; token = paramEntry.attributeName;
} else if (paramEntry instanceof Query) {
if (paramEntry.isViewQuery) {
viewQuery = paramEntry;
} else {
query = paramEntry;
}
} else if (paramEntry instanceof Inject) { } else if (paramEntry instanceof Inject) {
token = paramEntry.token; token = paramEntry.token;
} else if (isValidType(paramEntry) && isBlank(token)) { } else if (isValidType(paramEntry) && isBlank(token)) {
@ -548,8 +540,6 @@ export class CompileMetadataResolver {
isSelf, isSelf,
isSkipSelf, isSkipSelf,
isOptional, isOptional,
query: query ? this.getQueryMetadata(query, null, typeOrFunc) : null,
viewQuery: viewQuery ? this.getQueryMetadata(viewQuery, null, typeOrFunc) : null,
token: this.getTokenMetadata(token) token: this.getTokenMetadata(token)
}); });

View File

@ -197,9 +197,6 @@ export class ProviderElementContext {
return new CompileDiDependencyMetadata( return new CompileDiDependencyMetadata(
{isValue: true, value: attrValue == null ? null : attrValue}); {isValue: true, value: attrValue == null ? null : attrValue});
} }
if (isPresent(dep.query) || isPresent(dep.viewQuery)) {
return dep;
}
if (isPresent(dep.token)) { if (isPresent(dep.token)) {
// access builtints // access builtints
@ -503,11 +500,6 @@ function _getViewQueries(component: CompileDirectiveMetadata): Map<any, CompileQ
if (isPresent(component.viewQueries)) { if (isPresent(component.viewQueries)) {
component.viewQueries.forEach((query) => _addQueryToTokenMap(viewQueries, query)); component.viewQueries.forEach((query) => _addQueryToTokenMap(viewQueries, query));
} }
component.type.diDeps.forEach((dep) => {
if (isPresent(dep.viewQuery)) {
_addQueryToTokenMap(viewQueries, dep.viewQuery);
}
});
return viewQueries; return viewQueries;
} }
@ -518,11 +510,6 @@ function _getContentQueries(directives: CompileDirectiveMetadata[]):
if (isPresent(directive.queries)) { if (isPresent(directive.queries)) {
directive.queries.forEach((query) => _addQueryToTokenMap(contentQueries, query)); directive.queries.forEach((query) => _addQueryToTokenMap(contentQueries, query));
} }
directive.type.diDeps.forEach((dep) => {
if (isPresent(dep.query)) {
_addQueryToTokenMap(contentQueries, dep.query);
}
});
}); });
return contentQueries; return contentQueries;
} }

View File

@ -49,7 +49,6 @@ export class CompileElement extends CompileNode {
private _queryCount = 0; private _queryCount = 0;
private _queries = new Map<any, CompileQuery[]>(); private _queries = new Map<any, CompileQuery[]>();
private _componentConstructorViewQueryLists: o.Expression[] = [];
public contentNodesByNgContentIndex: Array<CompileViewRootNode>[] = null; public contentNodesByNgContentIndex: Array<CompileViewRootNode>[] = null;
public embeddedView: CompileView; public embeddedView: CompileView;
@ -257,16 +256,9 @@ export class CompileElement extends CompileNode {
}); });
if (isPresent(this.component)) { if (isPresent(this.component)) {
var componentConstructorViewQueryList = isPresent(this.component) ?
o.literalArr(this._componentConstructorViewQueryLists) :
o.NULL_EXPR;
var compExpr = isPresent(this.getComponent()) ? this.getComponent() : o.NULL_EXPR; var compExpr = isPresent(this.getComponent()) ? this.getComponent() : o.NULL_EXPR;
this.view.createMethod.addStmt( this.view.createMethod.addStmt(
this.appElement this.appElement.callMethod('initComponent', [compExpr, this._compViewExpr]).toStmt());
.callMethod(
'initComponent',
[compExpr, componentConstructorViewQueryList, this._compViewExpr])
.toStmt());
} }
} }
@ -342,20 +334,6 @@ export class CompileElement extends CompileNode {
private _getLocalDependency( private _getLocalDependency(
requestingProviderType: ProviderAstType, dep: CompileDiDependencyMetadata): o.Expression { requestingProviderType: ProviderAstType, dep: CompileDiDependencyMetadata): o.Expression {
var result: o.Expression = null; var result: o.Expression = null;
// constructor content query
if (!result && isPresent(dep.query)) {
result = this._addQuery(dep.query, null).queryList;
}
// constructor view query
if (!result && isPresent(dep.viewQuery)) {
result = createQueryList(
dep.viewQuery, null,
`_viewQuery_${dep.viewQuery.selectors[0].name}_${this.nodeIndex}_${this._componentConstructorViewQueryLists.length}`,
this.view);
this._componentConstructorViewQueryLists.push(result);
}
if (isPresent(dep.token)) { if (isPresent(dep.token)) {
// access builtins with special visibility // access builtins with special visibility
if (!result) { if (!result) {

View File

@ -121,16 +121,6 @@ export class CompileView implements NameResolver {
var query = new CompileQuery(queryMeta, queryList, directiveInstance, this); var query = new CompileQuery(queryMeta, queryList, directiveInstance, this);
addQueryToTokenMap(viewQueries, query); addQueryToTokenMap(viewQueries, query);
}); });
var constructorViewQueryCount = 0;
this.component.type.diDeps.forEach((dep) => {
if (isPresent(dep.viewQuery)) {
var queryList = o.THIS_EXPR.prop('declarationAppElement')
.prop('componentConstructorViewQueries')
.key(o.literal(constructorViewQueryCount++));
var query = new CompileQuery(dep.viewQuery, queryList, null, this);
addQueryToTokenMap(viewQueries, query);
}
});
} }
this.viewQueries = viewQueries; this.viewQueries = viewQueries;
templateVariableBindings.forEach( templateVariableBindings.forEach(

View File

@ -119,7 +119,7 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
'createTemplateAnchor', [o.NULL_EXPR, o.NULL_EXPR])) 'createTemplateAnchor', [o.NULL_EXPR, o.NULL_EXPR]))
.toStmt()); .toStmt());
view.rootNodes.push( view.rootNodes.push(
new CompileViewRootNode(CompileViewRootNodeType.Node, o.THIS_EXPR.prop(fieldName))) new CompileViewRootNode(CompileViewRootNodeType.Node, o.THIS_EXPR.prop(fieldName)));
} }
return view.rootNodes[view.rootNodes.length - 1].expr; return view.rootNodes[view.rootNodes.length - 1].expr;
} }

View File

@ -22,11 +22,10 @@ import {ViewType} from './view_type';
* that is needed for later instantiations. * that is needed for later instantiations.
*/ */
export class AppElement { export class AppElement {
public nestedViews: AppView<any>[] = null; public nestedViews: AppView<any>[];
public componentView: AppView<any> = null; public componentView: AppView<any>;
public component: any; public component: any;
public componentConstructorViewQueries: QueryList<any>[];
constructor( constructor(
public index: number, public parentIndex: number, public parentView: AppView<any>, public index: number, public parentIndex: number, public parentView: AppView<any>,
@ -36,10 +35,8 @@ export class AppElement {
get vcRef(): ViewContainerRef_ { return new ViewContainerRef_(this); } get vcRef(): ViewContainerRef_ { return new ViewContainerRef_(this); }
initComponent( initComponent(component: any, view: AppView<any>) {
component: any, componentConstructorViewQueries: QueryList<any>[], view: AppView<any>) {
this.component = component; this.component = component;
this.componentConstructorViewQueries = componentConstructorViewQueries;
this.componentView = view; this.componentView = view;
} }

View File

@ -37,7 +37,7 @@ class _View_TreeComponent_Host0 extends import1.AppView<any> {
this.renderer, 'tree', import4.EMPTY_INLINE_ARRAY, rootSelector, (null as any)); this.renderer, 'tree', import4.EMPTY_INLINE_ARRAY, rootSelector, (null as any));
this._vc_0 = new import2.AppElement(0, (null as any), this, this._el_0); this._vc_0 = new import2.AppElement(0, (null as any), this, this._el_0);
this._TreeComponent_0_4 = new _View_TreeComponent0(this._el_0); this._TreeComponent_0_4 = new _View_TreeComponent0(this._el_0);
this._vc_0.initComponent(this._TreeComponent_0_4.context, [], <any>this._TreeComponent_0_4); this._vc_0.initComponent(this._TreeComponent_0_4.context, <any>this._TreeComponent_0_4);
this.init([].concat([this._el_0]), [this._el_0], []); this.init([].concat([this._el_0]), [this._el_0], []);
return this._vc_0; return this._vc_0;
} }

View File

@ -42,7 +42,7 @@ class _View_TreeRootComponent_Host0 extends import1.AppView<any> {
this._TreeRootComponent_0_4_View = this._TreeRootComponent_0_4_View =
viewFactory_TreeRootComponent0(this.viewUtils, this.injector(0), this._appEl_0); viewFactory_TreeRootComponent0(this.viewUtils, this.injector(0), this._appEl_0);
this._TreeRootComponent_0_4 = new import3.TreeRootComponent(); this._TreeRootComponent_0_4 = new import3.TreeRootComponent();
this._appEl_0.initComponent(this._TreeRootComponent_0_4, [], this._TreeRootComponent_0_4_View); this._appEl_0.initComponent(this._TreeRootComponent_0_4, this._TreeRootComponent_0_4_View);
this._TreeRootComponent_0_4_View.create(this._TreeRootComponent_0_4, (null as any)); this._TreeRootComponent_0_4_View.create(this._TreeRootComponent_0_4, (null as any));
this.init([].concat([this._el_0]), [this._el_0], []); this.init([].concat([this._el_0]), [this._el_0], []);
return this._appEl_0; return this._appEl_0;