Skip to content

Commit 90f9738

Browse files
committed
fix: support assignment patterns via pre-analyze
1 parent 594574a commit 90f9738

File tree

31 files changed

+1756
-45
lines changed

31 files changed

+1756
-45
lines changed

.changeset/eight-badgers-join.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 support for assignment patterns.

packages/runtime-tags/src/__tests__/fixtures/function-tag-var-default-registration/__snapshots__/csr-sanitized.expected.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ container.querySelector("button").click();
1212
```
1313
```html
1414
<button>
15-
before
15+
after
1616
</button>
1717
```

packages/runtime-tags/src/__tests__/fixtures/function-tag-var-default-registration/__snapshots__/csr.expected.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ container.querySelector("button").click();
1616
```
1717
```html
1818
<button>
19-
before
19+
after
2020
</button>
2121
```
22+
23+
# Mutations
24+
```
25+
REMOVE #text in button
26+
INSERT button/#text
27+
```
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
export const $template = "<button>before</button>";
22
export const $walks = /* get, over(1) */" b";
3-
function updateText(ev) {
4-
ev.target.textContent = "after";
5-
}
3+
const updateText = $updateText;
64
import * as _ from "@marko/runtime-tags/debug/dom";
7-
const $pattern2 = /* @__PURE__ */_._const("$pattern", ($scope, $pattern) => $onClick($scope, $pattern.onClick));
8-
const $onClick__script = _._script("__tests__/template.marko_0_onClick", ($scope, {
5+
const $pattern2 = /* @__PURE__ */_._const("$pattern", ($scope, $pattern) => $onClick2($scope, $pattern.onClick));
6+
const $onClick3__script = _._script("__tests__/template.marko_0_onClick", ($scope, {
97
onClick
108
}) => _._on($scope["#button/0"], "click", onClick));
11-
const $onClick = /* @__PURE__ */_._const("onClick", $onClick__script);
9+
const $onClick3 = /* @__PURE__ */_._const("onClick", $onClick3__script);
10+
const $onClick2 = /* @__PURE__ */_._const("$onClick", ($scope, $onClick) => $onClick3($scope, void 0 !== $onClick ? $onClick : updateText));
1211
export function $setup($scope) {
1312
$pattern2($scope, {});
1413
}
14+
function $updateText(ev) {
15+
ev.target.textContent = "after";
16+
}
17+
_._resume("__tests__/template.marko_0/updateText", $updateText);
1518
export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup);

packages/runtime-tags/src/__tests__/fixtures/function-tag-var-default-registration/__snapshots__/html.expected/template.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
function updateText(ev) {
22
ev.target.textContent = "after";
33
}
4+
_._resume(updateText, "__tests__/template.marko_0/updateText");
45
import * as _ from "@marko/runtime-tags/debug/html";
56
export default _._template("__tests__/template.marko", input => {
67
const $scope0_id = _._scope_id();
78
const {
8-
onClick = updateText
9+
onClick: $onClick
910
} = {};
11+
const onClick = void 0 !== $onClick ? $onClick : updateText;
1012
_._html(`<button>before</button>${_._el_resume($scope0_id, "#button/0")}`);
1113
_._script($scope0_id, "__tests__/template.marko_0_onClick");
1214
_._scope($scope0_id, {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"vars": {
3+
"props": {}
4+
}
5+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Render
2+
```html
3+
<div
4+
class="a"
5+
>
6+
0 object
7+
</div>
8+
<div
9+
class="a"
10+
>
11+
1 object
12+
</div>
13+
<div
14+
class="a"
15+
>
16+
2 undefined
17+
</div>
18+
<div
19+
class="b"
20+
>
21+
0 object
22+
</div>
23+
<div
24+
class="b"
25+
>
26+
1 object
27+
</div>
28+
<div
29+
class="b"
30+
>
31+
2 undefined
32+
</div>
33+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Render
2+
```html
3+
<!---->
4+
<div
5+
class="a"
6+
>
7+
0 object
8+
</div>
9+
<div
10+
class="a"
11+
>
12+
1 object
13+
</div>
14+
<div
15+
class="a"
16+
>
17+
2 undefined
18+
</div>
19+
<div
20+
class="b"
21+
>
22+
0 object
23+
</div>
24+
<div
25+
class="b"
26+
>
27+
1 object
28+
</div>
29+
<div
30+
class="b"
31+
>
32+
2 undefined
33+
</div>
34+
<!---->
35+
```
36+
37+
# Mutations
38+
```
39+
INSERT #comment0, div0, div1, div2, div3, div4, div5, #comment1
40+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// size: 0
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const $ChildB_content__walks = /* next(1), replace, over(2), replace, out(1) */"D%c%l",
2+
$ChildB_content__template = "<div class=b><!> <!></div>",
3+
$ChildA_content__walks = /* next(1), replace, over(2), replace, out(1) */"D%c%l",
4+
$ChildA_content__template = "<div class=a><!> <!></div>";
5+
export const $template = `<!>${$ChildA_content__template}${$ChildA_content__template}${$ChildA_content__template}${$ChildB_content__template}${$ChildB_content__template}${$ChildB_content__template}<!>`;
6+
export const $walks = /* over(1), beginChild, $ChildA_content__walks, endChild, beginChild, $ChildA_content__walks, endChild, beginChild, $ChildA_content__walks, endChild, beginChild, $ChildB_content__walks, endChild, beginChild, $ChildB_content__walks, endChild, beginChild, $ChildB_content__walks, endChild, over(1) */`b/${$ChildA_content__walks}&/${$ChildA_content__walks}&/${$ChildA_content__walks}&/${$ChildB_content__walks}&/${$ChildB_content__walks}&/${$ChildB_content__walks}&b`;
7+
import * as _ from "@marko/runtime-tags/debug/dom";
8+
const $ChildB_content__$pattern = /* @__PURE__ */_._const("$pattern2", ($scope, $pattern2) => $ChildB_content__$bar($scope, $pattern2.bar));
9+
const $ChildB_content__bar = /* @__PURE__ */_._const("bar", ($scope, bar) => _._text($scope["#text/0"], bar));
10+
const $ChildB_content__$bar = /* @__PURE__ */_._const("$bar2", ($scope, $bar2) => $ChildB_content__bar($scope, void 0 !== $bar2 ? $bar2 : 1));
11+
const $ChildB_content__$foo = ($scope, $foo2) => {
12+
$ChildB_content__$pattern($scope, void 0 !== $foo2 ? $foo2 : {
13+
bar: 2
14+
});
15+
};
16+
const $ChildB_content__foo = /* @__PURE__ */_._const("foo", ($scope, foo) => {
17+
_._text($scope["#text/1"], typeof foo);
18+
$ChildB_content__$foo($scope, foo);
19+
});
20+
const $ChildB_content__$params = /* @__PURE__ */_._const("$params3", ($scope, $params3) => $ChildB_content__input($scope, $params3[0]));
21+
const $ChildB_content__input = /* @__PURE__ */_._const("input", ($scope, input) => $ChildB_content__foo($scope, input.foo));
22+
const $ChildA_content__$pattern = /* @__PURE__ */_._const("$pattern", ($scope, $pattern) => $ChildA_content__$bar($scope, $pattern.bar));
23+
const $ChildA_content__bar = /* @__PURE__ */_._const("bar", ($scope, bar) => _._text($scope["#text/0"], bar));
24+
const $ChildA_content__$bar = /* @__PURE__ */_._const("$bar", ($scope, $bar) => $ChildA_content__bar($scope, void 0 !== $bar ? $bar : 1));
25+
const $ChildA_content__$foo = ($scope, $foo) => {
26+
$ChildA_content__$pattern($scope, void 0 !== $foo ? $foo : {
27+
bar: 2
28+
});
29+
};
30+
const $ChildA_content__foo = /* @__PURE__ */_._const("foo", ($scope, foo) => {
31+
_._text($scope["#text/1"], typeof foo);
32+
$ChildA_content__$foo($scope, foo);
33+
});
34+
const $ChildA_content__$params = /* @__PURE__ */_._const("$params2", ($scope, $params2) => $ChildA_content__$temp($scope, $params2?.[0]));
35+
const $ChildA_content__$temp = /* @__PURE__ */_._const("$temp", ($scope, $temp) => $ChildA_content__foo($scope, $temp.foo));
36+
export function $setup($scope) {
37+
$ChildA_content__foo($scope["#childScope/0"], {
38+
bar: 0
39+
});
40+
$ChildA_content__foo($scope["#childScope/1"], {});
41+
$ChildA_content__foo($scope["#childScope/2"], void 0);
42+
$ChildB_content__foo($scope["#childScope/3"], {
43+
bar: 0
44+
});
45+
$ChildB_content__foo($scope["#childScope/4"], {});
46+
$ChildB_content__foo($scope["#childScope/5"], void 0);
47+
}
48+
export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup);

0 commit comments

Comments
 (0)