fix rest of the failed tests

pull/4297/head
Tan Li Hau 6 years ago
parent 6fb365e735
commit 4590b867ee

@ -277,7 +277,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;
}
if (this.slot_block) { if (this.slot_block) {
block = this.slot_block; block = this.slot_block;

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

@ -2,5 +2,7 @@ import Renderer, { RenderOptions } from '../Renderer';
import RawMustacheTag from '../../nodes/RawMustacheTag'; import RawMustacheTag from '../../nodes/RawMustacheTag';
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); renderer.add_expression(node.expression.node);
renderer.add_string('<!-- HTML_TAG_END -->');
} }

@ -184,6 +184,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(html: string, 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(html);
}
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(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.data !== data) text.data = data; if (text.data !== data) text.data = data;
@ -288,11 +315,18 @@ export class HtmlTag {
t: HTMLElement; t: HTMLElement;
a: HTMLElement; a: HTMLElement;
constructor(html: string, anchor: HTMLElement = null) { constructor(html: string | ChildNode[]) {
this.e = element('div'); this.e = element('div');
this.a = anchor; if (Array.isArray(html)) {
this.n = html;
} else {
this.u(html); this.u(html);
} }
}
b(anchor: HTMLElement = null) {
this.a = anchor;
}
m(target: HTMLElement, anchor: HTMLElement = null) { m(target: HTMLElement, anchor: HTMLElement = null) {
for (let i = 0; i < this.n.length; i += 1) { for (let i = 0; i < this.n.length; i += 1) {

@ -52,8 +52,9 @@ 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(raw_value, null); html_tag.b(null);
attr(div, "class", "comment"); attr(div, "class", "comment");
}, },
m(target, anchor) { m(target, anchor) {

@ -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,8 @@
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