pull/145/merge
FWeinb 9 years ago committed by GitHub
commit fdaf41f57d

@ -432,6 +432,10 @@ export default function generate ( parsed, source, options, names ) {
topLevelStatements.push( deindent` topLevelStatements.push( deindent`
function ${constructorName} ( options ) { function ${constructorName} ( options ) {
if (!(this instanceof ${constructorName})) {
return new ${constructorName}( options );
}
var component = this;${generator.usesRefs ? `\nthis.refs = {}` : ``} var component = this;${generator.usesRefs ? `\nthis.refs = {}` : ``}
var state = ${initialState};${templateProperties.computed ? `\napplyComputations( state, state, {} );` : ``} var state = ${initialState};${templateProperties.computed ? `\napplyComputations( state, state, {} );` : ``}

@ -0,0 +1,9 @@
export default {
html: '',
test: function ( assert, component, target, window ) {
const SvelteComponent = window.SvelteComponent;
assert.equal(new SvelteComponent({}) instanceof SvelteComponent, true);
assert.equal(SvelteComponent({}) instanceof SvelteComponent, true);
}
};

@ -279,6 +279,9 @@ describe( 'svelte', () => {
return env() return env()
.then( window => { .then( window => {
// Put the constructor on window for testing
window.SvelteComponent = SvelteComponent;
const target = window.document.querySelector( 'main' ); const target = window.document.querySelector( 'main' );
const component = new SvelteComponent({ const component = new SvelteComponent({

Loading…
Cancel
Save