diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 825b5e2a2e..d6ae9849c9 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -182,9 +182,7 @@ export default function dom( // TODO deprecate component.teardown() builder.addBlock(deindent` function ${name} ( options ) { - options = options || {}; - ${options.dev && - `if ( !options.target && !options._root ) throw new Error( "'target' is a required option" );`} + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); ${generator.usesRefs && `this.refs = {};`} this._state = ${templateProperties.data ? `@assign( @template.data(), options.data )` diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index c9fa1ef590..c74c34aac5 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -188,7 +188,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = assign( template.data(), options.data ); this._observers = { diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index a5dc4d5d58..007704ce0c 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -53,7 +53,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = assign( template.data(), options.data ); this._observers = { diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 35825f465d..ebc11878c7 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -141,7 +141,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; recompute( this._state, this._state, {}, true ); diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index bb2b420c84..9347d2de6a 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -30,7 +30,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; recompute( this._state, this._state, {}, true ); diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index ebbfffd1ec..6e93b70ae5 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -168,7 +168,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index d9af1bfe54..2ff902d897 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -37,7 +37,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { 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 9afe02d871..b49d8c2d0b 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -288,7 +288,7 @@ function create_each_block ( state, each_block_value, comment, i, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 6072df4896..28c694359b 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -144,7 +144,7 @@ function create_each_block ( state, each_block_value, comment, i, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index fa20cbc9ef..6443c745ef 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -177,7 +177,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index abbfef0f91..a668408648 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -48,7 +48,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { 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 73ac6bcf63..c8c944c266 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -223,7 +223,7 @@ function select_block_type ( state ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index e346847b37..9cee168f6b 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -88,7 +88,7 @@ function select_block_type ( state ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 2ce85c33e6..e3685a5f43 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -199,7 +199,7 @@ function create_if_block ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index efd23dc55d..bc0fcd21df 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -64,7 +64,7 @@ function create_if_block ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index c37d2f042a..c37d86bf08 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -169,7 +169,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 195fb2b7b1..604e402d1d 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -48,7 +48,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index eb9a6cdd4f..1b98be5468 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -133,7 +133,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index e35b716595..6447e07363 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -22,7 +22,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 6c4e62fa04..039f8c2c95 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -144,7 +144,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 3e72768ac8..3089a9cb08 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -33,7 +33,7 @@ function create_main_fragment ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { @@ -79,4 +79,4 @@ SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = functio template.setup( SvelteComponent ); -export default SvelteComponent; +export default SvelteComponent; \ 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 b969e80971..bf134de41f 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -383,7 +383,7 @@ function create_if_block_4 ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 046bf7fcbc..b07a8ee99e 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -248,7 +248,7 @@ function create_if_block_4 ( state, component ) { } function SvelteComponent ( options ) { - options = options || {}; + if ( !options || ( !options.target && !options._root ) ) throw new Error( "'target' is a required option" ); this._state = options.data || {}; this._observers = { diff --git a/test/runtime/index.js b/test/runtime/index.js index ce30be761b..cbe5785b6d 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -215,8 +215,7 @@ describe("runtime", () => { it("fails if options.target is missing in dev mode", () => { const { code } = svelte.compile(`
`, { format: "iife", - name: "SvelteComponent", - dev: true + name: "SvelteComponent" }); const SvelteComponent = eval( diff --git a/test/runtime/samples/pass-no-options/_config.js b/test/runtime/samples/pass-no-options/_config.js deleted file mode 100644 index 9683944f21..0000000000 --- a/test/runtime/samples/pass-no-options/_config.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - html: '

Just some static HTML

', - - test ( assert, component, target, window ) { - const newComp = new window.SvelteComponent(); - assert.equal(newComp instanceof window.SvelteComponent, true); - } -}; diff --git a/test/runtime/samples/pass-no-options/main.html b/test/runtime/samples/pass-no-options/main.html deleted file mode 100644 index bbf302b39e..0000000000 --- a/test/runtime/samples/pass-no-options/main.html +++ /dev/null @@ -1 +0,0 @@ -

Just some static HTML