|
|
|
@ -9,7 +9,6 @@ import Expression from '../../nodes/shared/Expression.js';
|
|
|
|
|
|
|
|
|
|
|
|
/** @extends Wrapper */
|
|
|
|
/** @extends Wrapper */
|
|
|
|
class AwaitBlockBranch extends Wrapper {
|
|
|
|
class AwaitBlockBranch extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {AwaitBlockWrapper} */
|
|
|
|
/** @type {AwaitBlockWrapper} */
|
|
|
|
parent;
|
|
|
|
parent;
|
|
|
|
|
|
|
|
|
|
|
|
@ -60,7 +59,14 @@ class AwaitBlockBranch extends Wrapper {
|
|
|
|
type: status
|
|
|
|
type: status
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.add_context(parent.node[status + '_node'], parent.node[status + '_contexts']);
|
|
|
|
this.add_context(parent.node[status + '_node'], parent.node[status + '_contexts']);
|
|
|
|
this.fragment = new FragmentWrapper(renderer, this.block, this.node.children, parent, strip_whitespace, next_sibling);
|
|
|
|
this.fragment = new FragmentWrapper(
|
|
|
|
|
|
|
|
renderer,
|
|
|
|
|
|
|
|
this.block,
|
|
|
|
|
|
|
|
this.node.children,
|
|
|
|
|
|
|
|
parent,
|
|
|
|
|
|
|
|
strip_whitespace,
|
|
|
|
|
|
|
|
next_sibling
|
|
|
|
|
|
|
|
);
|
|
|
|
this.is_dynamic = this.block.dependencies.size > 0;
|
|
|
|
this.is_dynamic = this.block.dependencies.size > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -69,16 +75,13 @@ class AwaitBlockBranch extends Wrapper {
|
|
|
|
* @param {import('../../nodes/shared/Context.js').Context[]} contexts
|
|
|
|
* @param {import('../../nodes/shared/Context.js').Context[]} contexts
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
add_context(node, contexts) {
|
|
|
|
add_context(node, contexts) {
|
|
|
|
if (!node)
|
|
|
|
if (!node) return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (node.type === 'Identifier') {
|
|
|
|
if (node.type === 'Identifier') {
|
|
|
|
this.value = node.name;
|
|
|
|
this.value = node.name;
|
|
|
|
this.renderer.add_to_context(this.value, true);
|
|
|
|
this.renderer.add_to_context(this.value, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
contexts.forEach((context) => {
|
|
|
|
contexts.forEach((context) => {
|
|
|
|
if (context.type !== 'DestructuredVariable')
|
|
|
|
if (context.type !== 'DestructuredVariable') return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.renderer.add_to_context(context.key.name, true);
|
|
|
|
this.renderer.add_to_context(context.key.name, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.value = this.block.parent.get_unique_name('value').name;
|
|
|
|
this.value = this.block.parent.get_unique_name('value').name;
|
|
|
|
@ -115,14 +118,19 @@ class AwaitBlockBranch extends Wrapper {
|
|
|
|
const props = this.is_destructured
|
|
|
|
const props = this.is_destructured
|
|
|
|
? this.value_contexts.map((prop) => {
|
|
|
|
? this.value_contexts.map((prop) => {
|
|
|
|
if (prop.type === 'ComputedProperty') {
|
|
|
|
if (prop.type === 'ComputedProperty') {
|
|
|
|
const expression = new Expression(this.renderer.component, this.node, this.has_consts(this.node) ? this.node.scope : null, prop.key);
|
|
|
|
const expression = new Expression(
|
|
|
|
|
|
|
|
this.renderer.component,
|
|
|
|
|
|
|
|
this.node,
|
|
|
|
|
|
|
|
this.has_consts(this.node) ? this.node.scope : null,
|
|
|
|
|
|
|
|
prop.key
|
|
|
|
|
|
|
|
);
|
|
|
|
return b`const ${prop.property_name} = ${expression.manipulate(this.block, '#ctx')};`;
|
|
|
|
return b`const ${prop.property_name} = ${expression.manipulate(this.block, '#ctx')};`;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @param {any} name */
|
|
|
|
/** @param {any} name */
|
|
|
|
const to_ctx = (name) => this.renderer.reference(name);
|
|
|
|
const to_ctx = (name) => this.renderer.reference(name);
|
|
|
|
return b `#ctx[${this.block.renderer.context_lookup.get(prop.key.name).index}] = ${prop.default_modifier(prop.modifier(x `#ctx[${this.value_index}]`), to_ctx)};`;
|
|
|
|
return b`#ctx[${
|
|
|
|
|
|
|
|
this.block.renderer.context_lookup.get(prop.key.name).index
|
|
|
|
|
|
|
|
}] = ${prop.default_modifier(prop.modifier(x`#ctx[${this.value_index}]`), to_ctx)};`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
: null;
|
|
|
|
: null;
|
|
|
|
@ -145,7 +153,6 @@ class AwaitBlockBranch extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
/** @extends Wrapper */
|
|
|
|
/** @extends Wrapper */
|
|
|
|
export default class AwaitBlockWrapper extends Wrapper {
|
|
|
|
export default class AwaitBlockWrapper extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('../../nodes/AwaitBlock.js').default} */
|
|
|
|
/** @type {import('../../nodes/AwaitBlock.js').default} */
|
|
|
|
node;
|
|
|
|
node;
|
|
|
|
|
|
|
|
|
|
|
|
@ -177,17 +184,23 @@ export default class AwaitBlockWrapper extends Wrapper {
|
|
|
|
let has_outros = false;
|
|
|
|
let has_outros = false;
|
|
|
|
['pending', 'then', 'catch'].forEach((status) => {
|
|
|
|
['pending', 'then', 'catch'].forEach((status) => {
|
|
|
|
const child = this.node[status];
|
|
|
|
const child = this.node[status];
|
|
|
|
const branch = new AwaitBlockBranch(status, renderer, block, this, child, strip_whitespace, next_sibling);
|
|
|
|
const branch = new AwaitBlockBranch(
|
|
|
|
|
|
|
|
status,
|
|
|
|
|
|
|
|
renderer,
|
|
|
|
|
|
|
|
block,
|
|
|
|
|
|
|
|
this,
|
|
|
|
|
|
|
|
child,
|
|
|
|
|
|
|
|
strip_whitespace,
|
|
|
|
|
|
|
|
next_sibling
|
|
|
|
|
|
|
|
);
|
|
|
|
renderer.blocks.push(branch.block);
|
|
|
|
renderer.blocks.push(branch.block);
|
|
|
|
if (branch.is_dynamic) {
|
|
|
|
if (branch.is_dynamic) {
|
|
|
|
is_dynamic = true;
|
|
|
|
is_dynamic = true;
|
|
|
|
// TODO should blocks update their own parents?
|
|
|
|
// TODO should blocks update their own parents?
|
|
|
|
block.add_dependencies(branch.block.dependencies);
|
|
|
|
block.add_dependencies(branch.block.dependencies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (branch.block.has_intros)
|
|
|
|
if (branch.block.has_intros) has_intros = true;
|
|
|
|
has_intros = true;
|
|
|
|
if (branch.block.has_outros) has_outros = true;
|
|
|
|
if (branch.block.has_outros)
|
|
|
|
|
|
|
|
has_outros = true;
|
|
|
|
|
|
|
|
this[status] = branch;
|
|
|
|
this[status] = branch;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
['pending', 'then', 'catch'].forEach((status) => {
|
|
|
|
['pending', 'then', 'catch'].forEach((status) => {
|
|
|
|
@ -243,7 +256,8 @@ export default class AwaitBlockWrapper 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';
|
|
|
|
const has_transitions = this.pending.block.has_intro_method || this.pending.block.has_outro_method;
|
|
|
|
const has_transitions =
|
|
|
|
|
|
|
|
this.pending.block.has_intro_method || this.pending.block.has_outro_method;
|
|
|
|
block.chunks.mount.push(b`
|
|
|
|
block.chunks.mount.push(b`
|
|
|
|
${info}.block.m(${initial_mount_node}, ${info}.anchor = ${anchor_node});
|
|
|
|
${info}.block.m(${initial_mount_node}, ${info}.anchor = ${anchor_node});
|
|
|
|
${info}.mount = () => ${update_mount_node};
|
|
|
|
${info}.mount = () => ${update_mount_node};
|
|
|
|
@ -268,14 +282,12 @@ export default class AwaitBlockWrapper extends Wrapper {
|
|
|
|
${update_await_block_branch}
|
|
|
|
${update_await_block_branch}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
${condition}
|
|
|
|
${condition}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (this.pending.block.has_update_method) {
|
|
|
|
if (this.pending.block.has_update_method) {
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
${update_await_block_branch}
|
|
|
|
${update_await_block_branch}
|
|
|
|
@ -301,6 +313,4 @@ export default class AwaitBlockWrapper extends Wrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @typedef {'pending' | 'then' | 'catch'} Status */
|
|
|
|
/** @typedef {'pending' | 'then' | 'catch'} Status */
|
|
|
|
|
|
|
|
|
|
|
|
|