refactor(compiler): add control.ignoreCurrentElement() to skip the current element

relates to #808
This commit is contained in:
Victor Berchet
2015-04-10 16:12:37 +02:00
committed by Misko Hevery
parent f0477e164a
commit 678d541da7
8 changed files with 60 additions and 52 deletions

View File

@ -13,6 +13,8 @@ export class CompileControl {
_parent:CompileElement;
_results;
_additionalChildren;
_ignoreCurrentElement: boolean;
constructor(steps) {
this._steps = steps;
this._currentStepIndex = 0;
@ -27,14 +29,21 @@ export class CompileControl {
var previousStepIndex = this._currentStepIndex;
var previousParent = this._parent;
for (var i=startStepIndex; i<this._steps.length; i++) {
this._ignoreCurrentElement = false;
for (var i = startStepIndex;
i < this._steps.length && !this._ignoreCurrentElement;
i++) {
var step = this._steps[i];
this._parent = parent;
this._currentStepIndex = i;
step.process(parent, current, this);
parent = this._parent;
}
ListWrapper.push(results, current);
if (!this._ignoreCurrentElement) {
ListWrapper.push(results, current);
}
this._currentStepIndex = previousStepIndex;
this._parent = previousParent;
@ -55,4 +64,14 @@ export class CompileControl {
}
ListWrapper.push(this._additionalChildren, element);
}
/**
* Ignores the current element.
*
* When a step call [ignoreCurrentElement], no further steps are executed on the current
* element and no [CompileElement] is added to the result list.
*/
ignoreCurrentElement() {
this._ignoreCurrentElement = true;
}
}

View File

@ -18,7 +18,6 @@ export class CompileElement {
distanceToInheritedBinder:number;
inheritedElementBinder:ElementBinderBuilder;
compileChildren: boolean;
ignoreBindings: boolean;
elementDescription: string; // e.g. '<div [class]="foo">' : used to provide context in case of error
constructor(element, compilationUnit = '') {
@ -34,8 +33,6 @@ export class CompileElement {
this.inheritedElementBinder = null;
this.distanceToInheritedBinder = 0;
this.compileChildren = true;
// set to true to ignore all the bindings on the element
this.ignoreBindings = false;
// description is calculated here as compilation steps may change the element
var tplDesc = assertionsEnabled()? getElementDescription(element) : null;
if (compilationUnit !== '') {

View File

@ -30,10 +30,6 @@ export class PropertyBindingParser extends CompileStep {
}
process(parent:CompileElement, current:CompileElement, control:CompileControl) {
if (current.ignoreBindings) {
return;
}
var attrs = current.attrs();
var newAttrs = MapWrapper.create();

View File

@ -19,7 +19,7 @@ export class TextInterpolationParser extends CompileStep {
}
process(parent:CompileElement, current:CompileElement, control:CompileControl) {
if (!current.compileChildren || current.ignoreBindings) {
if (!current.compileChildren) {
return;
}
var element = current.element;

View File

@ -23,12 +23,9 @@ export class ShadowDomCompileStep extends CompileStep {
}
process(parent:CompileElement, current:CompileElement, control:CompileControl) {
if (current.ignoreBindings) {
return;
}
var tagName = DOM.tagName(current.element).toUpperCase();
if (tagName == 'STYLE') {
this._processStyleElement(current);
this._processStyleElement(current, control);
} else if (tagName == 'CONTENT') {
this._processContentElement(current);
} else {
@ -39,17 +36,20 @@ export class ShadowDomCompileStep extends CompileStep {
}
}
_processStyleElement(current) {
current.ignoreBindings = true;
_processStyleElement(current:CompileElement, control:CompileControl) {
var stylePromise = this._shadowDomStrategy.processStyleElement(
this._template.componentId, this._template.absUrl, current.element
);
if (isPresent(stylePromise) && PromiseWrapper.isPromise(stylePromise)) {
ListWrapper.push(this._subTaskPromises, stylePromise);
}
// Style elements should not be further processed by the compiler, as they can not contain
// bindings. Skipping further compiler steps allow speeding up the compilation process.
control.ignoreCurrentElement();
}
_processContentElement(current) {
_processContentElement(current:CompileElement) {
if (this._shadowDomStrategy.hasNativeContentElement()) {
return;
}