Skip to content

Commit af42d86

Browse files
committed
fix binding to aliased props (sveltejs#3508)
1 parent d03a5de commit af42d86

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/compiler/compile/render_dom/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export default function dom(
223223

224224
component.rewrite_props(({ name, reassigned, export_name }) => {
225225
const value = `$${name}`;
226-
226+
227227
const insert = (reassigned || export_name)
228228
? b`${`$$subscribe_${name}`}()`
229229
: b`@component_subscribe($$self, ${name}, #value => $$invalidate('${value}', ${value} = #value))`;
@@ -426,10 +426,14 @@ export default function dom(
426426
}
427427

428428
const prop_names = x`[]`;
429+
const renamed_prop_names = [];
429430

430431
// TODO find a more idiomatic way of doing this
431432
props.forEach(v => {
432433
(prop_names as any).elements.push({ type: 'Literal', value: v.export_name });
434+
if (v.name !== v.export_name) {
435+
renamed_prop_names.push(p`${v.export_name}: "${v.name}"`);
436+
}
433437
});
434438

435439
if (options.customElement) {
@@ -440,7 +444,7 @@ export default function dom(
440444
441445
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
442446
443-
@init(this, { target: this.shadowRoot }, ${definition}, create_fragment, ${not_equal}, ${prop_names});
447+
@init(this, { target: this.shadowRoot }, ${definition}, create_fragment, ${not_equal}, ${prop_names}, ${renamed_prop_names.length > 0 && x`{ ${renamed_prop_names} }`});
444448
445449
${dev_props_check}
446450
@@ -492,7 +496,7 @@ export default function dom(
492496
constructor(options) {
493497
super(${options.dev && `options`});
494498
${should_add_css && b`if (!@_document.getElementById("${component.stylesheet.id}-style")) ${add_css}();`}
495-
@init(this, options, ${definition}, create_fragment, ${not_equal}, ${prop_names});
499+
@init(this, options, ${definition}, create_fragment, ${not_equal}, ${prop_names}, ${renamed_prop_names.length > 0 && x`{ ${renamed_prop_names} }`});
496500
${options.dev && b`@dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "${name.name}", options, id: create_fragment.name });`}
497501
498502
${dev_props_check}

src/runtime/internal/Component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface T$$ {
1313
callbacks: any;
1414
after_update: any[];
1515
props: any;
16+
renamed_props: any;
1617
fragment: null|any;
1718
not_equal: any;
1819
before_update: any[];
@@ -23,6 +24,9 @@ interface T$$ {
2324

2425
export function bind(component, name, callback) {
2526
if (component.$$.props.indexOf(name) === -1) return;
27+
if (component.$$.renamed_props && name in component.$$.renamed_props) {
28+
name = component.$$.renamed_props[name];
29+
}
2630
component.$$.bound[name] = callback;
2731
callback(component.$$.ctx[name]);
2832
}
@@ -70,7 +74,7 @@ function make_dirty(component, key) {
7074
component.$$.dirty[key] = true;
7175
}
7276

73-
export function init(component, options, instance, create_fragment, not_equal, prop_names) {
77+
export function init(component, options, instance, create_fragment, not_equal, prop_names, renamed_props) {
7478
const parent_component = current_component;
7579
set_current_component(component);
7680

@@ -82,6 +86,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
8286

8387
// state
8488
props: prop_names,
89+
renamed_props: renamed_props,
8590
update: noop,
8691
not_equal,
8792
bound: blank_object(),

0 commit comments

Comments
 (0)