diff --git a/compiler/generate/index.js b/compiler/generate/index.js index 1652ee3baf..bca700a96b 100644 --- a/compiler/generate/index.js +++ b/compiler/generate/index.js @@ -432,6 +432,8 @@ export default function generate ( parsed, source, options, names ) { topLevelStatements.push( deindent` function ${constructorName} ( options ) { + options = options || {}; + var component = this;${generator.usesRefs ? `\nthis.refs = {}` : ``} var state = ${initialState};${templateProperties.computed ? `\napplyComputations( state, state, {} );` : ``} diff --git a/test/compiler/pass-no-options/_config.js b/test/compiler/pass-no-options/_config.js new file mode 100644 index 0000000000..7a8e7a4fb6 --- /dev/null +++ b/test/compiler/pass-no-options/_config.js @@ -0,0 +1,7 @@ +export default { + html: '

Just some static HTML

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

Just some static HTML

diff --git a/test/test.js b/test/test.js index f53bef8a19..71fd3e9d83 100644 --- a/test/test.js +++ b/test/test.js @@ -279,6 +279,9 @@ describe( 'svelte', () => { return env() .then( window => { + // Put the constructor on window for testing + window.SvelteComponent = SvelteComponent; + const target = window.document.querySelector( 'main' ); const component = new SvelteComponent({