|
|
|
@ -5,9 +5,9 @@ import { CompileOptions } from '../../interfaces';
|
|
|
|
|
import { walk } from 'estree-walker';
|
|
|
|
|
import add_to_set from '../utils/add_to_set';
|
|
|
|
|
import { extract_names } from '../utils/scope';
|
|
|
|
|
import { invalidate } from '../utils/invalidate';
|
|
|
|
|
import { invalidate } from './invalidate';
|
|
|
|
|
import Block from './Block';
|
|
|
|
|
import { ClassDeclaration, FunctionExpression, Node, Statement, ObjectExpression } from 'estree';
|
|
|
|
|
import { ClassDeclaration, FunctionExpression, Node, Statement, ObjectExpression, Expression } from 'estree';
|
|
|
|
|
|
|
|
|
|
export default function dom(
|
|
|
|
|
component: Component,
|
|
|
|
@ -80,12 +80,12 @@ export default function dom(
|
|
|
|
|
const set = (uses_props || writable_props.length > 0 || component.slots.size > 0)
|
|
|
|
|
? x`
|
|
|
|
|
${$$props} => {
|
|
|
|
|
${uses_props && component.invalidate('$$props', x`$$props = @assign(@assign({}, $$props), $$new_props)`)}
|
|
|
|
|
${uses_props && renderer.invalidate('$$props', x`$$props = @assign(@assign({}, $$props), $$new_props)`)}
|
|
|
|
|
${writable_props.map(prop =>
|
|
|
|
|
b`if ('${prop.export_name}' in ${$$props}) ${component.invalidate(prop.name, x`${prop.name} = ${$$props}.${prop.export_name}`)};`
|
|
|
|
|
b`if ('${prop.export_name}' in ${$$props}) ${renderer.invalidate(prop.name, x`${prop.name} = ${$$props}.${prop.export_name}`)};`
|
|
|
|
|
)}
|
|
|
|
|
${component.slots.size > 0 &&
|
|
|
|
|
b`if ('$$scope' in ${$$props}) ${component.invalidate('$$scope', x`$$scope = ${$$props}.$$scope`)};`}
|
|
|
|
|
b`if ('$$scope' in ${$$props}) ${renderer.invalidate('$$scope', x`$$scope = ${$$props}.$$scope`)};`}
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
: null;
|
|
|
|
@ -105,7 +105,7 @@ export default function dom(
|
|
|
|
|
kind: 'get',
|
|
|
|
|
key: { type: 'Identifier', name: prop.export_name },
|
|
|
|
|
value: x`function() {
|
|
|
|
|
return ${prop.hoistable ? prop.name : x`this.$$.ctx.${prop.name}`}
|
|
|
|
|
return ${prop.hoistable ? prop.name : x`this.$$.ctx[${renderer.context_lookup.get(prop.name)}]`}
|
|
|
|
|
}`
|
|
|
|
|
});
|
|
|
|
|
} else if (component.compile_options.dev) {
|
|
|
|
@ -180,9 +180,9 @@ export default function dom(
|
|
|
|
|
const writable_vars = component.vars.filter(variable => !variable.module && variable.writable);
|
|
|
|
|
inject_state = (uses_props || writable_vars.length > 0) ? x`
|
|
|
|
|
${$$props} => {
|
|
|
|
|
${uses_props && component.invalidate('$$props', x`$$props = @assign(@assign({}, $$props), $$new_props)`)}
|
|
|
|
|
${uses_props && renderer.invalidate('$$props', x`$$props = @assign(@assign({}, $$props), $$new_props)`)}
|
|
|
|
|
${writable_vars.map(prop => b`
|
|
|
|
|
if ('${prop.name}' in $$props) ${component.invalidate(prop.name, x`${prop.name} = ${$$props}.${prop.name}`)};
|
|
|
|
|
if ('${prop.name}' in $$props) ${renderer.invalidate(prop.name, x`${prop.name} = ${$$props}.${prop.name}`)};
|
|
|
|
|
`)}
|
|
|
|
|
}
|
|
|
|
|
` : x`
|
|
|
|
@ -216,17 +216,18 @@ export default function dom(
|
|
|
|
|
// onto the initial function call
|
|
|
|
|
const names = new Set(extract_names(assignee));
|
|
|
|
|
|
|
|
|
|
this.replace(invalidate(component, scope, node, names));
|
|
|
|
|
this.replace(invalidate(renderer, scope, node, names));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
component.rewrite_props(({ name, reassigned, export_name }) => {
|
|
|
|
|
const value = `$${name}`;
|
|
|
|
|
const i = renderer.context_lookup.get(name);
|
|
|
|
|
|
|
|
|
|
const insert = (reassigned || export_name)
|
|
|
|
|
? b`${`$$subscribe_${name}`}()`
|
|
|
|
|
: b`@component_subscribe($$self, ${name}, #value => $$invalidate('${value}', ${value} = #value))`;
|
|
|
|
|
: b`@component_subscribe($$self, ${name}, #value => $$invalidate(${i}, ${value} = #value))`;
|
|
|
|
|
|
|
|
|
|
if (component.compile_options.dev) {
|
|
|
|
|
return b`@validate_store(${name}, '${name}'); ${insert}`;
|
|
|
|
@ -256,11 +257,13 @@ export default function dom(
|
|
|
|
|
${component.fully_hoisted}
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
const filtered_declarations = component.vars
|
|
|
|
|
.filter(v => ((v.referenced || v.export_name) && !v.hoistable))
|
|
|
|
|
.map(v => p`${v.name}`);
|
|
|
|
|
const filtered_declarations = renderer.context
|
|
|
|
|
.map(name => name ? ({
|
|
|
|
|
type: 'Identifier',
|
|
|
|
|
name
|
|
|
|
|
}) as Expression : x`null`);
|
|
|
|
|
|
|
|
|
|
if (uses_props) filtered_declarations.push(p`$$props: $$props = @exclude_internal_props($$props)`);
|
|
|
|
|
if (uses_props) filtered_declarations.push(x`$$props = @exclude_internal_props($$props)`);
|
|
|
|
|
|
|
|
|
|
const filtered_props = props.filter(prop => {
|
|
|
|
|
const variable = component.var_lookup.get(prop.name);
|
|
|
|
@ -273,11 +276,11 @@ export default function dom(
|
|
|
|
|
const reactive_stores = component.vars.filter(variable => variable.name[0] === '$' && variable.name[1] !== '$');
|
|
|
|
|
|
|
|
|
|
if (component.slots.size > 0) {
|
|
|
|
|
filtered_declarations.push(p`$$slots`, p`$$scope`);
|
|
|
|
|
filtered_declarations.push(x`$$slots`, x`$$scope`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (renderer.binding_groups.length > 0) {
|
|
|
|
|
filtered_declarations.push(p`$$binding_groups`);
|
|
|
|
|
filtered_declarations.push(x`$$binding_groups`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const instance_javascript = component.extract_javascript(component.ast.instance);
|
|
|
|
@ -307,7 +310,7 @@ export default function dom(
|
|
|
|
|
})
|
|
|
|
|
.map(({ name }) => b`
|
|
|
|
|
${component.compile_options.dev && b`@validate_store(${name.slice(1)}, '${name.slice(1)}');`}
|
|
|
|
|
@component_subscribe($$self, ${name.slice(1)}, $$value => $$invalidate('${name}', ${name} = $$value));
|
|
|
|
|
@component_subscribe($$self, ${name.slice(1)}, $$value => $$invalidate(${renderer.context_lookup.get(name)}, ${name} = $$value));
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
const resubscribable_reactive_store_unsubscribers = reactive_stores
|
|
|
|
@ -330,9 +333,7 @@ export default function dom(
|
|
|
|
|
return variable && (variable.writable || variable.mutated);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const condition = !uses_props && writable.length > 0 && (writable
|
|
|
|
|
.map(n => x`#changed.${n}`)
|
|
|
|
|
.reduce((lhs, rhs) => x`${lhs} || ${rhs}`));
|
|
|
|
|
const condition = !uses_props && writable.length > 0 && renderer.changed(writable);
|
|
|
|
|
|
|
|
|
|
let statement = d.node; // TODO remove label (use d.node.body) if it's not referenced
|
|
|
|
|
|
|
|
|
@ -358,7 +359,9 @@ export default function dom(
|
|
|
|
|
if (store && (store.reassigned || store.export_name)) {
|
|
|
|
|
const unsubscribe = `$$unsubscribe_${name}`;
|
|
|
|
|
const subscribe = `$$subscribe_${name}`;
|
|
|
|
|
return b`let ${$name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${name}, $$value => $$invalidate('${$name}', ${$name} = $$value)), ${name})`;
|
|
|
|
|
const i = renderer.context_lookup.get($name);
|
|
|
|
|
|
|
|
|
|
return b`let ${$name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${name}, $$value => $$invalidate(${i}, ${$name} = $$value)), ${name})`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return b`let ${$name};`;
|
|
|
|
@ -375,8 +378,8 @@ export default function dom(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const return_value = {
|
|
|
|
|
type: 'ObjectExpression',
|
|
|
|
|
properties: filtered_declarations
|
|
|
|
|
type: 'ArrayExpression',
|
|
|
|
|
elements: filtered_declarations
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const reactive_dependencies = {
|
|
|
|
|