Skip to content

Commit 5963a78

Browse files
authored
fix: duplicate setup when hoisting (#2916)
1 parent 280f4d3 commit 5963a78

File tree

16 files changed

+228
-1
lines changed

16 files changed

+228
-1
lines changed

.changeset/mean-pianos-march.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+
Fix duplicate setup identifier when hoisting
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"vars": {
3+
"props": {
4+
"$_": "r",
5+
"$init": "m",
6+
"$$get$hoisted_hoist": "o",
7+
"$$get$hoisted_hoistY": "t",
8+
"$$if_content__$hoisted_hoistY": "_",
9+
"$$if_content__hoistY": "e",
10+
"$$if_content__input_value": "n",
11+
"$$if_content__setup": "s",
12+
"$$if_content": "a",
13+
"$$if": "i",
14+
"$$show": "u",
15+
"$$hoistY": "c"
16+
}
17+
}
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Render
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Render
2+
```html
3+
<!---->
4+
<!---->
5+
<!---->
6+
<!---->
7+
```
8+
9+
# Mutations
10+
```
11+
INSERT #comment0, #comment1, #text, #comment2, #comment3
12+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// size: 158 (min) 86 (brotli)
2+
(_._resume("a2", _._hoist(0)),
3+
_._resume("a3", _._hoist(4)),
4+
_._resume(
5+
"a1",
6+
function ({
7+
_: {
8+
_: { 3: input_value },
9+
},
10+
}) {
11+
return () => input_value;
12+
},
13+
),
14+
_._resume("a0", function ({ 3: input_value }) {
15+
return () => input_value;
16+
}),
17+
init());
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export const $template = "<!><!><!>";
2+
export const $walks = /* over(1), replace, over(2) */"b%c";
3+
import * as _ from "@marko/runtime-tags/debug/dom";
4+
const $get$hoisted_hoist = _._resume("__tests__/template.marko_2_$hoisted_hoist2/hoist", _._hoist("hoist3"));
5+
const $if_content2__$hoisted_hoist = /* @__PURE__ */_._const("$hoisted_hoist2", ($scope, $hoisted_hoist2) => /* z */$hoisted_hoist2);
6+
const $if_content2__hoist = /* @__PURE__ */_._const("hoist3", ($scope, hoist3) => _._assert_hoist(hoist3));
7+
const $if_content2__input_value = /* @__PURE__ */_._closure_get("input_value", ($scope, input_value) => $if_content2__hoist($scope, $hoist2($scope)), $scope => $scope._._);
8+
const $if_content2__setup = $scope => {
9+
$if_content2__input_value($scope);
10+
$if_content2__$hoisted_hoist($scope, $get$hoisted_hoist($scope));
11+
};
12+
const $if_content2 = /* @__PURE__ */_._content_branch(0, 0, $if_content2__setup);
13+
const $if_content__if = /* @__PURE__ */_._if("#text/0", $if_content2);
14+
const $if_content__setup = $scope => {
15+
$if_content__input_value._($scope);
16+
/* y */2;
17+
$if_content__if($scope, 1 ? 0 : 1);
18+
};
19+
const $if_content__input_value = /* @__PURE__ */_._if_closure("input_value", "#text/0", 0, ($scope, input_value) => /* hoist2 */() => input_value);
20+
const $if_content = /* @__PURE__ */_._content_branch("<!><!><!>", /* over(1), replace, over(2) */"b%c", $if_content__setup);
21+
const $get$hoisted_hoist2 = _._resume("__tests__/template.marko_0_$hoisted_hoist/hoist", _._hoist("hoist1"));
22+
const $hoisted_hoist3 = /* @__PURE__ */_._const("$hoisted_hoist", ($scope, $hoisted_hoist) => /* x */$hoisted_hoist);
23+
const $hoist3 = /* @__PURE__ */_._const("hoist1", ($scope, hoist1) => _._assert_hoist(hoist1));
24+
const $input_value__closure = /* @__PURE__ */_._closure($if_content2__input_value);
25+
export const $input_value = /* @__PURE__ */_._const("input_value", ($scope, input_value) => {
26+
$hoist3($scope, $hoist($scope));
27+
$if_content__input_value($scope);
28+
$input_value__closure($scope);
29+
});
30+
const $if = /* @__PURE__ */_._if("#text/0", $if_content);
31+
export function $setup($scope) {
32+
$if($scope, 1 ? 0 : 1);
33+
$hoisted_hoist3($scope, $get$hoisted_hoist2($scope));
34+
}
35+
export const $input = /* @__PURE__ */_._const("input", ($scope, input) => $input_value($scope, input.value));
36+
function $hoist2({
37+
_: {
38+
_: {
39+
input_value
40+
}
41+
}
42+
}) {
43+
return () => input_value;
44+
}
45+
function $hoist({
46+
input_value
47+
}) {
48+
return () => input_value;
49+
}
50+
_._resume("__tests__/template.marko_2/hoist2", $hoist2);
51+
_._resume("__tests__/template.marko_0/hoist", $hoist);
52+
export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup, $input);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as _ from "@marko/runtime-tags/debug/html";
2+
export default _._template("__tests__/template.marko", input => {
3+
const $scope0_reason = _._scope_reason();
4+
const $scope0_id = _._scope_id();
5+
const $hoisted_hoist = _._hoist($scope0_id, "__tests__/template.marko_0_$hoisted_hoist/hoist");
6+
const $input_value__closures = new Set();
7+
const x = $hoisted_hoist;
8+
const hoist1 = _._resume(() => input.value, "__tests__/template.marko_0/hoist", $scope0_id);
9+
_._if(() => {
10+
if (1) {
11+
const $scope1_id = _._scope_id();
12+
const y = 2;
13+
const hoist2 = () => input.value;
14+
_._if(() => {
15+
if (1) {
16+
const $scope2_id = _._scope_id();
17+
const $hoisted_hoist2 = _._hoist($scope2_id, "__tests__/template.marko_2_$hoisted_hoist2/hoist");
18+
const z = $hoisted_hoist2;
19+
const hoist3 = _._resume(() => input.value, "__tests__/template.marko_2/hoist2", $scope2_id);
20+
_._subscribe($input_value__closures, _._scope($scope2_id, {
21+
hoist3,
22+
_: _._scope_with_id($scope1_id),
23+
"ClosureSignalIndex:input_value": _._serialize_if($scope0_reason, /* input.value */0) && 0
24+
}, "__tests__/template.marko", "8:4", {
25+
hoist3: "10:12"
26+
}));
27+
_._assert_hoist(hoist3);
28+
return 0;
29+
}
30+
}, $scope1_id, "#text/0", 1, 0, 0, 0, 1);
31+
_._scope($scope1_id, {
32+
_: _._scope_with_id($scope0_id)
33+
}, "__tests__/template.marko", "4:2");
34+
return 0;
35+
}
36+
}, $scope0_id, "#text/0", 1, 0, 0);
37+
_._scope($scope0_id, {
38+
input_value: input.value,
39+
hoist1,
40+
"ClosureScopes:input_value": _._serialize_if($scope0_reason, /* input.value */0) && $input_value__closures
41+
}, "__tests__/template.marko", 0, {
42+
input_value: ["input.value"],
43+
hoist1: "2:8"
44+
});
45+
_._assert_hoist(hoist1);
46+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Render
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Render
2+
```html
3+
<html>
4+
<head>
5+
<script>
6+
WALKER_RUNTIME("M")("_");
7+
M._.r = [_ =&gt; (_.d = [0, _.c = {
8+
"ConditionalScope:#text/0": _.b = {
9+
"ConditionalScope:#text/0": _.a = {}
10+
}
11+
}, _.b, _.a], _.a._ = _.b, _.b._ = _.c, _.a.hoist3 = _._[
12+
"__tests__/template.marko_2/hoist2"
13+
](_.a), _.c.hoist1 = _._[
14+
"__tests__/template.marko_0/hoist"
15+
](_.c), (_.e = new Set).add(_.a), _.d)];
16+
M._.w()
17+
</script>
18+
</head>
19+
<body />
20+
</html>
21+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Render End

0 commit comments

Comments
 (0)