Skip to content

Commit 1273f97

Browse files
authored
Merge pull request #3811 from sveltejs/gh-3508-alt
Alternative fix for #3508
2 parents da824c0 + 9d11827 commit 1273f97

File tree

80 files changed

+137
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+137
-110
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Also:
1010
* Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710))
1111
* Fix several bugs related to interaction of `{...spread}` attributes with other features ([#2721](https://github.com/sveltejs/svelte/issues/2721), [#2916](https://github.com/sveltejs/svelte/issues/2916), [#3421](https://github.com/sveltejs/svelte/issues/3421), [#3681](https://github.com/sveltejs/svelte/issues/3681), [#3764](https://github.com/sveltejs/svelte/issues/3764), [#3790](https://github.com/sveltejs/svelte/issues/3790))
1212
* Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828))
13+
* Fix binding to props that have been renamed with `export { ... as ... }` ([#3508](https://github.com/sveltejs/svelte/issues/3508))
1314
* Fix application of style scoping class in cases of ambiguity ([#3544](https://github.com/sveltejs/svelte/issues/3544))
1415
* Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579))
1516
* Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issues/3588))

src/compiler/compile/render_dom/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import add_to_set from '../utils/add_to_set';
77
import { extract_names } from '../utils/scope';
88
import { invalidate } from '../utils/invalidate';
99
import Block from './Block';
10-
import { ClassDeclaration, FunctionExpression, Node, Statement } from 'estree';
10+
import { ClassDeclaration, FunctionExpression, Node, Statement, ObjectExpression } from 'estree';
1111

1212
export default function dom(
1313
component: Component,
@@ -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))`;
@@ -425,12 +425,9 @@ export default function dom(
425425
`);
426426
}
427427

428-
const prop_names = x`[]`;
429-
430-
// TODO find a more idiomatic way of doing this
431-
props.forEach(v => {
432-
(prop_names as any).elements.push({ type: 'Literal', value: v.export_name });
433-
});
428+
const prop_names = x`{
429+
${props.map(v => p`${v.export_name}: ${v.export_name === v.name ? 0 : x`"${v.name}"`}}`)}
430+
}` as ObjectExpression;
434431

