Revert "fix(Compiler): fix text nodes after content tags"
This reverts commit d599fd3434f7ab5889be5a4d913769b185f918eb. but keeps the integration test. The test is made green by the following commits.
This commit is contained in:
parent
bc798b182d
commit
180e617866
@ -1,6 +1,6 @@
|
|||||||
import * as ldModule from './light_dom';
|
import * as ldModule from './light_dom';
|
||||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||||
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
import {isPresent} from 'angular2/src/facade/lang';
|
||||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||||
|
|
||||||
class ContentStrategy {
|
class ContentStrategy {
|
||||||
@ -20,6 +20,7 @@ class RenderedContent extends ContentStrategy {
|
|||||||
constructor(contentEl) {
|
constructor(contentEl) {
|
||||||
super();
|
super();
|
||||||
this.beginScript = contentEl;
|
this.beginScript = contentEl;
|
||||||
|
this.endScript = DOM.nextSibling(this.beginScript);
|
||||||
this.nodes = [];
|
this.nodes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,23 +28,15 @@ class RenderedContent extends ContentStrategy {
|
|||||||
// Previous content is removed.
|
// Previous content is removed.
|
||||||
insert(nodes: List</*node*/ any>) {
|
insert(nodes: List</*node*/ any>) {
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
|
|
||||||
if (isBlank(this.endScript)) {
|
|
||||||
// On first invocation, we need to create the end marker
|
|
||||||
this.endScript = DOM.createScriptTag('type', 'ng/contentEnd');
|
|
||||||
DOM.insertAfter(this.beginScript, this.endScript);
|
|
||||||
} else {
|
|
||||||
// On subsequent invocations, only remove all the nodes between the start end end markers
|
|
||||||
this._removeNodes();
|
|
||||||
}
|
|
||||||
|
|
||||||
DOM.insertAllBefore(this.endScript, nodes);
|
DOM.insertAllBefore(this.endScript, nodes);
|
||||||
|
this._removeNodesUntil(ListWrapper.isEmpty(nodes) ? this.endScript : nodes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_removeNodes() {
|
_removeNodesUntil(node) {
|
||||||
for (var node = DOM.nextSibling(this.beginScript); node !== this.endScript;
|
var p = DOM.parentElement(this.beginScript);
|
||||||
node = DOM.nextSibling(this.beginScript)) {
|
for (var next = DOM.nextSibling(this.beginScript); next !== node;
|
||||||
DOM.remove(node);
|
next = DOM.nextSibling(this.beginScript)) {
|
||||||
|
DOM.removeChild(p, next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,15 +47,13 @@ export class ShadowDomCompileStep implements CompileStep {
|
|||||||
var selector = attrs.get('select');
|
var selector = attrs.get('select');
|
||||||
selector = isPresent(selector) ? selector : '';
|
selector = isPresent(selector) ? selector : '';
|
||||||
|
|
||||||
// The content tag should be replaced by a pair of marker tags (start & end).
|
|
||||||
// The end marker creation is delayed to keep the number of elements constant.
|
|
||||||
// Creating the end marker here would invalidate the parent's textNodeIndices for the subsequent
|
|
||||||
// text nodes
|
|
||||||
var contentStart = DOM.createScriptTag('type', 'ng/contentStart');
|
var contentStart = DOM.createScriptTag('type', 'ng/contentStart');
|
||||||
if (assertionsEnabled()) {
|
if (assertionsEnabled()) {
|
||||||
DOM.setAttribute(contentStart, 'select', selector);
|
DOM.setAttribute(contentStart, 'select', selector);
|
||||||
}
|
}
|
||||||
|
var contentEnd = DOM.createScriptTag('type', 'ng/contentEnd');
|
||||||
DOM.insertBefore(current.element, contentStart);
|
DOM.insertBefore(current.element, contentStart);
|
||||||
|
DOM.insertBefore(current.element, contentEnd);
|
||||||
DOM.remove(current.element);
|
DOM.remove(current.element);
|
||||||
|
|
||||||
current.element = contentStart;
|
current.element = contentStart;
|
||||||
|
@ -13,6 +13,7 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
|
|||||||
import {Content} from 'angular2/src/render/dom/shadow_dom/content_tag';
|
import {Content} from 'angular2/src/render/dom/shadow_dom/content_tag';
|
||||||
|
|
||||||
var _scriptStart = `<script start=""></script>`;
|
var _scriptStart = `<script start=""></script>`;
|
||||||
|
var _scriptEnd = `<script end=""></script>`;
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('Content', function() {
|
describe('Content', function() {
|
||||||
@ -20,32 +21,35 @@ export function main() {
|
|||||||
var content;
|
var content;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
parent = el(`<div>${_scriptStart}</div>`);
|
parent = el(`<div>${_scriptStart}${_scriptEnd}`);
|
||||||
let contentStartMarker = DOM.firstChild(parent);
|
content = DOM.firstChild(parent);
|
||||||
content = new Content(contentStartMarker, '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should insert the nodes", () => {
|
it("should insert the nodes", () => {
|
||||||
content.init(null);
|
var c = new Content(content, '');
|
||||||
content.insert([el("<a>A</a>"), el("<b>B</b>")]);
|
c.init(null);
|
||||||
|
c.insert([el("<a></a>"), el("<b></b>")])
|
||||||
|
|
||||||
expect(parent).toHaveText('AB');
|
expect(DOM.getInnerHTML(parent))
|
||||||
|
.toEqual(`${_scriptStart}<a></a><b></b>${_scriptEnd}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should remove the nodes from the previous insertion", () => {
|
it("should remove the nodes from the previous insertion", () => {
|
||||||
content.init(null);
|
var c = new Content(content, '');
|
||||||
content.insert([el("<a>A</a>")]);
|
c.init(null);
|
||||||
content.insert([el("<b>B</b>")]);
|
c.insert([el("<a></a>")]);
|
||||||
|
c.insert([el("<b></b>")]);
|
||||||
|
|
||||||
expect(parent).toHaveText('B');
|
expect(DOM.getInnerHTML(parent)).toEqual(`${_scriptStart}<b></b>${_scriptEnd}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should clear nodes on inserting an empty list", () => {
|
it("should insert empty list", () => {
|
||||||
content.init(null);
|
var c = new Content(content, '');
|
||||||
content.insert([el("<a>A</a>")]);
|
c.init(null);
|
||||||
content.insert([]);
|
c.insert([el("<a></a>")]);
|
||||||
|
c.insert([]);
|
||||||
|
|
||||||
expect(parent).toHaveText('');
|
expect(DOM.getInnerHTML(parent)).toEqual(`${_scriptStart}${_scriptEnd}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
it,
|
it,
|
||||||
xit,
|
xit,
|
||||||
beforeEachBindings,
|
beforeEachBindings,
|
||||||
SpyObject
|
SpyObject,
|
||||||
} from 'angular2/test_lib';
|
} from 'angular2/test_lib';
|
||||||
|
|
||||||
import {bind} from 'angular2/di';
|
import {bind} from 'angular2/di';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user