Skip to content

Commit aeec614

Browse files
committed
fix: exclude change handlers from rest bindings
1 parent 15efc9e commit aeec614

File tree

9 files changed

+67
-87
lines changed

9 files changed

+67
-87
lines changed

.changeset/slimy-camels-exist.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+
Exclude change handlers from rest bindings

packages/runtime-tags/src/__tests__/fixtures/destructure-input-with-assignment/__snapshots__/dom.expected/tags/child.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ export const $walks = /* get, over(1) */" b";
33
export const $setup = () => {};
44
import * as _ from "@marko/runtime-tags/debug/dom";
55
const $valueChange2__script = _._script("__tests__/tags/child.marko_0_$valueChange", $scope => $scope.$valueChange(2));
6-
const $valueChange2 = /* @__PURE__ */_._const("$valueChange", $valueChange2__script);
6+
export const $valueChange2 = /* @__PURE__ */_._const("$valueChange", $valueChange2__script);
77
const $rest__script = _._script("__tests__/tags/child.marko_0_rest", $scope => _._attrs_script($scope, "#div/0"));
8-
const $rest = /* @__PURE__ */_._const("rest", $scope => {
8+
export const $rest = /* @__PURE__ */_._const("rest", $scope => {
99
_._attrs_content($scope, "#div/0", $scope.rest);
1010
$rest__script($scope);
1111
});
Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
1-
// size: 431 (min) 243 (brotli)
2-
const $valueChange2__script = _._script("a0", ($scope) => $scope.d(2)),
3-
$valueChange2 = _._const(3, $valueChange2__script),
4-
$rest__script = _._script("a1", ($scope) => _._attrs_script($scope, "a")),
5-
$rest = _._const(4, ($scope) => {
6-
(_._attrs_content($scope, "a", $scope.e), $rest__script($scope));
7-
}),
8-
$child_content__value = _._closure_get(1, ($scope) =>
1+
// size: 243 (min) 153 (brotli)
2+
(_._script("a0", ($scope) => $scope.d(2)),
3+
_._script("a1", ($scope) => _._attrs_script($scope, "a")));
4+
const $child_content__value = _._closure_get(1, ($scope) =>
95
_._text($scope.a, $scope._.b),
106
),
11-
$child_content__setup = $child_content__value,
12-
$child_content = _._content_resume("b1", " ", " b", $child_content__setup),
13-
$value__closure = _._closure($child_content__value),
14-
$value = _._let(1, ($scope) => {
15-
((($scope, input) => {
16-
((({ value: value, ...rest }) => {
17-
$rest($scope, rest);
18-
})(input),
19-
$valueChange2($scope, input.valueChange));
20-
})($scope.a, {
21-
value: $scope.b,
22-
valueChange: $valueChange($scope),
23-
content: $child_content($scope),
24-
}),
25-
$value__closure($scope));
26-
});
27-
function $valueChange($scope) {
7+
$child_content__setup = $child_content__value;
8+
_._content_resume("b1", " ", " b", $child_content__setup);
9+
const $value__closure = _._closure($child_content__value),
10+
$value = _._let(1, $value__closure);
11+
(_._resume("b0", function ($scope) {
2812
return (_new_value) => {
2913
$value($scope, _new_value);
3014
};
31-
}
32-
(_._resume("b0", $valueChange), init());
15+
}),
16+
init());

packages/runtime-tags/src/__tests__/fixtures/destructure-input-with-assignment/__snapshots__/dom.expected/template.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
export const $template = _child_template;
22
export const $walks = /* <child> */`/${_child_walks}&`;
33
import * as _ from "@marko/runtime-tags/debug/dom";
4-
import { $setup as _child, $input as _child_input, $template as _child_template, $walks as _child_walks } from "./tags/child.marko";
4+
import { $setup as _child, $valueChange2 as _child_input_valueChange, $rest as _child_input_$rest, $template as _child_template, $walks as _child_walks } from "./tags/child.marko";
55
const $child_content__value = /* @__PURE__ */_._closure_get("value", $scope => _._text($scope["#text/0"], $scope._.value));
66
const $child_content__setup = $child_content__value;
77
const $child_content = _._content_resume("__tests__/template.marko_1_content", " ", /* get, over(1) */" b", $child_content__setup);
88
const $value__closure = /* @__PURE__ */_._closure($child_content__value);
9-
const $value = /* @__PURE__ */_._let("value/1", $scope => {
10-
_child_input($scope["#childScope/0"], {
11-
value: $scope.value,
12-
valueChange: $valueChange($scope),
13-
content: $child_content($scope)
14-
});
15-
$value__closure($scope);
16-
});
9+
const $value = /* @__PURE__ */_._let("value/1", $value__closure);
1710
export function $setup($scope) {
1811
_child($scope["#childScope/0"]);
12+
_child_input_valueChange($scope["#childScope/0"], $valueChange($scope));
13+
_child_input_$rest($scope["#childScope/0"], {
14+
content: $child_content($scope)
15+
});
1916
$value($scope, 1);
2017
}
2118
function $valueChange($scope) {

packages/runtime-tags/src/__tests__/fixtures/destructure-input-with-assignment/__snapshots__/html.expected/template.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export default _._template("__tests__/template.marko", input => {
55
const $scope0_id = _._scope_id();
66
const $value__closures = new Set();
77
let value = 1;
8-
const $childScope = _._peek_scope_id();
98
_child({
10-
value: value,
119
valueChange: _._resume(_new_value => {
1210
value = _new_value;
1311
}, "__tests__/template.marko_0/valueChange", $scope0_id),
@@ -24,8 +22,7 @@ export default _._template("__tests__/template.marko", input => {
2422
});
2523
_._scope($scope0_id, {
2624
value,
27-
"ClosureScopes:value": $value__closures,
28-
"#childScope/0": _._existing_scope($childScope)
25+
"ClosureScopes:value": $value__closures
2926
}, "__tests__/template.marko", 0, {
3027
value: "1:5"
3128
});

packages/runtime-tags/src/__tests__/fixtures/destructure-input-with-assignment/__snapshots__/resume.expected.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
WALKER_RUNTIME("M")("_");
1313
M._.r = [_ =&gt; (_.e = [0, _.a = {
1414
value: 1,
15-
"ClosureScopes:value": _.f = new Set,
16-
"#childScope/0": _.c = {
17-
"BranchScopes:#div/0": _.b = {
18-
"ClosureSignalIndex:value": 0
19-
},
20-
"ConditionalRenderer:#div/0": "__tests__/template.marko_1_content",
21-
rest: _.d = {}
22-
}
23-
}, _.c, _.b], _.b._ = _.a, _.c.$valueChange = _._[
15+
"ClosureScopes:value": _.f = new Set
16+
}, _.b = {
17+
"BranchScopes:#div/0": _.d = {
18+
_: _.a,
19+
"ClosureSignalIndex:value": 0
20+
},
21+
"ConditionalRenderer:#div/0": "__tests__/template.marko_1_content",
22+
rest: _.c = {}
23+
}, _.d], _.b.$valueChange = _._[
2424
"__tests__/template.marko_0/valueChange"
25-
](_.a), _.d.content = _._[
25+
](_.a), _.c.content = _._[
2626
"__tests__/template.marko_1_content"
27-
](_.a), (_.f).add(_.b), _.e),
27+
](_.a), (_.f).add(_.d), _.e),
2828
"__tests__/tags/child.marko_0_rest 2 __tests__/tags/child.marko_0_$valueChange 2"
2929
];
3030
M._.w()
@@ -48,19 +48,19 @@
4848
WALKER_RUNTIME("M")("_");
4949
M._.r = [_ =&gt; (_.e = [0, _.a = {
5050
value: 1,
51-
"ClosureScopes:value": _.f = new Set,
52-
"#childScope/0": _.c = {
53-
"BranchScopes:#div/0": _.b = {
54-
"ClosureSignalIndex:value": 0
55-
},
56-
"ConditionalRenderer:#div/0": "__tests__/template.marko_1_content",
57-
rest: _.d = {}
58-
}
59-
}, _.c, _.b], _.b._ = _.a, _.c.$valueChange = _._[
51+
"ClosureScopes:value": _.f = new Set
52+
}, _.b = {
53+
"BranchScopes:#div/0": _.d = {
54+
_: _.a,
55+
"ClosureSignalIndex:value": 0
56+
},
57+
"ConditionalRenderer:#div/0": "__tests__/template.marko_1_content",
58+
rest: _.c = {}
59+
}, _.d], _.b.$valueChange = _._[
6060
"__tests__/template.marko_0/valueChange"
61-
](_.a), _.d.content = _._[
61+
](_.a), _.c.content = _._[
6262
"__tests__/template.marko_1_content"
63-
](_.a), (_.f).add(_.b), _.e),
63+
](_.a), (_.f).add(_.d), _.e),
6464
"__tests__/tags/child.marko_0_rest 2 __tests__/tags/child.marko_0_$valueChange 2"
6565
];
6666
M._.w()

packages/runtime-tags/src/__tests__/fixtures/destructure-input-with-assignment/__snapshots__/ssr.expected.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Write
22
```html
3-
<div>1<!--M_*3 #text/0--></div><!--M_*2 #div/0--><script>WALKER_RUNTIME("M")("_");M._.r=[_=>(_.e=[0,_.a={value:1,"ClosureScopes:value":_.f=new Set,"#childScope/0":_.c={"BranchScopes:#div/0":_.b={"ClosureSignalIndex:value":0},"ConditionalRenderer:#div/0":"__tests__/template.marko_1_content",rest:_.d={}}},_.c,_.b],_.b._=_.a,_.c.$valueChange=_._["__tests__/template.marko_0/valueChange"](_.a),_.d.content=_._["__tests__/template.marko_1_content"](_.a),(_.f).add(_.b),_.e),"__tests__/tags/child.marko_0_rest 2 __tests__/tags/child.marko_0_$valueChange 2"];M._.w()</script>
3+
<div>1<!--M_*3 #text/0--></div><!--M_*2 #div/0--><script>WALKER_RUNTIME("M")("_");M._.r=[_=>(_.e=[0,_.a={value:1,"ClosureScopes:value":_.f=new Set},_.b={"BranchScopes:#div/0":_.d={_:_.a,"ClosureSignalIndex:value":0},"ConditionalRenderer:#div/0":"__tests__/template.marko_1_content",rest:_.c={}},_.d],_.b.$valueChange=_._["__tests__/template.marko_0/valueChange"](_.a),_.c.content=_._["__tests__/template.marko_1_content"](_.a),(_.f).add(_.d),_.e),"__tests__/tags/child.marko_0_rest 2 __tests__/tags/child.marko_0_$valueChange 2"];M._.w()</script>
44
```
55

66
# Render End
@@ -17,19 +17,19 @@
1717
WALKER_RUNTIME("M")("_");
1818
M._.r = [_ =&gt; (_.e = [0, _.a = {
1919
value: 1,
20-
"ClosureScopes:value": _.f = new Set,
21-
"#childScope/0": _.c = {
22-
"BranchScopes:#div/0": _.b = {
23-
"ClosureSignalIndex:value": 0
24-
},
25-
"ConditionalRenderer:#div/0": "__tests__/template.marko_1_content",
26-
rest: _.d = {}
27-
}
28-
}, _.c, _.b], _.b._ = _.a, _.c.$valueChange = _._[
20+
"ClosureScopes:value": _.f = new Set
21+
}, _.b = {
22+
"BranchScopes:#div/0": _.d = {
23+
_: _.a,
24+
"ClosureSignalIndex:value": 0
25+
},
26+
"ConditionalRenderer:#div/0": "__tests__/template.marko_1_content",
27+
rest: _.c = {}
28+
}, _.d], _.b.$valueChange = _._[
2929
"__tests__/template.marko_0/valueChange"
30-
](_.a), _.d.content = _._[
30+
](_.a), _.c.content = _._[
3131
"__tests__/template.marko_1_content"
32-
](_.a), (_.f).add(_.b), _.e),
32+
](_.a), (_.f).add(_.d), _.e),
3333
"__tests__/tags/child.marko_0_rest 2 __tests__/tags/child.marko_0_$valueChange 2"
3434
];
3535
M._.w()

