pull/3539/head
Richard Harris 6 years ago
parent 85afdef2e5
commit 96b9343ce7

@ -460,7 +460,7 @@ export default class ElementWrapper extends Wrapper {
@_cancelAnimationFrame(${animation_frame}); @_cancelAnimationFrame(${animation_frame});
if (!${this.var}.paused) { if (!${this.var}.paused) {
${animation_frame} = @raf(${handler}); ${animation_frame} = @raf(${handler});
${needs_lock && `${lock} = true;`} ${needs_lock && b`${lock} = true;`}
} }
#ctx.${handler}.call(${this.var}, ${contextual_dependencies.size > 0 ? '#ctx' : null}); #ctx.${handler}.call(${this.var}, ${contextual_dependencies.size > 0 ? '#ctx' : null});
} }

@ -182,7 +182,7 @@ export default class IfBlockWrapper extends Wrapper {
: (this.next && this.next.var) || 'null'; : (this.next && this.next.var) || 'null';
const has_else = !(this.branches[this.branches.length - 1].condition); const has_else = !(this.branches[this.branches.length - 1].condition);
const if_exists_condition = has_else ? x`true` : name; const if_exists_condition = has_else ? null : name;
const dynamic = this.branches[0].block.has_update_method; // can use [0] as proxy for all, since they necessarily have the same value const dynamic = this.branches[0].block.has_update_method; // can use [0] as proxy for all, since they necessarily have the same value
const has_intros = this.branches[0].block.has_intro_method; const has_intros = this.branches[0].block.has_intro_method;
@ -213,12 +213,22 @@ export default class IfBlockWrapper extends Wrapper {
} }
} }
if (if_exists_condition) {
block.chunks.create.push(b`if (${if_exists_condition}) ${name}.c();`); block.chunks.create.push(b`if (${if_exists_condition}) ${name}.c();`);
} else {
block.chunks.create.push(b`${name}.c();`);
}
if (parent_nodes && this.renderer.options.hydratable) { if (parent_nodes && this.renderer.options.hydratable) {
if (if_exists_condition) {
block.chunks.claim.push( block.chunks.claim.push(
b`if (${if_exists_condition}) ${name}.l(${parent_nodes});` b`if (${if_exists_condition}) ${name}.l(${parent_nodes});`
); );
} else {
block.chunks.claim.push(
b`${name}.l(${parent_nodes});`
);
}
} }
if (has_intros || has_outros) { if (has_intros || has_outros) {
@ -286,15 +296,22 @@ export default class IfBlockWrapper extends Wrapper {
const initial_mount_node = parent_node || '#target'; const initial_mount_node = parent_node || '#target';
const anchor_node = parent_node ? 'null' : 'anchor'; const anchor_node = parent_node ? 'null' : 'anchor';
if (if_exists_condition) {
block.chunks.mount.push( block.chunks.mount.push(
b`if (${if_exists_condition}) ${name}.m(${initial_mount_node}, ${anchor_node});` b`if (${if_exists_condition}) ${name}.m(${initial_mount_node}, ${anchor_node});`
); );
} else {
block.chunks.mount.push(
b`${name}.m(${initial_mount_node}, ${anchor_node});`
);
}
if (this.needs_update) { if (this.needs_update) {
const update_mount_node = this.get_update_mount_node(anchor); const update_mount_node = this.get_update_mount_node(anchor);
const change_block = b` const change_block = b`
if (${if_exists_condition}) ${name}.d(1); ${if_exists_condition ? b`if (${if_exists_condition}) ${name}.d(1)` : b`${name}.d(1)`};
${name} = ${get_block}; ${name} = ${get_block};
if (${name}) { if (${name}) {
${name}.c(); ${name}.c();
@ -322,11 +339,17 @@ export default class IfBlockWrapper extends Wrapper {
block.chunks.update.push(b`${name}.p(#changed, #ctx);`); block.chunks.update.push(b`${name}.p(#changed, #ctx);`);
} }
if (if_exists_condition) {
block.chunks.destroy.push(b` block.chunks.destroy.push(b`
if (${if_exists_condition}) { if (${if_exists_condition}) {
${name}.d(${detaching}); ${name}.d(${detaching});
} }
`); `);
} else {
block.chunks.destroy.push(b`
${name}.d(${detaching});
`);
}
} }
// if any of the siblings have outros, we need to keep references to the blocks // if any of the siblings have outros, we need to keep references to the blocks
@ -554,8 +577,14 @@ export default class IfBlockWrapper extends Wrapper {
`); `);
} }
if (if_exists_condition) {
block.chunks.destroy.push(b` block.chunks.destroy.push(b`
if (${if_exists_condition}) ${name}.d(${detaching}); if (${if_exists_condition}) ${name}.d(${detaching});
`); `);
} else {
block.chunks.destroy.push(b`
${name}.d(${detaching});
`);
}
} }
} }

