remove whitespace around <:Window/> - fixes #943

pull/946/head
Rich Harris 7 years ago
parent 4c06226a5c
commit dc154987da

@ -449,9 +449,18 @@ function preprocessChildren(
const cleaned: Node[] = [];
let lastChild: Node;
let windowComponent;
node.children.forEach((child: Node) => {
if (child.type === 'Comment') return;
// special case — this is an easy way to remove whitespace surrounding
// <:Window/>. lil hacky but it works
if (child.type === 'Element' && child.name === ':Window') {
windowComponent = child;
return;
}
if (child.type === 'Text' && lastChild && lastChild.type === 'Text') {
lastChild.data += child.data;
lastChild.end = child.end;
@ -502,6 +511,7 @@ function preprocessChildren(
}
node.children = cleaned;
if (windowComponent) cleaned.unshift(windowComponent);
}
export default function preprocess(

@ -61,7 +61,7 @@ export default function visitWindow(
block.builders.init.addBlock(deindent`
function ${handlerName}(event) {
${handlerBody}
};
}
window.addEventListener("${attribute.name}", ${handlerName});
`);
@ -121,7 +121,7 @@ export default function visitWindow(
block.builders.init.addBlock(deindent`
function ${handlerName}(event) {
${handlerBody}
};
}
window.addEventListener("${event}", ${handlerName});
`);
@ -144,7 +144,7 @@ export default function visitWindow(
? `#component.get("${bindings.scrollY}")`
: `window.scrollY`};
window.scrollTo(x, y);
};
}
`);
if (bindings.scrollX)
@ -172,7 +172,7 @@ export default function visitWindow(
block.builders.init.addBlock(deindent`
function ${handlerName}(event) {
#component.set({ ${bindings.online}: navigator.onLine });
};
}
window.addEventListener("online", ${handlerName});
window.addEventListener("offline", ${handlerName});
`);

@ -189,7 +189,7 @@ var proto = {
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
var window_updating = false, text, p, text_1, text_2;
var window_updating = false, p, text, text_1;
function onwindowscroll(event) {
window_updating = true;
@ -208,27 +208,24 @@ function create_main_fragment(state, component) {
return {
c: function create() {
text = createText("\n\n");
p = createElement("p");
text_1 = createText("scrolled to ");
text_2 = createText(state.y);
text = createText("scrolled to ");
text_1 = createText(state.y);
},
m: function mount(target, anchor) {
insertNode(text, target, anchor);
insertNode(p, target, anchor);
appendNode(text, p);
appendNode(text_1, p);
appendNode(text_2, p);
},
p: function update(changed, state) {
if (changed.y) {
text_2.data = state.y;
text_1.data = state.y;
}
},
u: function unmount() {
detachNode(text);
detachNode(p);
},

@ -2,7 +2,7 @@
import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
var window_updating = false, text, p, text_1, text_2;
var window_updating = false, p, text, text_1;
function onwindowscroll(event) {
window_updating = true;
@ -11,7 +11,7 @@ function create_main_fragment(state, component) {
y: this.scrollY
});
window_updating = false;
};
}
window.addEventListener("scroll", onwindowscroll);
component.observe("y", function(y) {
@ -21,27 +21,24 @@ function create_main_fragment(state, component) {
return {
c: function create() {
text = createText("\n\n");
p = createElement("p");
text_1 = createText("scrolled to ");
text_2 = createText(state.y);
text = createText("scrolled to ");
text_1 = createText(state.y);
},
m: function mount(target, anchor) {
insertNode(text, target, anchor);
insertNode(p, target, anchor);
appendNode(text, p);
appendNode(text_1, p);
appendNode(text_2, p);
},
p: function update(changed, state) {
if (changed.y) {
text_2.data = state.y;
text_1.data = state.y;
}
},
u: function unmount() {
detachNode(text);
detachNode(p);
},

Loading…
Cancel
Save