Hello world!
\ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/command.sh b/test/cli/samples/dir-sourcemap/command.sh new file mode 100644 index 0000000000..37089f3f44 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/command.sh @@ -0,0 +1 @@ +svelte compile src -m -o actual \ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/expected/Main.js b/test/cli/samples/dir-sourcemap/expected/Main.js new file mode 100644 index 0000000000..7cdd41dd4a --- /dev/null +++ b/test/cli/samples/dir-sourcemap/expected/Main.js @@ -0,0 +1,181 @@ +/* src/Main.html generated by Svelte v2.3.0 */ +import Widget from './Widget.html'; + + + +function create_main_fragment(component, ctx) { + + var widget = new Widget({ + root: component.root + }); + + return { + c() { + widget._fragment.c(); + }, + + m(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u() { + widget._unmount(); + }, + + d() { + widget.destroy(false); + } + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function noop() {} + +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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function get() { + return this._state; +} + +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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} +export default Main; +//# sourceMappingURL=Main.js.map diff --git a/test/cli/samples/dir-sourcemap/expected/Main.js.map b/test/cli/samples/dir-sourcemap/expected/Main.js.map new file mode 100644 index 0000000000..cf890d4435 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/expected/Main.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["widget
"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/src/Main.html b/test/cli/samples/dir-sourcemap/src/Main.html new file mode 100644 index 0000000000..0f123bb0cb --- /dev/null +++ b/test/cli/samples/dir-sourcemap/src/Main.html @@ -0,0 +1,11 @@ +widget
\ No newline at end of file diff --git a/test/cli/samples/dir-subdir/command.sh b/test/cli/samples/dir-subdir/command.sh new file mode 100644 index 0000000000..10067cb1f9 --- /dev/null +++ b/test/cli/samples/dir-subdir/command.sh @@ -0,0 +1 @@ +svelte compile src -o actual \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/expected/Main.js b/test/cli/samples/dir-subdir/expected/Main.js new file mode 100644 index 0000000000..52c9caf092 --- /dev/null +++ b/test/cli/samples/dir-subdir/expected/Main.js @@ -0,0 +1,180 @@ +/* src/Main.html generated by Svelte v2.3.0 */ +import Widget from './widget/Widget.html'; + + + +function create_main_fragment(component, ctx) { + + var widget = new Widget({ + root: component.root + }); + + return { + c() { + widget._fragment.c(); + }, + + m(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u() { + widget._unmount(); + }, + + d() { + widget.destroy(false); + } + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function noop() {} + +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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function get() { + return this._state; +} + +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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} +export default Main; \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/expected/widget/Widget.js b/test/cli/samples/dir-subdir/expected/widget/Widget.js new file mode 100644 index 0000000000..66543c808e --- /dev/null +++ b/test/cli/samples/dir-subdir/expected/widget/Widget.js @@ -0,0 +1,173 @@ +/* src/widget/Widget.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Widget(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(Widget.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Widget.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function get() { + return this._state; +} + +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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} +export default Widget; \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/src/Main.html b/test/cli/samples/dir-subdir/src/Main.html new file mode 100644 index 0000000000..01fdc800d7 --- /dev/null +++ b/test/cli/samples/dir-subdir/src/Main.html @@ -0,0 +1,11 @@ +widget
\ No newline at end of file diff --git a/test/cli/samples/dir/command.sh b/test/cli/samples/dir/command.sh new file mode 100644 index 0000000000..10067cb1f9 --- /dev/null +++ b/test/cli/samples/dir/command.sh @@ -0,0 +1 @@ +svelte compile src -o actual \ No newline at end of file diff --git a/test/cli/samples/dir/expected/Main.js b/test/cli/samples/dir/expected/Main.js new file mode 100644 index 0000000000..77a56bf3bf --- /dev/null +++ b/test/cli/samples/dir/expected/Main.js @@ -0,0 +1,180 @@ +/* src/Main.html generated by Svelte v2.3.0 */ +import Widget from './Widget.html'; + + + +function create_main_fragment(component, ctx) { + + var widget = new Widget({ + root: component.root + }); + + return { + c() { + widget._fragment.c(); + }, + + m(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u() { + widget._unmount(); + }, + + d() { + widget.destroy(false); + } + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function noop() {} + +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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function get() { + return this._state; +} + +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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} +export default Main; \ No newline at end of file diff --git a/test/cli/samples/dir/expected/Widget.js b/test/cli/samples/dir/expected/Widget.js new file mode 100644 index 0000000000..ecb3303e7d --- /dev/null +++ b/test/cli/samples/dir/expected/Widget.js @@ -0,0 +1,173 @@ +/* src/Widget.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Widget(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(Widget.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Widget.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function get() { + return this._state; +} + +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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} +export default Widget; \ No newline at end of file diff --git a/test/cli/samples/dir/src/Main.html b/test/cli/samples/dir/src/Main.html new file mode 100644 index 0000000000..0f123bb0cb --- /dev/null +++ b/test/cli/samples/dir/src/Main.html @@ -0,0 +1,11 @@ +widget
\ No newline at end of file diff --git a/test/cli/samples/globals/command.sh b/test/cli/samples/globals/command.sh new file mode 100644 index 0000000000..9ed0c2a844 --- /dev/null +++ b/test/cli/samples/globals/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html -f iife -g the-answer:theAnswer > actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/globals/expected/Main.js b/test/cli/samples/globals/expected/Main.js new file mode 100644 index 0000000000..2db0a261a2 --- /dev/null +++ b/test/cli/samples/globals/expected/Main.js @@ -0,0 +1,197 @@ +/* src/Main.html generated by Svelte v2.3.0 */ +var Main = (function(answer) { "use strict"; + answer = (answer && answer.__esModule) ? answer["default"] : answer; + + function data() { + return { + answer: answer + }; +}; + + function create_main_fragment(component, ctx) { + var p, text, text_1; + + return { + c() { + p = createElement("p"); + text = createText("The answer is "); + text_1 = createText(ctx.answer); + }, + + m(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + }, + + p(changed, ctx) { + if (changed.answer) { + text_1.data = ctx.answer; + } + }, + + u() { + detachNode(p); + }, + + d: noop + }; + } + + function Main(options) { + init(this, options); + this._state = assign(data(), options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } + } + + assign(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + + Main.prototype._recompute = noop; + + function createElement(name) { + return document.createElement(name); + } + + function createText(data) { + return document.createTextNode(data); + } + + function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); + } + + function appendNode(node, target) { + target.appendChild(node); + } + + function detachNode(node) { + node.parentNode.removeChild(node); + } + + function noop() {} + + 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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; + } + + function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; + } + + function get() { + return this._state; + } + + 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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); + } + + function _unmount() { + if (this._fragment) this._fragment.u(); + } + + function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + } + + function blankObject() { + return Object.create(null); + } + + function callAll(fns) { + while (fns && fns.length) fns.shift()(); + } + return Main; +}(theAnswer)); \ No newline at end of file diff --git a/test/cli/samples/globals/src/Main.html b/test/cli/samples/globals/src/Main.html new file mode 100644 index 0000000000..053f2ec0f6 --- /dev/null +++ b/test/cli/samples/globals/src/Main.html @@ -0,0 +1,13 @@ +The answer is {answer}
+ + \ No newline at end of file diff --git a/test/cli/samples/sourcemap-inline/command.sh b/test/cli/samples/sourcemap-inline/command.sh new file mode 100644 index 0000000000..36b5b71b8d --- /dev/null +++ b/test/cli/samples/sourcemap-inline/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html -m inline -o actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/sourcemap-inline/expected/Main.js b/test/cli/samples/sourcemap-inline/expected/Main.js new file mode 100644 index 0000000000..fe639ac270 --- /dev/null +++ b/test/cli/samples/sourcemap-inline/expected/Main.js @@ -0,0 +1,174 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "Hello world!"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Main(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(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function get() { + return this._state; +} + +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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} +export default Main; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFpbi5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL01haW4uaHRtbCJdLCJzb3VyY2VzQ29udGVudCI6WyI8cD5IZWxsbyB3b3JsZCE8L3A+XG5cbjxzY3JpcHQ+XG5cdGV4cG9ydCBkZWZhdWx0IHtcblx0XHRvbnJlbmRlciAoKSB7XG5cdFx0XHRjb25zb2xlLmxvZyggJ2hlcmUnICk7XG5cdFx0fVxuXHR9O1xuPC9zY3JpcHQ+Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0= diff --git a/test/cli/samples/sourcemap-inline/src/Main.html b/test/cli/samples/sourcemap-inline/src/Main.html new file mode 100644 index 0000000000..944b54efb9 --- /dev/null +++ b/test/cli/samples/sourcemap-inline/src/Main.html @@ -0,0 +1,9 @@ +Hello world!
+ + \ No newline at end of file diff --git a/test/cli/samples/sourcemap/command.sh b/test/cli/samples/sourcemap/command.sh new file mode 100644 index 0000000000..4309d50b89 --- /dev/null +++ b/test/cli/samples/sourcemap/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html -m -o actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/sourcemap/expected/Main.js b/test/cli/samples/sourcemap/expected/Main.js new file mode 100644 index 0000000000..4f303ce506 --- /dev/null +++ b/test/cli/samples/sourcemap/expected/Main.js @@ -0,0 +1,174 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "Hello world!"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Main(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(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function get() { + return this._state; +} + +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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} +export default Main; +//# sourceMappingURL=Main.js.map diff --git a/test/cli/samples/sourcemap/expected/Main.js.map b/test/cli/samples/sourcemap/expected/Main.js.map new file mode 100644 index 0000000000..5133d81436 --- /dev/null +++ b/test/cli/samples/sourcemap/expected/Main.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["Hello world!
\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/test/cli/samples/sourcemap/src/Main.html b/test/cli/samples/sourcemap/src/Main.html new file mode 100644 index 0000000000..944b54efb9 --- /dev/null +++ b/test/cli/samples/sourcemap/src/Main.html @@ -0,0 +1,9 @@ +Hello world!
+ + \ No newline at end of file diff --git a/test/cli/samples/ssr/command.sh b/test/cli/samples/ssr/command.sh new file mode 100644 index 0000000000..30e155691a --- /dev/null +++ b/test/cli/samples/ssr/command.sh @@ -0,0 +1 @@ +svelte compile --generate ssr src/Main.html > actual/Main.js diff --git a/test/cli/samples/ssr/expected/Main.js b/test/cli/samples/ssr/expected/Main.js new file mode 100644 index 0000000000..adf4e19fa0 --- /dev/null +++ b/test/cli/samples/ssr/expected/Main.js @@ -0,0 +1,48 @@ +"use strict"; + +var Main = {}; + +Main.filename = "src/Main.html"; + +Main.data = function() { + return {}; +}; + +Main.render = function(state, options = {}) { + var components = new Set(); + + function addComponent(component) { + components.add(component); + } + + var result = { head: '', addComponent }; + var html = Main._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; + } + }; +} + +Main._render = function(__result, ctx, options) { + __result.addComponent(Main); + + ctx = Object.assign({}, ctx); + + return `Hello world!
`; +}; + +Main.css = { + code: '', + map: null +}; + +var warned = false; + +module.exports = Main; \ No newline at end of file diff --git a/test/cli/samples/ssr/src/Main.html b/test/cli/samples/ssr/src/Main.html new file mode 100644 index 0000000000..aa994ea13e --- /dev/null +++ b/test/cli/samples/ssr/src/Main.html @@ -0,0 +1 @@ +Hello world!
\ No newline at end of file diff --git a/test/cli/samples/store/command.sh b/test/cli/samples/store/command.sh new file mode 100644 index 0000000000..a734fdc772 --- /dev/null +++ b/test/cli/samples/store/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html --store > actual/Main.js diff --git a/test/cli/samples/store/expected/Main.js b/test/cli/samples/store/expected/Main.js new file mode 100644 index 0000000000..3588e60789 --- /dev/null +++ b/test/cli/samples/store/expected/Main.js @@ -0,0 +1,195 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var h1, text, text_1; + + return { + c() { + h1 = createElement("h1"); + text = createText("Hello "); + text_1 = createText(ctx.$name); + }, + + m(target, anchor) { + insertNode(h1, target, anchor); + appendNode(text, h1); + appendNode(text_1, h1); + }, + + p(changed, ctx) { + if (changed.$name) { + text_1.data = ctx.$name; + } + }, + + u() { + detachNode(h1); + }, + + d: noop + }; +} + +function Main(options) { + init(this, options); + this._state = assign(this.store._init(["name"]), options.data); + this.store._add(this, ["name"]); + + this._handlers.destroy = [removeFromStore]; + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function noop() {} + +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 assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function removeFromStore() { + this.store._remove(this); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function get() { + return this._state; +} + +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 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} +export default Main; \ No newline at end of file diff --git a/test/cli/samples/store/src/Main.html b/test/cli/samples/store/src/Main.html new file mode 100644 index 0000000000..3010a856fb --- /dev/null +++ b/test/cli/samples/store/src/Main.html @@ -0,0 +1 @@ +