@ -380,7 +380,7 @@ export default class InlineComponentWrapper extends Wrapper {
var ${switch_value} = ${snippet}; var ${switch_value} = ${snippet};
function ${switch_props}(#ctx) { function ${switch_props}(#ctx) {
${(this.node.attributes.length || this.node.bindings.length) && b` ${(this.node.attributes.length > 0 || this.node.bindings.length > 0) && b`
${props && b`let ${props} = ${attribute_object};`}`} ${props && b`let ${props} = ${attribute_object};`}`}
${statements} ${statements}
return ${component_opts}; return ${component_opts};
@ -462,7 +462,7 @@ export default class InlineComponentWrapper extends Wrapper {
: component.qualify(this.node.name); : component.qualify(this.node.name);
block.chunks.init.push(b` block.chunks.init.push(b`
${(this.node.attributes.length || this.node.bindings.length) && b` ${(this.node.attributes.length > 0 || this.node.bindings.length > 0) && b`
${props && b`let ${props} = ${attribute_object};`}`} ${props && b`let ${props} = ${attribute_object};`}`}
${statements} ${statements}
const ${name} = new ${expression}(${component_opts}); const ${name} = new ${expression}(${component_opts});

@ -2,7 +2,9 @@ import Renderer, { RenderOptions } from '../Renderer';
import Comment from '../../nodes/Comment'; import Comment from '../../nodes/Comment';
export default function(node: Comment, renderer: Renderer, options: RenderOptions) { export default function(node: Comment, renderer: Renderer, options: RenderOptions) {
if (options.preserveComments) { // TODO preserve comments
renderer.append(`<!--${node.data}-->`);
} // if (options.preserveComments) {
// renderer.append(`<!--${node.data}-->`);
// }
} }

@ -1,6 +1,6 @@
import DebugTag from '../../nodes/DebugTag'; import DebugTag from '../../nodes/DebugTag';
import Renderer, { RenderOptions } from '../Renderer'; import Renderer, { RenderOptions } from '../Renderer';
import { x } from 'code-red'; import { x, p } from 'code-red';
export default function(node: DebugTag, renderer: Renderer, options: RenderOptions) { export default function(node: DebugTag, renderer: Renderer, options: RenderOptions) {
if (!options.dev) return; if (!options.dev) return;
@ -9,7 +9,7 @@ export default function(node: DebugTag, renderer: Renderer, options: RenderOptio
const { line, column } = options.locate(node.start + 1); const { line, column } = options.locate(node.start + 1);
const obj = x`{ const obj = x`{
${node.expressions.map(e => e.node.name)} ${node.expressions.map(e => p`${e.node.name}`)}
}`; }`;
renderer.add_expression(x`@debug(${filename ? x`"${filename}"` : x`null`}, ${line}, ${column}, ${obj})`); renderer.add_expression(x`@debug(${filename ? x`"${filename}"` : x`null`}, ${line}, ${column}, ${obj})`);

@ -3,7 +3,7 @@ import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { loadConfig, svelte } from "../helpers.js"; import { loadConfig, svelte } from "../helpers.js";
describe.only("js", () => { describe("js", () => {
fs.readdirSync("test/js/samples").forEach(dir => { fs.readdirSync("test/js/samples").forEach(dir => {
if (dir[0] === ".") return; if (dir[0] === ".") return;

@ -1,18 +1,12 @@
/* generated by Svelte vX.Y.Z */ import { create_ssr_component, debug, each, escape } from "svelte/internal";
import {
create_ssr_component,
debug,
each,
escape
} from "svelte/internal";
const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
let { things, foo } = $$props; let { things } = $$props;
let { foo } = $$props;
if ($$props.things === void 0 && $$bindings.things && things !== void 0) $$bindings.things(things); if ($$props.things === void 0 && $$bindings.things && things !== void 0) $$bindings.things(things);
if ($$props.foo === void 0 && $$bindings.foo && foo !== void 0) $$bindings.foo(foo); if ($$props.foo === void 0 && $$bindings.foo && foo !== void 0) $$bindings.foo(foo);
return `${each(things, (thing) => `<span>${escape(thing.name)}</span> return `${each(things, thing => `<span>${escape(thing.name)}</span>
${debug(null, 7, 2, { foo })}`)} ${debug(null, 7, 2, { foo })}`)}
<p>foo: ${escape(foo)}</p>`; <p>foo: ${escape(foo)}</p>`;

@ -67,6 +67,7 @@ function create_fragment(ctx) {
if (current_block_type !== (current_block_type = select_block_type(changed, ctx))) { if (current_block_type !== (current_block_type = select_block_type(changed, ctx))) {
if_block.d(1); if_block.d(1);
if_block = current_block_type(ctx); if_block = current_block_type(ctx);
if (if_block) { if (if_block) {
if_block.c(); if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor); if_block.m(if_block_anchor.parentNode, if_block_anchor);

@ -1,4 +1,3 @@
/* generated by Svelte vX.Y.Z */
import { import {
SvelteComponent, SvelteComponent,
add_render_callback, add_render_callback,
@ -15,14 +14,20 @@ import {
} from "svelte/internal"; } from "svelte/internal";
function create_fragment(ctx) { function create_fragment(ctx) {
var audio, audio_updating = false, audio_animationframe, audio_is_paused = true, dispose; let audio;
let audio_updating = false;
let audio_animationframe;
let audio_is_paused = true;
let dispose;
function audio_timeupdate_handler() { function audio_timeupdate_handler() {
cancelAnimationFrame(audio_animationframe); cancelAnimationFrame(audio_animationframe);
if (!audio.paused) { if (!audio.paused) {
audio_animationframe = raf(audio_timeupdate_handler); audio_animationframe = raf(audio_timeupdate_handler);
audio_updating = true; audio_updating = true;
} }
ctx.audio_timeupdate_handler.call(audio); ctx.audio_timeupdate_handler.call(audio);
} }
@ -45,87 +50,97 @@ function create_fragment(ctx) {
listen(audio, "ratechange", ctx.audio_ratechange_handler) listen(audio, "ratechange", ctx.audio_ratechange_handler)
]; ];
}, },
m(target, anchor) { m(target, anchor) {
insert(target, audio, anchor); insert(target, audio, anchor);
audio.volume = ctx.volume;
audio.playbackRate = ctx.playbackRate;
},
p(changed, ctx) {
if (!audio_updating && changed.currentTime && !isNaN(ctx.currentTime)) {
audio.currentTime = ctx.currentTime;
}
if (changed.paused && audio_is_paused !== (audio_is_paused = ctx.paused)) {
audio[audio_is_paused ? "pause" : "play"]();
}
if (changed.volume && !isNaN(ctx.volume)) {
audio.volume = ctx.volume; audio.volume = ctx.volume;
}
if (changed.playbackRate && !isNaN(ctx.playbackRate)) {
audio.playbackRate = ctx.playbackRate; audio.playbackRate = ctx.playbackRate;
}, }
p(changed, ctx) {
if (!audio_updating && changed.currentTime && !isNaN(ctx.currentTime)) audio.currentTime = ctx.currentTime;
if (changed.paused && audio_is_paused !== (audio_is_paused = ctx.paused)) audio[audio_is_paused ? "pause" : "play"]();
if (changed.volume && !isNaN(ctx.volume)) audio.volume = ctx.volume;
if (changed.playbackRate && !isNaN(ctx.playbackRate)) audio.playbackRate = ctx.playbackRate;
audio_updating = false; audio_updating = false;
}, },
i: noop, i: noop,
o: noop, o: noop,
d(detaching) { d(detaching) {
if (detaching) { if (detaching) detach(audio);
detach(audio);
}
run_all(dispose); run_all(dispose);
} }
}; };
} }
function instance($$self, $$props, $$invalidate) { function instance($$self, $$props, $$invalidate) {
let { buffered, seekable, played, currentTime, duration, paused, volume, playbackRate } = $$props; let { buffered } = $$props;
let { seekable } = $$props;
let { played } = $$props;
let { currentTime } = $$props;
let { duration } = $$props;
let { paused } = $$props;
let { volume } = $$props;
let { playbackRate } = $$props;
function audio_timeupdate_handler() { function audio_timeupdate_handler() {
played = time_ranges_to_array(this.played); played = time_ranges_to_array(this.played);
currentTime = this.currentTime; currentTime = this.currentTime;
$$invalidate('played', played); $$invalidate("played", played);
$$invalidate('currentTime', currentTime); $$invalidate("currentTime", currentTime);
} }
function audio_durationchange_handler() { function audio_durationchange_handler() {
duration = this.duration; duration = this.duration;
$$invalidate('duration', duration); $$invalidate("duration", duration);
} }
function audio_play_pause_handler() { function audio_play_pause_handler() {
paused = this.paused; paused = this.paused;
$$invalidate('paused', paused); $$invalidate("paused", paused);
} }
function audio_progress_handler() { function audio_progress_handler() {
buffered = time_ranges_to_array(this.buffered); buffered = time_ranges_to_array(this.buffered);
$$invalidate('buffered', buffered); $$invalidate("buffered", buffered);
} }
function audio_loadedmetadata_handler() { function audio_loadedmetadata_handler() {
buffered = time_ranges_to_array(this.buffered); buffered = time_ranges_to_array(this.buffered);
seekable = time_ranges_to_array(this.seekable); seekable = time_ranges_to_array(this.seekable);
$$invalidate('buffered', buffered); $$invalidate("buffered", buffered);
$$invalidate('seekable', seekable); $$invalidate("seekable", seekable);
} }
function audio_volumechange_handler() { function audio_volumechange_handler() {
volume = this.volume; volume = this.volume;
$$invalidate('volume', volume); $$invalidate("volume", volume);
} }
function audio_ratechange_handler() { function audio_ratechange_handler() {
playbackRate = this.playbackRate; playbackRate = this.playbackRate;
$$invalidate('playbackRate', playbackRate); $$invalidate("playbackRate", playbackRate);
} }
$$self.$set = $$props => { $$self.$set = $$props => {
if ('buffered' in $$props) $$invalidate('buffered', buffered = $$props.buffered); if ("buffered" in $$props) $$invalidate("buffered", buffered = $$props.buffered);
if ('seekable' in $$props) $$invalidate('seekable', seekable = $$props.seekable); if ("seekable" in $$props) $$invalidate("seekable", seekable = $$props.seekable);
if ('played' in $$props) $$invalidate('played', played = $$props.played); if ("played" in $$props) $$invalidate("played", played = $$props.played);
if ('currentTime' in $$props) $$invalidate('currentTime', currentTime = $$props.currentTime); if ("currentTime" in $$props) $$invalidate("currentTime", currentTime = $$props.currentTime);
if ('duration' in $$props) $$invalidate('duration', duration = $$props.duration); if ("duration" in $$props) $$invalidate("duration", duration = $$props.duration);
if ('paused' in $$props) $$invalidate('paused', paused = $$props.paused); if ("paused" in $$props) $$invalidate("paused", paused = $$props.paused);
if ('volume' in $$props) $$invalidate('volume', volume = $$props.volume); if ("volume" in $$props) $$invalidate("volume", volume = $$props.volume);
if ('playbackRate' in $$props) $$invalidate('playbackRate', playbackRate = $$props.playbackRate); if ("playbackRate" in $$props) $$invalidate("playbackRate", playbackRate = $$props.playbackRate);
}; };
return { return {
@ -150,7 +165,17 @@ function instance($$self, $$props, $$invalidate) {
class Component extends SvelteComponent { class Component extends SvelteComponent {
constructor(options) { constructor(options) {
super(); super();
init(this, options, instance, create_fragment, safe_not_equal, ["buffered", "seekable", "played", "currentTime", "duration", "paused", "volume", "playbackRate"]);
init(this, options, instance, create_fragment, safe_not_equal, [
"buffered",
"seekable",
"played",
"currentTime",
"duration",
"paused",
"volume",
"playbackRate"
]);
} }
} }

@ -11,6 +11,7 @@ import {
transition_in, transition_in,
transition_out transition_out
} from "svelte/internal"; } from "svelte/internal";
import Imported from "Imported.svelte"; import Imported from "Imported.svelte";
function create_fragment(ctx) { function create_fragment(ctx) {

@ -5,14 +5,14 @@ function preload(input) {
return output; return output;
} }
function swipe(node, callback) {
}
function foo() { function foo() {
console.log("foo"); console.log("foo");
} }
function swipe(node, callback) {
}
const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
onMount(() => { onMount(() => {
console.log("onMount"); console.log("onMount");

@ -1,9 +1,8 @@
/* generated by Svelte vX.Y.Z */
import { create_ssr_component } from "svelte/internal"; import { create_ssr_component } from "svelte/internal";
const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { const Component = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
return `<div>content</div> return `<div>content</div>
<!-- comment -->
<div>more content</div>`; <div>more content</div>`;
}); });

Loading…
Cancel
Save