packages/runtime-tags/src/translator/util/references.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,13 @@ function createBindingsAndTrackReferences(
630630
key,
631631
undefined,
632632
);
633+
634+
if (hasRest && prop.value.extra?.binding?.assignmentSections) {
635+
excludeProperties = propsUtil.add(
636+
excludeProperties,
637+
`${key}Change`,
638+
);
639+
}
633640
}
634641
}
635642
}

packages/runtime-tags/src/translator/util/translate-var.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { forEachIdentifierPath } from "./for-each-identifier";
44
import { generateUidIdentifier } from "./generate-uid";
55
import { getDeclaredBindingExpression } from "./get-defined-binding-expression";
66
import { toArray } from "./optional";
7-
import { getCanonicalBinding, propsUtil } from "./references";
7+
import { getCanonicalBinding } from "./references";
88
import { getOrCreateSection } from "./sections";
99
import { getSerializeReason } from "./serialize-reasons";
1010
import { toPropertyName } from "./to-property-name";
@@ -49,16 +49,6 @@ export default function translateVar(
4949
t.identifier(changeBinding.name),
5050
),
5151
);
52-
const lastProperty = pattern.get("properties").at(-1);
53-
if (lastProperty?.node.type === "RestElement") {
54-
const restBinding = lastProperty.node.argument.extra?.binding;
55-
if (restBinding) {
56-
restBinding.excludeProperties = propsUtil.add(
57-
restBinding.excludeProperties,
58-
changeName,
59-
);
60-
}
61-
}
6252
}
6353
}
6454
}

0 commit comments

Comments
 (0)