Merge branch 'master' into codegen

pull/673/head
Rich Harris 8 years ago committed by GitHub
commit 263a34d35c

@ -209,8 +209,9 @@ export default function dom(
var nodes = @children( options.target ); var nodes = @children( options.target );
options.hydrate ? this._fragment.claim( nodes ) : this._fragment.create(); options.hydrate ? this._fragment.claim( nodes ) : this._fragment.create();
nodes.forEach( @detachNode ); nodes.forEach( @detachNode );
` ` :
: deindent` deindent`
${options.dev && `if ( options.hydrate ) throw new Error( 'options.hydrate only works if the component was compiled with the \`hydratable: true\` option' );`}
this._fragment.create(); this._fragment.create();
`} `}
this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null ); this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null );

@ -230,4 +230,23 @@ describe("runtime", () => {
new SvelteComponent(); new SvelteComponent();
}, /'target' is a required option/); }, /'target' is a required option/);
}); });
it("fails if options.hydrate is true but the component is non-hydratable", () => {
const { code } = svelte.compile(`<div></div>`, {
format: "iife",
name: "SvelteComponent",
dev: true
});
const SvelteComponent = eval(
`(function () { ${code}; return SvelteComponent; }())`
);
assert.throws(() => {
new SvelteComponent({
target: {},
hydrate: true
});
}, /options.hydrate only works if the component was compiled with the `hydratable: true` option/);
});
}); });

Loading…
Cancel
Save