dont store props in temp variable unnecessarily

pull/1839/head
Rich Harris 7 years ago
parent ec4010672d
commit 0e4dd20d82

@ -96,7 +96,7 @@ export default class InlineComponentWrapper extends Wrapper {
const updates: string[] = []; const updates: string[] = [];
const postupdates: string[] = []; const postupdates: string[] = [];
const props = block.getUniqueName(`${name}_props`); let props;
const name_changes = block.getUniqueName(`${name}_changes`); const name_changes = block.getUniqueName(`${name}_changes`);
const usesSpread = !!this.node.attributes.find(a => a.isSpread); const usesSpread = !!this.node.attributes.find(a => a.isSpread);
@ -111,6 +111,7 @@ export default class InlineComponentWrapper extends Wrapper {
if (!usesSpread && this.node.bindings.length === 0) { if (!usesSpread && this.node.bindings.length === 0) {
componentInitProperties.push(`props: ${attributeObject}`); componentInitProperties.push(`props: ${attributeObject}`);
} else { } else {
props = block.getUniqueName(`${name}_props`);
componentInitProperties.push(`props: ${props}`); componentInitProperties.push(`props: ${props}`);
} }
} }
@ -292,7 +293,7 @@ export default class InlineComponentWrapper extends Wrapper {
function ${switch_props}(ctx) { function ${switch_props}(ctx) {
${(this.node.attributes.length || this.node.bindings.length) && deindent` ${(this.node.attributes.length || this.node.bindings.length) && deindent`
var ${props} = ${attributeObject};`} ${props && `const ${props} = ${attributeObject};`}`}
${statements} ${statements}
return { return {
${componentInitProperties.join(',\n')} ${componentInitProperties.join(',\n')}
@ -386,7 +387,7 @@ export default class InlineComponentWrapper extends Wrapper {
block.builders.init.addBlock(deindent` block.builders.init.addBlock(deindent`
${(this.node.attributes.length || this.node.bindings.length) && deindent` ${(this.node.attributes.length || this.node.bindings.length) && deindent`
var ${props} = ${attributeObject};`} ${props && `const ${props} = ${attributeObject};`}`}
${statements} ${statements}
var ${name} = new ${expression}({ var ${name} = new ${expression}({
${componentInitProperties.join(',\n')} ${componentInitProperties.join(',\n')}

Loading…
Cancel
Save