partially remove component.props

pull/2011/head
Richard Harris 7 years ago
parent 8345107f5c
commit 492d7afc85

@ -165,9 +165,6 @@ export default class Component {
module: false module: false
}); });
}); });
// TODO remove this
this.props = props.map(name => ({ name, as: name }));
} }
} }
@ -685,12 +682,6 @@ export default class Component {
this.extract_imports(script.content, false); this.extract_imports(script.content, false);
this.extract_exports(script.content, false); this.extract_exports(script.content, false);
this.track_mutations(); this.track_mutations();
// TODO remove this, just use component.symbols everywhere
this.props = this.vars.filter(variable => !variable.module && variable.exported_as).map(variable => ({
name: variable.name,
as: variable.exported_as
}));
} }
walk_instance_js_post_template() { walk_instance_js_post_template() {
@ -781,12 +772,6 @@ export default class Component {
const { code, instance_scope, instance_scope_map: map, meta } = this; const { code, instance_scope, instance_scope_map: map, meta } = this;
let scope = instance_scope; let scope = instance_scope;
// TODO we will probably end up wanting to use this elsewhere
const exported = new Set();
this.props.forEach(prop => {
exported.add(prop.name);
});
const coalesced_declarations = []; const coalesced_declarations = [];
let current_group; let current_group;
@ -803,14 +788,15 @@ export default class Component {
if (node.type === 'VariableDeclaration') { if (node.type === 'VariableDeclaration') {
if (node.kind === 'var' || scope === instance_scope) { if (node.kind === 'var' || scope === instance_scope) {
let has_meta_props = false;
let has_exports = false; let has_exports = false;
let has_only_exports = true; let has_only_exports = true;
node.declarations.forEach(declarator => { node.declarations.forEach(declarator => {
extractNames(declarator.id).forEach(name => { extractNames(declarator.id).forEach(name => {
const variable = component.var_lookup.get(name);
if (name === meta.props_object) { if (name === meta.props_object) {
if (exported.has(name)) { if (variable.exported_as) {
component.error(declarator, { component.error(declarator, {
code: 'exported-meta-props', code: 'exported-meta-props',
message: `Cannot export props binding` message: `Cannot export props binding`
@ -829,11 +815,9 @@ export default class Component {
} else { } else {
code.overwrite(declarator.id.end, declarator.end, ' = $$props'); code.overwrite(declarator.id.end, declarator.end, ' = $$props');
} }
has_meta_props = true;
} }
if (exported.has(name)) { if (variable.exported_as) {
has_exports = true; has_exports = true;
} else { } else {
has_only_exports = false; has_only_exports = false;

@ -70,6 +70,12 @@ export default function dom(
options.css !== false options.css !== false
); );
// TODO remove this, just use component.symbols everywhere
component.props = component.vars.filter(variable => !variable.module && variable.exported_as).map(variable => ({
name: variable.name,
as: variable.exported_as
}));
const props = component.props.filter(x => component.writable_declarations.has(x.name)); const props = component.props.filter(x => component.writable_declarations.has(x.name));
const set = (component.meta.props || props.length > 0 || renderer.slots.size > 0) const set = (component.meta.props || props.length > 0 || renderer.slots.size > 0)

@ -24,13 +24,14 @@ export default function ssr(
let user_code; let user_code;
// TODO remove this, just use component.symbols everywhere
const props = component.vars.filter(variable => !variable.module && variable.exported_as);
if (component.javascript) { if (component.javascript) {
component.rewrite_props(); component.rewrite_props();
user_code = component.javascript; user_code = component.javascript;
} else if (!component.ast.instance && !component.ast.module && component.props.length > 0) { } else if (!component.ast.instance && !component.ast.module && props.length > 0) {
const props = component.props.map(prop => prop.as).filter(name => name[0] !== '$'); user_code = `let { ${props.map(prop => prop.exported_as).join(', ')} } = $$props;`
user_code = `let { ${props.join(', ')} } = $$props;`
} }
const reactive_stores = Array.from(component.template_references).filter(n => n[0] === '$'); const reactive_stores = Array.from(component.template_references).filter(n => n[0] === '$');
@ -44,8 +45,8 @@ export default function ssr(
// TODO only do this for props with a default value // TODO only do this for props with a default value
const parent_bindings = component.javascript const parent_bindings = component.javascript
? component.props.map(prop => { ? props.map(prop => {
return `if ($$props.${prop.as} === void 0 && $$bindings.${prop.as} && ${prop.name} !== void 0) $$bindings.${prop.as}(${prop.name});`; return `if ($$props.${prop.exported_as} === void 0 && $$bindings.${prop.exported_as} && ${prop.name} !== void 0) $$bindings.${prop.exported_as}(${prop.name});`;
}) })
: []; : [];

Loading…
Cancel
Save