diff --git a/src/compile/index.ts b/src/compile/index.ts index c24465af06..f49f8b98db 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -46,16 +46,6 @@ function validate_options(options: CompileOptions, stats: Stats) { } export default function compile(source: string, options: CompileOptions = {}) { - const onerror = options.onerror || (err => { - throw err; - }); - - if (options.onerror) { - // TODO remove in v3 - deprecate(`Instead of using options.onerror, wrap svelte.compile in a try-catch block`); - delete options.onerror; - } - options = normalize_options(options); const stats = new Stats({ @@ -64,33 +54,29 @@ export default function compile(source: string, options: CompileOptions = {}) { let ast: Ast; - try { - validate_options(options, stats); - - stats.start('parse'); - ast = parse(source, options); - stats.stop('parse'); - - stats.start('create component'); - const component = new Component( - ast, - source, - options.name || 'SvelteComponent', - options, - stats - ); - stats.stop('create component'); - - if (options.generate === false) { - return { ast, stats: stats.render(null), js: null, css: null }; - } - - if (options.generate === 'ssr') { - return renderSSR(component, options); - } - - return renderDOM(component, options); - } catch (err) { - onerror(err); + validate_options(options, stats); + + stats.start('parse'); + ast = parse(source, options); + stats.stop('parse'); + + stats.start('create component'); + const component = new Component( + ast, + source, + options.name || 'SvelteComponent', + options, + stats + ); + stats.stop('create component'); + + if (options.generate === false) { + return { ast, stats: stats.render(null), js: null, css: null }; } + + if (options.generate === 'ssr') { + return renderSSR(component, options); + } + + return renderDOM(component, options); } \ No newline at end of file diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 27897ac6f7..bdaef47edf 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -18,9 +18,7 @@ export default function dom( const { block } = renderer; - if (component.options.nestedTransitions) { - block.hasOutroMethod = true; - } + block.hasOutroMethod = true; // prevent fragment being created twice (#1063) if (options.customElement) block.builders.create.addLine(`this.c = @noop;`); diff --git a/src/compile/render-dom/wrappers/AwaitBlock.ts b/src/compile/render-dom/wrappers/AwaitBlock.ts index fe092f5b1d..de1cc1a613 100644 --- a/src/compile/render-dom/wrappers/AwaitBlock.ts +++ b/src/compile/render-dom/wrappers/AwaitBlock.ts @@ -112,7 +112,7 @@ export default class AwaitBlockWrapper extends Wrapper { this.then.block.hasOutroMethod = hasOutros; this.catch.block.hasOutroMethod = hasOutros; - if (hasOutros && this.renderer.options.nestedTransitions) { + if (hasOutros) { block.addOutro(); } } @@ -206,7 +206,7 @@ export default class AwaitBlockWrapper extends Wrapper { `); } - if (this.pending.block.hasOutroMethod && this.renderer.options.nestedTransitions) { + if (this.pending.block.hasOutroMethod) { const countdown = block.getUniqueName('countdown'); block.builders.outro.addBlock(deindent` const ${countdown} = @callAfter(#outrocallback, 3); diff --git a/src/compile/render-dom/wrappers/EachBlock.ts b/src/compile/render-dom/wrappers/EachBlock.ts index ec46bf4423..37f36abdf3 100644 --- a/src/compile/render-dom/wrappers/EachBlock.ts +++ b/src/compile/render-dom/wrappers/EachBlock.ts @@ -344,7 +344,7 @@ export default class EachBlockWrapper extends Wrapper { ${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`} `); - if (this.block.hasOutros && this.renderer.component.options.nestedTransitions) { + if (this.block.hasOutros) { const countdown = block.getUniqueName('countdown'); block.builders.outro.addBlock(deindent` const ${countdown} = @callAfter(#outrocallback, ${blocks}.length); @@ -501,7 +501,7 @@ export default class EachBlockWrapper extends Wrapper { } } - if (outroBlock && this.renderer.component.options.nestedTransitions) { + if (outroBlock) { const countdown = block.getUniqueName('countdown'); block.builders.outro.addBlock(deindent` ${iterations} = ${iterations}.filter(Boolean); diff --git a/src/compile/render-dom/wrappers/IfBlock.ts b/src/compile/render-dom/wrappers/IfBlock.ts index e9ebf58896..af0af437ba 100644 --- a/src/compile/render-dom/wrappers/IfBlock.ts +++ b/src/compile/render-dom/wrappers/IfBlock.ts @@ -125,10 +125,8 @@ export default class IfBlockWrapper extends Wrapper { createBranches(this.node); - if (component.options.nestedTransitions) { - if (hasIntros) block.addIntro(); - if (hasOutros) block.addOutro(); - } + if (hasIntros) block.addIntro(); + if (hasOutros) block.addOutro(); blocks.forEach(block => { block.hasUpdateMethod = isDynamic; @@ -163,19 +161,17 @@ export default class IfBlockWrapper extends Wrapper { if (hasOutros) { this.renderCompoundWithOutros(block, parentNode, parentNodes, dynamic, vars); - if (this.renderer.options.nestedTransitions) { - block.builders.outro.addBlock(deindent` - if (${name}) ${name}.o(#outrocallback); - else #outrocallback(); - `); - } + block.builders.outro.addBlock(deindent` + if (${name}) ${name}.o(#outrocallback); + else #outrocallback(); + `); } else { this.renderCompound(block, parentNode, parentNodes, dynamic, vars); } } else { this.renderSimple(block, parentNode, parentNodes, dynamic, vars); - if (hasOutros && this.renderer.options.nestedTransitions) { + if (hasOutros) { block.builders.outro.addBlock(deindent` if (${name}) ${name}.o(#outrocallback); else #outrocallback(); diff --git a/src/compile/render-dom/wrappers/InlineComponent/index.ts b/src/compile/render-dom/wrappers/InlineComponent/index.ts index 4586761a71..0c72c3447d 100644 --- a/src/compile/render-dom/wrappers/InlineComponent/index.ts +++ b/src/compile/render-dom/wrappers/InlineComponent/index.ts @@ -68,9 +68,7 @@ export default class InlineComponentWrapper extends Wrapper { this.fragment = new FragmentWrapper(renderer, block, node.children, this, stripWhitespace, nextSibling); } - if (renderer.component.options.nestedTransitions) { - block.addOutro(); - } + block.addOutro(); } render( @@ -318,14 +316,11 @@ export default class InlineComponentWrapper extends Wrapper { block.builders.update.addBlock(deindent` if (${switch_value} !== (${switch_value} = ${snippet})) { if (${name}) { - ${component.options.nestedTransitions - ? deindent` @groupOutros(); const old_component = ${name}; old_component.$$fragment.o(() => { old_component.$destroy(); - });` - : `${name}.$destroy();`} + }); } if (${switch_value}) { @@ -409,11 +404,9 @@ export default class InlineComponentWrapper extends Wrapper { `); } - if (component.options.nestedTransitions) { - block.builders.outro.addLine( - `if (${name}) ${name}.$$fragment.o(#outrocallback);` - ); - } + block.builders.outro.addLine( + `if (${name}) ${name}.$$fragment.o(#outrocallback);` + ); } remount(name: string) { diff --git a/src/index.ts b/src/index.ts index b58fc2b837..d881be7146 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,29 +3,15 @@ import { CompileOptions } from './interfaces'; import deprecate from './utils/deprecate'; export function create(source: string, options: CompileOptions = {}) { - const onerror = options.onerror || (err => { - throw err; - }); - - if (options.onerror) { - // TODO remove in v3 - deprecate(`Instead of using options.onerror, wrap svelte.create in a try-catch block`); - delete options.onerror; - } - options.format = 'eval'; - try { - const compiled = compile(source, options); + const compiled = compile(source, options); - if (!compiled || !compiled.js.code) { - return; - } - - return (new Function(`return ${compiled.js.code}`))(); - } catch (err) { - onerror(err); + if (!compiled || !compiled.js.code) { + return; } + + return (new Function(`return ${compiled.js.code}`))(); } export { default as compile } from './compile/index'; diff --git a/src/interfaces.ts b/src/interfaces.ts index eb26ba55c8..ff12dc66e7 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -61,11 +61,6 @@ export interface CompileOptions { preserveComments?: boolean | false; onwarn?: (warning: Warning) => void; - - // to remove in v3 - onerror?: (error: Error) => void; - skipIntroByDefault?: boolean; - nestedTransitions?: boolean; } export interface Visitor {