\ No newline at end of file
diff --git a/test/css/samples/omit-scoping-attribute-attribute-selector/_config.js b/test/css/samples/omit-scoping-attribute-attribute-selector/_config.js
deleted file mode 100644
index b37866f9b6..0000000000
--- a/test/css/samples/omit-scoping-attribute-attribute-selector/_config.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export default {
- cascade: false
-};
\ No newline at end of file
diff --git a/test/css/samples/omit-scoping-attribute-attribute-selector/expected.css b/test/css/samples/omit-scoping-attribute-attribute-selector/expected.css
index bd48ef22c5..ddb620207d 100644
--- a/test/css/samples/omit-scoping-attribute-attribute-selector/expected.css
+++ b/test/css/samples/omit-scoping-attribute-attribute-selector/expected.css
@@ -1 +1 @@
-[autoplay][svelte-xyz]{color:red}
\ No newline at end of file
+[autoplay].svelte-xyz{color:red}
\ No newline at end of file
diff --git a/test/css/samples/omit-scoping-attribute-attribute-selector/expected.html b/test/css/samples/omit-scoping-attribute-attribute-selector/expected.html
index 6a5b104388..52175f98b6 100644
--- a/test/css/samples/omit-scoping-attribute-attribute-selector/expected.html
+++ b/test/css/samples/omit-scoping-attribute-attribute-selector/expected.html
@@ -1,2 +1,2 @@
-
+
\ No newline at end of file
diff --git a/test/css/samples/omit-scoping-attribute-class-dynamic/_config.js b/test/css/samples/omit-scoping-attribute-class-dynamic/_config.js
deleted file mode 100644
index b37866f9b6..0000000000
--- a/test/css/samples/omit-scoping-attribute-class-dynamic/_config.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export default {
- cascade: false
-};
\ No newline at end of file
diff --git a/test/css/samples/omit-scoping-attribute-class-dynamic/expected.css b/test/css/samples/omit-scoping-attribute-class-dynamic/expected.css
index 6c4e704d2c..431f704106 100644
--- a/test/css/samples/omit-scoping-attribute-class-dynamic/expected.css
+++ b/test/css/samples/omit-scoping-attribute-class-dynamic/expected.css
@@ -1 +1 @@
-.foo[svelte-xyz]{color:red}
\ No newline at end of file
+.foo.svelte-xyz{color:red}
\ No newline at end of file
diff --git a/test/css/samples/omit-scoping-attribute-class-dynamic/expected.html b/test/css/samples/omit-scoping-attribute-class-dynamic/expected.html
index c45e8d88a6..451140e6e1 100644
--- a/test/css/samples/omit-scoping-attribute-class-dynamic/expected.html
+++ b/test/css/samples/omit-scoping-attribute-class-dynamic/expected.html
@@ -1,2 +1,2 @@
-
this is styled
+
this is styled
this is unstyled
\ No newline at end of file
diff --git a/test/css/samples/omit-scoping-attribute-class-dynamic/input.html b/test/css/samples/omit-scoping-attribute-class-dynamic/input.html
index 1ef2a1796a..40c8ad0b32 100644
--- a/test/css/samples/omit-scoping-attribute-class-dynamic/input.html
+++ b/test/css/samples/omit-scoping-attribute-class-dynamic/input.html
@@ -1,4 +1,4 @@
-
this is styled
+
this is styled
this is unstyled
\ No newline at end of file
diff --git a/test/css/samples/supports-query/expected.css b/test/css/samples/supports-query/expected.css
new file mode 100644
index 0000000000..3fdef34d6e
--- /dev/null
+++ b/test/css/samples/supports-query/expected.css
@@ -0,0 +1 @@
+@supports (display: grid){.maybe-grid.svelte-xyz{display:grid}}
\ No newline at end of file
diff --git a/test/css/samples/supports-query/input.html b/test/css/samples/supports-query/input.html
new file mode 100644
index 0000000000..776a7e9369
--- /dev/null
+++ b/test/css/samples/supports-query/input.html
@@ -0,0 +1,9 @@
+
something with a nice layout
+
+
diff --git a/test/css/samples/universal-selector/expected.css b/test/css/samples/universal-selector/expected.css
index ef584e723a..3eda95e446 100644
--- a/test/css/samples/universal-selector/expected.css
+++ b/test/css/samples/universal-selector/expected.css
@@ -1 +1 @@
-[svelte-xyz],[svelte-xyz] *{color:red}
\ No newline at end of file
+.svelte-xyz{color:red}
\ No newline at end of file
diff --git a/test/css/samples/unknown-at-rule/expected.css b/test/css/samples/unknown-at-rule/expected.css
index bc350108ba..31c3bf9c6f 100644
--- a/test/css/samples/unknown-at-rule/expected.css
+++ b/test/css/samples/unknown-at-rule/expected.css
@@ -1 +1 @@
-div[svelte-xyz],[svelte-xyz] div{@apply --funky-div;}
\ No newline at end of file
+div.svelte-xyz{@apply --funky-div;}
\ No newline at end of file
diff --git a/test/css/samples/unused-selector-leading/_config.js b/test/css/samples/unused-selector-leading/_config.js
index a5ae65ffa2..c01e978405 100644
--- a/test/css/samples/unused-selector-leading/_config.js
+++ b/test/css/samples/unused-selector-leading/_config.js
@@ -1,13 +1,18 @@
export default {
- cascade: false,
-
warnings: [
{
filename: "SvelteComponent.html",
+ code: `css-unused-selector`,
message: "Unused CSS selector",
- loc: {
+ start: {
+ line: 4,
+ column: 1,
+ character: 34
+ },
+ end: {
line: 4,
- column: 1
+ column: 5,
+ character: 38
},
pos: 34,
frame: `
@@ -21,10 +26,17 @@ export default {
{
filename: "SvelteComponent.html",
+ code: `css-unused-selector`,
message: "Unused CSS selector",
- loc: {
+ start: {
+ line: 4,
+ column: 13,
+ character: 46
+ },
+ end: {
line: 4,
- column: 13
+ column: 17,
+ character: 50
},
pos: 46,
frame: `
diff --git a/test/css/samples/unused-selector-leading/expected.css b/test/css/samples/unused-selector-leading/expected.css
index eb0b2678cf..ff57dc09b9 100644
--- a/test/css/samples/unused-selector-leading/expected.css
+++ b/test/css/samples/unused-selector-leading/expected.css
@@ -1 +1 @@
-.bar[svelte-xyz]{color:red}
\ No newline at end of file
+.bar.svelte-xyz{color:red}
\ No newline at end of file
diff --git a/test/css/samples/unused-selector-leading/expected.html b/test/css/samples/unused-selector-leading/expected.html
index 21f585b7e1..3f3d680596 100644
--- a/test/css/samples/unused-selector-leading/expected.html
+++ b/test/css/samples/unused-selector-leading/expected.html
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/css/samples/unused-selector-ternary/_config.js b/test/css/samples/unused-selector-ternary/_config.js
index 427e75a35d..f99ad90601 100644
--- a/test/css/samples/unused-selector-ternary/_config.js
+++ b/test/css/samples/unused-selector-ternary/_config.js
@@ -1,18 +1,23 @@
export default {
- cascade: false,
-
data: {
active: true
},
warnings: [{
filename: "SvelteComponent.html",
+ code: `css-unused-selector`,
message: "Unused CSS selector",
- loc: {
+ start: {
+ line: 12,
+ column: 1,
+ character: 123
+ },
+ end: {
line: 12,
- column: 1
+ column: 13,
+ character: 135
},
- pos: 125,
+ pos: 123,
frame: `
10: }
11:
diff --git a/test/css/samples/unused-selector-ternary/expected.css b/test/css/samples/unused-selector-ternary/expected.css
index b6bba2d5f3..16fbddce58 100644
--- a/test/css/samples/unused-selector-ternary/expected.css
+++ b/test/css/samples/unused-selector-ternary/expected.css
@@ -1 +1 @@
-.active[svelte-xyz]{color:red}.inactive[svelte-xyz]{color:blue}
\ No newline at end of file
+.active.svelte-xyz{color:red}.inactive.svelte-xyz{color:blue}
\ No newline at end of file
diff --git a/test/css/samples/unused-selector-ternary/expected.html b/test/css/samples/unused-selector-ternary/expected.html
index 5b0c6b6143..02fc551836 100644
--- a/test/css/samples/unused-selector-ternary/expected.html
+++ b/test/css/samples/unused-selector-ternary/expected.html
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/css/samples/unused-selector-ternary/input.html b/test/css/samples/unused-selector-ternary/input.html
index edffee317e..728dfa766a 100644
--- a/test/css/samples/unused-selector-ternary/input.html
+++ b/test/css/samples/unused-selector-ternary/input.html
@@ -1,4 +1,4 @@
-
+
`;
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
this._fragment.c();
this._fragment.m(this.shadowRoot, null);
- if (options.target) this._mount(options.target, options.anchor || null);
+ if (options.target) this._mount(options.target, options.anchor);
}
static get observedAttributes() {
@@ -231,15 +179,13 @@ class SvelteComponent extends HTMLElement {
}
}
-customElements.define("custom-element", SvelteComponent);
-assign(SvelteComponent.prototype, proto, {
+assign(SvelteComponent.prototype, proto);
+assign(SvelteComponent.prototype, {
_mount(target, anchor) {
target.insertBefore(this, anchor);
- },
-
- _unmount() {
- this.parentNode.removeChild(this);
}
});
+customElements.define("custom-element", SvelteComponent);
+
export default SvelteComponent;
diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js
index 496586e632..e86d8a3cb3 100644
--- a/test/js/samples/css-shadow-dom-keyframes/expected.js
+++ b/test/js/samples/css-shadow-dom-keyframes/expected.js
@@ -1,27 +1,27 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var div;
return {
- c: function create() {
+ c() {
div = createElement("div");
div.textContent = "fades in";
this.c = noop;
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
},
p: noop,
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
@@ -34,12 +34,12 @@ class SvelteComponent extends HTMLElement {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = ``;
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
this._fragment.c();
this._fragment.m(this.shadowRoot, null);
- if (options.target) this._mount(options.target, options.anchor || null);
+ if (options.target) this._mount(options.target, options.anchor);
}
static get observedAttributes() {
@@ -51,14 +51,12 @@ class SvelteComponent extends HTMLElement {
}
}
-customElements.define("custom-element", SvelteComponent);
-assign(SvelteComponent.prototype, proto, {
+assign(SvelteComponent.prototype, proto);
+assign(SvelteComponent.prototype, {
_mount(target, anchor) {
target.insertBefore(this, anchor);
- },
-
- _unmount() {
- this.parentNode.removeChild(this);
}
});
+
+customElements.define("custom-element", SvelteComponent);
export default SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/deconflict-builtins/expected-bundle.js b/test/js/samples/deconflict-builtins/expected-bundle.js
new file mode 100644
index 0000000000..effd1571f6
--- /dev/null
+++ b/test/js/samples/deconflict-builtins/expected-bundle.js
@@ -0,0 +1,262 @@
+function noop() {}
+
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
+}
+
+function appendNode(node, target) {
+ target.appendChild(node);
+}
+
+function insertNode(node, target, anchor) {
+ target.insertBefore(node, anchor);
+}
+
+function detachNode(node) {
+ node.parentNode.removeChild(node);
+}
+
+function destroyEach(iterations, detach) {
+ for (var i = 0; i < iterations.length; i += 1) {
+ if (iterations[i]) iterations[i].d(detach);
+ }
+}
+
+function createElement(name) {
+ return document.createElement(name);
+}
+
+function createText(data) {
+ return document.createTextNode(data);
+}
+
+function createComment() {
+ return document.createComment('');
+}
+
+function blankObject() {
+ return Object.create(null);
+}
+
+function destroy(detach) {
+ this.destroy = noop;
+ this.fire('destroy');
+ this.set = noop;
+
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
+}
+
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+}
+
+function fire(eventName, data) {
+ var handlers =
+ eventName in this._handlers && this._handlers[eventName].slice();
+ if (!handlers) return;
+
+ for (var i = 0; i < handlers.length; i += 1) {
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
+ }
+}
+
+function get() {
+ return this._state;
+}
+
+function init(component, options) {
+ component._handlers = blankObject();
+ component._bind = options._bind;
+
+ component.options = options;
+ component.root = options.root || component;
+ component.store = component.root.store || options.store;
+}
+
+function on(eventName, handler) {
+ var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
+ handlers.push(handler);
+
+ return {
+ cancel: function() {
+ var index = handlers.indexOf(handler);
+ if (~index) handlers.splice(index, 1);
+ }
+ };
+}
+
+function set(newState) {
+ this._set(assign({}, newState));
+ if (this.root._lock) return;
+ this.root._lock = true;
+ callAll(this.root._beforecreate);
+ callAll(this.root._oncreate);
+ callAll(this.root._aftercreate);
+ this.root._lock = false;
+}
+
+function _set(newState) {
+ var oldState = this._state,
+ changed = {},
+ dirty = false;
+
+ for (var key in newState) {
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ }
+ if (!dirty) return;
+
+ this._state = assign(assign({}, oldState), newState);
+ this._recompute(changed, this._state);
+ if (this._bind) this._bind(changed, this._state);
+
+ if (this._fragment) {
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
+ this._fragment.p(changed, this._state);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
+ }
+}
+
+function callAll(fns) {
+ while (fns && fns.length) fns.shift()();
+}
+
+function _mount(target, anchor) {
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
+}
+
+var proto = {
+ destroy,
+ get,
+ fire,
+ on,
+ set,
+ _recompute: noop,
+ _set,
+ _mount,
+ _differs
+};
+
+/* generated by Svelte vX.Y.Z */
+
+function create_main_fragment(component, ctx) {
+ var each_anchor;
+
+ var each_value = ctx.createElement;
+
+ var each_blocks = [];
+
+ for (var i = 0; i < each_value.length; i += 1) {
+ each_blocks[i] = create_each_block(component, get_each_context(ctx, each_value, i));
+ }
+
+ return {
+ c() {
+ for (var i = 0; i < each_blocks.length; i += 1) {
+ each_blocks[i].c();
+ }
+
+ each_anchor = createComment();
+ },
+
+ m(target, anchor) {
+ for (var i = 0; i < each_blocks.length; i += 1) {
+ each_blocks[i].m(target, anchor);
+ }
+
+ insertNode(each_anchor, target, anchor);
+ },
+
+ p(changed, ctx) {
+ if (changed.createElement) {
+ each_value = ctx.createElement;
+
+ for (var i = 0; i < each_value.length; i += 1) {
+ const child_ctx = get_each_context(ctx, each_value, i);
+
+ if (each_blocks[i]) {
+ each_blocks[i].p(changed, child_ctx);
+ } else {
+ each_blocks[i] = create_each_block(component, child_ctx);
+ each_blocks[i].c();
+ each_blocks[i].m(each_anchor.parentNode, each_anchor);
+ }
+ }
+
+ for (; i < each_blocks.length; i += 1) {
+ each_blocks[i].d(1);
+ }
+ each_blocks.length = each_value.length;
+ }
+ },
+
+ d(detach) {
+ destroyEach(each_blocks, detach);
+
+ if (detach) {
+ detachNode(each_anchor);
+ }
+ }
+ };
+}
+
+// (1:0) {#each createElement as node}
+function create_each_block(component, ctx) {
+ var span, text_value = ctx.node, text;
+
+ return {
+ c() {
+ span = createElement("span");
+ text = createText(text_value);
+ },
+
+ m(target, anchor) {
+ insertNode(span, target, anchor);
+ appendNode(text, span);
+ },
+
+ p(changed, ctx) {
+ if ((changed.createElement) && text_value !== (text_value = ctx.node)) {
+ text.data = text_value;
+ }
+ },
+
+ d(detach) {
+ if (detach) {
+ detachNode(span);
+ }
+ }
+ };
+}
+
+function get_each_context(ctx, list, i) {
+ const child_ctx = Object.create(ctx);
+ child_ctx.node = list[i];
+ child_ctx.each_value = list;
+ child_ctx.node_index = i;
+ return child_ctx;
+}
+
+function SvelteComponent(options) {
+ init(this, options);
+ this._state = assign({}, options.data);
+
+ this._fragment = create_main_fragment(this, this._state);
+
+ if (options.target) {
+ this._fragment.c();
+ this._mount(options.target, options.anchor);
+ }
+}
+
+assign(SvelteComponent.prototype, proto);
+
+export default SvelteComponent;
diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js
new file mode 100644
index 0000000000..8ae4b5dc3e
--- /dev/null
+++ b/test/js/samples/deconflict-builtins/expected.js
@@ -0,0 +1,115 @@
+/* generated by Svelte vX.Y.Z */
+import { appendNode, assign, createComment, createElement, createText, destroyEach, detachNode, init, insertNode, proto } from "svelte/shared.js";
+
+function create_main_fragment(component, ctx) {
+ var each_anchor;
+
+ var each_value = ctx.createElement;
+
+ var each_blocks = [];
+
+ for (var i = 0; i < each_value.length; i += 1) {
+ each_blocks[i] = create_each_block(component, get_each_context(ctx, each_value, i));
+ }
+
+ return {
+ c() {
+ for (var i = 0; i < each_blocks.length; i += 1) {
+ each_blocks[i].c();
+ }
+
+ each_anchor = createComment();
+ },
+
+ m(target, anchor) {
+ for (var i = 0; i < each_blocks.length; i += 1) {
+ each_blocks[i].m(target, anchor);
+ }
+
+ insertNode(each_anchor, target, anchor);
+ },
+
+ p(changed, ctx) {
+ if (changed.createElement) {
+ each_value = ctx.createElement;
+
+ for (var i = 0; i < each_value.length; i += 1) {
+ const child_ctx = get_each_context(ctx, each_value, i);
+
+ if (each_blocks[i]) {
+ each_blocks[i].p(changed, child_ctx);
+ } else {
+ each_blocks[i] = create_each_block(component, child_ctx);
+ each_blocks[i].c();
+ each_blocks[i].m(each_anchor.parentNode, each_anchor);
+ }
+ }
+
+ for (; i < each_blocks.length; i += 1) {
+ each_blocks[i].d(1);
+ }
+ each_blocks.length = each_value.length;
+ }
+ },
+
+ d(detach) {
+ destroyEach(each_blocks, detach);
+
+ if (detach) {
+ detachNode(each_anchor);
+ }
+ }
+ };
+}
+
+// (1:0) {#each createElement as node}
+function create_each_block(component, ctx) {
+ var span, text_value = ctx.node, text;
+
+ return {
+ c() {
+ span = createElement("span");
+ text = createText(text_value);
+ },
+
+ m(target, anchor) {
+ insertNode(span, target, anchor);
+ appendNode(text, span);
+ },
+
+ p(changed, ctx) {
+ if ((changed.createElement) && text_value !== (text_value = ctx.node)) {
+ text.data = text_value;
+ }
+ },
+
+ d(detach) {
+ if (detach) {
+ detachNode(span);
+ }
+ }
+ };
+}
+
+function get_each_context(ctx, list, i) {
+ const child_ctx = Object.create(ctx);
+ child_ctx.node = list[i];
+ child_ctx.each_value = list;
+ child_ctx.node_index = i;
+ return child_ctx;
+}
+
+function SvelteComponent(options) {
+ init(this, options);
+ this._state = assign({}, options.data);
+
+ this._fragment = create_main_fragment(this, this._state);
+
+ if (options.target) {
+ this._fragment.c();
+ this._mount(options.target, options.anchor);
+ }
+}
+
+assign(SvelteComponent.prototype, proto);
+export default SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/deconflict-builtins/input.html b/test/js/samples/deconflict-builtins/input.html
new file mode 100644
index 0000000000..48a413b323
--- /dev/null
+++ b/test/js/samples/deconflict-builtins/input.html
@@ -0,0 +1,3 @@
+{#each createElement as node}
+
{node}
+{/each}
\ No newline at end of file
diff --git a/test/js/samples/deconflict-globals/expected-bundle.js b/test/js/samples/deconflict-globals/expected-bundle.js
index ba22542c4b..06e30f87bc 100644
--- a/test/js/samples/deconflict-globals/expected-bundle.js
+++ b/test/js/samples/deconflict-globals/expected-bundle.js
@@ -1,16 +1,13 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
+}
- return target;
+function assignTrue(tar, src) {
+ for (var k in src) tar[k] = 1;
+ return tar;
}
function blankObject() {
@@ -20,36 +17,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -58,16 +34,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -76,30 +57,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -127,18 +85,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -147,28 +105,23 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
+
function data_1() {
return {
foo: 'bar'
@@ -178,8 +131,7 @@ function data_1() {
function oncreate() {
alert(JSON.stringify(data()));
}
-
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
return {
c: noop,
@@ -188,8 +140,6 @@ function create_main_fragment(state, component) {
p: noop,
- u: noop,
-
d: noop
};
}
@@ -198,19 +148,20 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign(data_1(), options.data);
- var _oncreate = oncreate.bind(this);
-
if (!options.root) {
this._oncreate = [];
}
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
- this.root._oncreate.push(_oncreate);
+ this.root._oncreate.push(() => {
+ oncreate.call(this);
+ this.fire("update", { changed: assignTrue({}, this._state), current: this._state });
+ });
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
callAll(this._oncreate);
}
diff --git a/test/js/samples/deconflict-globals/expected.js b/test/js/samples/deconflict-globals/expected.js
index 8730f4e3c3..afac48dfbd 100644
--- a/test/js/samples/deconflict-globals/expected.js
+++ b/test/js/samples/deconflict-globals/expected.js
@@ -1,5 +1,5 @@
/* generated by Svelte vX.Y.Z */
-import { assign, callAll, init, noop, proto } from "svelte/shared.js";
+import { assign, assignTrue, callAll, init, noop, proto } from "svelte/shared.js";
function data_1() {
return {
@@ -11,7 +11,7 @@ function oncreate() {
alert(JSON.stringify(data()));
};
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
return {
c: noop,
@@ -20,8 +20,6 @@ function create_main_fragment(state, component) {
p: noop,
- u: noop,
-
d: noop
};
}
@@ -30,19 +28,20 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign(data_1(), options.data);
- var _oncreate = oncreate.bind(this);
-
if (!options.root) {
this._oncreate = [];
}
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
- this.root._oncreate.push(_oncreate);
+ this.root._oncreate.push(() => {
+ oncreate.call(this);
+ this.fire("update", { changed: assignTrue({}, this._state), current: this._state });
+ });
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
callAll(this._oncreate);
}
diff --git a/test/js/samples/dev-warning-missing-data-computed/_config.js b/test/js/samples/dev-warning-missing-data-computed/_config.js
new file mode 100644
index 0000000000..b1f2518e8a
--- /dev/null
+++ b/test/js/samples/dev-warning-missing-data-computed/_config.js
@@ -0,0 +1,5 @@
+export default {
+ options: {
+ dev: true
+ }
+};
\ No newline at end of file
diff --git a/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js b/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js
new file mode 100644
index 0000000000..bb93b05841
--- /dev/null
+++ b/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js
@@ -0,0 +1,227 @@
+function noop() {}
+
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
+}
+
+function appendNode(node, target) {
+ target.appendChild(node);
+}
+
+function insertNode(node, target, anchor) {
+ target.insertBefore(node, anchor);
+}
+
+function detachNode(node) {
+ node.parentNode.removeChild(node);
+}
+
+function createElement(name) {
+ return document.createElement(name);
+}
+
+function createText(data) {
+ return document.createTextNode(data);
+}
+
+function blankObject() {
+ return Object.create(null);
+}
+
+function destroy(detach) {
+ this.destroy = noop;
+ this.fire('destroy');
+ this.set = noop;
+
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
+}
+
+function destroyDev(detach) {
+ destroy.call(this, detach);
+ this.destroy = function() {
+ console.warn('Component was already destroyed');
+ };
+}
+
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+}
+
+function fire(eventName, data) {
+ var handlers =
+ eventName in this._handlers && this._handlers[eventName].slice();
+ if (!handlers) return;
+
+ for (var i = 0; i < handlers.length; i += 1) {
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
+ }
+}
+
+function get() {
+ return this._state;
+}
+
+function init(component, options) {
+ component._handlers = blankObject();
+ component._bind = options._bind;
+
+ component.options = options;
+ component.root = options.root || component;
+ component.store = component.root.store || options.store;
+}
+
+function on(eventName, handler) {
+ var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
+ handlers.push(handler);
+
+ return {
+ cancel: function() {
+ var index = handlers.indexOf(handler);
+ if (~index) handlers.splice(index, 1);
+ }
+ };
+}
+
+function set(newState) {
+ this._set(assign({}, newState));
+ if (this.root._lock) return;
+ this.root._lock = true;
+ callAll(this.root._beforecreate);
+ callAll(this.root._oncreate);
+ callAll(this.root._aftercreate);
+ this.root._lock = false;
+}
+
+function _set(newState) {
+ var oldState = this._state,
+ changed = {},
+ dirty = false;
+
+ for (var key in newState) {
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ }
+ if (!dirty) return;
+
+ this._state = assign(assign({}, oldState), newState);
+ this._recompute(changed, this._state);
+ if (this._bind) this._bind(changed, this._state);
+
+ if (this._fragment) {
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
+ this._fragment.p(changed, this._state);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
+ }
+}
+
+function setDev(newState) {
+ if (typeof newState !== 'object') {
+ throw new Error(
+ this._debugName + '.set was called without an object of data key-values to update.'
+ );
+ }
+
+ this._checkReadOnly(newState);
+ set.call(this, newState);
+}
+
+function callAll(fns) {
+ while (fns && fns.length) fns.shift()();
+}
+
+function _mount(target, anchor) {
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
+}
+
+var protoDev = {
+ destroy: destroyDev,
+ get,
+ fire,
+ on,
+ set: setDev,
+ _recompute: noop,
+ _set,
+ _mount,
+ _differs
+};
+
+/* generated by Svelte vX.Y.Z */
+
+function bar({ foo }) {
+ return foo * 2;
+}
+
+function create_main_fragment(component, ctx) {
+ var p, text_value = ctx.Math.max(0, ctx.foo), text, text_1, text_2;
+
+ return {
+ c: function create() {
+ p = createElement("p");
+ text = createText(text_value);
+ text_1 = createText("\n\t");
+ text_2 = createText(ctx.bar);
+ },
+
+ m: function mount(target, anchor) {
+ insertNode(p, target, anchor);
+ appendNode(text, p);
+ appendNode(text_1, p);
+ appendNode(text_2, p);
+ },
+
+ p: function update(changed, ctx) {
+ if ((changed.Math || changed.foo) && text_value !== (text_value = ctx.Math.max(0, ctx.foo))) {
+ text.data = text_value;
+ }
+
+ if (changed.bar) {
+ text_2.data = ctx.bar;
+ }
+ },
+
+ d: function destroy$$1(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
+ };
+}
+
+function SvelteComponent(options) {
+ this._debugName = '
';
+ if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");
+ init(this, options);
+ this._state = assign({ Math : Math }, options.data);
+ this._recompute({ foo: 1 }, this._state);
+ if (!('foo' in this._state)) console.warn(" was created without expected data property 'foo'");
+
+ this._fragment = create_main_fragment(this, this._state);
+
+ if (options.target) {
+ if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
+ this._fragment.c();
+ this._mount(options.target, options.anchor);
+ }
+}
+
+assign(SvelteComponent.prototype, protoDev);
+
+SvelteComponent.prototype._checkReadOnly = function _checkReadOnly(newState) {
+ if ('bar' in newState && !this._updatingReadonlyProperty) throw new Error(": Cannot set read-only property 'bar'");
+};
+
+SvelteComponent.prototype._recompute = function _recompute(changed, state) {
+ if (changed.foo) {
+ if (this._differs(state.bar, (state.bar = bar(state)))) changed.bar = true;
+ }
+};
+
+export default SvelteComponent;
diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js
new file mode 100644
index 0000000000..5efb1f0a5e
--- /dev/null
+++ b/test/js/samples/dev-warning-missing-data-computed/expected.js
@@ -0,0 +1,72 @@
+/* generated by Svelte vX.Y.Z */
+import { appendNode, assign, createElement, createText, detachNode, init, insertNode, protoDev } from "svelte/shared.js";
+
+function bar({ foo }) {
+ return foo * 2;
+}
+
+function create_main_fragment(component, ctx) {
+ var p, text_value = ctx.Math.max(0, ctx.foo), text, text_1, text_2;
+
+ return {
+ c: function create() {
+ p = createElement("p");
+ text = createText(text_value);
+ text_1 = createText("\n\t");
+ text_2 = createText(ctx.bar);
+ },
+
+ m: function mount(target, anchor) {
+ insertNode(p, target, anchor);
+ appendNode(text, p);
+ appendNode(text_1, p);
+ appendNode(text_2, p);
+ },
+
+ p: function update(changed, ctx) {
+ if ((changed.Math || changed.foo) && text_value !== (text_value = ctx.Math.max(0, ctx.foo))) {
+ text.data = text_value;
+ }
+
+ if (changed.bar) {
+ text_2.data = ctx.bar;
+ }
+ },
+
+ d: function destroy(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
+ };
+}
+
+function SvelteComponent(options) {
+ this._debugName = '';
+ if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");
+ init(this, options);
+ this._state = assign({ Math : Math }, options.data);
+ this._recompute({ foo: 1 }, this._state);
+ if (!('foo' in this._state)) console.warn(" was created without expected data property 'foo'");
+
+ this._fragment = create_main_fragment(this, this._state);
+
+ if (options.target) {
+ if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
+ this._fragment.c();
+ this._mount(options.target, options.anchor);
+ }
+}
+
+assign(SvelteComponent.prototype, protoDev);
+
+SvelteComponent.prototype._checkReadOnly = function _checkReadOnly(newState) {
+ if ('bar' in newState && !this._updatingReadonlyProperty) throw new Error(": Cannot set read-only property 'bar'");
+};
+
+SvelteComponent.prototype._recompute = function _recompute(changed, state) {
+ if (changed.foo) {
+ if (this._differs(state.bar, (state.bar = bar(state)))) changed.bar = true;
+ }
+}
+export default SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/dev-warning-missing-data-computed/input.html b/test/js/samples/dev-warning-missing-data-computed/input.html
new file mode 100644
index 0000000000..06eb210493
--- /dev/null
+++ b/test/js/samples/dev-warning-missing-data-computed/input.html
@@ -0,0 +1,12 @@
+
+ {Math.max(0, foo)}
+ {bar}
+
+
+
\ No newline at end of file
diff --git a/test/js/samples/do-use-dataset/expected-bundle.js b/test/js/samples/do-use-dataset/expected-bundle.js
index 2079e6607c..e30355de25 100644
--- a/test/js/samples/do-use-dataset/expected-bundle.js
+++ b/test/js/samples/do-use-dataset/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -36,36 +28,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -74,16 +45,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -92,30 +68,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -143,18 +96,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -163,63 +116,54 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var div, text, div_1;
return {
- c: function create() {
+ c() {
div = createElement("div");
text = createText("\n");
div_1 = createElement("div");
- this.h();
- },
-
- h: function hydrate() {
div.dataset.foo = "bar";
- div_1.dataset.foo = state.bar;
+ div_1.dataset.foo = ctx.bar;
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
insertNode(text, target, anchor);
insertNode(div_1, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.bar) {
- div_1.dataset.foo = state.bar;
+ div_1.dataset.foo = ctx.bar;
}
},
- u: function unmount() {
- detachNode(div);
- detachNode(text);
- detachNode(div_1);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ detachNode(text);
+ detachNode(div_1);
+ }
+ }
};
}
@@ -227,11 +171,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/do-use-dataset/expected.js b/test/js/samples/do-use-dataset/expected.js
index 1ae7417469..a57edb8483 100644
--- a/test/js/samples/do-use-dataset/expected.js
+++ b/test/js/samples/do-use-dataset/expected.js
@@ -1,41 +1,37 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
+import { assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var div, text, div_1;
return {
- c: function create() {
+ c() {
div = createElement("div");
text = createText("\n");
div_1 = createElement("div");
- this.h();
- },
-
- h: function hydrate() {
div.dataset.foo = "bar";
- div_1.dataset.foo = state.bar;
+ div_1.dataset.foo = ctx.bar;
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
insertNode(text, target, anchor);
insertNode(div_1, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.bar) {
- div_1.dataset.foo = state.bar;
+ div_1.dataset.foo = ctx.bar;
}
},
- u: function unmount() {
- detachNode(div);
- detachNode(text);
- detachNode(div_1);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ detachNode(text);
+ detachNode(div_1);
+ }
+ }
};
}
@@ -43,11 +39,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/do-use-dataset/input.html b/test/js/samples/do-use-dataset/input.html
index acd9d623b4..fcd821731e 100644
--- a/test/js/samples/do-use-dataset/input.html
+++ b/test/js/samples/do-use-dataset/input.html
@@ -1,2 +1,2 @@
-
+
diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js
index efcfcc8f30..3cbc5ca530 100644
--- a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js
+++ b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -40,36 +32,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -78,16 +49,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -96,30 +72,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -147,18 +100,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -167,63 +120,54 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var div, text, div_1;
return {
- c: function create() {
+ c() {
div = createElement("div");
text = createText("\n");
div_1 = createElement("div");
- this.h();
- },
-
- h: function hydrate() {
setAttribute(div, "data-foo", "bar");
- setAttribute(div_1, "data-foo", state.bar);
+ setAttribute(div_1, "data-foo", ctx.bar);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
insertNode(text, target, anchor);
insertNode(div_1, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.bar) {
- setAttribute(div_1, "data-foo", state.bar);
+ setAttribute(div_1, "data-foo", ctx.bar);
}
},
- u: function unmount() {
- detachNode(div);
- detachNode(text);
- detachNode(div_1);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ detachNode(text);
+ detachNode(div_1);
+ }
+ }
};
}
@@ -231,11 +175,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected.js b/test/js/samples/dont-use-dataset-in-legacy/expected.js
index 03eef26ced..1475687e2d 100644
--- a/test/js/samples/dont-use-dataset-in-legacy/expected.js
+++ b/test/js/samples/dont-use-dataset-in-legacy/expected.js
@@ -1,41 +1,37 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js";
+import { assign, createElement, createText, detachNode, init, insertNode, proto, setAttribute } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var div, text, div_1;
return {
- c: function create() {
+ c() {
div = createElement("div");
text = createText("\n");
div_1 = createElement("div");
- this.h();
- },
-
- h: function hydrate() {
setAttribute(div, "data-foo", "bar");
- setAttribute(div_1, "data-foo", state.bar);
+ setAttribute(div_1, "data-foo", ctx.bar);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
insertNode(text, target, anchor);
insertNode(div_1, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.bar) {
- setAttribute(div_1, "data-foo", state.bar);
+ setAttribute(div_1, "data-foo", ctx.bar);
}
},
- u: function unmount() {
- detachNode(div);
- detachNode(text);
- detachNode(div_1);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ detachNode(text);
+ detachNode(div_1);
+ }
+ }
};
}
@@ -43,11 +39,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/dont-use-dataset-in-legacy/input.html b/test/js/samples/dont-use-dataset-in-legacy/input.html
index acd9d623b4..fcd821731e 100644
--- a/test/js/samples/dont-use-dataset-in-legacy/input.html
+++ b/test/js/samples/dont-use-dataset-in-legacy/input.html
@@ -1,2 +1,2 @@
-
+
diff --git a/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js b/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js
index cf43bbd130..80e1f60366 100644
--- a/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js
+++ b/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function appendNode(node, target) {
@@ -40,36 +32,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -78,16 +49,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -96,30 +72,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -147,18 +100,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -167,61 +120,52 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var svg, g, g_1;
return {
- c: function create() {
+ c() {
svg = createSvgElement("svg");
g = createSvgElement("g");
g_1 = createSvgElement("g");
- this.h();
- },
-
- h: function hydrate() {
setAttribute(g, "data-foo", "bar");
- setAttribute(g_1, "data-foo", state.bar);
+ setAttribute(g_1, "data-foo", ctx.bar);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(svg, target, anchor);
appendNode(g, svg);
appendNode(g_1, svg);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.bar) {
- setAttribute(g_1, "data-foo", state.bar);
+ setAttribute(g_1, "data-foo", ctx.bar);
}
},
- u: function unmount() {
- detachNode(svg);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(svg);
+ }
+ }
};
}
@@ -229,11 +173,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/dont-use-dataset-in-svg/expected.js b/test/js/samples/dont-use-dataset-in-svg/expected.js
index b87f152298..42bc11876e 100644
--- a/test/js/samples/dont-use-dataset-in-svg/expected.js
+++ b/test/js/samples/dont-use-dataset-in-svg/expected.js
@@ -1,39 +1,35 @@
/* generated by Svelte vX.Y.Z */
-import { appendNode, assign, createSvgElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js";
+import { appendNode, assign, createSvgElement, detachNode, init, insertNode, proto, setAttribute } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var svg, g, g_1;
return {
- c: function create() {
+ c() {
svg = createSvgElement("svg");
g = createSvgElement("g");
g_1 = createSvgElement("g");
- this.h();
- },
-
- h: function hydrate() {
setAttribute(g, "data-foo", "bar");
- setAttribute(g_1, "data-foo", state.bar);
+ setAttribute(g_1, "data-foo", ctx.bar);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(svg, target, anchor);
appendNode(g, svg);
appendNode(g_1, svg);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.bar) {
- setAttribute(g_1, "data-foo", state.bar);
+ setAttribute(g_1, "data-foo", ctx.bar);
}
},
- u: function unmount() {
- detachNode(svg);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(svg);
+ }
+ }
};
}
@@ -41,11 +37,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/dont-use-dataset-in-svg/input.html b/test/js/samples/dont-use-dataset-in-svg/input.html
index c351e2dc18..3032322b80 100644
--- a/test/js/samples/dont-use-dataset-in-svg/input.html
+++ b/test/js/samples/dont-use-dataset-in-svg/input.html
@@ -1,4 +1,4 @@
diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js
index e35826e354..2c2c8838da 100644
--- a/test/js/samples/each-block-changed-check/expected-bundle.js
+++ b/test/js/samples/each-block-changed-check/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function appendNode(node, target) {
@@ -31,9 +23,9 @@ function detachAfter(before) {
}
}
-function destroyEach(iterations) {
+function destroyEach(iterations, detach) {
for (var i = 0; i < iterations.length; i += 1) {
- if (iterations[i]) iterations[i].d();
+ if (iterations[i]) iterations[i].d(detach);
}
}
@@ -52,36 +44,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -90,16 +61,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -108,30 +84,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -159,18 +112,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -179,51 +132,46 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var text, p, text_1;
- var comments = state.comments;
+ var each_value = ctx.comments;
var each_blocks = [];
- for (var i = 0; i < comments.length; i += 1) {
- each_blocks[i] = create_each_block(state, comments, comments[i], i, component);
+ for (var i = 0; i < each_value.length; i += 1) {
+ each_blocks[i] = create_each_block(component, get_each_context(ctx, each_value, i));
}
return {
- c: function create() {
+ c() {
for (var i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
text = createText("\n\n");
p = createElement("p");
- text_1 = createText(state.foo);
+ text_1 = createText(ctx.foo);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
for (var i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(target, anchor);
}
@@ -233,56 +181,53 @@ function create_main_fragment(state, component) {
appendNode(text_1, p);
},
- p: function update(changed, state) {
- var comments = state.comments;
-
+ p(changed, ctx) {
if (changed.comments || changed.elapsed || changed.time) {
- for (var i = 0; i < comments.length; i += 1) {
+ each_value = ctx.comments;
+
+ for (var i = 0; i < each_value.length; i += 1) {
+ const child_ctx = get_each_context(ctx, each_value, i);
+
if (each_blocks[i]) {
- each_blocks[i].p(changed, state, comments, comments[i], i);
+ each_blocks[i].p(changed, child_ctx);
} else {
- each_blocks[i] = create_each_block(state, comments, comments[i], i, component);
+ each_blocks[i] = create_each_block(component, child_ctx);
each_blocks[i].c();
each_blocks[i].m(text.parentNode, text);
}
}
for (; i < each_blocks.length; i += 1) {
- each_blocks[i].u();
- each_blocks[i].d();
+ each_blocks[i].d(1);
}
- each_blocks.length = comments.length;
+ each_blocks.length = each_value.length;
}
if (changed.foo) {
- text_1.data = state.foo;
+ text_1.data = ctx.foo;
}
},
- u: function unmount() {
- for (var i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].u();
- }
-
- detachNode(text);
- detachNode(p);
- },
+ d(detach) {
+ destroyEach(each_blocks, detach);
- d: function destroy$$1() {
- destroyEach(each_blocks);
+ if (detach) {
+ detachNode(text);
+ detachNode(p);
+ }
}
};
}
-// (1:0) {{#each comments as comment, i}}
-function create_each_block(state, comments, comment, i, component) {
- var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before;
+// (1:0) {#each comments as comment, i}
+function create_each_block(component, ctx) {
+ var div, strong, text, text_1, span, text_2_value = ctx.comment.author, text_2, text_3, text_4_value = ctx.elapsed(ctx.comment.time, ctx.time), text_4, text_5, text_6, raw_value = ctx.comment.html, raw_before;
return {
- c: function create() {
+ c() {
div = createElement("div");
strong = createElement("strong");
- text = createText(i);
+ text = createText(ctx.i);
text_1 = createText("\n\n\t\t");
span = createElement("span");
text_2 = createText(text_2_value);
@@ -291,15 +236,11 @@ function create_each_block(state, comments, comment, i, component) {
text_5 = createText(" ago:");
text_6 = createText("\n\n\t\t");
raw_before = createElement('noscript');
- this.h();
- },
-
- h: function hydrate() {
span.className = "meta";
div.className = "comment";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
appendNode(strong, div);
appendNode(text, strong);
@@ -314,40 +255,46 @@ function create_each_block(state, comments, comment, i, component) {
raw_before.insertAdjacentHTML("afterend", raw_value);
},
- p: function update(changed, state, comments, comment, i) {
- if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) {
+ p(changed, ctx) {
+ if ((changed.comments) && text_2_value !== (text_2_value = ctx.comment.author)) {
text_2.data = text_2_value;
}
- if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time))) {
+ if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = ctx.elapsed(ctx.comment.time, ctx.time))) {
text_4.data = text_4_value;
}
- if ((changed.comments) && raw_value !== (raw_value = comment.html)) {
+ if ((changed.comments) && raw_value !== (raw_value = ctx.comment.html)) {
detachAfter(raw_before);
raw_before.insertAdjacentHTML("afterend", raw_value);
}
},
- u: function unmount() {
- detachAfter(raw_before);
-
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
+function get_each_context(ctx, list, i) {
+ const child_ctx = Object.create(ctx);
+ child_ctx.comment = list[i];
+ child_ctx.each_value = list;
+ child_ctx.i = i;
+ return child_ctx;
+}
+
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js
index 29a57322e0..609556bae0 100644
--- a/test/js/samples/each-block-changed-check/expected.js
+++ b/test/js/samples/each-block-changed-check/expected.js
@@ -1,29 +1,29 @@
/* generated by Svelte vX.Y.Z */
-import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
+import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var text, p, text_1;
- var comments = state.comments;
+ var each_value = ctx.comments;
var each_blocks = [];
- for (var i = 0; i < comments.length; i += 1) {
- each_blocks[i] = create_each_block(state, comments, comments[i], i, component);
+ for (var i = 0; i < each_value.length; i += 1) {
+ each_blocks[i] = create_each_block(component, get_each_context(ctx, each_value, i));
}
return {
- c: function create() {
+ c() {
for (var i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
text = createText("\n\n");
p = createElement("p");
- text_1 = createText(state.foo);
+ text_1 = createText(ctx.foo);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
for (var i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(target, anchor);
}
@@ -33,56 +33,53 @@ function create_main_fragment(state, component) {
appendNode(text_1, p);
},
- p: function update(changed, state) {
- var comments = state.comments;
-
+ p(changed, ctx) {
if (changed.comments || changed.elapsed || changed.time) {
- for (var i = 0; i < comments.length; i += 1) {
+ each_value = ctx.comments;
+
+ for (var i = 0; i < each_value.length; i += 1) {
+ const child_ctx = get_each_context(ctx, each_value, i);
+
if (each_blocks[i]) {
- each_blocks[i].p(changed, state, comments, comments[i], i);
+ each_blocks[i].p(changed, child_ctx);
} else {
- each_blocks[i] = create_each_block(state, comments, comments[i], i, component);
+ each_blocks[i] = create_each_block(component, child_ctx);
each_blocks[i].c();
each_blocks[i].m(text.parentNode, text);
}
}
for (; i < each_blocks.length; i += 1) {
- each_blocks[i].u();
- each_blocks[i].d();
+ each_blocks[i].d(1);
}
- each_blocks.length = comments.length;
+ each_blocks.length = each_value.length;
}
if (changed.foo) {
- text_1.data = state.foo;
+ text_1.data = ctx.foo;
}
},
- u: function unmount() {
- for (var i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].u();
- }
+ d(detach) {
+ destroyEach(each_blocks, detach);
- detachNode(text);
- detachNode(p);
- },
-
- d: function destroy() {
- destroyEach(each_blocks);
+ if (detach) {
+ detachNode(text);
+ detachNode(p);
+ }
}
};
}
-// (1:0) {{#each comments as comment, i}}
-function create_each_block(state, comments, comment, i, component) {
- var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before;
+// (1:0) {#each comments as comment, i}
+function create_each_block(component, ctx) {
+ var div, strong, text, text_1, span, text_2_value = ctx.comment.author, text_2, text_3, text_4_value = ctx.elapsed(ctx.comment.time, ctx.time), text_4, text_5, text_6, raw_value = ctx.comment.html, raw_before;
return {
- c: function create() {
+ c() {
div = createElement("div");
strong = createElement("strong");
- text = createText(i);
+ text = createText(ctx.i);
text_1 = createText("\n\n\t\t");
span = createElement("span");
text_2 = createText(text_2_value);
@@ -91,15 +88,11 @@ function create_each_block(state, comments, comment, i, component) {
text_5 = createText(" ago:");
text_6 = createText("\n\n\t\t");
raw_before = createElement('noscript');
- this.h();
- },
-
- h: function hydrate() {
span.className = "meta";
div.className = "comment";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
appendNode(strong, div);
appendNode(text, strong);
@@ -114,40 +107,46 @@ function create_each_block(state, comments, comment, i, component) {
raw_before.insertAdjacentHTML("afterend", raw_value);
},
- p: function update(changed, state, comments, comment, i) {
- if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) {
+ p(changed, ctx) {
+ if ((changed.comments) && text_2_value !== (text_2_value = ctx.comment.author)) {
text_2.data = text_2_value;
}
- if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time))) {
+ if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = ctx.elapsed(ctx.comment.time, ctx.time))) {
text_4.data = text_4_value;
}
- if ((changed.comments) && raw_value !== (raw_value = comment.html)) {
+ if ((changed.comments) && raw_value !== (raw_value = ctx.comment.html)) {
detachAfter(raw_before);
raw_before.insertAdjacentHTML("afterend", raw_value);
}
},
- u: function unmount() {
- detachAfter(raw_before);
-
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
+function get_each_context(ctx, list, i) {
+ const child_ctx = Object.create(ctx);
+ child_ctx.comment = list[i];
+ child_ctx.each_value = list;
+ child_ctx.i = i;
+ return child_ctx;
+}
+
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/each-block-changed-check/input.html b/test/js/samples/each-block-changed-check/input.html
index 5a80a1a6c1..b5b5703857 100644
--- a/test/js/samples/each-block-changed-check/input.html
+++ b/test/js/samples/each-block-changed-check/input.html
@@ -1,13 +1,13 @@
-{{#each comments as comment, i}}
+{#each comments as comment, i}
-{{/each}}
+{/each}
-{{foo}}
\ No newline at end of file
+{foo}
\ No newline at end of file
diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js
index 43db3035a3..10715bd84c 100644
--- a/test/js/samples/event-handlers-custom/expected-bundle.js
+++ b/test/js/samples/event-handlers-custom/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -32,36 +24,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -70,16 +41,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -88,30 +64,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -139,18 +92,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -159,67 +112,59 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
+
function foo( node, callback ) {
// code goes here
}
-
var methods = {
foo ( bar ) {
console.log( bar );
}
};
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var button, foo_handler;
return {
- c: function create() {
+ c() {
button = createElement("button");
button.textContent = "foo";
- this.h();
- },
-
- h: function hydrate() {
foo_handler = foo.call(component, button, function(event) {
- var state = component.get();
- component.foo( state.bar );
+ component.foo( ctx.bar );
});
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(button, target, anchor);
},
- p: noop,
+ p(changed, _ctx) {
+ ctx = _ctx;
- u: function unmount() {
- detachNode(button);
},
- d: function destroy$$1() {
- foo_handler.teardown();
+ d(detach) {
+ if (detach) {
+ detachNode(button);
+ }
+
+ foo_handler.destroy();
}
};
}
@@ -228,14 +173,15 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
-assign(SvelteComponent.prototype, methods, proto);
+assign(SvelteComponent.prototype, proto);
+assign(SvelteComponent.prototype, methods);
export default SvelteComponent;
diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js
index f7862efb62..86741c470c 100644
--- a/test/js/samples/event-handlers-custom/expected.js
+++ b/test/js/samples/event-handlers-custom/expected.js
@@ -1,5 +1,5 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
+import { assign, createElement, detachNode, init, insertNode, proto } from "svelte/shared.js";
function foo( node, callback ) {
// code goes here
@@ -11,35 +11,33 @@ var methods = {
}
};
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var button, foo_handler;
return {
- c: function create() {
+ c() {
button = createElement("button");
button.textContent = "foo";
- this.h();
- },
-
- h: function hydrate() {
foo_handler = foo.call(component, button, function(event) {
- var state = component.get();
- component.foo( state.bar );
+ component.foo( ctx.bar );
});
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(button, target, anchor);
},
- p: noop,
+ p(changed, _ctx) {
+ ctx = _ctx;
- u: function unmount() {
- detachNode(button);
},
- d: function destroy() {
- foo_handler.teardown();
+ d(detach) {
+ if (detach) {
+ detachNode(button);
+ }
+
+ foo_handler.destroy();
}
};
}
@@ -48,13 +46,14 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
-assign(SvelteComponent.prototype, methods, proto);
+assign(SvelteComponent.prototype, proto);
+assign(SvelteComponent.prototype, methods);
export default SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/head-no-whitespace/expected-bundle.js b/test/js/samples/head-no-whitespace/expected-bundle.js
index 91f894bc30..539ea3e5a4 100644
--- a/test/js/samples/head-no-whitespace/expected-bundle.js
+++ b/test/js/samples/head-no-whitespace/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function appendNode(node, target) {
@@ -32,36 +24,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -70,16 +41,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -88,30 +64,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -139,18 +92,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -159,58 +112,47 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var meta, meta_1;
return {
- c: function create() {
+ c() {
meta = createElement("meta");
meta_1 = createElement("meta");
- this.h();
- },
-
- h: function hydrate() {
meta.name = "twitter:creator";
meta.content = "@sveltejs";
meta_1.name = "twitter:title";
meta_1.content = "Svelte";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
appendNode(meta, document.head);
appendNode(meta_1, document.head);
},
p: noop,
- u: function unmount() {
+ d(detach) {
detachNode(meta);
detachNode(meta_1);
- },
-
- d: noop
+ }
};
}
@@ -218,11 +160,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/head-no-whitespace/expected.js b/test/js/samples/head-no-whitespace/expected.js
index 32a1a5da88..58b3f0e311 100644
--- a/test/js/samples/head-no-whitespace/expected.js
+++ b/test/js/samples/head-no-whitespace/expected.js
@@ -1,36 +1,30 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createElement, detachNode, init, noop, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var meta, meta_1;
return {
- c: function create() {
+ c() {
meta = createElement("meta");
meta_1 = createElement("meta");
- this.h();
- },
-
- h: function hydrate() {
meta.name = "twitter:creator";
meta.content = "@sveltejs";
meta_1.name = "twitter:title";
meta_1.content = "Svelte";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
appendNode(meta, document.head);
appendNode(meta_1, document.head);
},
p: noop,
- u: function unmount() {
+ d(detach) {
detachNode(meta);
detachNode(meta_1);
- },
-
- d: noop
+ }
};
}
@@ -38,11 +32,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/head-no-whitespace/input.html b/test/js/samples/head-no-whitespace/input.html
index 37c387083d..000b643abe 100644
--- a/test/js/samples/head-no-whitespace/input.html
+++ b/test/js/samples/head-no-whitespace/input.html
@@ -1,4 +1,4 @@
-<:Head>
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/js/samples/if-block-no-update/expected-bundle.js b/test/js/samples/if-block-no-update/expected-bundle.js
index b309a25e96..d54a62c227 100644
--- a/test/js/samples/if-block-no-update/expected-bundle.js
+++ b/test/js/samples/if-block-no-update/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -36,36 +28,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -74,16 +45,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -92,30 +68,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -143,18 +96,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -163,124 +116,116 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var if_block_anchor;
- var current_block_type = select_block_type(state);
- var if_block = current_block_type(state, component);
+ function select_block_type(ctx) {
+ if (ctx.foo) return create_if_block;
+ return create_if_block_1;
+ }
+
+ var current_block_type = select_block_type(ctx);
+ var if_block = current_block_type(component, ctx);
return {
- c: function create() {
+ c() {
if_block.c();
if_block_anchor = createComment();
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
if_block.m(target, anchor);
insertNode(if_block_anchor, target, anchor);
},
- p: function update(changed, state) {
- if (current_block_type !== (current_block_type = select_block_type(state))) {
- if_block.u();
- if_block.d();
- if_block = current_block_type(state, component);
+ p(changed, ctx) {
+ if (current_block_type !== (current_block_type = select_block_type(ctx))) {
+ if_block.d(1);
+ if_block = current_block_type(component, ctx);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
},
- u: function unmount() {
- if_block.u();
- detachNode(if_block_anchor);
- },
-
- d: function destroy$$1() {
- if_block.d();
+ d(detach) {
+ if_block.d(detach);
+ if (detach) {
+ detachNode(if_block_anchor);
+ }
}
};
}
-// (1:0) {{#if foo}}
-function create_if_block(state, component) {
+// (1:0) {#if foo}
+function create_if_block(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "foo!";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (3:0) {{else}}
-function create_if_block_1(state, component) {
+// (3:0) {:else}
+function create_if_block_1(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "not foo!";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-function select_block_type(state) {
- if (state.foo) return create_if_block;
- return create_if_block_1;
-}
-
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js
index 8f030e4e53..6bed171850 100644
--- a/test/js/samples/if-block-no-update/expected.js
+++ b/test/js/samples/if-block-no-update/expected.js
@@ -1,102 +1,99 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
+import { assign, createComment, createElement, detachNode, init, insertNode, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var if_block_anchor;
- var current_block_type = select_block_type(state);
- var if_block = current_block_type(state, component);
+ function select_block_type(ctx) {
+ if (ctx.foo) return create_if_block;
+ return create_if_block_1;
+ }
+
+ var current_block_type = select_block_type(ctx);
+ var if_block = current_block_type(component, ctx);
return {
- c: function create() {
+ c() {
if_block.c();
if_block_anchor = createComment();
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
if_block.m(target, anchor);
insertNode(if_block_anchor, target, anchor);
},
- p: function update(changed, state) {
- if (current_block_type !== (current_block_type = select_block_type(state))) {
- if_block.u();
- if_block.d();
- if_block = current_block_type(state, component);
+ p(changed, ctx) {
+ if (current_block_type !== (current_block_type = select_block_type(ctx))) {
+ if_block.d(1);
+ if_block = current_block_type(component, ctx);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
},
- u: function unmount() {
- if_block.u();
- detachNode(if_block_anchor);
- },
-
- d: function destroy() {
- if_block.d();
+ d(detach) {
+ if_block.d(detach);
+ if (detach) {
+ detachNode(if_block_anchor);
+ }
}
};
}
-// (1:0) {{#if foo}}
-function create_if_block(state, component) {
+// (1:0) {#if foo}
+function create_if_block(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "foo!";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (3:0) {{else}}
-function create_if_block_1(state, component) {
+// (3:0) {:else}
+function create_if_block_1(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "not foo!";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-function select_block_type(state) {
- if (state.foo) return create_if_block;
- return create_if_block_1;
-}
-
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/if-block-no-update/input.html b/test/js/samples/if-block-no-update/input.html
index c73bfc6242..57de219159 100644
--- a/test/js/samples/if-block-no-update/input.html
+++ b/test/js/samples/if-block-no-update/input.html
@@ -1,5 +1,5 @@
-{{#if foo}}
+{#if foo}
foo!
-{{else}}
+{:else}
not foo!
-{{/if}}
\ No newline at end of file
+{/if}
\ No newline at end of file
diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js
index 5084639f4b..9a067201fb 100644
--- a/test/js/samples/if-block-simple/expected-bundle.js
+++ b/test/js/samples/if-block-simple/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -36,36 +28,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -74,16 +45,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -92,30 +68,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -143,18 +96,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -163,88 +116,80 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var if_block_anchor;
- var if_block = (state.foo) && create_if_block(state, component);
+ var if_block = (ctx.foo) && create_if_block(component, ctx);
return {
- c: function create() {
+ c() {
if (if_block) if_block.c();
if_block_anchor = createComment();
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
if (if_block) if_block.m(target, anchor);
insertNode(if_block_anchor, target, anchor);
},
- p: function update(changed, state) {
- if (state.foo) {
+ p(changed, ctx) {
+ if (ctx.foo) {
if (!if_block) {
- if_block = create_if_block(state, component);
+ if_block = create_if_block(component, ctx);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
} else if (if_block) {
- if_block.u();
- if_block.d();
+ if_block.d(1);
if_block = null;
}
},
- u: function unmount() {
- if (if_block) if_block.u();
- detachNode(if_block_anchor);
- },
-
- d: function destroy$$1() {
- if (if_block) if_block.d();
+ d(detach) {
+ if (if_block) if_block.d(detach);
+ if (detach) {
+ detachNode(if_block_anchor);
+ }
}
};
}
-// (1:0) {{#if foo}}
-function create_if_block(state, component) {
+// (1:0) {#if foo}
+function create_if_block(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "foo!";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
@@ -252,11 +197,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js
index 0b9fbece70..98458d918f 100644
--- a/test/js/samples/if-block-simple/expected.js
+++ b/test/js/samples/if-block-simple/expected.js
@@ -1,66 +1,63 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
+import { assign, createComment, createElement, detachNode, init, insertNode, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var if_block_anchor;
- var if_block = (state.foo) && create_if_block(state, component);
+ var if_block = (ctx.foo) && create_if_block(component, ctx);
return {
- c: function create() {
+ c() {
if (if_block) if_block.c();
if_block_anchor = createComment();
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
if (if_block) if_block.m(target, anchor);
insertNode(if_block_anchor, target, anchor);
},
- p: function update(changed, state) {
- if (state.foo) {
+ p(changed, ctx) {
+ if (ctx.foo) {
if (!if_block) {
- if_block = create_if_block(state, component);
+ if_block = create_if_block(component, ctx);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
} else if (if_block) {
- if_block.u();
- if_block.d();
+ if_block.d(1);
if_block = null;
}
},
- u: function unmount() {
- if (if_block) if_block.u();
- detachNode(if_block_anchor);
- },
-
- d: function destroy() {
- if (if_block) if_block.d();
+ d(detach) {
+ if (if_block) if_block.d(detach);
+ if (detach) {
+ detachNode(if_block_anchor);
+ }
}
};
}
-// (1:0) {{#if foo}}
-function create_if_block(state, component) {
+// (1:0) {#if foo}
+function create_if_block(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "foo!";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
@@ -68,11 +65,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/if-block-simple/input.html b/test/js/samples/if-block-simple/input.html
index 050095b913..e36517e10c 100644
--- a/test/js/samples/if-block-simple/input.html
+++ b/test/js/samples/if-block-simple/input.html
@@ -1,3 +1,3 @@
-{{#if foo}}
+{#if foo}
foo!
-{{/if}}
\ No newline at end of file
+{/if}
\ No newline at end of file
diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js
index 753d61db71..13da6e5fc0 100644
--- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js
+++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -36,36 +28,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -74,16 +45,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -92,30 +68,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -143,18 +96,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -163,61 +116,52 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var div;
return {
- c: function create() {
+ c() {
div = createElement("div");
- this.h();
- },
-
- h: function hydrate() {
- setStyle(div, "color", state.color);
- setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)");
+ setStyle(div, "color", ctx.color);
+ setStyle(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)");
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.color) {
- setStyle(div, "color", state.color);
+ setStyle(div, "color", ctx.color);
}
if (changed.x || changed.y) {
- setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)");
+ setStyle(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)");
}
},
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
@@ -225,11 +169,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js
index 77173460e2..742da2b3d9 100644
--- a/test/js/samples/inline-style-optimized-multiple/expected.js
+++ b/test/js/samples/inline-style-optimized-multiple/expected.js
@@ -1,39 +1,35 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js";
+import { assign, createElement, detachNode, init, insertNode, proto, setStyle } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var div;
return {
- c: function create() {
+ c() {
div = createElement("div");
- this.h();
+ setStyle(div, "color", ctx.color);
+ setStyle(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)");
},
- h: function hydrate() {
- setStyle(div, "color", state.color);
- setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)");
- },
-
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.color) {
- setStyle(div, "color", state.color);
+ setStyle(div, "color", ctx.color);
}
if (changed.x || changed.y) {
- setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)");
+ setStyle(div, "transform", "translate(" + ctx.x + "px," + ctx.y + "px)");
}
},
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
@@ -41,11 +37,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/inline-style-optimized-multiple/input.html b/test/js/samples/inline-style-optimized-multiple/input.html
index 92d9cb805d..d9448e0ab0 100644
--- a/test/js/samples/inline-style-optimized-multiple/input.html
+++ b/test/js/samples/inline-style-optimized-multiple/input.html
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js
index cf360881b1..f27fd1f154 100644
--- a/test/js/samples/inline-style-optimized-url/expected-bundle.js
+++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -36,36 +28,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -74,16 +45,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -92,30 +68,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -143,18 +96,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -163,56 +116,47 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var div;
return {
- c: function create() {
+ c() {
div = createElement("div");
- this.h();
- },
-
- h: function hydrate() {
- setStyle(div, "background", "url(data:image/png;base64," + state.data + ")");
+ setStyle(div, "background", "url(data:image/png;base64," + ctx.data + ")");
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.data) {
- setStyle(div, "background", "url(data:image/png;base64," + state.data + ")");
+ setStyle(div, "background", "url(data:image/png;base64," + ctx.data + ")");
}
},
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
@@ -220,11 +164,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js
index bed00356f6..2eb51e0818 100644
--- a/test/js/samples/inline-style-optimized-url/expected.js
+++ b/test/js/samples/inline-style-optimized-url/expected.js
@@ -1,34 +1,30 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js";
+import { assign, createElement, detachNode, init, insertNode, proto, setStyle } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var div;
return {
- c: function create() {
+ c() {
div = createElement("div");
- this.h();
+ setStyle(div, "background", "url(data:image/png;base64," + ctx.data + ")");
},
- h: function hydrate() {
- setStyle(div, "background", "url(data:image/png;base64," + state.data + ")");
- },
-
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.data) {
- setStyle(div, "background", "url(data:image/png;base64," + state.data + ")");
+ setStyle(div, "background", "url(data:image/png;base64," + ctx.data + ")");
}
},
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
@@ -36,11 +32,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/inline-style-optimized-url/input.html b/test/js/samples/inline-style-optimized-url/input.html
index 7e3b2928eb..677da52c30 100644
--- a/test/js/samples/inline-style-optimized-url/input.html
+++ b/test/js/samples/inline-style-optimized-url/input.html
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js
index 38024df4ff..1df7465c86 100644
--- a/test/js/samples/inline-style-optimized/expected-bundle.js
+++ b/test/js/samples/inline-style-optimized/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -36,36 +28,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -74,16 +45,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -92,30 +68,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -143,18 +96,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -163,56 +116,47 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var div;
return {
- c: function create() {
+ c() {
div = createElement("div");
- this.h();
- },
-
- h: function hydrate() {
- setStyle(div, "color", state.color);
+ setStyle(div, "color", ctx.color);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.color) {
- setStyle(div, "color", state.color);
+ setStyle(div, "color", ctx.color);
}
},
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
@@ -220,11 +164,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js
index 7f873e296c..9c55bc6e84 100644
--- a/test/js/samples/inline-style-optimized/expected.js
+++ b/test/js/samples/inline-style-optimized/expected.js
@@ -1,34 +1,30 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js";
+import { assign, createElement, detachNode, init, insertNode, proto, setStyle } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var div;
return {
- c: function create() {
+ c() {
div = createElement("div");
- this.h();
+ setStyle(div, "color", ctx.color);
},
- h: function hydrate() {
- setStyle(div, "color", state.color);
- },
-
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.color) {
- setStyle(div, "color", state.color);
+ setStyle(div, "color", ctx.color);
}
},
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
+ }
};
}
@@ -36,11 +32,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/inline-style-optimized/input.html b/test/js/samples/inline-style-optimized/input.html
index ff7d95fb6e..004fd595c9 100644
--- a/test/js/samples/inline-style-optimized/input.html
+++ b/test/js/samples/inline-style-optimized/input.html
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js
index 320c733a43..ed8e4fd01c 100644
--- a/test/js/samples/inline-style-unoptimized/expected-bundle.js
+++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -36,36 +28,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -74,16 +45,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -92,30 +68,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -143,18 +96,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -163,67 +116,58 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var div, text, div_1, div_1_style_value;
return {
- c: function create() {
+ c() {
div = createElement("div");
text = createText("\n");
div_1 = createElement("div");
- this.h();
- },
-
- h: function hydrate() {
- div.style.cssText = state.style;
- div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value;
+ div.style.cssText = ctx.style;
+ div_1.style.cssText = div_1_style_value = "" + ctx.key + ": " + ctx.value;
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
insertNode(text, target, anchor);
insertNode(div_1, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.style) {
- div.style.cssText = state.style;
+ div.style.cssText = ctx.style;
}
- if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value)) {
+ if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + ctx.key + ": " + ctx.value)) {
div_1.style.cssText = div_1_style_value;
}
},
- u: function unmount() {
- detachNode(div);
- detachNode(text);
- detachNode(div_1);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ detachNode(text);
+ detachNode(div_1);
+ }
+ }
};
}
@@ -231,11 +175,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js
index 4c4d38d2bf..41ffd501e0 100644
--- a/test/js/samples/inline-style-unoptimized/expected.js
+++ b/test/js/samples/inline-style-unoptimized/expected.js
@@ -1,45 +1,41 @@
/* generated by Svelte vX.Y.Z */
-import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
+import { assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var div, text, div_1, div_1_style_value;
return {
- c: function create() {
+ c() {
div = createElement("div");
text = createText("\n");
div_1 = createElement("div");
- this.h();
+ div.style.cssText = ctx.style;
+ div_1.style.cssText = div_1_style_value = "" + ctx.key + ": " + ctx.value;
},
- h: function hydrate() {
- div.style.cssText = state.style;
- div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value;
- },
-
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
insertNode(text, target, anchor);
insertNode(div_1, target, anchor);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.style) {
- div.style.cssText = state.style;
+ div.style.cssText = ctx.style;
}
- if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value)) {
+ if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + ctx.key + ": " + ctx.value)) {
div_1.style.cssText = div_1_style_value;
}
},
- u: function unmount() {
- detachNode(div);
- detachNode(text);
- detachNode(div_1);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ detachNode(text);
+ detachNode(div_1);
+ }
+ }
};
}
@@ -47,11 +43,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/inline-style-unoptimized/input.html b/test/js/samples/inline-style-unoptimized/input.html
index 87e4592bfd..eac76d5b6e 100644
--- a/test/js/samples/inline-style-unoptimized/input.html
+++ b/test/js/samples/inline-style-unoptimized/input.html
@@ -1,2 +1,2 @@
-
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/test/js/samples/input-range/expected-bundle.js b/test/js/samples/input-range/expected-bundle.js
new file mode 100644
index 0000000000..048c9e088f
--- /dev/null
+++ b/test/js/samples/input-range/expected-bundle.js
@@ -0,0 +1,198 @@
+function noop() {}
+
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
+}
+
+function insertNode(node, target, anchor) {
+ target.insertBefore(node, anchor);
+}
+
+function detachNode(node) {
+ node.parentNode.removeChild(node);
+}
+
+function createElement(name) {
+ return document.createElement(name);
+}
+
+function addListener(node, event, handler) {
+ node.addEventListener(event, handler, false);
+}
+
+function removeListener(node, event, handler) {
+ node.removeEventListener(event, handler, false);
+}
+
+function setAttribute(node, attribute, value) {
+ node.setAttribute(attribute, value);
+}
+
+function toNumber(value) {
+ return value === '' ? undefined : +value;
+}
+
+function blankObject() {
+ return Object.create(null);
+}
+
+function destroy(detach) {
+ this.destroy = noop;
+ this.fire('destroy');
+ this.set = noop;
+
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
+}
+
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+}
+
+function fire(eventName, data) {
+ var handlers =
+ eventName in this._handlers && this._handlers[eventName].slice();
+ if (!handlers) return;
+
+ for (var i = 0; i < handlers.length; i += 1) {
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
+ }
+}
+
+function get() {
+ return this._state;
+}
+
+function init(component, options) {
+ component._handlers = blankObject();
+ component._bind = options._bind;
+
+ component.options = options;
+ component.root = options.root || component;
+ component.store = component.root.store || options.store;
+}
+
+function on(eventName, handler) {
+ var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
+ handlers.push(handler);
+
+ return {
+ cancel: function() {
+ var index = handlers.indexOf(handler);
+ if (~index) handlers.splice(index, 1);
+ }
+ };
+}
+
+function set(newState) {
+ this._set(assign({}, newState));
+ if (this.root._lock) return;
+ this.root._lock = true;
+ callAll(this.root._beforecreate);
+ callAll(this.root._oncreate);
+ callAll(this.root._aftercreate);
+ this.root._lock = false;
+}
+
+function _set(newState) {
+ var oldState = this._state,
+ changed = {},
+ dirty = false;
+
+ for (var key in newState) {
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ }
+ if (!dirty) return;
+
+ this._state = assign(assign({}, oldState), newState);
+ this._recompute(changed, this._state);
+ if (this._bind) this._bind(changed, this._state);
+
+ if (this._fragment) {
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
+ this._fragment.p(changed, this._state);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
+ }
+}
+
+function callAll(fns) {
+ while (fns && fns.length) fns.shift()();
+}
+
+function _mount(target, anchor) {
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
+}
+
+var proto = {
+ destroy,
+ get,
+ fire,
+ on,
+ set,
+ _recompute: noop,
+ _set,
+ _mount,
+ _differs
+};
+
+/* generated by Svelte vX.Y.Z */
+
+function create_main_fragment(component, ctx) {
+ var input;
+
+ function input_change_input_handler() {
+ component.set({ value: toNumber(input.value) });
+ }
+
+ return {
+ c() {
+ input = createElement("input");
+ addListener(input, "change", input_change_input_handler);
+ addListener(input, "input", input_change_input_handler);
+ setAttribute(input, "type", "range");
+ },
+
+ m(target, anchor) {
+ insertNode(input, target, anchor);
+
+ input.value = ctx.value;
+ },
+
+ p(changed, ctx) {
+ input.value = ctx.value;
+ },
+
+ d(detach) {
+ if (detach) {
+ detachNode(input);
+ }
+
+ removeListener(input, "change", input_change_input_handler);
+ removeListener(input, "input", input_change_input_handler);
+ }
+ };
+}
+
+function SvelteComponent(options) {
+ init(this, options);
+ this._state = assign({}, options.data);
+
+ this._fragment = create_main_fragment(this, this._state);
+
+ if (options.target) {
+ this._fragment.c();
+ this._mount(options.target, options.anchor);
+ }
+}
+
+assign(SvelteComponent.prototype, proto);
+
+export default SvelteComponent;
diff --git a/test/js/samples/input-range/expected.js b/test/js/samples/input-range/expected.js
new file mode 100644
index 0000000000..0899036bac
--- /dev/null
+++ b/test/js/samples/input-range/expected.js
@@ -0,0 +1,53 @@
+/* generated by Svelte vX.Y.Z */
+import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener, setAttribute, toNumber } from "svelte/shared.js";
+
+function create_main_fragment(component, ctx) {
+ var input;
+
+ function input_change_input_handler() {
+ component.set({ value: toNumber(input.value) });
+ }
+
+ return {
+ c() {
+ input = createElement("input");
+ addListener(input, "change", input_change_input_handler);
+ addListener(input, "input", input_change_input_handler);
+ setAttribute(input, "type", "range");
+ },
+
+ m(target, anchor) {
+ insertNode(input, target, anchor);
+
+ input.value = ctx.value;
+ },
+
+ p(changed, ctx) {
+ input.value = ctx.value;
+ },
+
+ d(detach) {
+ if (detach) {
+ detachNode(input);
+ }
+
+ removeListener(input, "change", input_change_input_handler);
+ removeListener(input, "input", input_change_input_handler);
+ }
+ };
+}
+
+function SvelteComponent(options) {
+ init(this, options);
+ this._state = assign({}, options.data);
+
+ this._fragment = create_main_fragment(this, this._state);
+
+ if (options.target) {
+ this._fragment.c();
+ this._mount(options.target, options.anchor);
+ }
+}
+
+assign(SvelteComponent.prototype, proto);
+export default SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/input-range/input.html b/test/js/samples/input-range/input.html
new file mode 100644
index 0000000000..e080b9a81b
--- /dev/null
+++ b/test/js/samples/input-range/input.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/test/js/samples/input-without-blowback-guard/expected-bundle.js b/test/js/samples/input-without-blowback-guard/expected-bundle.js
index eacaca85a6..67915bc81b 100644
--- a/test/js/samples/input-without-blowback-guard/expected-bundle.js
+++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -33,6 +25,10 @@ function removeListener(node, event, handler) {
node.removeEventListener(event, handler, false);
}
+function setAttribute(node, attribute, value) {
+ node.setAttribute(attribute, value);
+}
+
function blankObject() {
return Object.create(null);
}
@@ -40,36 +36,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -78,16 +53,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -96,30 +76,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -147,18 +104,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -167,29 +124,24 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var input;
function input_change_handler() {
@@ -197,31 +149,27 @@ function create_main_fragment(state, component) {
}
return {
- c: function create() {
+ c() {
input = createElement("input");
- this.h();
- },
-
- h: function hydrate() {
addListener(input, "change", input_change_handler);
- input.type = "checkbox";
+ setAttribute(input, "type", "checkbox");
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(input, target, anchor);
- input.checked = state.foo;
+ input.checked = ctx.foo;
},
- p: function update(changed, state) {
- input.checked = state.foo;
+ p(changed, ctx) {
+ input.checked = ctx.foo;
},
- u: function unmount() {
- detachNode(input);
- },
+ d(detach) {
+ if (detach) {
+ detachNode(input);
+ }
- d: function destroy$$1() {
removeListener(input, "change", input_change_handler);
}
};
@@ -231,11 +179,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js
index 03f27ab6d9..635987f16b 100644
--- a/test/js/samples/input-without-blowback-guard/expected.js
+++ b/test/js/samples/input-without-blowback-guard/expected.js
@@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
-import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js";
+import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener, setAttribute } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var input;
function input_change_handler() {
@@ -9,31 +9,27 @@ function create_main_fragment(state, component) {
}
return {
- c: function create() {
+ c() {
input = createElement("input");
- this.h();
- },
-
- h: function hydrate() {
addListener(input, "change", input_change_handler);
- input.type = "checkbox";
+ setAttribute(input, "type", "checkbox");
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(input, target, anchor);
- input.checked = state.foo;
+ input.checked = ctx.foo;
},
- p: function update(changed, state) {
- input.checked = state.foo;
+ p(changed, ctx) {
+ input.checked = ctx.foo;
},
- u: function unmount() {
- detachNode(input);
- },
+ d(detach) {
+ if (detach) {
+ detachNode(input);
+ }
- d: function destroy() {
removeListener(input, "change", input_change_handler);
}
};
@@ -43,11 +39,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js
index 7b730f08d9..9f806ed42a 100644
--- a/test/js/samples/legacy-input-type/expected-bundle.js
+++ b/test/js/samples/legacy-input-type/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -38,36 +30,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -76,16 +47,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -94,30 +70,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -145,18 +98,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -165,52 +118,43 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var input;
return {
- c: function create() {
+ c() {
input = createElement("input");
- this.h();
- },
-
- h: function hydrate() {
setInputType(input, "search");
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(input, target, anchor);
},
p: noop,
- u: function unmount() {
- detachNode(input);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(input);
+ }
+ }
};
}
@@ -218,11 +162,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js
index 719f550044..2e1c279b20 100644
--- a/test/js/samples/legacy-input-type/expected.js
+++ b/test/js/samples/legacy-input-type/expected.js
@@ -1,30 +1,26 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var input;
return {
- c: function create() {
+ c() {
input = createElement("input");
- this.h();
- },
-
- h: function hydrate() {
setInputType(input, "search");
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(input, target, anchor);
},
p: noop,
- u: function unmount() {
- detachNode(input);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(input);
+ }
+ }
};
}
@@ -32,11 +28,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/legacy-quote-class/_config.js b/test/js/samples/legacy-quote-class/_config.js
deleted file mode 100644
index 838683ae37..0000000000
--- a/test/js/samples/legacy-quote-class/_config.js
+++ /dev/null
@@ -1,6 +0,0 @@
-export default {
- options: {
- hydratable: true,
- legacy: true
- }
-};
\ No newline at end of file
diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js
deleted file mode 100644
index 499a82c46e..0000000000
--- a/test/js/samples/legacy-quote-class/expected-bundle.js
+++ /dev/null
@@ -1,258 +0,0 @@
-function noop() {}
-
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
-}
-
-function insertNode(node, target, anchor) {
- target.insertBefore(node, anchor);
-}
-
-function detachNode(node) {
- node.parentNode.removeChild(node);
-}
-
-function createElement(name) {
- return document.createElement(name);
-}
-
-function createSvgElement(name) {
- return document.createElementNS('http://www.w3.org/2000/svg', name);
-}
-
-function children (element) {
- return Array.from(element.childNodes);
-}
-
-function claimElement (nodes, name, attributes, svg) {
- for (var i = 0; i < nodes.length; i += 1) {
- var node = nodes[i];
- if (node.nodeName === name) {
- for (var j = 0; j < node.attributes.length; j += 1) {
- var attribute = node.attributes[j];
- if (!attributes[attribute.name]) node.removeAttribute(attribute.name);
- }
- return nodes.splice(i, 1)[0]; // TODO strip unwanted attributes
- }
- }
-
- return svg ? createSvgElement(name) : createElement(name);
-}
-
-function blankObject() {
- return Object.create(null);
-}
-
-function destroy(detach) {
- this.destroy = noop;
- this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
-
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
-}
-
-function fire(eventName, data) {
- var handlers =
- eventName in this._handlers && this._handlers[eventName].slice();
- if (!handlers) return;
-
- for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
- }
-}
-
-function get(key) {
- return key ? this._state[key] : this._state;
-}
-
-function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
- component._handlers = blankObject();
- component._bind = options._bind;
-
- component.options = options;
- component.root = options.root || component;
- component.store = component.root.store || options.store;
-}
-
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
-function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
- var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
- handlers.push(handler);
-
- return {
- cancel: function() {
- var index = handlers.indexOf(handler);
- if (~index) handlers.splice(index, 1);
- }
- };
-}
-
-function set(newState) {
- this._set(assign({}, newState));
- if (this.root._lock) return;
- this.root._lock = true;
- callAll(this.root._beforecreate);
- callAll(this.root._oncreate);
- callAll(this.root._aftercreate);
- this.root._lock = false;
-}
-
-function _set(newState) {
- var oldState = this._state,
- changed = {},
- dirty = false;
-
- for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
- }
- if (!dirty) return;
-
- this._state = assign({}, oldState, newState);
- this._recompute(changed, this._state);
- if (this._bind) this._bind(changed, this._state);
-
- if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
- this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
- }
-}
-
-function callAll(fns) {
- while (fns && fns.length) fns.shift()();
-}
-
-function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
-}
-
-var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
- _recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
-};
-
-/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
- var div;
-
- return {
- c: function create() {
- div = createElement("div");
- this.h();
- },
-
- l: function claim(nodes) {
- div = claimElement(nodes, "DIV", { "class": true }, false);
- var div_nodes = children(div);
-
- div_nodes.forEach(detachNode);
- this.h();
- },
-
- h: function hydrate() {
- div.className = "foo";
- },
-
- m: function mount(target, anchor) {
- insertNode(div, target, anchor);
- },
-
- p: noop,
-
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
- };
-}
-
-function SvelteComponent(options) {
- init(this, options);
- this._state = assign({}, options.data);
-
- this._fragment = create_main_fragment(this._state, this);
-
- if (options.target) {
- var nodes = children(options.target);
- options.hydrate ? this._fragment.l(nodes) : this._fragment.c();
- nodes.forEach(detachNode);
- this._fragment.m(options.target, options.anchor || null);
- }
-}
-
-assign(SvelteComponent.prototype, proto);
-
-export default SvelteComponent;
diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js
deleted file mode 100644
index 0b49103c47..0000000000
--- a/test/js/samples/legacy-quote-class/expected.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/* generated by Svelte vX.Y.Z */
-import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
-
-function create_main_fragment(state, component) {
- var div;
-
- return {
- c: function create() {
- div = createElement("div");
- this.h();
- },
-
- l: function claim(nodes) {
- div = claimElement(nodes, "DIV", { "class": true }, false);
- var div_nodes = children(div);
-
- div_nodes.forEach(detachNode);
- this.h();
- },
-
- h: function hydrate() {
- div.className = "foo";
- },
-
- m: function mount(target, anchor) {
- insertNode(div, target, anchor);
- },
-
- p: noop,
-
- u: function unmount() {
- detachNode(div);
- },
-
- d: noop
- };
-}
-
-function SvelteComponent(options) {
- init(this, options);
- this._state = assign({}, options.data);
-
- this._fragment = create_main_fragment(this._state, this);
-
- if (options.target) {
- var nodes = children(options.target);
- options.hydrate ? this._fragment.l(nodes) : this._fragment.c();
- nodes.forEach(detachNode);
- this._fragment.m(options.target, options.anchor || null);
- }
-}
-
-assign(SvelteComponent.prototype, proto);
-export default SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/legacy-quote-class/input.html b/test/js/samples/legacy-quote-class/input.html
deleted file mode 100644
index c6a8a8c95d..0000000000
--- a/test/js/samples/legacy-quote-class/input.html
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js
index bbd56d8123..fbb235a80d 100644
--- a/test/js/samples/media-bindings/expected-bundle.js
+++ b/test/js/samples/media-bindings/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -48,36 +40,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -86,16 +57,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -104,30 +80,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -155,18 +108,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -175,29 +128,24 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var audio, audio_is_paused = true, audio_updating = false, audio_animationframe;
function audio_timeupdate_handler() {
@@ -233,42 +181,38 @@ function create_main_fragment(state, component) {
}
return {
- c: function create() {
+ c() {
audio = createElement("audio");
- this.h();
- },
-
- h: function hydrate() {
addListener(audio, "timeupdate", audio_timeupdate_handler);
- if (!('played' in state && 'currentTime' in state)) component.root._beforecreate.push(audio_timeupdate_handler);
+ if (!('played' in ctx && 'currentTime' in ctx)) component.root._beforecreate.push(audio_timeupdate_handler);
addListener(audio, "durationchange", audio_durationchange_handler);
- if (!('duration' in state)) component.root._beforecreate.push(audio_durationchange_handler);
+ if (!('duration' in ctx)) component.root._beforecreate.push(audio_durationchange_handler);
addListener(audio, "play", audio_play_pause_handler);
addListener(audio, "pause", audio_play_pause_handler);
addListener(audio, "progress", audio_progress_handler);
- if (!('buffered' in state)) component.root._beforecreate.push(audio_progress_handler);
+ if (!('buffered' in ctx)) component.root._beforecreate.push(audio_progress_handler);
addListener(audio, "loadedmetadata", audio_loadedmetadata_handler);
- if (!('buffered' in state && 'seekable' in state)) component.root._beforecreate.push(audio_loadedmetadata_handler);
+ if (!('buffered' in ctx && 'seekable' in ctx)) component.root._beforecreate.push(audio_loadedmetadata_handler);
addListener(audio, "volumechange", audio_volumechange_handler);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(audio, target, anchor);
- audio.volume = state.volume;
+ audio.volume = ctx.volume;
},
- p: function update(changed, state) {
- if (!audio_updating && !isNaN(state.currentTime )) audio.currentTime = state.currentTime ;
- if (!audio_updating && audio_is_paused !== (audio_is_paused = state.paused )) audio[audio_is_paused ? "pause" : "play"]();
- if (!audio_updating && !isNaN(state.volume)) audio.volume = state.volume;
+ p(changed, ctx) {
+ if (!audio_updating && !isNaN(ctx.currentTime )) audio.currentTime = ctx.currentTime ;
+ if (!audio_updating && audio_is_paused !== (audio_is_paused = ctx.paused )) audio[audio_is_paused ? "pause" : "play"]();
+ if (!audio_updating && !isNaN(ctx.volume)) audio.volume = ctx.volume;
},
- u: function unmount() {
- detachNode(audio);
- },
+ d(detach) {
+ if (detach) {
+ detachNode(audio);
+ }
- d: function destroy$$1() {
removeListener(audio, "timeupdate", audio_timeupdate_handler);
removeListener(audio, "durationchange", audio_durationchange_handler);
removeListener(audio, "play", audio_play_pause_handler);
@@ -289,11 +233,11 @@ function SvelteComponent(options) {
this._beforecreate = [];
}
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
callAll(this._beforecreate);
}
diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js
index ae80f288f6..f2400877e2 100644
--- a/test/js/samples/media-bindings/expected.js
+++ b/test/js/samples/media-bindings/expected.js
@@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { addListener, assign, callAll, createElement, detachNode, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var audio, audio_is_paused = true, audio_updating = false, audio_animationframe;
function audio_timeupdate_handler() {
@@ -37,42 +37,38 @@ function create_main_fragment(state, component) {
}
return {
- c: function create() {
+ c() {
audio = createElement("audio");
- this.h();
- },
-
- h: function hydrate() {
addListener(audio, "timeupdate", audio_timeupdate_handler);
- if (!('played' in state && 'currentTime' in state)) component.root._beforecreate.push(audio_timeupdate_handler);
+ if (!('played' in ctx && 'currentTime' in ctx)) component.root._beforecreate.push(audio_timeupdate_handler);
addListener(audio, "durationchange", audio_durationchange_handler);
- if (!('duration' in state)) component.root._beforecreate.push(audio_durationchange_handler);
+ if (!('duration' in ctx)) component.root._beforecreate.push(audio_durationchange_handler);
addListener(audio, "play", audio_play_pause_handler);
addListener(audio, "pause", audio_play_pause_handler);
addListener(audio, "progress", audio_progress_handler);
- if (!('buffered' in state)) component.root._beforecreate.push(audio_progress_handler);
+ if (!('buffered' in ctx)) component.root._beforecreate.push(audio_progress_handler);
addListener(audio, "loadedmetadata", audio_loadedmetadata_handler);
- if (!('buffered' in state && 'seekable' in state)) component.root._beforecreate.push(audio_loadedmetadata_handler);
+ if (!('buffered' in ctx && 'seekable' in ctx)) component.root._beforecreate.push(audio_loadedmetadata_handler);
addListener(audio, "volumechange", audio_volumechange_handler);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(audio, target, anchor);
- audio.volume = state.volume;
+ audio.volume = ctx.volume;
},
- p: function update(changed, state) {
- if (!audio_updating && !isNaN(state.currentTime )) audio.currentTime = state.currentTime ;
- if (!audio_updating && audio_is_paused !== (audio_is_paused = state.paused )) audio[audio_is_paused ? "pause" : "play"]();
- if (!audio_updating && !isNaN(state.volume)) audio.volume = state.volume;
+ p(changed, ctx) {
+ if (!audio_updating && !isNaN(ctx.currentTime )) audio.currentTime = ctx.currentTime ;
+ if (!audio_updating && audio_is_paused !== (audio_is_paused = ctx.paused )) audio[audio_is_paused ? "pause" : "play"]();
+ if (!audio_updating && !isNaN(ctx.volume)) audio.volume = ctx.volume;
},
- u: function unmount() {
- detachNode(audio);
- },
+ d(detach) {
+ if (detach) {
+ detachNode(audio);
+ }
- d: function destroy() {
removeListener(audio, "timeupdate", audio_timeupdate_handler);
removeListener(audio, "durationchange", audio_durationchange_handler);
removeListener(audio, "play", audio_play_pause_handler);
@@ -93,11 +89,11 @@ function SvelteComponent(options) {
this._beforecreate = [];
}
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
callAll(this._beforecreate);
}
diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js
index f8e0722db7..bfab868082 100644
--- a/test/js/samples/non-imported-component/expected-bundle.js
+++ b/test/js/samples/non-imported-component/expected-bundle.js
@@ -2,17 +2,9 @@ import Imported from 'Imported.html';
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function insertNode(node, target, anchor) {
@@ -34,36 +26,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -72,16 +43,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -90,30 +66,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -141,18 +94,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -161,29 +114,26 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+
+
+function create_main_fragment(component, ctx) {
var text;
var imported = new Imported({
@@ -195,13 +145,13 @@ function create_main_fragment(state, component) {
});
return {
- c: function create() {
+ c() {
imported._fragment.c();
text = createText("\n");
nonimported._fragment.c();
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
imported._mount(target, anchor);
insertNode(text, target, anchor);
nonimported._mount(target, anchor);
@@ -209,15 +159,13 @@ function create_main_fragment(state, component) {
p: noop,
- u: function unmount() {
- imported._unmount();
- detachNode(text);
- nonimported._unmount();
- },
+ d(detach) {
+ imported.destroy(detach);
+ if (detach) {
+ detachNode(text);
+ }
- d: function destroy$$1() {
- imported.destroy(false);
- nonimported.destroy(false);
+ nonimported.destroy(detach);
}
};
}
@@ -232,11 +180,11 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
this._lock = true;
callAll(this._beforecreate);
diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js
index e7fc2c7255..c070fa76d4 100644
--- a/test/js/samples/non-imported-component/expected.js
+++ b/test/js/samples/non-imported-component/expected.js
@@ -4,7 +4,7 @@ import Imported from 'Imported.html';
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var text;
var imported = new Imported({
@@ -16,13 +16,13 @@ function create_main_fragment(state, component) {
});
return {
- c: function create() {
+ c() {
imported._fragment.c();
text = createText("\n");
nonimported._fragment.c();
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
imported._mount(target, anchor);
insertNode(text, target, anchor);
nonimported._mount(target, anchor);
@@ -30,15 +30,13 @@ function create_main_fragment(state, component) {
p: noop,
- u: function unmount() {
- imported._unmount();
- detachNode(text);
- nonimported._unmount();
- },
+ d(detach) {
+ imported.destroy(detach);
+ if (detach) {
+ detachNode(text);
+ }
- d: function destroy() {
- imported.destroy(false);
- nonimported.destroy(false);
+ nonimported.destroy(detach);
}
};
}
@@ -53,11 +51,11 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
this._lock = true;
callAll(this._beforecreate);
diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js
deleted file mode 100644
index e53dd0de5e..0000000000
--- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js
+++ /dev/null
@@ -1,217 +0,0 @@
-function noop() {}
-
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
-}
-
-function blankObject() {
- return Object.create(null);
-}
-
-function destroy(detach) {
- this.destroy = noop;
- this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
-
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
-}
-
-function fire(eventName, data) {
- var handlers =
- eventName in this._handlers && this._handlers[eventName].slice();
- if (!handlers) return;
-
- for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
- }
-}
-
-function get(key) {
- return key ? this._state[key] : this._state;
-}
-
-function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
- component._handlers = blankObject();
- component._bind = options._bind;
-
- component.options = options;
- component.root = options.root || component;
- component.store = component.root.store || options.store;
-}
-
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
-function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
- var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
- handlers.push(handler);
-
- return {
- cancel: function() {
- var index = handlers.indexOf(handler);
- if (~index) handlers.splice(index, 1);
- }
- };
-}
-
-function set(newState) {
- this._set(assign({}, newState));
- if (this.root._lock) return;
- this.root._lock = true;
- callAll(this.root._beforecreate);
- callAll(this.root._oncreate);
- callAll(this.root._aftercreate);
- this.root._lock = false;
-}
-
-function _set(newState) {
- var oldState = this._state,
- changed = {},
- dirty = false;
-
- for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
- }
- if (!dirty) return;
-
- this._state = assign({}, oldState, newState);
- this._recompute(changed, this._state);
- if (this._bind) this._bind(changed, this._state);
-
- if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
- this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
- }
-}
-
-function callAll(fns) {
- while (fns && fns.length) fns.shift()();
-}
-
-function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
-}
-
-var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
- _recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
-};
-
-/* generated by Svelte vX.Y.Z */
-function oncreate() {}
-
-function ondestroy() {}
-
-function create_main_fragment(state, component) {
-
- return {
- c: noop,
-
- m: noop,
-
- p: noop,
-
- u: noop,
-
- d: noop
- };
-}
-
-function SvelteComponent(options) {
- init(this, options);
- this._state = assign({}, options.data);
-
- this._handlers.destroy = [ondestroy];
-
- var _oncreate = oncreate.bind(this);
-
- if (!options.root) {
- this._oncreate = [];
- }
-
- this._fragment = create_main_fragment(this._state, this);
-
- this.root._oncreate.push(_oncreate);
-
- if (options.target) {
- this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
-
- callAll(this._oncreate);
- }
-}
-
-assign(SvelteComponent.prototype, proto);
-
-export default SvelteComponent;
diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js
deleted file mode 100644
index 51763c0b00..0000000000
--- a/test/js/samples/onrender-onteardown-rewritten/expected.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/* generated by Svelte vX.Y.Z */
-import { assign, callAll, init, noop, proto } from "svelte/shared.js";
-
-function oncreate() {};
-
-function ondestroy() {};
-
-function create_main_fragment(state, component) {
-
- return {
- c: noop,
-
- m: noop,
-
- p: noop,
-
- u: noop,
-
- d: noop
- };
-}
-
-function SvelteComponent(options) {
- init(this, options);
- this._state = assign({}, options.data);
-
- this._handlers.destroy = [ondestroy];
-
- var _oncreate = oncreate.bind(this);
-
- if (!options.root) {
- this._oncreate = [];
- }
-
- this._fragment = create_main_fragment(this._state, this);
-
- this.root._oncreate.push(_oncreate);
-
- if (options.target) {
- this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
-
- callAll(this._oncreate);
- }
-}
-
-assign(SvelteComponent.prototype, proto);
-export default SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/onrender-onteardown-rewritten/input.html b/test/js/samples/onrender-onteardown-rewritten/input.html
deleted file mode 100644
index 1d3b9e3f7b..0000000000
--- a/test/js/samples/onrender-onteardown-rewritten/input.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
\ No newline at end of file
diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js
index 58ee3a67a0..30d69d6180 100644
--- a/test/js/samples/setup-method/expected-bundle.js
+++ b/test/js/samples/setup-method/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function blankObject() {
@@ -20,36 +12,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -58,16 +29,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -76,30 +52,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -127,18 +80,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -147,28 +100,23 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
+
var methods = {
foo ( bar ) {
console.log( bar );
@@ -185,7 +133,7 @@ function setup(Component) {
Component.prototype.foo( 'baz' );
}
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
return {
c: noop,
@@ -194,8 +142,6 @@ function create_main_fragment(state, component) {
p: noop,
- u: noop,
-
d: noop
};
}
@@ -204,15 +150,16 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
-assign(SvelteComponent.prototype, methods, proto);
+assign(SvelteComponent.prototype, proto);
+assign(SvelteComponent.prototype, methods);
setup(SvelteComponent);
diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js
index 092a32ed3b..855e7635b0 100644
--- a/test/js/samples/setup-method/expected.js
+++ b/test/js/samples/setup-method/expected.js
@@ -17,7 +17,7 @@ function setup(Component) {
Component.prototype.foo( 'baz' );
}
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
return {
c: noop,
@@ -26,8 +26,6 @@ function create_main_fragment(state, component) {
p: noop,
- u: noop,
-
d: noop
};
}
@@ -36,15 +34,16 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
-assign(SvelteComponent.prototype, methods, proto);
+assign(SvelteComponent.prototype, proto);
+assign(SvelteComponent.prototype, methods);
setup(SvelteComponent);
export default SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/ssr-no-oncreate-etc/expected-bundle.js b/test/js/samples/ssr-no-oncreate-etc/expected-bundle.js
index 42c2006f75..e2f68fda3c 100644
--- a/test/js/samples/ssr-no-oncreate-etc/expected-bundle.js
+++ b/test/js/samples/ssr-no-oncreate-etc/expected-bundle.js
@@ -1,9 +1,7 @@
function preload(input) {
return output;
}
-
var SvelteComponent = {};
-
SvelteComponent.data = function() {
return {};
};
@@ -30,10 +28,10 @@ SvelteComponent.render = function(state, options = {}) {
};
};
-SvelteComponent._render = function(__result, state, options) {
+SvelteComponent._render = function(__result, ctx, options) {
__result.addComponent(SvelteComponent);
- state = Object.assign({}, state);
+ ctx = Object.assign({}, ctx);
return ``;
};
@@ -43,22 +41,6 @@ SvelteComponent.css = {
map: null
};
-var warned = false;
-SvelteComponent.renderCss = function() {
- if (!warned) {
- console.error('Component.renderCss(...) is deprecated and will be removed in v2 — use Component.render(...).css instead');
- warned = true;
- }
-
- var components = [];
-
- return {
- css: components.map(x => x.css).join('\n'),
- map: null,
- components
- };
-};
-
SvelteComponent.preload = preload;
module.exports = SvelteComponent;
diff --git a/test/js/samples/ssr-no-oncreate-etc/expected.js b/test/js/samples/ssr-no-oncreate-etc/expected.js
index d9b616e763..5a2af8759f 100644
--- a/test/js/samples/ssr-no-oncreate-etc/expected.js
+++ b/test/js/samples/ssr-no-oncreate-etc/expected.js
@@ -32,10 +32,10 @@ SvelteComponent.render = function(state, options = {}) {
};
}
-SvelteComponent._render = function(__result, state, options) {
+SvelteComponent._render = function(__result, ctx, options) {
__result.addComponent(SvelteComponent);
- state = Object.assign({}, state);
+ ctx = Object.assign({}, ctx);
return ``;
};
@@ -46,20 +46,6 @@ SvelteComponent.css = {
};
var warned = false;
-SvelteComponent.renderCss = function() {
- if (!warned) {
- console.error('Component.renderCss(...) is deprecated and will be removed in v2 — use Component.render(...).css instead');
- warned = true;
- }
-
- var components = [];
-
- return {
- css: components.map(x => x.css).join('\n'),
- map: null,
- components
- };
-};
SvelteComponent.preload = preload;
diff --git a/test/js/samples/ssr-preserve-comments/_config.js b/test/js/samples/ssr-preserve-comments/_config.js
new file mode 100644
index 0000000000..9e62c8d192
--- /dev/null
+++ b/test/js/samples/ssr-preserve-comments/_config.js
@@ -0,0 +1,6 @@
+export default {
+ options: {
+ generate: 'ssr',
+ preserveComments: true
+ }
+};
diff --git a/test/js/samples/ssr-preserve-comments/expected-bundle.js b/test/js/samples/ssr-preserve-comments/expected-bundle.js
new file mode 100644
index 0000000000..06799a65da
--- /dev/null
+++ b/test/js/samples/ssr-preserve-comments/expected-bundle.js
@@ -0,0 +1,43 @@
+var SvelteComponent = {};
+SvelteComponent.data = function() {
+ return {};
+};
+
+SvelteComponent.render = function(state, options = {}) {
+ var components = new Set();
+
+ function addComponent(component) {
+ components.add(component);
+ }
+
+ var result = { head: '', addComponent };
+ var html = SvelteComponent._render(result, state, options);
+
+ var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
+
+ return {
+ html,
+ head: result.head,
+ css: { code: cssCode, map: null },
+ toString() {
+ return html;
+ }
+ };
+};
+
+SvelteComponent._render = function(__result, ctx, options) {
+ __result.addComponent(SvelteComponent);
+
+ ctx = Object.assign({}, ctx);
+
+ return `content
+
+more content
`;
+};
+
+SvelteComponent.css = {
+ code: '',
+ map: null
+};
+
+module.exports = SvelteComponent;
diff --git a/test/js/samples/ssr-preserve-comments/expected.js b/test/js/samples/ssr-preserve-comments/expected.js
new file mode 100644
index 0000000000..ccbadca003
--- /dev/null
+++ b/test/js/samples/ssr-preserve-comments/expected.js
@@ -0,0 +1,48 @@
+"use strict";
+
+var SvelteComponent = {};;
+
+SvelteComponent.data = function() {
+ return {};
+};
+
+SvelteComponent.render = function(state, options = {}) {
+ var components = new Set();
+
+ function addComponent(component) {
+ components.add(component);
+ }
+
+ var result = { head: '', addComponent };
+ var html = SvelteComponent._render(result, state, options);
+
+ var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
+
+ return {
+ html,
+ head: result.head,
+ css: { code: cssCode, map: null },
+ toString() {
+ return html;
+ }
+ };
+}
+
+SvelteComponent._render = function(__result, ctx, options) {
+ __result.addComponent(SvelteComponent);
+
+ ctx = Object.assign({}, ctx);
+
+ return `content
+
+more content
`;
+};
+
+SvelteComponent.css = {
+ code: '',
+ map: null
+};
+
+var warned = false;
+
+module.exports = SvelteComponent;
\ No newline at end of file
diff --git a/test/js/samples/ssr-preserve-comments/input.html b/test/js/samples/ssr-preserve-comments/input.html
new file mode 100644
index 0000000000..7f7e291caa
--- /dev/null
+++ b/test/js/samples/ssr-preserve-comments/input.html
@@ -0,0 +1,3 @@
+content
+
+more content
diff --git a/test/js/samples/svg-title/expected-bundle.js b/test/js/samples/svg-title/expected-bundle.js
index 12f06bcf92..faf86f14cb 100644
--- a/test/js/samples/svg-title/expected-bundle.js
+++ b/test/js/samples/svg-title/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function appendNode(node, target) {
@@ -40,36 +32,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -78,16 +49,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -96,30 +72,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -147,18 +100,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -167,39 +120,34 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var svg, title, text;
return {
- c: function create() {
+ c() {
svg = createSvgElement("svg");
title = createSvgElement("title");
text = createText("a title");
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(svg, target, anchor);
appendNode(title, svg);
appendNode(text, title);
@@ -207,11 +155,11 @@ function create_main_fragment(state, component) {
p: noop,
- u: function unmount() {
- detachNode(svg);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(svg);
+ }
+ }
};
}
@@ -219,11 +167,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/svg-title/expected.js b/test/js/samples/svg-title/expected.js
index 39ccf227c0..96a1ea09d1 100644
--- a/test/js/samples/svg-title/expected.js
+++ b/test/js/samples/svg-title/expected.js
@@ -1,17 +1,17 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createSvgElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var svg, title, text;
return {
- c: function create() {
+ c() {
svg = createSvgElement("svg");
title = createSvgElement("title");
text = createText("a title");
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(svg, target, anchor);
appendNode(title, svg);
appendNode(text, title);
@@ -19,11 +19,11 @@ function create_main_fragment(state, component) {
p: noop,
- u: function unmount() {
- detachNode(svg);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(svg);
+ }
+ }
};
}
@@ -31,11 +31,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/title/expected-bundle.js b/test/js/samples/title/expected-bundle.js
index 6eb3471b5b..1c4fd5e84f 100644
--- a/test/js/samples/title/expected-bundle.js
+++ b/test/js/samples/title/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function blankObject() {
@@ -20,36 +12,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -58,16 +29,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -76,30 +52,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -127,18 +80,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -147,46 +100,39 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var title_value;
- document.title = title_value = "a " + state.custom + " title";
+ document.title = title_value = "a " + ctx.custom + " title";
return {
c: noop,
m: noop,
- p: function update(changed, state) {
- if ((changed.custom) && title_value !== (title_value = "a " + state.custom + " title")) {
+ p(changed, ctx) {
+ if ((changed.custom) && title_value !== (title_value = "a " + ctx.custom + " title")) {
document.title = title_value;
}
},
- u: noop,
-
d: noop
};
}
@@ -195,11 +141,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/title/expected.js b/test/js/samples/title/expected.js
index 6aa903d25e..f5aa312569 100644
--- a/test/js/samples/title/expected.js
+++ b/test/js/samples/title/expected.js
@@ -1,24 +1,22 @@
/* generated by Svelte vX.Y.Z */
import { assign, init, noop, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var title_value;
- document.title = title_value = "a " + state.custom + " title";
+ document.title = title_value = "a " + ctx.custom + " title";
return {
c: noop,
m: noop,
- p: function update(changed, state) {
- if ((changed.custom) && title_value !== (title_value = "a " + state.custom + " title")) {
+ p(changed, ctx) {
+ if ((changed.custom) && title_value !== (title_value = "a " + ctx.custom + " title")) {
document.title = title_value;
}
},
- u: noop,
-
d: noop
};
}
@@ -27,11 +25,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/title/input.html b/test/js/samples/title/input.html
index b006a8f50f..0eb2a9519d 100644
--- a/test/js/samples/title/input.html
+++ b/test/js/samples/title/input.html
@@ -1,3 +1,3 @@
-<:Head>
- a {{custom}} title
-
\ No newline at end of file
+
+ a {custom} title
+
\ No newline at end of file
diff --git a/test/js/samples/use-elements-as-anchors/expected-bundle.js b/test/js/samples/use-elements-as-anchors/expected-bundle.js
index e2ee1e61fb..3a3879b91e 100644
--- a/test/js/samples/use-elements-as-anchors/expected-bundle.js
+++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function appendNode(node, target) {
@@ -44,36 +36,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
+ this.set = noop;
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
-}
-
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -82,16 +53,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -100,30 +76,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -151,18 +104,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -171,43 +124,38 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor;
- var if_block = (state.a) && create_if_block(state, component);
+ var if_block = (ctx.a) && create_if_block(component, ctx);
- var if_block_1 = (state.b) && create_if_block_1(state, component);
+ var if_block_1 = (ctx.b) && create_if_block_1(component, ctx);
- var if_block_2 = (state.c) && create_if_block_2(state, component);
+ var if_block_2 = (ctx.c) && create_if_block_2(component, ctx);
- var if_block_3 = (state.d) && create_if_block_3(state, component);
+ var if_block_3 = (ctx.d) && create_if_block_3(component, ctx);
- var if_block_4 = (state.e) && create_if_block_4(state, component);
+ var if_block_4 = (ctx.e) && create_if_block_4(component, ctx);
return {
- c: function create() {
+ c() {
div = createElement("div");
if (if_block) if_block.c();
text = createText("\n\n\t");
@@ -227,7 +175,7 @@ function create_main_fragment(state, component) {
if_block_4_anchor = createComment();
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
if (if_block) if_block.m(div, null);
appendNode(text, div);
@@ -245,196 +193,191 @@ function create_main_fragment(state, component) {
insertNode(if_block_4_anchor, target, anchor);
},
- p: function update(changed, state) {
- if (state.a) {
+ p(changed, ctx) {
+ if (ctx.a) {
if (!if_block) {
- if_block = create_if_block(state, component);
+ if_block = create_if_block(component, ctx);
if_block.c();
if_block.m(div, text);
}
} else if (if_block) {
- if_block.u();
- if_block.d();
+ if_block.d(1);
if_block = null;
}
- if (state.b) {
+ if (ctx.b) {
if (!if_block_1) {
- if_block_1 = create_if_block_1(state, component);
+ if_block_1 = create_if_block_1(component, ctx);
if_block_1.c();
if_block_1.m(div, text_3);
}
} else if (if_block_1) {
- if_block_1.u();
- if_block_1.d();
+ if_block_1.d(1);
if_block_1 = null;
}
- if (state.c) {
+ if (ctx.c) {
if (!if_block_2) {
- if_block_2 = create_if_block_2(state, component);
+ if_block_2 = create_if_block_2(component, ctx);
if_block_2.c();
if_block_2.m(div, text_4);
}
} else if (if_block_2) {
- if_block_2.u();
- if_block_2.d();
+ if_block_2.d(1);
if_block_2 = null;
}
- if (state.d) {
+ if (ctx.d) {
if (!if_block_3) {
- if_block_3 = create_if_block_3(state, component);
+ if_block_3 = create_if_block_3(component, ctx);
if_block_3.c();
if_block_3.m(div, null);
}
} else if (if_block_3) {
- if_block_3.u();
- if_block_3.d();
+ if_block_3.d(1);
if_block_3 = null;
}
- if (state.e) {
+ if (ctx.e) {
if (!if_block_4) {
- if_block_4 = create_if_block_4(state, component);
+ if_block_4 = create_if_block_4(component, ctx);
if_block_4.c();
if_block_4.m(if_block_4_anchor.parentNode, if_block_4_anchor);
}
} else if (if_block_4) {
- if_block_4.u();
- if_block_4.d();
+ if_block_4.d(1);
if_block_4 = null;
}
},
- u: function unmount() {
- detachNode(div);
- if (if_block) if_block.u();
- if (if_block_1) if_block_1.u();
- if (if_block_2) if_block_2.u();
- if (if_block_3) if_block_3.u();
- detachNode(text_8);
- if (if_block_4) if_block_4.u();
- detachNode(if_block_4_anchor);
- },
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
- d: function destroy$$1() {
if (if_block) if_block.d();
if (if_block_1) if_block_1.d();
if (if_block_2) if_block_2.d();
if (if_block_3) if_block_3.d();
- if (if_block_4) if_block_4.d();
+ if (detach) {
+ detachNode(text_8);
+ }
+
+ if (if_block_4) if_block_4.d(detach);
+ if (detach) {
+ detachNode(if_block_4_anchor);
+ }
}
};
}
-// (2:1) {{#if a}}
-function create_if_block(state, component) {
+// (2:1) {#if a}
+function create_if_block(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "a";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (8:1) {{#if b}}
-function create_if_block_1(state, component) {
+// (8:1) {#if b}
+function create_if_block_1(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "b";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (12:1) {{#if c}}
-function create_if_block_2(state, component) {
+// (12:1) {#if c}
+function create_if_block_2(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "c";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (18:1) {{#if d}}
-function create_if_block_3(state, component) {
+// (18:1) {#if d}
+function create_if_block_3(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "d";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (25:0) {{#if e}}
-function create_if_block_4(state, component) {
+// (25:0) {#if e}
+function create_if_block_4(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "e";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
@@ -442,11 +385,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js
index d2609c45b0..9e33cb6e03 100644
--- a/test/js/samples/use-elements-as-anchors/expected.js
+++ b/test/js/samples/use-elements-as-anchors/expected.js
@@ -1,21 +1,21 @@
/* generated by Svelte vX.Y.Z */
-import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
+import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor;
- var if_block = (state.a) && create_if_block(state, component);
+ var if_block = (ctx.a) && create_if_block(component, ctx);
- var if_block_1 = (state.b) && create_if_block_1(state, component);
+ var if_block_1 = (ctx.b) && create_if_block_1(component, ctx);
- var if_block_2 = (state.c) && create_if_block_2(state, component);
+ var if_block_2 = (ctx.c) && create_if_block_2(component, ctx);
- var if_block_3 = (state.d) && create_if_block_3(state, component);
+ var if_block_3 = (ctx.d) && create_if_block_3(component, ctx);
- var if_block_4 = (state.e) && create_if_block_4(state, component);
+ var if_block_4 = (ctx.e) && create_if_block_4(component, ctx);
return {
- c: function create() {
+ c() {
div = createElement("div");
if (if_block) if_block.c();
text = createText("\n\n\t");
@@ -35,7 +35,7 @@ function create_main_fragment(state, component) {
if_block_4_anchor = createComment();
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(div, target, anchor);
if (if_block) if_block.m(div, null);
appendNode(text, div);
@@ -53,196 +53,191 @@ function create_main_fragment(state, component) {
insertNode(if_block_4_anchor, target, anchor);
},
- p: function update(changed, state) {
- if (state.a) {
+ p(changed, ctx) {
+ if (ctx.a) {
if (!if_block) {
- if_block = create_if_block(state, component);
+ if_block = create_if_block(component, ctx);
if_block.c();
if_block.m(div, text);
}
} else if (if_block) {
- if_block.u();
- if_block.d();
+ if_block.d(1);
if_block = null;
}
- if (state.b) {
+ if (ctx.b) {
if (!if_block_1) {
- if_block_1 = create_if_block_1(state, component);
+ if_block_1 = create_if_block_1(component, ctx);
if_block_1.c();
if_block_1.m(div, text_3);
}
} else if (if_block_1) {
- if_block_1.u();
- if_block_1.d();
+ if_block_1.d(1);
if_block_1 = null;
}
- if (state.c) {
+ if (ctx.c) {
if (!if_block_2) {
- if_block_2 = create_if_block_2(state, component);
+ if_block_2 = create_if_block_2(component, ctx);
if_block_2.c();
if_block_2.m(div, text_4);
}
} else if (if_block_2) {
- if_block_2.u();
- if_block_2.d();
+ if_block_2.d(1);
if_block_2 = null;
}
- if (state.d) {
+ if (ctx.d) {
if (!if_block_3) {
- if_block_3 = create_if_block_3(state, component);
+ if_block_3 = create_if_block_3(component, ctx);
if_block_3.c();
if_block_3.m(div, null);
}
} else if (if_block_3) {
- if_block_3.u();
- if_block_3.d();
+ if_block_3.d(1);
if_block_3 = null;
}
- if (state.e) {
+ if (ctx.e) {
if (!if_block_4) {
- if_block_4 = create_if_block_4(state, component);
+ if_block_4 = create_if_block_4(component, ctx);
if_block_4.c();
if_block_4.m(if_block_4_anchor.parentNode, if_block_4_anchor);
}
} else if (if_block_4) {
- if_block_4.u();
- if_block_4.d();
+ if_block_4.d(1);
if_block_4 = null;
}
},
- u: function unmount() {
- detachNode(div);
- if (if_block) if_block.u();
- if (if_block_1) if_block_1.u();
- if (if_block_2) if_block_2.u();
- if (if_block_3) if_block_3.u();
- detachNode(text_8);
- if (if_block_4) if_block_4.u();
- detachNode(if_block_4_anchor);
- },
+ d(detach) {
+ if (detach) {
+ detachNode(div);
+ }
- d: function destroy() {
if (if_block) if_block.d();
if (if_block_1) if_block_1.d();
if (if_block_2) if_block_2.d();
if (if_block_3) if_block_3.d();
- if (if_block_4) if_block_4.d();
+ if (detach) {
+ detachNode(text_8);
+ }
+
+ if (if_block_4) if_block_4.d(detach);
+ if (detach) {
+ detachNode(if_block_4_anchor);
+ }
}
};
}
-// (2:1) {{#if a}}
-function create_if_block(state, component) {
+// (2:1) {#if a}
+function create_if_block(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "a";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (8:1) {{#if b}}
-function create_if_block_1(state, component) {
+// (8:1) {#if b}
+function create_if_block_1(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "b";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (12:1) {{#if c}}
-function create_if_block_2(state, component) {
+// (12:1) {#if c}
+function create_if_block_2(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "c";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (18:1) {{#if d}}
-function create_if_block_3(state, component) {
+// (18:1) {#if d}
+function create_if_block_3(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "d";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
-// (25:0) {{#if e}}
-function create_if_block_4(state, component) {
+// (25:0) {#if e}
+function create_if_block_4(component, ctx) {
var p;
return {
- c: function create() {
+ c() {
p = createElement("p");
p.textContent = "e";
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: noop
+ d(detach) {
+ if (detach) {
+ detachNode(p);
+ }
+ }
};
}
@@ -250,11 +245,11 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/use-elements-as-anchors/input.html b/test/js/samples/use-elements-as-anchors/input.html
index c55e7bd4de..9c18d40f58 100644
--- a/test/js/samples/use-elements-as-anchors/input.html
+++ b/test/js/samples/use-elements-as-anchors/input.html
@@ -1,27 +1,27 @@
- {{#if a}}
+ {#if a}
a
- {{/if}}
+ {/if}
this can be used as an anchor
- {{#if b}}
+ {#if b}
b
- {{/if}}
+ {/if}
- {{#if c}}
+ {#if c}
c
- {{/if}}
+ {/if}
so can this
- {{#if d}}
+ {#if d}
d
- {{/if}}
+ {/if}
-{{#if e}}
+{#if e}
e
-{{/if}}
\ No newline at end of file
+{/if}
\ No newline at end of file
diff --git a/test/js/samples/window-binding-scroll/expected-bundle.js b/test/js/samples/window-binding-scroll/expected-bundle.js
index a8a932c8b7..a26fb90ce5 100644
--- a/test/js/samples/window-binding-scroll/expected-bundle.js
+++ b/test/js/samples/window-binding-scroll/expected-bundle.js
@@ -1,16 +1,8 @@
function noop() {}
-function assign(target) {
- var k,
- source,
- i = 1,
- len = arguments.length;
- for (; i < len; i++) {
- source = arguments[i];
- for (k in source) target[k] = source[k];
- }
-
- return target;
+function assign(tar, src) {
+ for (var k in src) tar[k] = src[k];
+ return tar;
}
function appendNode(node, target) {
@@ -40,36 +32,15 @@ function blankObject() {
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
- this.set = this.get = noop;
-
- if (detach !== false) this._fragment.u();
- this._fragment.d();
- this._fragment = this._state = null;
-}
+ this.set = noop;
-function differs(a, b) {
- return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
+ this._fragment.d(detach !== false);
+ this._fragment = null;
+ this._state = {};
}
-function dispatchObservers(component, group, changed, newState, oldState) {
- for (var key in group) {
- if (!changed[key]) continue;
-
- var newValue = newState[key];
- var oldValue = oldState[key];
-
- var callbacks = group[key];
- if (!callbacks) continue;
-
- for (var i = 0; i < callbacks.length; i += 1) {
- var callback = callbacks[i];
- if (callback.__calling) continue;
-
- callback.__calling = true;
- callback.call(component, newValue, oldValue);
- callback.__calling = false;
- }
- }
+function _differs(a, b) {
+ return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
@@ -78,16 +49,21 @@ function fire(eventName, data) {
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
- handlers[i].call(this, data);
+ var handler = handlers[i];
+
+ if (!handler.__calling) {
+ handler.__calling = true;
+ handler.call(this, data);
+ handler.__calling = false;
+ }
}
}
-function get(key) {
- return key ? this._state[key] : this._state;
+function get() {
+ return this._state;
}
function init(component, options) {
- component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
@@ -96,30 +72,7 @@ function init(component, options) {
component.store = component.root.store || options.store;
}
-function observe(key, callback, options) {
- var group = options && options.defer
- ? this._observers.post
- : this._observers.pre;
-
- (group[key] || (group[key] = [])).push(callback);
-
- if (!options || options.init !== false) {
- callback.__calling = true;
- callback.call(this, this._state[key]);
- callback.__calling = false;
- }
-
- return {
- cancel: function() {
- var index = group[key].indexOf(callback);
- if (~index) group[key].splice(index, 1);
- }
- };
-}
-
function on(eventName, handler) {
- if (eventName === 'teardown') return this.on('destroy', handler);
-
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
@@ -147,18 +100,18 @@ function _set(newState) {
dirty = false;
for (var key in newState) {
- if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
+ if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
- this._state = assign({}, oldState, newState);
+ this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
- dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
+ this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
- dispatchObservers(this, this._observers.post, changed, this._state, oldState);
+ this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
@@ -167,29 +120,24 @@ function callAll(fns) {
}
function _mount(target, anchor) {
- this._fragment.m(target, anchor);
-}
-
-function _unmount() {
- if (this._fragment) this._fragment.u();
+ this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
var proto = {
- destroy: destroy,
- get: get,
- fire: fire,
- observe: observe,
- on: on,
- set: set,
- teardown: destroy,
+ destroy,
+ get,
+ fire,
+ on,
+ set,
_recompute: noop,
- _set: _set,
- _mount: _mount,
- _unmount: _unmount
+ _set,
+ _mount,
+ _differs
};
/* generated by Svelte vX.Y.Z */
-function create_main_fragment(state, component) {
+
+function create_main_fragment(component, ctx) {
var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1;
function onwindowscroll(event) {
@@ -197,44 +145,46 @@ function create_main_fragment(state, component) {
window_updating = true;
component.set({
- y: this.scrollY
+ y: this.pageYOffset
});
window_updating = false;
}
window.addEventListener("scroll", onwindowscroll);
- component.observe("y", function(y) {
- window_updating = true;
- clearTimeout(window_updating_timeout);
- window.scrollTo(window.scrollX, y);
- window_updating_timeout = setTimeout(clear_window_updating, 100);
+ component.on("state", ({ changed, current }) => {
+ if (changed["y"]) {
+ window_updating = true;
+ clearTimeout(window_updating_timeout);
+ window.scrollTo(window.pageXOffset, current["y"]);
+ window_updating_timeout = setTimeout(clear_window_updating, 100);
+ }
});
return {
- c: function create() {
+ c() {
p = createElement("p");
text = createText("scrolled to ");
- text_1 = createText(state.y);
+ text_1 = createText(ctx.y);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
appendNode(text, p);
appendNode(text_1, p);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.y) {
- text_1.data = state.y;
+ text_1.data = ctx.y;
}
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: function destroy$$1() {
+ d(detach) {
window.removeEventListener("scroll", onwindowscroll);
+
+ if (detach) {
+ detachNode(p);
+ }
}
};
}
@@ -242,13 +192,13 @@ function create_main_fragment(state, component) {
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._state.y = window.scrollY;
+ this._state.y = window.pageYOffset;
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js
index 70eae003d7..ce8a8213b6 100644
--- a/test/js/samples/window-binding-scroll/expected.js
+++ b/test/js/samples/window-binding-scroll/expected.js
@@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js";
-function create_main_fragment(state, component) {
+function create_main_fragment(component, ctx) {
var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1;
function onwindowscroll(event) {
@@ -9,44 +9,46 @@ function create_main_fragment(state, component) {
window_updating = true;
component.set({
- y: this.scrollY
+ y: this.pageYOffset
});
window_updating = false;
}
window.addEventListener("scroll", onwindowscroll);
- component.observe("y", function(y) {
- window_updating = true;
- clearTimeout(window_updating_timeout);
- window.scrollTo(window.scrollX, y);
- window_updating_timeout = setTimeout(clear_window_updating, 100);
+ component.on("state", ({ changed, current }) => {
+ if (changed["y"]) {
+ window_updating = true;
+ clearTimeout(window_updating_timeout);
+ window.scrollTo(window.pageXOffset, current["y"]);
+ window_updating_timeout = setTimeout(clear_window_updating, 100);
+ }
});
return {
- c: function create() {
+ c() {
p = createElement("p");
text = createText("scrolled to ");
- text_1 = createText(state.y);
+ text_1 = createText(ctx.y);
},
- m: function mount(target, anchor) {
+ m(target, anchor) {
insertNode(p, target, anchor);
appendNode(text, p);
appendNode(text_1, p);
},
- p: function update(changed, state) {
+ p(changed, ctx) {
if (changed.y) {
- text_1.data = state.y;
+ text_1.data = ctx.y;
}
},
- u: function unmount() {
- detachNode(p);
- },
-
- d: function destroy() {
+ d(detach) {
window.removeEventListener("scroll", onwindowscroll);
+
+ if (detach) {
+ detachNode(p);
+ }
}
};
}
@@ -54,13 +56,13 @@ function create_main_fragment(state, component) {
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
- this._state.y = window.scrollY;
+ this._state.y = window.pageYOffset;
- this._fragment = create_main_fragment(this._state, this);
+ this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
- this._fragment.m(options.target, options.anchor || null);
+ this._mount(options.target, options.anchor);
}
}
diff --git a/test/js/samples/window-binding-scroll/input.html b/test/js/samples/window-binding-scroll/input.html
index 2365bfcc96..f2f6e2c91c 100644
--- a/test/js/samples/window-binding-scroll/input.html
+++ b/test/js/samples/window-binding-scroll/input.html
@@ -1,3 +1,3 @@
-<:Window bind:scrollY=y/>
+
-scrolled to {{y}}
\ No newline at end of file
+scrolled to {y}
\ No newline at end of file
diff --git a/test/js/update.js b/test/js/update.js
index a22e4a08b5..d50eb9780e 100644
--- a/test/js/update.js
+++ b/test/js/update.js
@@ -2,9 +2,9 @@
// their _actual equivalents. Only use it when you're sure that you haven't
// broken anything!
const fs = require("fs");
-const glob = require("glob");
+const glob = require("tiny-glob/sync.js");
-glob.sync("samples/*/_actual*", { cwd: __dirname }).forEach(file => {
+glob("samples/*/_actual*", { cwd: __dirname }).forEach(file => {
const actual = fs.readFileSync(`${__dirname}/${file}`, "utf-8");
fs.writeFileSync(
`${__dirname}/${file.replace("_actual", "expected")}`,
diff --git a/test/parser/index.js b/test/parser/index.js
index 93060ef1ff..7a87fc51b1 100644
--- a/test/parser/index.js
+++ b/test/parser/index.js
@@ -16,33 +16,30 @@ describe('parse', () => {
}
(solo ? it.only : it)(dir, () => {
- const input = fs
- .readFileSync(`test/parser/samples/${dir}/input.html`, 'utf-8')
- .replace(/\s+$/, '');
-
const options = tryToLoadJson(`test/parser/samples/${dir}/options.json`) || {};
+ const input = fs.readFileSync(`test/parser/samples/${dir}/input.html`, 'utf-8').replace(/\s+$/, '');
+ const expectedOutput = tryToLoadJson(`test/parser/samples/${dir}/output.json`);
+ const expectedError = tryToLoadJson(`test/parser/samples/${dir}/error.json`);
+
try {
const actual = svelte.parse(input, options);
- fs.writeFileSync(
- `test/parser/samples/${dir}/_actual.json`,
- JSON.stringify(actual, null, '\t')
- );
- const expected = require(`./samples/${dir}/output.json`);
- assert.deepEqual(actual.html, expected.html);
- assert.deepEqual(actual.css, expected.css);
- assert.deepEqual(actual.js, expected.js);
+ fs.writeFileSync(`test/parser/samples/${dir}/_actual.json`, JSON.stringify(actual, null, '\t'));
+
+ assert.deepEqual(actual.html, expectedOutput.html);
+ assert.deepEqual(actual.css, expectedOutput.css);
+ assert.deepEqual(actual.js, expectedOutput.js);
} catch (err) {
if (err.name !== 'ParseError') throw err;
+ if (!expectedError) throw err;
try {
- const expected = require(`./samples/${dir}/error.json`);
-
- assert.equal(err.message, expected.message);
- assert.deepEqual(err.loc, expected.loc);
- assert.equal(err.pos, expected.pos);
- assert.equal(err.toString().split('\n')[0], `${expected.message} (${expected.loc.line}:${expected.loc.column})`);
+ assert.equal(err.code, expectedError.code);
+ assert.equal(err.message, expectedError.message);
+ assert.deepEqual(err.start, expectedError.start);
+ assert.equal(err.pos, expectedError.pos);
+ assert.equal(err.toString().split('\n')[0], `${expectedError.message} (${expectedError.start.line}:${expectedError.start.column})`);
} catch (err2) {
const e = err2.code === 'MODULE_NOT_FOUND' ? err : err2;
throw e;
@@ -71,8 +68,7 @@ describe('parse', () => {
});
it('includes AST in svelte.compile output', () => {
- const dir = fs.readdirSync('test/parser/samples')[0];
- const source = fs.readFileSync(`test/parser/samples/${dir}/input.html`, 'utf-8');
+ const source = fs.readFileSync(`test/parser/samples/attribute-dynamic/input.html`, 'utf-8');
const { ast } = svelte.compile(source);
const parsed = svelte.parse(source);
diff --git a/test/parser/samples/action-with-call/input.html b/test/parser/samples/action-with-call/input.html
new file mode 100644
index 0000000000..246bf02c59
--- /dev/null
+++ b/test/parser/samples/action-with-call/input.html
@@ -0,0 +1 @@
+
diff --git a/test/parser/samples/action-with-call/output.json b/test/parser/samples/action-with-call/output.json
new file mode 100644
index 0000000000..f5cc6824f3
--- /dev/null
+++ b/test/parser/samples/action-with-call/output.json
@@ -0,0 +1,47 @@
+{
+ "hash": 1937205193,
+ "html": {
+ "start": 0,
+ "end": 38,
+ "type": "Fragment",
+ "children": [
+ {
+ "start": 0,
+ "end": 38,
+ "type": "Element",
+ "name": "input",
+ "attributes": [
+ {
+ "start": 7,
+ "end": 37,
+ "type": "Action",
+ "name": "tooltip",
+ "expression": {
+ "type": "CallExpression",
+ "start": 20,
+ "end": 36,
+ "callee": {
+ "type": "Identifier",
+ "start": 20,
+ "end": 21,
+ "name": "t"
+ },
+ "arguments": [
+ {
+ "type": "Literal",
+ "start": 22,
+ "end": 35,
+ "value": "tooltip msg",
+ "raw": "'tooltip msg'"
+ }
+ ]
+ }
+ }
+ ],
+ "children": []
+ }
+ ]
+ },
+ "css": null,
+ "js": null
+}
\ No newline at end of file
diff --git a/test/parser/samples/action-with-identifier/input.html b/test/parser/samples/action-with-identifier/input.html
new file mode 100644
index 0000000000..14a65e83ed
--- /dev/null
+++ b/test/parser/samples/action-with-identifier/input.html
@@ -0,0 +1 @@
+
diff --git a/test/parser/samples/action-with-identifier/output.json b/test/parser/samples/action-with-identifier/output.json
new file mode 100644
index 0000000000..6c39ed94bc
--- /dev/null
+++ b/test/parser/samples/action-with-identifier/output.json
@@ -0,0 +1,33 @@
+{
+ "hash": 1937205193,
+ "html": {
+ "start": 0,
+ "end": 29,
+ "type": "Fragment",
+ "children": [
+ {
+ "start": 0,
+ "end": 29,
+ "type": "Element",
+ "name": "input",
+ "attributes": [
+ {
+ "start": 7,
+ "end": 28,
+ "type": "Action",
+ "name": "tooltip",
+ "expression": {
+ "type": "Identifier",
+ "start": 20,
+ "end": 27,
+ "name": "message"
+ }
+ }
+ ],
+ "children": []
+ }
+ ]
+ },
+ "css": null,
+ "js": null
+}
\ No newline at end of file
diff --git a/test/parser/samples/action-with-literal/input.html b/test/parser/samples/action-with-literal/input.html
new file mode 100644
index 0000000000..60e16eacfc
--- /dev/null
+++ b/test/parser/samples/action-with-literal/input.html
@@ -0,0 +1 @@
+
diff --git a/test/parser/samples/action-with-literal/output.json b/test/parser/samples/action-with-literal/output.json
new file mode 100644
index 0000000000..0da0318887
--- /dev/null
+++ b/test/parser/samples/action-with-literal/output.json
@@ -0,0 +1,34 @@
+{
+ "hash": 1937205193,
+ "html": {
+ "start": 0,
+ "end": 35,
+ "type": "Fragment",
+ "children": [
+ {
+ "start": 0,
+ "end": 35,
+ "type": "Element",
+ "name": "input",
+ "attributes": [
+ {
+ "start": 7,
+ "end": 34,
+ "type": "Action",
+ "name": "tooltip",
+ "expression": {
+ "type": "Literal",
+ "start": 20,
+ "end": 33,
+ "value": "tooltip msg",
+ "raw": "'tooltip msg'"
+ }
+ }
+ ],
+ "children": []
+ }
+ ]
+ },
+ "css": null,
+ "js": null
+}
\ No newline at end of file
diff --git a/test/parser/samples/action/input.html b/test/parser/samples/action/input.html
new file mode 100644
index 0000000000..64409c2a65
--- /dev/null
+++ b/test/parser/samples/action/input.html
@@ -0,0 +1 @@
+
diff --git a/test/parser/samples/action/output.json b/test/parser/samples/action/output.json
new file mode 100644
index 0000000000..597ae297a5
--- /dev/null
+++ b/test/parser/samples/action/output.json
@@ -0,0 +1,28 @@
+{
+ "hash": 1937205193,
+ "html": {
+ "start": 0,
+ "end": 21,
+ "type": "Fragment",
+ "children": [
+ {
+ "start": 0,
+ "end": 21,
+ "type": "Element",
+ "name": "input",
+ "attributes": [
+ {
+ "start": 7,
+ "end": 20,
+ "type": "Action",
+ "name": "autofocus",
+ "expression": null
+ }
+ ],
+ "children": []
+ }
+ ]
+ },
+ "css": null,
+ "js": null
+}
\ No newline at end of file
diff --git a/test/parser/samples/attribute-dynamic-boolean/input.html b/test/parser/samples/attribute-dynamic-boolean/input.html
index 59683fecb1..ba531f2f81 100644
--- a/test/parser/samples/attribute-dynamic-boolean/input.html
+++ b/test/parser/samples/attribute-dynamic-boolean/input.html
@@ -1 +1 @@
-
+
diff --git a/test/parser/samples/attribute-dynamic-boolean/output.json b/test/parser/samples/attribute-dynamic-boolean/output.json
index af1635a55d..4d08df34a0 100644
--- a/test/parser/samples/attribute-dynamic-boolean/output.json
+++ b/test/parser/samples/attribute-dynamic-boolean/output.json
@@ -1,30 +1,30 @@
{
- "hash": 3179574701,
+ "hash": "7xolfv",
"html": {
"start": 0,
- "end": 45,
+ "end": 41,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 45,
+ "end": 41,
"type": "Element",
"name": "textarea",
"attributes": [
{
"start": 10,
- "end": 33,
+ "end": 29,
"type": "Attribute",
"name": "readonly",
"value": [
{
- "start": 20,
- "end": 32,
+ "start": 19,
+ "end": 29,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 22,
- "end": 30,
+ "start": 20,
+ "end": 28,
"name": "readonly"
}
}
diff --git a/test/parser/samples/attribute-dynamic-reserved/input.html b/test/parser/samples/attribute-dynamic-reserved/input.html
index 6b149d165f..d973a9dea0 100644
--- a/test/parser/samples/attribute-dynamic-reserved/input.html
+++ b/test/parser/samples/attribute-dynamic-reserved/input.html
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/parser/samples/attribute-dynamic-reserved/output.json b/test/parser/samples/attribute-dynamic-reserved/output.json
index aef0e5cb63..4b6506b0cd 100644
--- a/test/parser/samples/attribute-dynamic-reserved/output.json
+++ b/test/parser/samples/attribute-dynamic-reserved/output.json
@@ -1,30 +1,30 @@
{
- "hash": 2788845841,
+ "hash": "l0cddf",
"html": {
"start": 0,
- "end": 29,
+ "end": 25,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 29,
+ "end": 25,
"type": "Element",
"name": "div",
"attributes": [
{
"start": 5,
- "end": 22,
+ "end": 18,
"type": "Attribute",
"name": "class",
"value": [
{
- "start": 12,
- "end": 21,
+ "start": 11,
+ "end": 18,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 14,
- "end": 19,
+ "start": 12,
+ "end": 17,
"name": "class"
}
}
diff --git a/test/parser/samples/attribute-dynamic/input.html b/test/parser/samples/attribute-dynamic/input.html
index 84a34b91ff..9171ae22a7 100644
--- a/test/parser/samples/attribute-dynamic/input.html
+++ b/test/parser/samples/attribute-dynamic/input.html
@@ -1 +1 @@
-{{color}}
+{color}
diff --git a/test/parser/samples/attribute-dynamic/output.json b/test/parser/samples/attribute-dynamic/output.json
index 79ef81065f..7ccb40d313 100644
--- a/test/parser/samples/attribute-dynamic/output.json
+++ b/test/parser/samples/attribute-dynamic/output.json
@@ -1,19 +1,19 @@
{
- "hash": 804348386,
+ "hash": "ehtsx6",
"html": {
"start": 0,
- "end": 46,
+ "end": 42,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 46,
+ "end": 42,
"type": "Element",
"name": "div",
"attributes": [
{
"start": 5,
- "end": 30,
+ "end": 28,
"type": "Attribute",
"name": "style",
"value": [
@@ -25,18 +25,18 @@
},
{
"start": 19,
- "end": 28,
+ "end": 26,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 21,
- "end": 26,
+ "start": 20,
+ "end": 25,
"name": "color"
}
},
{
- "start": 28,
- "end": 29,
+ "start": 26,
+ "end": 27,
"type": "Text",
"data": ";"
}
@@ -45,13 +45,13 @@
],
"children": [
{
- "start": 31,
- "end": 40,
+ "start": 29,
+ "end": 36,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 33,
- "end": 38,
+ "start": 30,
+ "end": 35,
"name": "color"
}
}
diff --git a/test/parser/samples/attribute-multiple/input.html b/test/parser/samples/attribute-multiple/input.html
index a5adf38f2c..6f61bd6289 100644
--- a/test/parser/samples/attribute-multiple/input.html
+++ b/test/parser/samples/attribute-multiple/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/attribute-shorthand/input.html b/test/parser/samples/attribute-shorthand/input.html
index e26deafb3a..35468de006 100644
--- a/test/parser/samples/attribute-shorthand/input.html
+++ b/test/parser/samples/attribute-shorthand/input.html
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/parser/samples/attribute-shorthand/output.json b/test/parser/samples/attribute-shorthand/output.json
index b6578c13eb..598356350b 100644
--- a/test/parser/samples/attribute-shorthand/output.json
+++ b/test/parser/samples/attribute-shorthand/output.json
@@ -2,18 +2,18 @@
"hash": 1705925892,
"html": {
"start": 0,
- "end": 10,
+ "end": 11,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 10,
+ "end": 11,
"type": "Element",
"name": "div",
"attributes": [
{
"start": 5,
- "end": 8,
+ "end": 9,
"type": "Attribute",
"name": "id",
"value": [
diff --git a/test/parser/samples/attribute-static-boolean/input.html b/test/parser/samples/attribute-static-boolean/input.html
index 3ca3bfd9a8..1536f3e1e8 100644
--- a/test/parser/samples/attribute-static-boolean/input.html
+++ b/test/parser/samples/attribute-static-boolean/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/attribute-static/input.html b/test/parser/samples/attribute-static/input.html
index 3cb2e4b233..c6a8a8c95d 100644
--- a/test/parser/samples/attribute-static/input.html
+++ b/test/parser/samples/attribute-static/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/attribute-unique-error/error.json b/test/parser/samples/attribute-unique-error/error.json
index b4ab7a57b5..dd14572149 100644
--- a/test/parser/samples/attribute-unique-error/error.json
+++ b/test/parser/samples/attribute-unique-error/error.json
@@ -1,8 +1,10 @@
{
+ "code": "duplicate-attribute",
"message": "Attributes need to be unique",
- "loc": {
+ "start": {
"line": 1,
- "column": 17
+ "column": 17,
+ "character": 17
},
"pos": 17
}
diff --git a/test/parser/samples/attribute-unique-error/input.html b/test/parser/samples/attribute-unique-error/input.html
index 4088350ce0..37fec733b3 100644
--- a/test/parser/samples/attribute-unique-error/input.html
+++ b/test/parser/samples/attribute-unique-error/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/attribute-unquoted/input.html b/test/parser/samples/attribute-unquoted/input.html
index 2d388456d0..4bab0df72f 100644
--- a/test/parser/samples/attribute-unquoted/input.html
+++ b/test/parser/samples/attribute-unquoted/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/await-then-catch/input.html b/test/parser/samples/await-then-catch/input.html
index 36489b9043..79f5162ace 100644
--- a/test/parser/samples/await-then-catch/input.html
+++ b/test/parser/samples/await-then-catch/input.html
@@ -1,7 +1,7 @@
-{{#await thePromise}}
+{#await thePromise}
loading...
-{{then theValue}}
- the value is {{theValue}}
-{{catch theError}}
- oh no! {{theError.message}}
-{{/await}}
\ No newline at end of file
+{:then theValue}
+ the value is {theValue}
+{:catch theError}
+ oh no! {theError.message}
+{/await}
\ No newline at end of file
diff --git a/test/parser/samples/await-then-catch/output.json b/test/parser/samples/await-then-catch/output.json
index 4f149e6a0c..22ad4242e3 100644
--- a/test/parser/samples/await-then-catch/output.json
+++ b/test/parser/samples/await-then-catch/output.json
@@ -1,143 +1,143 @@
{
- "hash": 1040536517,
+ "hash": "1b28gs9",
"html": {
"start": 0,
- "end": 158,
+ "end": 148,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 158,
+ "end": 148,
"type": "AwaitBlock",
"expression": {
"type": "Identifier",
- "start": 9,
- "end": 19,
+ "start": 8,
+ "end": 18,
"name": "thePromise"
},
"value": "theValue",
"error": "theError",
"pending": {
- "start": 21,
- "end": 41,
+ "start": 19,
+ "end": 39,
"type": "PendingBlock",
"children": [
{
- "start": 21,
- "end": 23,
+ "start": 19,
+ "end": 21,
"type": "Text",
"data": "\n\t"
},
{
- "start": 23,
- "end": 40,
+ "start": 21,
+ "end": 38,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 26,
- "end": 36,
+ "start": 24,
+ "end": 34,
"type": "Text",
"data": "loading..."
}
]
},
{
- "start": 40,
- "end": 41,
+ "start": 38,
+ "end": 39,
"type": "Text",
"data": "\n"
}
]
},
"then": {
- "start": 41,
- "end": 93,
+ "start": 39,
+ "end": 88,
"type": "ThenBlock",
"children": [
{
- "start": 58,
- "end": 60,
+ "start": 55,
+ "end": 57,
"type": "Text",
"data": "\n\t"
},
{
- "start": 60,
- "end": 92,
+ "start": 57,
+ "end": 87,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 63,
- "end": 76,
+ "start": 60,
+ "end": 73,
"type": "Text",
"data": "the value is "
},
{
- "start": 76,
- "end": 88,
+ "start": 73,
+ "end": 83,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 78,
- "end": 86,
+ "start": 74,
+ "end": 82,
"name": "theValue"
}
}
]
},
{
- "start": 92,
- "end": 93,
+ "start": 87,
+ "end": 88,
"type": "Text",
"data": "\n"
}
]
},
"catch": {
- "start": 93,
- "end": 148,
+ "start": 88,
+ "end": 140,
"type": "CatchBlock",
"children": [
{
- "start": 111,
- "end": 113,
+ "start": 105,
+ "end": 107,
"type": "Text",
"data": "\n\t"
},
{
- "start": 113,
- "end": 147,
+ "start": 107,
+ "end": 139,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 116,
- "end": 123,
+ "start": 110,
+ "end": 117,
"type": "Text",
"data": "oh no! "
},
{
- "start": 123,
- "end": 143,
+ "start": 117,
+ "end": 135,
"type": "MustacheTag",
"expression": {
"type": "MemberExpression",
- "start": 125,
- "end": 141,
+ "start": 118,
+ "end": 134,
"object": {
"type": "Identifier",
- "start": 125,
- "end": 133,
+ "start": 118,
+ "end": 126,
"name": "theError"
},
"property": {
"type": "Identifier",
- "start": 134,
- "end": 141,
+ "start": 127,
+ "end": 134,
"name": "message"
},
"computed": false
@@ -146,8 +146,8 @@
]
},
{
- "start": 147,
- "end": 148,
+ "start": 139,
+ "end": 140,
"type": "Text",
"data": "\n"
}
diff --git a/test/parser/samples/binding-shorthand/input.html b/test/parser/samples/binding-shorthand/input.html
index 31f9c872b0..7f8116bdde 100644
--- a/test/parser/samples/binding-shorthand/input.html
+++ b/test/parser/samples/binding-shorthand/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/binding-shorthand/output.json b/test/parser/samples/binding-shorthand/output.json
index 8a7b615cf4..4c92fb9e20 100644
--- a/test/parser/samples/binding-shorthand/output.json
+++ b/test/parser/samples/binding-shorthand/output.json
@@ -8,7 +8,7 @@
{
"start": 0,
"end": 18,
- "type": "Element",
+ "type": "Component",
"name": "Widget",
"attributes": [
{
diff --git a/test/parser/samples/binding/input.html b/test/parser/samples/binding/input.html
index 6a7bf8566c..3af20a9ced 100644
--- a/test/parser/samples/binding/input.html
+++ b/test/parser/samples/binding/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/comment/input.html b/test/parser/samples/comment/input.html
index b35c49dac8..3b3ffe3222 100644
--- a/test/parser/samples/comment/input.html
+++ b/test/parser/samples/comment/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/component-dynamic/input.html b/test/parser/samples/component-dynamic/input.html
index 0d5be48552..1dad5eb269 100644
--- a/test/parser/samples/component-dynamic/input.html
+++ b/test/parser/samples/component-dynamic/input.html
@@ -1 +1 @@
-<:Component {foo ? Foo : Bar}>
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/parser/samples/component-dynamic/output.json b/test/parser/samples/component-dynamic/output.json
index 614c28c0a9..67e8f1e4ca 100644
--- a/test/parser/samples/component-dynamic/output.json
+++ b/test/parser/samples/component-dynamic/output.json
@@ -1,37 +1,37 @@
{
- "hash": 410218696,
+ "hash": "2u5ec3",
"html": {
"start": 0,
- "end": 43,
+ "end": 62,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 43,
- "type": "Element",
- "name": ":Component",
+ "end": 62,
+ "type": "Component",
+ "name": "svelte:component",
"attributes": [],
"children": [],
"expression": {
"type": "ConditionalExpression",
- "start": 13,
- "end": 28,
+ "start": 25,
+ "end": 40,
"test": {
"type": "Identifier",
- "start": 13,
- "end": 16,
+ "start": 25,
+ "end": 28,
"name": "foo"
},
"consequent": {
"type": "Identifier",
- "start": 19,
- "end": 22,
+ "start": 31,
+ "end": 34,
"name": "Foo"
},
"alternate": {
"type": "Identifier",
- "start": 25,
- "end": 28,
+ "start": 37,
+ "end": 40,
"name": "Bar"
}
}
diff --git a/test/parser/samples/convert-entities-in-element/input.html b/test/parser/samples/convert-entities-in-element/input.html
index bc5c086536..f05dc391ad 100644
--- a/test/parser/samples/convert-entities-in-element/input.html
+++ b/test/parser/samples/convert-entities-in-element/input.html
@@ -1 +1 @@
-Hello & World
+Hello & World
\ No newline at end of file
diff --git a/test/parser/samples/convert-entities/input.html b/test/parser/samples/convert-entities/input.html
index e25e3214f2..161463ec58 100644
--- a/test/parser/samples/convert-entities/input.html
+++ b/test/parser/samples/convert-entities/input.html
@@ -1 +1 @@
-Hello & World
+Hello & World
\ No newline at end of file
diff --git a/test/parser/samples/css-ref-selector/input.html b/test/parser/samples/css-ref-selector/input.html
index 07ab3790f7..696075f93f 100644
--- a/test/parser/samples/css-ref-selector/input.html
+++ b/test/parser/samples/css-ref-selector/input.html
@@ -4,4 +4,4 @@
ref:foo {
color: red;
}
-
+
\ No newline at end of file
diff --git a/test/parser/samples/css/input.html b/test/parser/samples/css/input.html
index 659c4343f6..a573bcf778 100644
--- a/test/parser/samples/css/input.html
+++ b/test/parser/samples/css/input.html
@@ -4,4 +4,4 @@
div {
color: red;
}
-
+
\ No newline at end of file
diff --git a/test/parser/samples/each-block-destructured/input.html b/test/parser/samples/each-block-destructured/input.html
index 7209f5503d..4ddf33ef85 100644
--- a/test/parser/samples/each-block-destructured/input.html
+++ b/test/parser/samples/each-block-destructured/input.html
@@ -1,3 +1,3 @@
-{{#each animals as [key, value]}}
- {{key}}: {{value}}
-{{/each}}
+{#each animals as [key, value]}
+ {key}: {value}
+{/each}
diff --git a/test/parser/samples/each-block-destructured/output.json b/test/parser/samples/each-block-destructured/output.json
index 897fec88b8..554b0cdcb0 100644
--- a/test/parser/samples/each-block-destructured/output.json
+++ b/test/parser/samples/each-block-destructured/output.json
@@ -1,64 +1,77 @@
{
- "hash": 2621498076,
"html": {
"start": 0,
- "end": 70,
+ "end": 62,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 70,
+ "end": 62,
"type": "EachBlock",
"expression": {
"type": "Identifier",
- "start": 8,
- "end": 15,
+ "start": 7,
+ "end": 14,
"name": "animals"
},
"children": [
{
- "start": 35,
- "end": 60,
+ "start": 33,
+ "end": 54,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 38,
- "end": 45,
+ "start": 36,
+ "end": 41,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 40,
- "end": 43,
+ "start": 37,
+ "end": 40,
"name": "key"
}
},
{
- "start": 45,
- "end": 47,
+ "start": 41,
+ "end": 43,
"type": "Text",
"data": ": "
},
{
- "start": 47,
- "end": 56,
+ "start": 43,
+ "end": 50,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 49,
- "end": 54,
+ "start": 44,
+ "end": 49,
"name": "value"
}
}
]
}
],
- "destructuredContexts": [
- "key",
- "value"
- ],
- "context": "key_value"
+ "context": {
+ "start": 18,
+ "end": null,
+ "type": "ArrayPattern",
+ "elements": [
+ {
+ "start": 19,
+ "end": 22,
+ "type": "Identifier",
+ "name": "key"
+ },
+ {
+ "start": 24,
+ "end": 29,
+ "type": "Identifier",
+ "name": "value"
+ }
+ ]
+ }
}
]
},
diff --git a/test/parser/samples/each-block-else/input.html b/test/parser/samples/each-block-else/input.html
index 59925e8db7..dc96d8b946 100644
--- a/test/parser/samples/each-block-else/input.html
+++ b/test/parser/samples/each-block-else/input.html
@@ -1,5 +1,5 @@
-{{#each animals as animal}}
- {{animal}}
-{{else}}
+{#each animals as animal}
+ {animal}
+{:else}
no animals
-{{/each}}
+{/each}
diff --git a/test/parser/samples/each-block-else/output.json b/test/parser/samples/each-block-else/output.json
index 0dadad5f65..283b0f0418 100644
--- a/test/parser/samples/each-block-else/output.json
+++ b/test/parser/samples/each-block-else/output.json
@@ -1,58 +1,62 @@
{
- "hash": 3238289871,
"html": {
"start": 0,
- "end": 84,
+ "end": 77,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 84,
+ "end": 77,
"type": "EachBlock",
"expression": {
"type": "Identifier",
- "start": 8,
- "end": 15,
+ "start": 7,
+ "end": 14,
"name": "animals"
},
"children": [
{
- "start": 29,
- "end": 46,
+ "start": 27,
+ "end": 42,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 32,
- "end": 42,
+ "start": 30,
+ "end": 38,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 34,
- "end": 40,
+ "start": 31,
+ "end": 37,
"name": "animal"
}
}
]
}
],
- "context": "animal",
+ "context": {
+ "start": 18,
+ "end": 24,
+ "type": "Identifier",
+ "name": "animal"
+ },
"else": {
- "start": 55,
- "end": 75,
+ "start": 50,
+ "end": 70,
"type": "ElseBlock",
"children": [
{
- "start": 57,
- "end": 74,
+ "start": 52,
+ "end": 69,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 60,
- "end": 70,
+ "start": 55,
+ "end": 65,
"type": "Text",
"data": "no animals"
}
diff --git a/test/parser/samples/each-block-indexed/input.html b/test/parser/samples/each-block-indexed/input.html
index 5c1c74da66..d5602ec82c 100644
--- a/test/parser/samples/each-block-indexed/input.html
+++ b/test/parser/samples/each-block-indexed/input.html
@@ -1,3 +1,3 @@
-{{#each animals as animal, i}}
- {{i}}: {{animal}}
-{{/each}}
+{#each animals as animal, i}
+ {i}: {animal}
+{/each}
diff --git a/test/parser/samples/each-block-indexed/output.json b/test/parser/samples/each-block-indexed/output.json
index fc8954d6ad..1039e67b7c 100644
--- a/test/parser/samples/each-block-indexed/output.json
+++ b/test/parser/samples/each-block-indexed/output.json
@@ -1,60 +1,64 @@
{
- "hash": 2841674990,
"html": {
"start": 0,
- "end": 66,
+ "end": 58,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 66,
+ "end": 58,
"type": "EachBlock",
"expression": {
"type": "Identifier",
- "start": 8,
- "end": 15,
+ "start": 7,
+ "end": 14,
"name": "animals"
},
"children": [
{
- "start": 32,
- "end": 56,
+ "start": 30,
+ "end": 50,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 35,
- "end": 40,
+ "start": 33,
+ "end": 36,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 37,
- "end": 38,
+ "start": 34,
+ "end": 35,
"name": "i"
}
},
{
- "start": 40,
- "end": 42,
+ "start": 36,
+ "end": 38,
"type": "Text",
"data": ": "
},
{
- "start": 42,
- "end": 52,
+ "start": 38,
+ "end": 46,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 44,
- "end": 50,
+ "start": 39,
+ "end": 45,
"name": "animal"
}
}
]
}
],
- "context": "animal",
+ "context": {
+ "start": 18,
+ "end": 24,
+ "type": "Identifier",
+ "name": "animal"
+ },
"index": "i"
}
]
diff --git a/test/parser/samples/each-block-keyed/input.html b/test/parser/samples/each-block-keyed/input.html
index 2bc79c9c8b..46348678d4 100644
--- a/test/parser/samples/each-block-keyed/input.html
+++ b/test/parser/samples/each-block-keyed/input.html
@@ -1,3 +1,3 @@
-{{#each todos as todo @id}}
- {{todo}}
-{{/each}}
+{#each todos as todo (todo.id)}
+ {todo}
+{/each}
diff --git a/test/parser/samples/each-block-keyed/output.json b/test/parser/samples/each-block-keyed/output.json
index 1a16afb82b..e627c5c8c9 100644
--- a/test/parser/samples/each-block-keyed/output.json
+++ b/test/parser/samples/each-block-keyed/output.json
@@ -1,5 +1,4 @@
{
- "hash": 2025411181,
"html": {
"start": 0,
"end": 54,
@@ -11,34 +10,56 @@
"type": "EachBlock",
"expression": {
"type": "Identifier",
- "start": 8,
- "end": 13,
+ "start": 7,
+ "end": 12,
"name": "todos"
},
"children": [
{
- "start": 29,
- "end": 44,
+ "start": 33,
+ "end": 46,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 32,
- "end": 40,
+ "start": 36,
+ "end": 42,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 34,
- "end": 38,
+ "start": 37,
+ "end": 41,
"name": "todo"
}
}
]
}
],
- "context": "todo",
- "key": "id"
+ "context": {
+ "start": 16,
+ "end": 20,
+ "type": "Identifier",
+ "name": "todo"
+ },
+ "key": {
+ "type": "MemberExpression",
+ "start": 22,
+ "end": 29,
+ "object": {
+ "type": "Identifier",
+ "start": 22,
+ "end": 26,
+ "name": "todo"
+ },
+ "property": {
+ "type": "Identifier",
+ "start": 27,
+ "end": 29,
+ "name": "id"
+ },
+ "computed": false
+ }
}
]
},
diff --git a/test/parser/samples/each-block/input.html b/test/parser/samples/each-block/input.html
index 23bfc3c465..83a5e88ddd 100644
--- a/test/parser/samples/each-block/input.html
+++ b/test/parser/samples/each-block/input.html
@@ -1,3 +1,3 @@
-{{#each animals as animal}}
- {{animal}}
-{{/each}}
+{#each animals as animal}
+ {animal}
+{/each}
diff --git a/test/parser/samples/each-block/output.json b/test/parser/samples/each-block/output.json
index e549faca39..a92f3410d1 100644
--- a/test/parser/samples/each-block/output.json
+++ b/test/parser/samples/each-block/output.json
@@ -1,43 +1,47 @@
{
- "hash": 220340986,
"html": {
"start": 0,
- "end": 56,
+ "end": 50,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 56,
+ "end": 50,
"type": "EachBlock",
"expression": {
"type": "Identifier",
- "start": 8,
- "end": 15,
+ "start": 7,
+ "end": 14,
"name": "animals"
},
"children": [
{
- "start": 29,
- "end": 46,
+ "start": 27,
+ "end": 42,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
- "start": 32,
- "end": 42,
+ "start": 30,
+ "end": 38,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 34,
- "end": 40,
+ "start": 31,
+ "end": 37,
"name": "animal"
}
}
]
}
],
- "context": "animal"
+ "context": {
+ "start": 18,
+ "end": 24,
+ "type": "Identifier",
+ "name": "animal"
+ }
}
]
},
diff --git a/test/parser/samples/element-with-mustache/input.html b/test/parser/samples/element-with-mustache/input.html
index 6a2a43bf79..1e9232da02 100644
--- a/test/parser/samples/element-with-mustache/input.html
+++ b/test/parser/samples/element-with-mustache/input.html
@@ -1 +1 @@
-hello {{name}}!
+hello {name}!
diff --git a/test/parser/samples/element-with-mustache/output.json b/test/parser/samples/element-with-mustache/output.json
index fd6799e192..76e71dc327 100644
--- a/test/parser/samples/element-with-mustache/output.json
+++ b/test/parser/samples/element-with-mustache/output.json
@@ -2,12 +2,12 @@
"hash": 1265376132,
"html": {
"start": 0,
- "end": 24,
+ "end": 22,
"type": "Fragment",
"children": [
{
"start": 0,
- "end": 24,
+ "end": 22,
"type": "Element",
"name": "h1",
"attributes": [],
@@ -20,18 +20,18 @@
},
{
"start": 10,
- "end": 18,
+ "end": 16,
"type": "MustacheTag",
"expression": {
"type": "Identifier",
- "start": 12,
- "end": 16,
+ "start": 11,
+ "end": 15,
"name": "name"
}
},
{
- "start": 18,
- "end": 19,
+ "start": 16,
+ "end": 17,
"type": "Text",
"data": "!"
}
diff --git a/test/parser/samples/element-with-text/input.html b/test/parser/samples/element-with-text/input.html
index 61dba8bc46..fcf3199655 100644
--- a/test/parser/samples/element-with-text/input.html
+++ b/test/parser/samples/element-with-text/input.html
@@ -1 +1 @@
-test
+test
\ No newline at end of file
diff --git a/test/parser/samples/elements/input.html b/test/parser/samples/elements/input.html
index c50eddd41f..937d25b42e 100644
--- a/test/parser/samples/elements/input.html
+++ b/test/parser/samples/elements/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/error-binding-disabled/error.json b/test/parser/samples/error-binding-disabled/error.json
index 36ad59d26f..63f01e7056 100644
--- a/test/parser/samples/error-binding-disabled/error.json
+++ b/test/parser/samples/error-binding-disabled/error.json
@@ -1,8 +1,10 @@
{
+ "code": "binding-disabled",
"message": "Two-way binding is disabled",
- "loc": {
+ "start": {
"line": 1,
- "column": 7
+ "column": 7,
+ "character": 7
},
"pos": 7
}
\ No newline at end of file
diff --git a/test/parser/samples/error-binding-disabled/input.html b/test/parser/samples/error-binding-disabled/input.html
index 6a7bf8566c..3af20a9ced 100644
--- a/test/parser/samples/error-binding-disabled/input.html
+++ b/test/parser/samples/error-binding-disabled/input.html
@@ -1 +1 @@
-
+
\ No newline at end of file
diff --git a/test/parser/samples/error-binding-mustaches/error.json b/test/parser/samples/error-binding-mustaches/error.json
index 9d67bfba1a..b2a5c1c564 100644
--- a/test/parser/samples/error-binding-mustaches/error.json
+++ b/test/parser/samples/error-binding-mustaches/error.json
@@ -1,8 +1,10 @@
{
- "message": "bound values should not be wrapped — use 'foo', not '{{foo}}'",
- "loc": {
+ "code": "invalid-directive-value",
+ "message": "directive values should not be wrapped — use 'foo', not '{foo}'",
+ "start": {
"line": 1,
- "column": 19
+ "column": 19,
+ "character": 19
},
"pos": 19
}
\ No newline at end of file
diff --git a/test/parser/samples/error-binding-mustaches/input.html b/test/parser/samples/error-binding-mustaches/input.html
index a334ea7055..2629696c9e 100644
--- a/test/parser/samples/error-binding-mustaches/input.html
+++ b/test/parser/samples/error-binding-mustaches/input.html
@@ -1 +1 @@
-
+
diff --git a/test/parser/samples/error-binding-rvalue/error.json b/test/parser/samples/error-binding-rvalue/error.json
index 85b4a6f9ac..2d081afac5 100644
--- a/test/parser/samples/error-binding-rvalue/error.json
+++ b/test/parser/samples/error-binding-rvalue/error.json
@@ -1,8 +1,10 @@
{
- "message": "Cannot bind to rvalue",
+ "code": "invalid-directive-value",
+ "message": "Can only bind to an identifier (e.g. `foo`) or a member expression (e.g. `foo.bar` or `foo[baz]`)",
"pos": 19,
- "loc": {
+ "start": {
"line": 1,
- "column": 19
+ "column": 19,
+ "character": 19
}
}
\ No newline at end of file
diff --git a/test/parser/samples/error-comment-unclosed/error.json b/test/parser/samples/error-comment-unclosed/error.json
new file mode 100644
index 0000000000..8e355fb821
--- /dev/null
+++ b/test/parser/samples/error-comment-unclosed/error.json
@@ -0,0 +1,10 @@
+{
+ "code": "unexpected-eof",
+ "message": "comment was left open, expected -->",
+ "start": {
+ "line": 1,
+ "column": 24,
+ "character": 24
+ },
+ "pos": 24
+}
diff --git a/test/parser/samples/error-comment-unclosed/input.html b/test/parser/samples/error-comment-unclosed/input.html
new file mode 100644
index 0000000000..fe6d748e1b
--- /dev/null
+++ b/test/parser/samples/error-comment-unclosed/input.html
@@ -0,0 +1 @@
+`,
test ( assert, component, target, window ) {
const inputs = [ ...target.querySelectorAll( 'input' ) ];
- const items = component.get( 'items' );
+ const items = component.get().items;
const event = new window.Event( 'input' );
assert.equal( inputs[0].value, 'one' );
diff --git a/test/runtime/samples/binding-input-text-contextual/main.html b/test/runtime/samples/binding-input-text-contextual/main.html
index 5f07fadc26..7b3f35244f 100644
--- a/test/runtime/samples/binding-input-text-contextual/main.html
+++ b/test/runtime/samples/binding-input-text-contextual/main.html
@@ -1,3 +1,3 @@
-{{#each items as item}}
-
-{{/each}}
+{#each items as item}
+
+{/each}
diff --git a/test/runtime/samples/binding-input-text-deconflicted/main.html b/test/runtime/samples/binding-input-text-deconflicted/main.html
index 391a47c3f1..9d631bf040 100644
--- a/test/runtime/samples/binding-input-text-deconflicted/main.html
+++ b/test/runtime/samples/binding-input-text-deconflicted/main.html
@@ -1,2 +1,2 @@
-Hello {{component.name}}!
+Hello {component.name}!
\ No newline at end of file
diff --git a/test/runtime/samples/binding-input-text-deep-computed-dynamic/main.html b/test/runtime/samples/binding-input-text-deep-computed-dynamic/main.html
index 3a95b383e4..d3afde0a7a 100644
--- a/test/runtime/samples/binding-input-text-deep-computed-dynamic/main.html
+++ b/test/runtime/samples/binding-input-text-deep-computed-dynamic/main.html
@@ -1,2 +1,2 @@
-{{JSON.stringify(obj)}}
\ No newline at end of file
+{JSON.stringify(obj)}
\ No newline at end of file
diff --git a/test/runtime/samples/binding-input-text-deep-computed/_config.js b/test/runtime/samples/binding-input-text-deep-computed/_config.js
index 597395ed52..33cc605a61 100644
--- a/test/runtime/samples/binding-input-text-deep-computed/_config.js
+++ b/test/runtime/samples/binding-input-text-deep-computed/_config.js
@@ -20,7 +20,7 @@ export default {
assert.equal( target.innerHTML, `\nhello bob
` );
- const user = component.get( 'user' );
+ const user = component.get().user;
user.name = 'carol';
component.set({ user });
diff --git a/test/runtime/samples/binding-input-text-deep-computed/main.html b/test/runtime/samples/binding-input-text-deep-computed/main.html
index 281849a4d0..55ad4b53fa 100644
--- a/test/runtime/samples/binding-input-text-deep-computed/main.html
+++ b/test/runtime/samples/binding-input-text-deep-computed/main.html
@@ -1,2 +1,2 @@
-hello {{user.name}}
+hello {user.name}
diff --git a/test/runtime/samples/binding-input-text-deep-contextual-computed-dynamic/main.html b/test/runtime/samples/binding-input-text-deep-contextual-computed-dynamic/main.html
index b2f36850f4..1af3bee5b6 100644
--- a/test/runtime/samples/binding-input-text-deep-contextual-computed-dynamic/main.html
+++ b/test/runtime/samples/binding-input-text-deep-contextual-computed-dynamic/main.html
@@ -1,4 +1,4 @@
-{{#each objects as obj}}
+{#each objects as obj}
- {{JSON.stringify(obj)}}
-{{/each}}
\ No newline at end of file
+ {JSON.stringify(obj)}
+{/each}
\ No newline at end of file
diff --git a/test/runtime/samples/binding-input-text-deep-contextual/_config.js b/test/runtime/samples/binding-input-text-deep-contextual/_config.js
index 587110786c..8cf72df956 100644
--- a/test/runtime/samples/binding-input-text-deep-contextual/_config.js
+++ b/test/runtime/samples/binding-input-text-deep-contextual/_config.js
@@ -19,7 +19,7 @@ export default {
assert.equal( target.innerHTML, `` );
- const items = component.get( 'items' );
+ const items = component.get().items;
items[2].description = 'five';
component.set({ items });
diff --git a/test/runtime/samples/binding-input-text-deep-contextual/main.html b/test/runtime/samples/binding-input-text-deep-contextual/main.html
index 210e4e4fea..7d21a2ddb2 100644
--- a/test/runtime/samples/binding-input-text-deep-contextual/main.html
+++ b/test/runtime/samples/binding-input-text-deep-contextual/main.html
@@ -1,3 +1,3 @@
-{{#each items as item}}
-
-{{/each}}
+{#each items as item}
+
+{/each}
diff --git a/test/runtime/samples/binding-input-text-deep/_config.js b/test/runtime/samples/binding-input-text-deep/_config.js
index 9ef090f864..f1abe383a6 100644
--- a/test/runtime/samples/binding-input-text-deep/_config.js
+++ b/test/runtime/samples/binding-input-text-deep/_config.js
@@ -19,7 +19,7 @@ export default {
assert.equal( target.innerHTML, `\nhello bob
` );
- const user = component.get( 'user' );
+ const user = component.get().user;
user.name = 'carol';
component.set({ user });
diff --git a/test/runtime/samples/binding-input-text-deep/main.html b/test/runtime/samples/binding-input-text-deep/main.html
index 8ed32a7e90..f7f7d4dbc0 100644
--- a/test/runtime/samples/binding-input-text-deep/main.html
+++ b/test/runtime/samples/binding-input-text-deep/main.html
@@ -1,2 +1,2 @@
-hello {{user.name}}
+hello {user.name}
diff --git a/test/runtime/samples/binding-input-text/_config.js b/test/runtime/samples/binding-input-text/_config.js
index ccbe234d12..2c54fc8c32 100644
--- a/test/runtime/samples/binding-input-text/_config.js
+++ b/test/runtime/samples/binding-input-text/_config.js
@@ -1,21 +1,32 @@
export default {
data: {
- name: 'world'
+ name: 'world',
},
- html: `\nhello world
`,
- test ( assert, component, target, window ) {
- const input = target.querySelector( 'input' );
- assert.equal( input.value, 'world' );
- const event = new window.Event( 'input' );
+ html: `
+
+ hello world
+ `,
+
+ test(assert, component, target, window) {
+ const input = target.querySelector('input');
+ assert.equal(input.value, 'world');
+
+ const event = new window.Event('input');
input.value = 'everybody';
- input.dispatchEvent( event );
+ input.dispatchEvent(event);
- assert.equal( target.innerHTML, `\nhello everybody
` );
+ assert.htmlEqual(target.innerHTML, `
+
+ hello everybody
+ `);
component.set({ name: 'goodbye' });
- assert.equal( input.value, 'goodbye' );
- assert.equal( target.innerHTML, `\nhello goodbye
` );
- }
+ assert.equal(input.value, 'goodbye');
+ assert.htmlEqual(target.innerHTML, `
+
+ hello goodbye
+ `);
+ },
};
diff --git a/test/runtime/samples/binding-input-text/main.html b/test/runtime/samples/binding-input-text/main.html
index 806f31fbdd..143c9054b1 100644
--- a/test/runtime/samples/binding-input-text/main.html
+++ b/test/runtime/samples/binding-input-text/main.html
@@ -1,2 +1,2 @@
-hello {{name}}
+hello {name}
diff --git a/test/runtime/samples/binding-input-with-event/_config.js b/test/runtime/samples/binding-input-with-event/_config.js
index c09f09439b..1b4736e0aa 100644
--- a/test/runtime/samples/binding-input-with-event/_config.js
+++ b/test/runtime/samples/binding-input-with-event/_config.js
@@ -13,7 +13,7 @@ export default {
input.dispatchEvent( event );
assert.equal( input.value, '43' );
- assert.equal( component.get( 'a' ), 43 );
+ assert.equal( component.get().a, 43 );
component.destroy();
}
diff --git a/test/runtime/samples/binding-select-implicit-option-value/_config.js b/test/runtime/samples/binding-select-implicit-option-value/_config.js
index 40a7364797..1ab8de20aa 100644
--- a/test/runtime/samples/binding-select-implicit-option-value/_config.js
+++ b/test/runtime/samples/binding-select-implicit-option-value/_config.js
@@ -19,14 +19,14 @@ export default {
const options = [...target.querySelectorAll('option')];
assert.ok(options[1].selected);
- assert.equal(component.get('foo'), 2);
+ assert.equal(component.get().foo, 2);
const change = new window.Event('change');
options[2].selected = true;
select.dispatchEvent(change);
- assert.equal(component.get('foo'), 3);
+ assert.equal(component.get().foo, 3);
assert.htmlEqual( target.innerHTML, `