Skip to content

Commit 0619e6e

Browse files
authored
Merge pull request sveltejs#3394 from sveltejs/sveltejsgh-2290
coerce tag values to string
2 parents bb9a9ef + 655701e commit 0619e6e

File tree

15 files changed

+43
-26
lines changed

15 files changed

+43
-26
lines changed

src/compiler/compile/render_dom/wrappers/shared/Tag.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ export default class Tag extends Wrapper {
2424
const value = this.node.should_cache && block.get_unique_name(`${this.var}_value`);
2525
const content = this.node.should_cache ? value : snippet;
2626

27-
if (this.node.should_cache) block.add_variable(value, snippet);
27+
if (this.node.should_cache) block.add_variable(value, `${snippet} + ""`);
2828

2929
if (dependencies.length > 0) {
3030
const changed_check = (
3131
(block.has_outros ? `!#current || ` : '') +
3232
dependencies.map((dependency: string) => `changed.${dependency}`).join(' || ')
3333
);
3434

35-
const update_cached_value = `${value} !== (${value} = ${snippet})`;
35+
const update_cached_value = `${value} !== (${value} = ${snippet} + "")`;
3636

3737
const condition = this.node.should_cache
3838
? `(${changed_check}) && ${update_cached_value}`

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function get_each_context(ctx, list, i) {
2525

2626
// (8:0) {#each things as thing}
2727
function create_each_block(ctx) {
28-
var span, t0_value = ctx.thing.name, t0, t1;
28+
var span, t0_value = ctx.thing.name + "", t0, t1;
2929

3030
return {
3131
c: function create() {
@@ -48,7 +48,7 @@ function create_each_block(ctx) {
4848
},
4949

5050
p: function update(changed, ctx) {
51-
if ((changed.things) && t0_value !== (t0_value = ctx.thing.name)) {
51+
if ((changed.things) && t0_value !== (t0_value = ctx.thing.name + "")) {
5252
set_data(t0, t0_value);
5353
}
5454

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function get_each_context(ctx, list, i) {
2525

2626
// (6:0) {#each things as thing}
2727
function create_each_block(ctx) {
28-
var span, t0_value = ctx.thing.name, t0, t1;
28+
var span, t0_value = ctx.thing.name + "", t0, t1;
2929

3030
return {
3131
c: function create() {
@@ -48,7 +48,7 @@ function create_each_block(ctx) {
4848
},
4949

5050
p: function update(changed, ctx) {
51-
if ((changed.things) && t0_value !== (t0_value = ctx.thing.name)) {
51+
if ((changed.things) && t0_value !== (t0_value = ctx.thing.name + "")) {
5252
set_data(t0, t0_value);
5353
}
5454

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function get_each_context(ctx, list, i) {
2222

2323
// (5:0) {#each createElement as node}
2424
function create_each_block(ctx) {
25-
var span, t_value = ctx.node, t;
25+
var span, t_value = ctx.node + "", t;
2626

2727
return {
2828
c() {
@@ -36,7 +36,7 @@ function create_each_block(ctx) {
3636
},
3737

3838
p(changed, ctx) {
39-
if ((changed.createElement) && t_value !== (t_value = ctx.node)) {
39+
if ((changed.createElement) && t_value !== (t_value = ctx.node + "")) {
4040
set_data(t, t_value);
4141
}
4242
},

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
const file = undefined;
1818

1919
function create_fragment(ctx) {
20-
var p, t0_value = Math.max(0, ctx.foo), t0, t1, t2;
20+
var p, t0_value = Math.max(0, ctx.foo) + "", t0, t1, t2;
2121

2222
return {
2323
c: function create() {
@@ -40,7 +40,7 @@ function create_fragment(ctx) {
4040
},
4141

4242
p: function update(changed, ctx) {
43-
if ((changed.foo) && t0_value !== (t0_value = Math.max(0, ctx.foo))) {
43+
if ((changed.foo) && t0_value !== (t0_value = Math.max(0, ctx.foo) + "")) {
4444
set_data(t0, t0_value);
4545
}
4646

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function get_each_context(ctx, list, i) {
2222

2323
// (9:0) {#each [a, b, c, d, e] as num}
2424
function create_each_block(ctx) {
25-
var span, t_value = ctx.num, t;
25+
var span, t_value = ctx.num + "", t;
2626

2727
return {
2828
c() {
@@ -36,7 +36,7 @@ function create_each_block(ctx) {
3636
},
3737

3838
p(changed, ctx) {
39-
if ((changed.a || changed.b || changed.c || changed.d || changed.e) && t_value !== (t_value = ctx.num)) {
39+
if ((changed.a || changed.b || changed.c || changed.d || changed.e) && t_value !== (t_value = ctx.num + "")) {
4040
set_data(t, t_value);
4141
}
4242
},

test/js/samples/each-block-changed-check/expected.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function get_each_context(ctx, list, i) {
2525

2626
// (8:0) {#each comments as comment, i}
2727
function create_each_block(ctx) {
28-
var div, strong, t0, t1, span, t2_value = ctx.comment.author, t2, t3, t4_value = ctx.elapsed(ctx.comment.time, ctx.time), t4, t5, t6, html_tag, raw_value = ctx.comment.html;
28+
var div, strong, t0, t1, span, t2_value = ctx.comment.author + "", t2, t3, t4_value = ctx.elapsed(ctx.comment.time, ctx.time) + "", t4, t5, t6, html_tag, raw_value = ctx.comment.html + "";
2929

3030
return {
3131
c() {
@@ -59,15 +59,15 @@ function create_each_block(ctx) {
5959
},
6060

6161
p(changed, ctx) {
62-
if ((changed.comments) && t2_value !== (t2_value = ctx.comment.author)) {
62+
if ((changed.comments) && t2_value !== (t2_value = ctx.comment.author + "")) {
6363
set_data(t2, t2_value);
6464
}
6565

66-
if ((changed.elapsed || changed.comments || changed.time) && t4_value !== (t4_value = ctx.elapsed(ctx.comment.time, ctx.time))) {
66+
if ((changed.elapsed || changed.comments || changed.time) && t4_value !== (t4_value = ctx.elapsed(ctx.comment.time, ctx.time) + "")) {
6767
set_data(t4, t4_value);
6868
}
6969

70-
if ((changed.comments) && raw_value !== (raw_value = ctx.comment.html)) {
70+
if ((changed.comments) && raw_value !== (raw_value = ctx.comment.html + "")) {
7171
html_tag.p(raw_value);
7272
}
7373
},

test/js/samples/each-block-keyed-animated/expected.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function get_each_context(ctx, list, i) {
2525

2626
// (19:0) {#each things as thing (thing.id)}
2727
function create_each_block(key_1, ctx) {
28-
var div, t_value = ctx.thing.name, t, rect, stop_animation = noop;
28+
var div, t_value = ctx.thing.name + "", t, rect, stop_animation = noop;
2929

3030
return {
3131
key: key_1,
@@ -44,7 +44,7 @@ function create_each_block(key_1, ctx) {
4444
},
4545

4646
p(changed, ctx) {
47-
if ((changed.things) && t_value !== (t_value = ctx.thing.name)) {
47+
if ((changed.things) && t_value !== (t_value = ctx.thing.name + "")) {
4848
set_data(t, t_value);
4949
}
5050
},

test/js/samples/each-block-keyed/expected.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function get_each_context(ctx, list, i) {
2323

2424
// (5:0) {#each things as thing (thing.id)}
2525
function create_each_block(key_1, ctx) {
26-
var div, t_value = ctx.thing.name, t;
26+
var div, t_value = ctx.thing.name + "", t;
2727

2828
return {
2929
key: key_1,
@@ -42,7 +42,7 @@ function create_each_block(key_1, ctx) {
4242
},
4343

4444
p(changed, ctx) {
45-
if ((changed.things) && t_value !== (t_value = ctx.thing.name)) {
45+
if ((changed.things) && t_value !== (t_value = ctx.thing.name + "")) {
4646
set_data(t, t_value);
4747
}
4848
},

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "svelte/internal";
1313

1414
function create_fragment(ctx) {
15-
var b, t_value = get_answer(), t;
15+
var b, t_value = get_answer() + "", t;
1616

1717
return {
1818
c() {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "svelte/internal";
1313

1414
function create_fragment(ctx) {
15-
var b, t_value = get_answer(), t;
15+
var b, t_value = get_answer() + "", t;
1616

1717
return {
1818
c() {

test/js/samples/instrumentation-script-x-equals-x/expected.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "svelte/internal";
1616

1717
function create_fragment(ctx) {
18-
var button, t1, p, t2, t3_value = ctx.things.length, t3, dispose;
18+
var button, t1, p, t2, t3_value = ctx.things.length + "", t3, dispose;
1919

2020
return {
2121
c() {
@@ -37,7 +37,7 @@ function create_fragment(ctx) {
3737
},
3838

3939
p(changed, ctx) {
40-
if ((changed.things) && t3_value !== (t3_value = ctx.things.length)) {
40+
if ((changed.things) && t3_value !== (t3_value = ctx.things.length + "")) {
4141
set_data(t3, t3_value);
4242
}
4343
},

test/js/samples/instrumentation-template-x-equals-x/expected.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "svelte/internal";
1616

1717
function create_fragment(ctx) {
18-
var button, t1, p, t2, t3_value = ctx.things.length, t3, dispose;
18+
var button, t1, p, t2, t3_value = ctx.things.length + "", t3, dispose;
1919

2020
return {
2121
c() {
@@ -37,7 +37,7 @@ function create_fragment(ctx) {
3737
},
3838

3939
p(changed, ctx) {
40-
if ((changed.things) && t3_value !== (t3_value = ctx.things.length)) {
40+
if ((changed.things) && t3_value !== (t3_value = ctx.things.length + "")) {
4141
set_data(t3, t3_value);
4242
}
4343
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
html: `1-1`,
3+
4+
test: ({ assert, component, target }) => {
5+
component.a.b[0] = 2;
6+
component.a = component.a;
7+
8+
assert.htmlEqual(target.innerHTML, `2-2`);
9+
}
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
export let a = { b: [1] };
3+
4+
const identity = x => x;
5+
</script>
6+
7+
{a.b}-{identity(a.b)}

0 commit comments

Comments
 (0)