fix rest of the failed tests

pull/4444/head
Tan Li Hau 7 years ago committed by tanhauhau
parent e1f7c60ea9
commit e7efc3e568

@ -232,7 +232,12 @@ export default class ElementWrapper extends Wrapper {
render(block: Block, parent_node: Identifier, parent_nodes: Identifier) { render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
const { renderer } = this; const { renderer } = this;
if (this.node.name === 'noscript') return; if (this.node.name === 'noscript') {
if (renderer.options.hydratable) {
block.chunks.claim.push(b`@claim_noscript(${parent_nodes});`);
}
return;
}
const node = this.var; const node = this.var;
const nodes = parent_nodes && block.get_unique_name(`${this.var.name}_nodes`); // if we're in unclaimable territory, i.e. <head>, parent_nodes is null const nodes = parent_nodes && block.get_unique_name(`${this.var.name}_nodes`); // if we're in unclaimable territory, i.e. <head>, parent_nodes is null

@ -51,8 +51,11 @@ export default class RawMustacheTagWrapper extends Tag {
const update_anchor = needs_anchor ? html_anchor : this.next ? this.next.var : 'null'; const update_anchor = needs_anchor ? html_anchor : this.next ? this.next.var : 'null';
block.chunks.hydrate.push(b`${html_tag} = new @HtmlTag(${update_anchor});`); block.chunks.create.push(b`${html_tag} = new @HtmlTag(${update_anchor});`);
block.chunks.mount.push(b`${html_tag}.m(${init}, ${parent_node || '#target'}, ${parent_node ? null : '#anchor'});`); if (this.renderer.options.hydratable) {
block.chunks.claim.push(b`${html_tag} = @claim_html_tag(${update_anchor}, ${_parent_nodes});`);
}
block.chunks.mount.push(b`${html_tag}.m(${init}, ${parent_node || '#target'}, ${parent_node ? null : 'anchor'});`);
if (needs_anchor) { if (needs_anchor) {
block.add_element(html_anchor, x`@empty()`, x`@empty()`, parent_node); block.add_element(html_anchor, x`@empty()`, x`@empty()`, parent_node);

@ -3,5 +3,7 @@ import RawMustacheTag from '../../nodes/RawMustacheTag';
import { Expression } from 'estree'; import { Expression } from 'estree';
export default function(node: RawMustacheTag, renderer: Renderer, _options: RenderOptions) { export default function(node: RawMustacheTag, renderer: Renderer, _options: RenderOptions) {
renderer.add_string('<!-- HTML_TAG_START -->');
renderer.add_expression(node.expression.node as Expression); renderer.add_expression(node.expression.node as Expression);
renderer.add_string('<!-- HTML_TAG_END -->');
} }

@ -191,6 +191,33 @@ export function claim_space(nodes) {
return claim_text(nodes, ' '); return claim_text(nodes, ' ');
} }
export function claim_noscript(nodes) {
detach(claim_element(nodes, 'NOSCRIPT', {}, false));
}
function find_comment(nodes, text, start) {
for (let i = start; i < nodes.length; i += 1) {
const node = nodes[i];
if (node.nodeType === 8 /* comment node */ && node.textContent.trim() === text) {
return i;
}
}
return nodes.length;
}
export function claim_html_tag(update_anchor, nodes) {
// find html opening tag
const start_index = find_comment(nodes, 'HTML_TAG_START', 0);
const end_index = find_comment(nodes, 'HTML_TAG_END', start_index);
if (start_index === end_index) {
return new HtmlTag(update_anchor);
}
const html_tag_nodes = nodes.splice(start_index, end_index + 1);
detach(html_tag_nodes[0]);
detach(html_tag_nodes[html_tag_nodes.length - 1]);
return new HtmlTag(update_anchor, html_tag_nodes.slice(1, html_tag_nodes.length - 1));
}
export function set_data(text, data) { export function set_data(text, data) {
data = '' + data; data = '' + data;
if (text.wholeText !== data) text.data = data; if (text.wholeText !== data) text.data = data;
@ -318,27 +345,38 @@ export function query_selector_all(selector: string, parent: HTMLElement = docum
} }
export class HtmlTag { export class HtmlTag {
// parent for creating node
e: HTMLElement; e: HTMLElement;
// html tag nodes
n: ChildNode[]; n: ChildNode[];
// hydration claimed nodes
l: ChildNode[] | void;
// target
t: HTMLElement; t: HTMLElement;
// anchor
a: HTMLElement; a: HTMLElement;
constructor(anchor: HTMLElement = null) { constructor(anchor: HTMLElement = null, claimed_nodes?: ChildNode[]) {
this.a = anchor; this.a = anchor;
this.e = this.n = null; this.e = this.n = null;
this.l = claimed_nodes;
} }
m(html: string, target: HTMLElement, anchor: HTMLElement = null) { m(html: string, target: HTMLElement, anchor: HTMLElement = null) {
if (!this.e) { if (!this.e) {
this.e = element(target.nodeName as keyof HTMLElementTagNameMap); this.e = element(target.nodeName as keyof HTMLElementTagNameMap);
this.t = target; this.t = target;
this.h(html); if (this.l) {
this.n = this.l;
} else {
this.h(html);
}
} }
this.i(anchor); this.i(anchor);
} }
h(html) { h(html: string) {
this.e.innerHTML = html; this.e.innerHTML = html;
this.n = Array.from(this.e.childNodes); this.n = Array.from(this.e.childNodes);
} }

@ -52,6 +52,7 @@ function create_each_block(ctx) {
t4 = text(t4_value); t4 = text(t4_value);
t5 = text(" ago:"); t5 = text(" ago:");
t6 = space(); t6 = space();
html_tag = new HtmlTag(raw_value);
attr(span, "class", "meta"); attr(span, "class", "meta");
html_tag = new HtmlTag(null); html_tag = new HtmlTag(null);
attr(div, "class", "comment"); attr(div, "class", "comment");

@ -9,10 +9,6 @@ export default {
<p>foo 1</p> <p>foo 1</p>
`, `,
before_test() {
delete require.cache[path.resolve(__dirname, 'components.js')];
},
test({ assert, component, target }) { test({ assert, component, target }) {
component.a = 2; component.a = 2;
assert.htmlEqual(target.innerHTML, ` assert.htmlEqual(target.innerHTML, `

@ -1,3 +0,0 @@
import Foo from './Foo.svelte';
export default { Foo };

@ -0,0 +1,5 @@
<script context="module">
import Foo from './Foo.svelte';
export const Components = { Foo };
</script>

@ -1,5 +1,5 @@
<script> <script>
import Components from './components.js'; import { Components } from './components.svelte';
export let a; export let a;
</script> </script>

@ -1,4 +1,4 @@
export default { export default {
html: '<text>hello world</text>', html: '<svg><text>hello world</text></svg>',
preserveIdentifiers: true preserveIdentifiers: true
}; };

@ -1,5 +1,6 @@
<script> <script>
let foo = 'hello world' let foo = 'hello world'
</script> </script>
<svg>
<text>{foo}</text> <text>{foo}</text>
</svg>

@ -1,5 +1,4 @@
export default { export default {
skip_if_ssr: true,
props: { props: {
raw: '<span><em>raw html!!!\\o/</span></em>' raw: '<span><em>raw html!!!\\o/</span></em>'

Loading…
Cancel
Save