diff --git a/src/index.ts b/src/index.ts index 1b9fc8fa61..a82cc48ffe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -150,7 +150,7 @@ function create(source: string, _options: CompileOptions = {}) { } try { - return (new Function(compiled.js.code))(); + return (new Function(`return ${compiled.js.code}`))(); } catch (err) { if (_options.onerror) { _options.onerror(err); diff --git a/test/create/index.js b/test/create/index.js index 3c2387d737..cb4beb623a 100644 --- a/test/create/index.js +++ b/test/create/index.js @@ -4,7 +4,7 @@ import { svelte, deindent } from "../helpers.js"; describe("create", () => { it("should return a component constructor", () => { const source = deindent` -
{{prop}}
+
{prop}
`; const component = svelte.create(source); @@ -13,7 +13,7 @@ describe("create", () => { it("should throw error when source is invalid ", done => { const source = deindent` -
{{prop}
+
{prop
`; const component = svelte.create(source, { @@ -27,7 +27,7 @@ describe("create", () => { it("should return undefined when source is invalid ", () => { const source = deindent` -
{{prop}
+
{prop
`; const component = svelte.create(source, {