Skip to content

Commit 9cba851

Browse files
committed
fix: prevent tag arguments normalized as input
1 parent 40b332e commit 9cba851

File tree

27 files changed

+257
-55
lines changed

27 files changed

+257
-55
lines changed

.changeset/kind-rockets-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@marko/runtime-tags": patch
3+
---
4+
5+
Ensure when tag arguments are used for a dynamic tag with a single argument that it does not become treated the same as normal input. The normal input runtime will add the `content` as well as default to an empty object which was breaking some usages of tag arguments.

packages/runtime-tags/src/__tests__/fixtures/basic-nested-params/__snapshots__/dom.expected/tags/child.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const _expr_content_value = /* @__PURE__ */_$.intersection(5, _scope => {
77
content,
88
value
99
} = _scope;
10-
_dynamicTag(_scope, content, () => value);
10+
_dynamicTag(_scope, content, () => [value]);
1111
});
12-
const _dynamicTag = /* @__PURE__ */_$.dynamicTag("#text/0");
12+
const _dynamicTag = /* @__PURE__ */_$.dynamicTag("#text/0", 0, 0, 1);
1313
export const _value = /* @__PURE__ */_$.value("value", _expr_content_value);
1414
export const _content = /* @__PURE__ */_$.value("content", _expr_content_value);
1515
export const _input = /* @__PURE__ */_$.value("input", (_scope, input) => {

packages/runtime-tags/src/__tests__/fixtures/basic-nested-params/__snapshots__/dom.expected/template.hydrate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// size: 620 (min) 309 (brotli)
1+
// size: 629 (min) 314 (brotli)
22
const _expr_content_value = _$.intersection(5, (_scope) => {
33
const { 3: content, 4: value } = _scope;
4-
_dynamicTag(_scope, content, () => value);
4+
_dynamicTag(_scope, content, () => [value]);
55
}),
6-
_dynamicTag = _$.dynamicTag(),
6+
_dynamicTag = _$.dynamicTag(0, 0, 0, 1),
77
_value = _$.value(4, _expr_content_value),
88
_content = _$.value(3, _expr_content_value),
99
_inner$child_content = _$.value(3, (_scope, inner) =>

packages/runtime-tags/src/__tests__/fixtures/basic-nested-params/__snapshots__/html.expected/tags/child.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default _$.createTemplate("__tests__/tags/child.marko", input => {
66
value
77
} = input;
88
_$.write("<div>");
9-
_$.dynamicTag(_scope0_id, "#text/0", content, value, 0, 0, 1);
9+
_$.dynamicTag(_scope0_id, "#text/0", content, [value], 0, 1, 1);
1010
_$.write("</div>");
1111
_$.writeScope(_scope0_id, {
1212
content,

packages/runtime-tags/src/__tests__/fixtures/custom-tag-parameters-from-single-arg/__snapshots__/dom.expected/tags/custom-tag.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const _expr_input_content_x = /* @__PURE__ */_$.intersection(7, _scope => {
66
input_content,
77
x
88
} = _scope;
9-
_dynamicTag(_scope, input_content, () => x);
9+
_dynamicTag(_scope, input_content, () => [x]);
1010
});
11-
const _dynamicTag = /* @__PURE__ */_$.dynamicTag("#text/2");
11+
const _dynamicTag = /* @__PURE__ */_$.dynamicTag("#text/2", 0, 0, 1);
1212
const _x_effect = _$.effect("__tests__/tags/custom-tag.marko_0_x", (_scope, {
1313
x
1414
}) => _$.on(_scope["#button/0"], "click", function () {

packages/runtime-tags/src/__tests__/fixtures/custom-tag-parameters-from-single-arg/__snapshots__/dom.expected/template.hydrate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// size: 335 (min) 225 (brotli)
1+
// size: 343 (min) 219 (brotli)
22
const _expr_input_content_x = _$.intersection(7, (_scope) => {
33
const { 5: input_content, 6: x } = _scope;
4-
_dynamicTag(_scope, input_content, () => x);
4+
_dynamicTag(_scope, input_content, () => [x]);
55
}),
6-
_dynamicTag = _$.dynamicTag(2),
6+
_dynamicTag = _$.dynamicTag(2, 0, 0, 1),
77
_x_effect = _$.effect("a0", (_scope, { 6: x }) =>
88
_$.on(_scope[0], "click", function () {
99
_x(_scope, x + 1);

packages/runtime-tags/src/__tests__/fixtures/custom-tag-parameters-from-single-arg/__snapshots__/html.expected/tags/custom-tag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default _$.createTemplate("__tests__/tags/custom-tag.marko", input => {
33
const _scope0_id = _$.nextScopeId();
44
let x = 1;
55
_$.write(`<button class=inc>${_$.escapeXML(x)}${_$.markResumeNode(_scope0_id, "#text/1")}</button>${_$.markResumeNode(_scope0_id, "#button/0")}`);
6-
_$.dynamicTag(_scope0_id, "#text/2", input.content, x, 0, 0, 1);
6+
_$.dynamicTag(_scope0_id, "#text/2", input.content, [x], 0, 1, 1);
77
_$.writeEffect(_scope0_id, "__tests__/tags/custom-tag.marko_0_x");
88
_$.writeScope(_scope0_id, {
99
input_content: input.content,

packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-args-tag-var/__snapshots__/dom.expected/template.hydrate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// size: 366 (min) 221 (brotli)
1+
// size: 370 (min) 229 (brotli)
22
const _setup = () => {},
33
_input = _$.value(2, (_scope, input) => {
44
_$.data(_scope[0], input), _$.tagVarSignal(_scope, input);
55
});
66
const tags = [
77
_$.createTemplate("a", "<div>Child: <!></div>", "Db%l", _setup, _input),
88
],
9-
_dynamicTag = _$.dynamicTag(2, 0, () => _y),
9+
_dynamicTag = _$.dynamicTag(2, 0, () => _y, 1),
1010
_y = _$.registerBoundSignal(
1111
"b0",
1212
_$.value(6, (_scope, y) => _$.data(_scope[4], y)),
@@ -18,7 +18,7 @@ const tags = [
1818
),
1919
_x = _$.state(5, (_scope, x) => {
2020
_$.data(_scope[1], x),
21-
_dynamicTag(_scope, tags[0], () => x),
21+
_dynamicTag(_scope, tags[0], () => [x]),
2222
_x_effect(_scope);
2323
});
2424
init();

packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-args-tag-var/__snapshots__/dom.expected/template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const _walks = /* get, next(1), over(1), replace, out(1), dynamicTagWithV
33
import customTag from './tags/custom-tag.marko';
44
const tags = [customTag];
55
import * as _$ from "@marko/runtime-tags/debug/dom";
6-
const _dynamicTag = /* @__PURE__ */_$.dynamicTag("#text/2", 0, () => _y);
6+
const _dynamicTag = /* @__PURE__ */_$.dynamicTag("#text/2", 0, () => _y, 1);
77
const _y = _$.registerBoundSignal("__tests__/template.marko_0_y/var", /* @__PURE__ */_$.value("y", (_scope, y) => _$.data(_scope["#text/4"], y)));
88
const _x_effect = _$.effect("__tests__/template.marko_0_x", (_scope, {
99
x
@@ -12,7 +12,7 @@ const _x_effect = _$.effect("__tests__/template.marko_0_x", (_scope, {
1212
}));
1313
const _x = /* @__PURE__ */_$.state("x/5", (_scope, x) => {
1414
_$.data(_scope["#text/1"], x);
15-
_dynamicTag(_scope, tags[0], () => x);
15+
_dynamicTag(_scope, tags[0], () => [x]);
1616
_x_effect(_scope);
1717
});
1818
export function _setup(_scope) {

packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-args-tag-var/__snapshots__/html.expected/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default _$.createTemplate("__tests__/template.marko", input => {
66
let x = 1;
77
_$.write(`<button>Count: <!>${_$.escapeXML(x)}${_$.markResumeNode(_scope0_id, "#text/1")}</button>${_$.markResumeNode(_scope0_id, "#button/0")}`);
88
const _dynamicScope = _$.peekNextScope();
9-
const y = _$.dynamicTag(_scope0_id, "#text/2", tags[0], x, 0, 0, 1);
9+
const y = _$.dynamicTag(_scope0_id, "#text/2", tags[0], [x], 0, 1, 1);
1010
_$.setTagVar(_scope0_id, "#scopeOffset/3", _dynamicScope, "__tests__/template.marko_0_y/var");
1111
_$.write(`<div>Parent: <!>${_$.escapeXML(y)}${_$.markResumeNode(_scope0_id, "#text/4")}</div>`);
1212
_$.writeEffect(_scope0_id, "__tests__/template.marko_0_x");

packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-args/__snapshots__/csr-sanitized.expected.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
<div>
77
1
88
</div>
9+
<div>
10+
false
11+
</div>
12+
<div>
13+
true
14+
</div>
15+
<div>
16+
"spread1"
17+
</div>
918
```
1019

1120

@@ -20,6 +29,15 @@ container.querySelector("button").click();
2029
<div>
2130
2
2231
</div>
32+
<div>
33+
false
34+
</div>
35+
<div>
36+
true
37+
</div>
38+
<div>
39+
"spread1"
40+
</div>
2341
```
2442

2543

@@ -34,6 +52,15 @@ container.querySelector("button").click();
3452
<div>
3553
3
3654
</div>
55+
<div>
56+
false
57+
</div>
58+
<div>
59+
true
60+
</div>
61+
<div>
62+
"spread1"
63+
</div>
3764
```
3865

3966

@@ -48,4 +75,13 @@ container.querySelector("button").click();
4875
<div>
4976
4
5077
</div>
78+
<div>
79+
false
80+
</div>
81+
<div>
82+
true
83+
</div>
84+
<div>
85+
"spread1"
86+
</div>
5187
```

packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-args/__snapshots__/csr.expected.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66
<div>
77
1
88
</div>
9+
<div>
10+
false
11+
</div>
12+
<div>
13+
true
14+
</div>
15+
<div>
16+
"spread1"
17+
</div>
918
<!---->
1019
```
1120

1221
# Mutations
1322
```
14-
INSERT button, div, #comment
23+
INSERT button, div0, div1, div2, div3, #comment
1524
```
1625

1726
# Render
@@ -25,13 +34,22 @@ container.querySelector("button").click();
2534
<div>
2635
2
2736
</div>
37+
<div>
38+
false
39+
</div>
40+
<div>
41+
true
42+
</div>
43+
<div>
44+
"spread1"
45+
</div>
2846
<!---->
2947
```
3048

3149
# Mutations
3250
```
3351
UPDATE button/#text1 "1" => "2"
34-
UPDATE div/#text "1" => "2"
52+
UPDATE div0/#text "1" => "2"
3553
```
3654

3755
# Render
@@ -45,13 +63,22 @@ container.querySelector("button").click();
4563
<div>
4664
3
4765
</div>
66+
<div>
67+
false
68+
</div>
69+
<div>
70+
true
71+
</div>
72+
<div>
73+
"spread1"
74+
</div>
4875
<!---->
4976
```
5077

5178
# Mutations
5279
```
5380
UPDATE button/#text1 "2" => "3"
54-
UPDATE div/#text "2" => "3"
81+
UPDATE div0/#text "2" => "3"
5582
```
5683

5784
# Render
@@ -65,11 +92,20 @@ container.querySelector("button").click();
6592
<div>
6693
4
6794
</div>
95+
<div>
96+
false
97+
</div>
98+
<div>
99+
true
100+
</div>
101+
<div>
102+
"spread1"
103+
</div>
68104
<!---->
69105
```
70106

71107
# Mutations
72108
```
73109
UPDATE button/#text1 "3" => "4"
74-
UPDATE div/#text "3" => "4"
110+
UPDATE div0/#text "3" => "4"
75111
```

packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-args/__snapshots__/dom.expected/tags/custom-tag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export const _template = "<div> </div>";
22
export const _walks = /* next(1), get, out(1) */"D l";
33
export const _setup = () => {};
44
import * as _$ from "@marko/runtime-tags/debug/dom";
5-
export const _input = /* @__PURE__ */_$.value("input", (_scope, input) => _$.data(_scope["#text/0"], input));
5+
export const _input = /* @__PURE__ */_$.value("input", (_scope, input) => _$.data(_scope["#text/0"], JSON.stringify(input)));
66
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/custom-tag.marko", _template, _walks, _setup, _input);

packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-args/__snapshots__/dom.expected/template.hydrate.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
// size: 273 (min) 187 (brotli)
1+
// size: 289 (min) 204 (brotli)
22
const _setup = () => {},
3-
_input = _$.value(2, (_scope, input) => _$.data(_scope[0], input));
3+
_input = _$.value(2, (_scope, input) =>
4+
_$.data(_scope[0], JSON.stringify(input)),
5+
);
46
const tags = [_$.createTemplate("a", "<div> </div>", "D l", _setup, _input)],
57
_dynamicTag = _$.dynamicTag(2, 0, 0, 1),
6-
_x_effect = _$.effect("b0", (_scope, { 3: x }) =>
8+
_x_effect = _$.effect("b0", (_scope, { 6: x }) =>
79
_$.on(_scope[0], "click", function () {
810
_x(_scope, x + 1);
911
}),
1012
),
11-
_x = _$.state(3, (_scope, x) => {
13+
_x = _$.state(6, (_scope, x) => {
1214
_$.data(_scope[1], x),
1315
_dynamicTag(_scope, tags[0], () => [x, "foo"]),
1416
_x_effect(_scope);
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
export const _template = "<button>Count: <!></button><!><!>";
2-
export const _walks = /* get, next(1), over(1), replace, out(1), replace, over(1) */" Db%l%bD";
1+
export const _template = "<button>Count: <!></button><!><!><!><!><!>";
2+
export const _walks = /* get, next(1), over(1), replace, out(1), replace, over(1), replace, over(1), replace, over(1), replace, over(1) */" Db%l%b%b%b%bD";
33
import customTag from './tags/custom-tag.marko';
44
const tags = [customTag];
55
import * as _$ from "@marko/runtime-tags/debug/dom";
6+
const _dynamicTag4 = /* @__PURE__ */_$.dynamicTag("#text/5", 0, 0, 1);
7+
const _dynamicTag3 = /* @__PURE__ */_$.dynamicTag("#text/4", 0, 0, 1);
8+
const _dynamicTag2 = /* @__PURE__ */_$.dynamicTag("#text/3", 0, 0, 1);
69
const _dynamicTag = /* @__PURE__ */_$.dynamicTag("#text/2", 0, 0, 1);
710
const _x_effect = _$.effect("__tests__/template.marko_0_x", (_scope, {
811
x
912
}) => _$.on(_scope["#button/0"], "click", function () {
1013
_x(_scope, x + 1), x;
1114
}));
12-
const _x = /* @__PURE__ */_$.state("x/3", (_scope, x) => {
15+
const _x = /* @__PURE__ */_$.state("x/6", (_scope, x) => {
1316
_$.data(_scope["#text/1"], x);
1417
_dynamicTag(_scope, tags[0], () => [x, 'foo']);
1518
_x_effect(_scope);
1619
});
1720
export function _setup(_scope) {
1821
_x(_scope, 1);
22+
_dynamicTag2(_scope, tags[0], () => [false]);
23+
_dynamicTag3(_scope, tags[0], () => [true]);
24+
_dynamicTag4(_scope, tags[0], () => [...["spread1", "spread2"]]);
1925
}
2026
export default /* @__PURE__ */_$.createTemplate("__tests__/template.marko", _template, _walks, _setup);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as _$ from "@marko/runtime-tags/debug/html";
22
export default _$.createTemplate("__tests__/tags/custom-tag.marko", input => {
33
const _scope0_id = _$.nextScopeId();
4-
_$.write(`<div>${_$.escapeXML(input)}${_$.markResumeNode(_scope0_id, "#text/0")}</div>`);
4+
_$.write(`<div>${_$.escapeXML(JSON.stringify(input))}${_$.markResumeNode(_scope0_id, "#text/0")}</div>`);
55
});

packages/runtime-tags/src/__tests__/fixtures/dynamic-tag-args/__snapshots__/html.expected/template.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export default _$.createTemplate("__tests__/template.marko", input => {
66
let x = 1;
77
_$.write(`<button>Count: <!>${_$.escapeXML(x)}${_$.markResumeNode(_scope0_id, "#text/1")}</button>${_$.markResumeNode(_scope0_id, "#button/0")}`);
88
_$.dynamicTag(_scope0_id, "#text/2", tags[0], [x, 'foo'], 0, 1, 1);
9+
_$.dynamicTag(_scope0_id, "#text/3", tags[0], [false], 0, 1);
10+
_$.dynamicTag(_scope0_id, "#text/4", tags[0], [true], 0, 1);
11+
_$.dynamicTag(_scope0_id, "#text/5", tags[0], [...["spread1", "spread2"]], 0, 1);
912
_$.writeEffect(_scope0_id, "__tests__/template.marko_0_x");
1013
_$.writeScope(_scope0_id, {
1114
x

0 commit comments

Comments
 (0)