diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 9b9d888cf6..c4ee996f88 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -153,7 +153,7 @@ export default function dom( // generate initial state object const expectedProperties = Array.from(generator.expectedProperties); const globals = expectedProperties.filter(prop => globalWhitelist.has(prop)); - const storeProps = options.store || templateProperties.store ? expectedProperties.filter(prop => prop[0] === '$') : []; + const storeProps = expectedProperties.filter(prop => prop[0] === '$'); const initialState = []; if (globals.length > 0) { diff --git a/src/generators/nodes/Binding.ts b/src/generators/nodes/Binding.ts index f1725a6d73..1ac182102b 100644 --- a/src/generators/nodes/Binding.ts +++ b/src/generators/nodes/Binding.ts @@ -159,12 +159,8 @@ function getEventHandler( dependencies: string[], value: string, ) { - let storeDependencies = []; - - if (generator.options.store) { - storeDependencies = dependencies.filter(prop => prop[0] === '$').map(prop => prop.slice(1)); - dependencies = dependencies.filter(prop => prop[0] !== '$'); - } + const storeDependencies = dependencies.filter(prop => prop[0] === '$').map(prop => prop.slice(1)); + dependencies = dependencies.filter(prop => prop[0] !== '$'); if (block.contexts.has(name)) { const tail = attribute.value.type === 'MemberExpression' @@ -207,7 +203,7 @@ function getEventHandler( let props; let storeProps; - if (generator.options.store && name[0] === '$') { + if (name[0] === '$') { props = []; storeProps = [`${name.slice(1)}: ${value}`]; } else { diff --git a/src/generators/nodes/Component.ts b/src/generators/nodes/Component.ts index 7f441c024f..fb881ef40e 100644 --- a/src/generators/nodes/Component.ts +++ b/src/generators/nodes/Component.ts @@ -217,7 +217,7 @@ export default class Component extends Node { ${binding.dependencies .map((name: string) => { - const isStoreProp = generator.options.store && name[0] === '$'; + const isStoreProp = name[0] === '$'; const prop = isStoreProp ? name.slice(1) : name; const newState = isStoreProp ? 'newStoreState' : 'newState'; @@ -230,7 +230,7 @@ export default class Component extends Node { } else { - const isStoreProp = generator.options.store && key[0] === '$'; + const isStoreProp = key[0] === '$'; const prop = isStoreProp ? key.slice(1) : key; const newState = isStoreProp ? 'newStoreState' : 'newState'; diff --git a/src/generators/server-side-rendering/index.ts b/src/generators/server-side-rendering/index.ts index 4006379b1e..dc4b49df51 100644 --- a/src/generators/server-side-rendering/index.ts +++ b/src/generators/server-side-rendering/index.ts @@ -75,7 +75,7 @@ export default function ssr( // generate initial state object const expectedProperties = Array.from(generator.expectedProperties); const globals = expectedProperties.filter(prop => globalWhitelist.has(prop)); - const storeProps = options.store || templateProperties.store ? expectedProperties.filter(prop => prop[0] === '$') : []; + const storeProps = expectedProperties.filter(prop => prop[0] === '$'); const initialState = []; if (globals.length > 0) { @@ -84,9 +84,7 @@ export default function ssr( if (storeProps.length > 0) { const initialize = `_init([${storeProps.map(prop => `"${prop.slice(1)}"`)}])` - if (options.store || templateProperties.store) { - initialState.push(`options.store.${initialize}`); - } + initialState.push(`options.store.${initialize}`); } if (templateProperties.data) { diff --git a/src/generators/server-side-rendering/visitors/Component.ts b/src/generators/server-side-rendering/visitors/Component.ts index e7325261e3..c31ddd917f 100644 --- a/src/generators/server-side-rendering/visitors/Component.ts +++ b/src/generators/server-side-rendering/visitors/Component.ts @@ -103,9 +103,7 @@ export default function visitComponent( let open = `\${${expression}._render(__result, ${props}`; const options = []; - if (generator.options.store) { - options.push(`store: options.store`); - } + options.push(`store: options.store`); if (node.children.length) { const appendTarget: AppendTarget = { diff --git a/src/interfaces.ts b/src/interfaces.ts index 8a16b57b54..ddafe52119 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -56,12 +56,10 @@ export interface CompileOptions { dev?: boolean; immutable?: boolean; shared?: boolean | string; - cascade?: boolean; hydratable?: boolean; legacy?: boolean; customElement?: CustomElementOptions | true; css?: boolean; - store?: boolean; preserveComments?: boolean | false; diff --git a/src/validate/html/validateEventHandler.ts b/src/validate/html/validateEventHandler.ts index 086ae2f7b6..854a371ff5 100644 --- a/src/validate/html/validateEventHandler.ts +++ b/src/validate/html/validateEventHandler.ts @@ -31,24 +31,13 @@ export default function validateEventHandlerCallee( return; } - if (name === 'store' && attribute.expression.callee.type === 'MemberExpression') { - if (!validator.options.store) { - validator.warn(attribute.expression, { - code: `options-missing-store`, - message: 'compile with `store: true` in order to call store methods' - }); - } - return; - } - if ( (callee.type === 'Identifier' && validBuiltins.has(callee.name)) || validator.methods.has(callee.name) ) return; - const validCallees = ['this.*', 'event.*', 'options.*', 'console.*'].concat( - validator.options.store ? 'store.*' : [], + const validCallees = ['this.*', 'event.*', 'options.*', 'console.*', 'store.*'].concat( Array.from(validBuiltins), Array.from(validator.methods.keys()) ); diff --git a/src/validate/index.ts b/src/validate/index.ts index 3bdbbc231b..390dbf0714 100644 --- a/src/validate/index.ts +++ b/src/validate/index.ts @@ -101,7 +101,7 @@ export default function validate( stats: Stats, options: CompileOptions ) { - const { onerror, name, filename, store, dev, parser } = options; + const { onerror, name, filename, dev, parser } = options; try { if (name && !/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name)) { @@ -122,7 +122,6 @@ export default function validate( const validator = new Validator(parsed, source, stats, { name, filename, - store, dev, parser }); diff --git a/test/helpers.js b/test/helpers.js index ee065d3675..2b84764c62 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -178,13 +178,6 @@ export function showOutput(cwd, options = {}, compile = svelte.compile) { glob.sync('**/*.html', { cwd }).forEach(file => { if (file[0] === '_') return; - // TODO remove this post-v2 - if (/-v2\.html$/.test(file)) { - if (!options.v2) return; - } else if (options.v2 && fs.existsSync(`${cwd}/${file.replace('.html', '-v2.html')}`)) { - return; - } - const name = path.basename(file) .slice(0, -path.extname(file).length) .replace(/^\d/, '_$&') @@ -195,7 +188,7 @@ export function showOutput(cwd, options = {}, compile = svelte.compile) { Object.assign(options, { filename: file, name: capitalise(name), - parser: options.v2 ? 'v2' : 'v1' + parser: 'v2' // TODO remove }) ); 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 0a91509619..0000000000 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ /dev/null @@ -1,173 +0,0 @@ -function noop() {} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -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 != 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); -} - -function _unmount() { - if (this._fragment) this._fragment.u(); -} - -var proto = { - destroy, - get, - fire, - on, - set, - _recompute: noop, - _set, - _mount, - _unmount, - _differs -}; - -/* generated by Svelte vX.Y.Z */ - -function oncreate() {} -function ondestroy() {} -function create_main_fragment(component, state) { - - 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 self = this; - var _oncreate = function() { - var changed = { }; - oncreate.call(self); - self.fire("update", { changed: changed, current: self._state }); - }; - - if (!options.root) { - this._oncreate = []; - } - - this._fragment = create_main_fragment(this, this._state); - - this.root._oncreate.push(_oncreate); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - - 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 fed341a7f9..0000000000 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ /dev/null @@ -1,53 +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(component, state) { - - 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 self = this; - var _oncreate = function() { - var changed = { }; - oncreate.call(self); - self.fire("update", { changed: changed, current: self._state }); - }; - - if (!options.root) { - this._oncreate = []; - } - - this._fragment = create_main_fragment(this, this._state); - - this.root._oncreate.push(_oncreate); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - - 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 @@ -<script> - export default { - // this test should be removed in v2 - onrender () {}, - onteardown () {} - }; -</script> \ No newline at end of file diff --git a/test/runtime/index.js b/test/runtime/index.js index 913fddacf2..806b0dab79 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -172,12 +172,12 @@ describe.only("runtime", () => { config.error(assert, err); } else { failed.add(dir); - showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store, v2: true }, compile); // eslint-disable-line no-console + showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, compile); // eslint-disable-line no-console throw err; } }) .then(() => { - if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store, v2: true }, compile); + if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, compile); }); }); }