435432
if (options.customElement) {
436433
const declaration = b`

src/runtime/internal/Component.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
22
import { current_component, set_current_component } from './lifecycle';
3-
import { blank_object, is_function, run, run_all, noop } from './utils';
3+
import { blank_object, is_function, run, run_all, noop, has_prop } from './utils';
44
import { children } from './dom';
55
import { transition_in } from './transitions';
66

@@ -12,7 +12,7 @@ interface T$$ {
1212
update: () => void;
1313
callbacks: any;
1414
after_update: any[];
15-
props: any;
15+
props: Record<string, 0 | string>;
1616
fragment: null|any;
1717
not_equal: any;
1818
before_update: any[];
@@ -22,9 +22,11 @@ interface T$$ {
2222
}
2323

2424
export function bind(component, name, callback) {
25-
if (component.$$.props.indexOf(name) === -1) return;
26-
component.$$.bound[name] = callback;
27-
callback(component.$$.ctx[name]);
25+
if (has_prop(component.$$.props, name)) {
26+
name = component.$$.props[name] || name;
27+
component.$$.bound[name] = callback;
28+
callback(component.$$.ctx[name]);
29+
}
2830
}
2931

3032
export function mount_component(component, target, anchor) {
@@ -70,18 +72,18 @@ function make_dirty(component, key) {
7072
component.$$.dirty[key] = true;
7173
}
7274

73-
export function init(component, options, instance, create_fragment, not_equal, prop_names) {
75+
export function init(component, options, instance, create_fragment, not_equal, props) {
7476
const parent_component = current_component;
7577
set_current_component(component);
7678

77-
const props = options.props || {};
79+
const prop_values = options.props || {};
7880

7981
const $$: T$$ = component.$$ = {
8082
fragment: null,
8183
ctx: null,
8284

8385
// state
84-
props: prop_names,
86+
props,
8587
update: noop,
8688
not_equal,
8789
bound: blank_object(),
@@ -101,14 +103,14 @@ export function init(component, options, instance, create_fragment, not_equal, p
101103
let ready = false;
102104

103105
$$.ctx = instance
104-
? instance(component, props, (key, ret, value = ret) => {
106+
? instance(component, prop_values, (key, ret, value = ret) => {
105107
if ($$.ctx && not_equal($$.ctx[key], $$.ctx[key] = value)) {
106108
if ($$.bound[key]) $$.bound[key](value);
107109
if (ready) make_dirty(component, key);
108110
}
109111
return ret;
110112
})
111-
: props;
113+
: prop_values;
112114

113115
$$.update();
114116
ready = true;

src/runtime/internal/dom.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { has_prop } from "./utils";
2+
13
export function append(target: Node, node: Node) {
24
target.appendChild(node);
35
}
@@ -29,7 +31,7 @@ export function object_without_properties<T, K extends keyof T>(obj: T, exclude:
2931
const target = {} as Pick<T, Exclude<keyof T, K>>;
3032
for (const k in obj) {
3133
if (
32-
Object.prototype.hasOwnProperty.call(obj, k)
34+
has_prop(obj, k)
3335
// @ts-ignore
3436
&& exclude.indexOf(k) === -1
3537
) {

src/runtime/internal/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,5 @@ export function set_store_value(store, ret, value = ret) {
105105
store.set(value);
106106
return ret;
107107
}
108+
109+
export const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);

test/js/samples/action-custom-event-handler/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function handleFoo(bar) {
3939
}
4040

4141
function foo(node, callback) {
42-
42+
4343
}
4444

4545
function instance($$self, $$props, $$invalidate) {
@@ -56,7 +56,7 @@ function instance($$self, $$props, $$invalidate) {
5656
class Component extends SvelteComponent {
5757
constructor(options) {
5858
super();
59-
init(this, options, instance, create_fragment, safe_not_equal, ["bar"]);
59+
init(this, options, instance, create_fragment, safe_not_equal, { bar: 0 });
6060
}
6161
}
6262

test/js/samples/action/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function link(node) {
5252
class Component extends SvelteComponent {
5353
constructor(options) {
5454
super();
55-
init(this, options, null, create_fragment, safe_not_equal, []);
55+
init(this, options, null, create_fragment, safe_not_equal, {});
5656
}
5757
}
5858

test/js/samples/bind-online/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function instance($$self, $$props, $$invalidate) {
4242
class Component extends SvelteComponent {
4343
constructor(options) {
4444
super();
45-
init(this, options, instance, create_fragment, safe_not_equal, []);
45+
init(this, options, instance, create_fragment, safe_not_equal, {});
4646
}
4747
}
4848

test/js/samples/bind-open/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function instance($$self, $$props, $$invalidate) {
5858
class Component extends SvelteComponent {
5959
constructor(options) {
6060
super();
61-
init(this, options, instance, create_fragment, safe_not_equal, ["open"]);
61+
init(this, options, instance, create_fragment, safe_not_equal, { open: 0 });
6262
}
6363
}
6464

test/js/samples/bind-width-height/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function instance($$self, $$props, $$invalidate) {
5656
class Component extends SvelteComponent {
5757
constructor(options) {
5858
super();
59-
init(this, options, instance, create_fragment, safe_not_equal, ["w", "h"]);
59+
init(this, options, instance, create_fragment, safe_not_equal, { w: 0, h: 0 });
6060
}
6161
}
6262

test/js/samples/capture-inject-dev-only/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function instance($$self, $$props, $$invalidate) {
6868
class Component extends SvelteComponent {
6969
constructor(options) {
7070
super();
71-
init(this, options, instance, create_fragment, safe_not_equal, []);
71+
init(this, options, instance, create_fragment, safe_not_equal, {});
7272
}
7373
}
7474

test/js/samples/collapses-text-around-comments/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Component extends SvelteComponent {
5858
constructor(options) {
5959
super();
6060
if (!document.getElementById("svelte-1a7i8ec-style")) add_css();
61-
init(this, options, instance, create_fragment, safe_not_equal, ["foo"]);
61+
init(this, options, instance, create_fragment, safe_not_equal, { foo: 0 });
6262
}
6363
}
6464

test/js/samples/component-static-array/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function instance($$self) {
4545
class Component extends SvelteComponent {
4646
constructor(options) {
4747
super();
48-
init(this, options, instance, create_fragment, safe_not_equal, []);
48+
init(this, options, instance, create_fragment, safe_not_equal, {});
4949
}
5050
}
5151

test/js/samples/component-static-immutable/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function instance($$self) {
4545
class Component extends SvelteComponent {
4646
constructor(options) {
4747
super();
48-
init(this, options, instance, create_fragment, not_equal, []);
48+
init(this, options, instance, create_fragment, not_equal, {});
4949
}
5050
}
5151

test/js/samples/component-static-immutable2/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function instance($$self) {
4545
class Component extends SvelteComponent {
4646
constructor(options) {
4747
super();
48-
init(this, options, instance, create_fragment, not_equal, []);
48+
init(this, options, instance, create_fragment, not_equal, {});
4949
}
5050
}
5151

test/js/samples/component-static-var/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function instance($$self, $$props, $$invalidate) {
9191
class Component extends SvelteComponent {
9292
constructor(options) {
9393
super();
94-
init(this, options, instance, create_fragment, safe_not_equal, []);
94+
init(this, options, instance, create_fragment, safe_not_equal, {});
9595
}
9696
}
9797

test/js/samples/component-static/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function instance($$self) {
4545
class Component extends SvelteComponent {
4646
constructor(options) {
4747
super();
48-
init(this, options, instance, create_fragment, safe_not_equal, []);
48+
init(this, options, instance, create_fragment, safe_not_equal, {});
4949
}
5050
}
5151

test/js/samples/component-store-access-invalidate/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function instance($$self, $$props, $$invalidate) {
4848
class Component extends SvelteComponent {
4949
constructor(options) {
5050
super();
51-
init(this, options, instance, create_fragment, safe_not_equal, []);
51+
init(this, options, instance, create_fragment, safe_not_equal, {});
5252
}
5353
}
5454

test/js/samples/component-store-file-invalidate/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function instance($$self, $$props, $$invalidate) {
3434
class Component extends SvelteComponent {
3535
constructor(options) {
3636
super();
37-
init(this, options, instance, create_fragment, safe_not_equal, ["increment"]);
37+
init(this, options, instance, create_fragment, safe_not_equal, { increment: 0 });
3838
}
3939

4040
get increment() {

test/js/samples/component-store-reassign-invalidate/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function instance($$self, $$props, $$invalidate) {
6767
class Component extends SvelteComponent {
6868
constructor(options) {
6969
super();
70-
init(this, options, instance, create_fragment, safe_not_equal, []);
70+
init(this, options, instance, create_fragment, safe_not_equal, {});
7171
}
7272
}
7373

test/js/samples/computed-collapsed-if/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function instance($$self, $$props, $$invalidate) {
3232
class Component extends SvelteComponent {
3333
constructor(options) {
3434
super();
35-
init(this, options, instance, create_fragment, safe_not_equal, ["x", "a", "b"]);
35+
init(this, options, instance, create_fragment, safe_not_equal, { x: 0, a: 0, b: 0 });
3636
}
3737

3838
get a() {

test/js/samples/css-media-query/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Component extends SvelteComponent {
4141
constructor(options) {
4242
super();
4343
if (!document.getElementById("svelte-1slhpfn-style")) add_css();
44-
init(this, options, null, create_fragment, safe_not_equal, []);
44+
init(this, options, null, create_fragment, safe_not_equal, {});
4545
}
4646
}
4747

test/js/samples/css-shadow-dom-keyframes/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Component extends SvelteElement {
3333
constructor(options) {
3434
super();
3535
this.shadowRoot.innerHTML = `<style>div{animation:foo 1s}@keyframes foo{0%{opacity:0}100%{opacity:1}}</style>`;
36-
init(this, { target: this.shadowRoot }, null, create_fragment, safe_not_equal, []);
36+
init(this, { target: this.shadowRoot }, null, create_fragment, safe_not_equal, {});
3737

3838
if (options) {
3939
if (options.target) {

test/js/samples/data-attribute/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function instance($$self, $$props, $$invalidate) {
5656
class Component extends SvelteComponent {
5757
constructor(options) {
5858
super();
59-
init(this, options, instance, create_fragment, safe_not_equal, ["bar"]);
59+
init(this, options, instance, create_fragment, safe_not_equal, { bar: 0 });
6060
}
6161
}
6262

test/js/samples/debug-empty/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function instance($$self, $$props, $$invalidate) {
9292
class Component extends SvelteComponentDev {
9393
constructor(options) {
9494
super(options);
95-
init(this, options, instance, create_fragment, safe_not_equal, ["name"]);
95+
init(this, options, instance, create_fragment, safe_not_equal, { name: 0 });
9696

9797
dispatch_dev("SvelteRegisterComponent", {
9898
component: this,

test/js/samples/debug-foo-bar-baz-things/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function instance($$self, $$props, $$invalidate) {
192192
class Component extends SvelteComponentDev {
193193
constructor(options) {
194194
super(options);
195-
init(this, options, instance, create_fragment, safe_not_equal, ["things", "foo", "bar", "baz"]);
195+
init(this, options, instance, create_fragment, safe_not_equal, { things: 0, foo: 0, bar: 0, baz: 0 });
196196

197197
dispatch_dev("SvelteRegisterComponent", {
198198
component: this,

test/js/samples/debug-foo/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function instance($$self, $$props, $$invalidate) {
186186
class Component extends SvelteComponentDev {
187187
constructor(options) {
188188
super(options);
189-
init(this, options, instance, create_fragment, safe_not_equal, ["things", "foo"]);
189+
init(this, options, instance, create_fragment, safe_not_equal, { things: 0, foo: 0 });
190190

191191
dispatch_dev("SvelteRegisterComponent", {
192192
component: this,

test/js/samples/debug-hoisted/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function instance($$self) {
6464
class Component extends SvelteComponentDev {
6565
constructor(options) {
6666
super(options);
67-
init(this, options, instance, create_fragment, safe_not_equal, []);
67+
init(this, options, instance, create_fragment, safe_not_equal, {});
6868

6969
dispatch_dev("SvelteRegisterComponent", {
7070
component: this,

test/js/samples/debug-no-dependencies/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function create_fragment(ctx) {
132132
class Component extends SvelteComponentDev {
133133
constructor(options) {
134134
super(options);
135-
init(this, options, null, create_fragment, safe_not_equal, []);
135+
init(this, options, null, create_fragment, safe_not_equal, {});
136136

137137
dispatch_dev("SvelteRegisterComponent", {
138138
component: this,

test/js/samples/deconflict-builtins/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function instance($$self, $$props, $$invalidate) {
112112
class Component extends SvelteComponent {
113113
constructor(options) {
114114
super();
115-
init(this, options, instance, create_fragment, safe_not_equal, ["createElement"]);
115+
init(this, options, instance, create_fragment, safe_not_equal, { createElement: 0 });
116116
}
117117
}
118118

test/js/samples/deconflict-globals/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function instance($$self, $$props, $$invalidate) {
2929
class Component extends SvelteComponent {
3030
constructor(options) {
3131
super();
32-
init(this, options, instance, create_fragment, safe_not_equal, ["foo"]);
32+
init(this, options, instance, create_fragment, safe_not_equal, { foo: 0 });
3333
}
3434
}
3535

test/js/samples/dev-warning-missing-data-computed/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function instance($$self, $$props, $$invalidate) {
9696
class Component extends SvelteComponentDev {
9797
constructor(options) {
9898
super(options);
99-
init(this, options, instance, create_fragment, safe_not_equal, ["foo"]);
99+
init(this, options, instance, create_fragment, safe_not_equal, { foo: 0 });
100100

101101
dispatch_dev("SvelteRegisterComponent", {
102102
component: this,

test/js/samples/dont-invalidate-this/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function make_uppercase() {
3838
class Component extends SvelteComponent {
3939
constructor(options) {
4040
super();
41-
init(this, options, null, create_fragment, safe_not_equal, []);
41+
init(this, options, null, create_fragment, safe_not_equal, {});
4242
}
4343
}
4444

0 commit comments

Comments
 (0)