diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index f606e61d8c..6003c57c8f 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -151,9 +151,9 @@ 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" );`} + this.options = options; ${generator.usesRefs && `this.refs = {};`} this._state = ${templateProperties.data ? `@assign( @template.data(), options.data )` diff --git a/test/runtime/index.js b/test/runtime/index.js index 5b109dcd32..78415ac428 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -81,6 +81,12 @@ describe("runtime", () => { code.slice(0, startIndex).split('\n').map(x => spaces(x.length)).join('\n') + code.slice(startIndex).replace(/export default .+/, ""); acorn.parse(es5, { ecmaVersion: 5 }); + + if (/Object\.assign/.test(es5)) { + throw new Error( + "cannot use Object.assign in generated code, as it is not supported everywhere" + ); + } } catch (err) { failed.add(dir); showOutput(cwd, { shared }); // eslint-disable-line no-console @@ -133,11 +139,6 @@ describe("runtime", () => { throw err; } - let usedObjectAssign = false; - Object.assign = () => { - usedObjectAssign = true; - }; - global.window = window; // Put the constructor on window for testing @@ -151,13 +152,13 @@ describe("runtime", () => { warnings.push(warning); }; - const component = new SvelteComponent({ + const options = Object.assign({}, { target, hydrate, data: config.data - }); + }, config.options || {}); - Object.assign = Object_assign; + const component = new SvelteComponent(options); console.warn = warn; @@ -183,15 +184,7 @@ describe("runtime", () => { component.destroy(); assert.equal(target.innerHTML, ""); } - - if (usedObjectAssign) { - throw new Error( - "cannot use Object.assign in generated code, as it is not supported everywhere" - ); - } } catch (err) { - Object.assign = Object_assign; - if (config.error && !unintendedError) { config.error(assert, err); } else { diff --git a/test/runtime/samples/options/_config.js b/test/runtime/samples/options/_config.js new file mode 100644 index 0000000000..6f321d7a6f --- /dev/null +++ b/test/runtime/samples/options/_config.js @@ -0,0 +1,12 @@ +export default { + 'skip-ssr': true, + html: `
from this.options
`, + + options: { + text: 'from this.options' + }, + + test(assert, component) { + assert.equal(component.options.text, 'from this.options'); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/options/main.html b/test/runtime/samples/options/main.html new file mode 100644 index 0000000000..2cd6339235 --- /dev/null +++ b/test/runtime/samples/options/main.html @@ -0,0 +1,11 @@ +{{text}}
+ + \ No newline at end of file