diff --git a/src/generators/dom/Block.js b/src/generators/dom/Block.js index f2d507c035..c8327e0b5d 100644 --- a/src/generators/dom/Block.js +++ b/src/generators/dom/Block.js @@ -176,7 +176,7 @@ export default class Block { } if ( this.hasIntroTransitions ) { - if ( this.builders.outro.isEmpty() ) { + if ( this.builders.intro.isEmpty() ) { properties.addBlock( `intro: ${this.generator.helper( 'noop' )},` ); } else { properties.addBlock( deindent` diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index fcd36fcba2..ea2bc706b8 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -303,22 +303,19 @@ export default function dom ( parsed, source, options ) { } }); - if ( typeof value === 'function' ) { // exclude transitionManager — special case + if ( key === 'transitionManager' ) { // special case + const global = `_svelteTransitionManager`; + + builders.main.addBlock( + `var ${generator.alias( 'transitionManager' )} = window.${global} || ( window.${global} = ${code});` + ); + } else { const alias = generator.alias( fn.id.name ); if ( alias !== fn.id.name ) code.overwrite( fn.id.start, fn.id.end, alias ); builders.main.addBlock( code.toString() ); } }); - - if ( generator.hasIntroTransitions || generator.hasOutroTransitions ) { - const global = `_svelteTransitionManager`; - const transitionManager = toSource( shared.transitionManager ); - - builders.main.addBlock( - `var ${generator.alias( 'transitionManager' )} = window.${global} || ( window.${global} = ${transitionManager});` - ); - } } return generator.generate( builders.main.toString(), options, { name, format } ); diff --git a/src/shared/transitions.js b/src/shared/transitions.js index ddf3c55b3b..01a13b77ec 100644 --- a/src/shared/transitions.js +++ b/src/shared/transitions.js @@ -44,7 +44,7 @@ export function wrapTransition ( node, fn, params, intro, outgroup ) { return assign( transition, { update: function ( now ) { - const p = now - this.start; + var p = now - this.start; this.t = this.a + this.d * ease( p / this.duration ); obj.tick( this.t ); }, @@ -94,7 +94,7 @@ export function wrapTransition ( node, fn, params, intro, outgroup ) { .join( ', ' ); }, update: function ( now ) { - const p = now - this.start; + var p = now - this.start; this.t = this.a + this.d * ease( p / this.duration ); }, done: function () { diff --git a/test/runtime/index.js b/test/runtime/index.js index e67192cbc6..153d8100f3 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -90,17 +90,19 @@ describe( 'runtime', () => { let SvelteComponent; - try { - SvelteComponent = require( `./samples/${dir}/main.html` ).default; - } catch ( err ) { - if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console - throw err; - } - let unintendedError = null; return env() .then( window => { + global.window = window; + + try { + SvelteComponent = require( `./samples/${dir}/main.html` ).default; + } catch ( err ) { + if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console + throw err; + } + Object.assign = () => { throw new Error( 'cannot use Object.assign in generated code, as it is not supported everywhere' ); }; diff --git a/test/runtime/samples/transition-intro/_config.js b/test/runtime/samples/transition-intro-js/_config.js similarity index 89% rename from test/runtime/samples/transition-intro/_config.js rename to test/runtime/samples/transition-intro-js/_config.js index bb60ad0e80..18bd552663 100644 --- a/test/runtime/samples/transition-intro/_config.js +++ b/test/runtime/samples/transition-intro-js/_config.js @@ -4,7 +4,7 @@ export default { let callback; window.performance = { now: () => now }; - window.requestAnimationFrame = cb => callback = cb; + global.requestAnimationFrame = cb => callback = cb; component.set({ visible: true }); const div = target.querySelector( 'div' ); diff --git a/test/runtime/samples/transition-intro-js/main.html b/test/runtime/samples/transition-intro-js/main.html new file mode 100644 index 0000000000..9a3b4f34b8 --- /dev/null +++ b/test/runtime/samples/transition-intro-js/main.html @@ -0,0 +1,18 @@ +{{#if visible}} +