Skip to content

Commit 47a9811

Browse files
committed
alternative fix for #3508
1 parent 1c7d61e commit 47a9811

File tree

74 files changed

+116
-113
lines changed

Some content is hidden

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

74 files changed

+116
-113
lines changed

src/compiler/compile/render_dom/index.ts

Lines changed: 9 additions & 9 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,
@@ -425,15 +425,15 @@ export default function dom(
425425
`);
426426
}
427427

428-
const prop_names = x`[]`;
429-
const renamed_prop_names = [];
428+
const prop_names = x`{}` as ObjectExpression;
430429

431430
// TODO find a more idiomatic way of doing this
432431
props.forEach(v => {
433-
(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-
}
432+
prop_names.properties.push(
433+
v.name === v.export_name
434+
? p`${v.name}: 0`
435+
: p`${v.export_name}: "${v.name}"`
436+
);
437437
});
438438

439439
if (options.customElement) {
@@ -444,7 +444,7 @@ export default function dom(
444444
445445
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
446446
447-
@init(this, { target: this.shadowRoot }, ${definition}, create_fragment, ${not_equal}, ${prop_names}, ${renamed_prop_names.length > 0 && x`{ ${renamed_prop_names} }`});
447+
@init(this, { target: this.shadowRoot }, ${definition}, create_fragment, ${not_equal}, ${prop_names});
448448
449449
${dev_props_check}
450450
@@ -496,7 +496,7 @@ export default function dom(
496496
constructor(options) {
497497
super(${options.dev && `options`});
498498
${should_add_css && b`if (!@_document.getElementById("${component.stylesheet.id}-style")) ${add_css}();`}
499-
@init(this, options, ${definition}, create_fragment, ${not_equal}, ${prop_names}, ${renamed_prop_names.length > 0 && x`{ ${renamed_prop_names} }`});
499+
@init(this, options, ${definition}, create_fragment, ${not_equal}, ${prop_names});
500500
${options.dev && b`@dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "${name.name}", options, id: create_fragment.name });`}
501501
502502
${dev_props_check}

src/runtime/internal/Component.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ interface T$$ {
1212
update: () => void;
1313
callbacks: any;
1414
after_update: any[];
15-
props: any;
16-
renamed_props: any;
15+
props: Record<string, 0 | string>;
1716
fragment: null|any;
1817
not_equal: any;
1918
before_update: any[];
@@ -23,12 +22,11 @@ interface T$$ {
2322
}
2423

2524
export function bind(component, name, callback) {
26-
if (component.$$.props.indexOf(name) === -1) return;
27-
if (component.$$.renamed_props && name in component.$$.renamed_props) {
28-
name = component.$$.renamed_props[name];
25+
if (name in component.$$.props) {
26+
name = component.$$.props[name] || name;
27+
component.$$.bound[name] = callback;
28+
callback(component.$$.ctx[name]);
2929
}
30-
component.$$.bound[name] = callback;
31-
callback(component.$$.ctx[name]);
3230
}
3331

3432
export function mount_component(component, target, anchor) {
@@ -74,19 +72,18 @@ function make_dirty(component, key) {
7472
component.$$.dirty[key] = true;
7573
}
7674

77-
export function init(component, options, instance, create_fragment, not_equal, prop_names, renamed_props) {
75+
export function init(component, options, instance, create_fragment, not_equal, props) {
7876
const parent_component = current_component;
7977
set_current_component(component);
8078

81-
const props = options.props || {};
79+
const prop_values = options.props || {};
8280

8381
const $$: T$$ = component.$$ = {
8482
fragment: null,
8583
ctx: null,
8684

8785
// state
88-
props: prop_names,
89-
renamed_props,
86+
props,
9087
update: noop,
9188
not_equal,
9289
bound: blank_object(),
@@ -106,14 +103,14 @@ export function init(component, options, instance, create_fragment, not_equal, p
106103
let ready = false;
107104

108105
$$.ctx = instance
109-
? instance(component, props, (key, ret, value = ret) => {
106+
? instance(component, prop_values, (key, ret, value = ret) => {
110107
if ($$.ctx && not_equal($$.ctx[key], $$.ctx[key] = value)) {
111108
if ($$.bound[key]) $$.bound[key](value);
112109
if (ready) make_dirty(component, key);
113110
}
114111
return ret;
115112
})
116-
: props;
113+
: prop_values;
117114

118115
$$.update();
119116
ready = true;

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

test/js/samples/dynamic-import/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const func = () => import("./Foo.svelte");
4444
class Component extends SvelteComponent {
4545
constructor(options) {
4646
super();
47-
init(this, options, null, create_fragment, safe_not_equal, []);
47+
init(this, options, null, create_fragment, safe_not_equal, {});
4848
}
4949
}
5050

test/js/samples/each-block-array-literal/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function instance($$self, $$props, $$invalidate) {
118118
class Component extends SvelteComponent {
119119
constructor(options) {
120120
super();
121-
init(this, options, instance, create_fragment, safe_not_equal, ["a", "b", "c", "d", "e"]);
121+
init(this, options, instance, create_fragment, safe_not_equal, { a: 0, b: 0, c: 0, d: 0, e: 0 });
122122
}
123123
}
124124

0 commit comments

Comments
 (0)