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;