brumate 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{boot-Difa0qdg.d.ts → boot-CMvhoWRu.d.ts} +2 -2
- package/dist/cli.js +2 -2
- package/dist/{client-DvsU9qxG.d.ts → client-C4kNKGwH.d.ts} +18 -5
- package/dist/{client-BYHGusTe.js → client-eVI8Wc95.js} +199 -33
- package/dist/client-eVI8Wc95.js.map +1 -0
- package/dist/{defer-B63oF5Oa.js → defer-pKO0S6UT.js} +2 -2
- package/dist/{defer-B63oF5Oa.js.map → defer-pKO0S6UT.js.map} +1 -1
- package/dist/{devtools-D_SQpXTg.js → devtools-DqqqdI4b.js} +4 -4
- package/dist/{devtools-D_SQpXTg.js.map → devtools-DqqqdI4b.js.map} +1 -1
- package/dist/{devtools-panel-B9yokst5.js → devtools-panel--GYjFZ35.js} +2 -2
- package/dist/{devtools-panel-B9yokst5.js.map → devtools-panel--GYjFZ35.js.map} +1 -1
- package/dist/{features-D5kLyihb.js → features-CbgII-o7.js} +4 -2
- package/dist/features-CbgII-o7.js.map +1 -0
- package/dist/{files-s4wmjcZV.js → files-CR-V05xd.js} +2 -2
- package/dist/{files-s4wmjcZV.js.map → files-CR-V05xd.js.map} +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +2 -7
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BLPt-dZZ.js → inspect-ddfGeww0.js} +236 -57
- package/dist/inspect-ddfGeww0.js.map +1 -0
- package/dist/{loader-DKxhLjJw.js → loader-CQkAXO0g.js} +11 -3
- package/dist/loader-CQkAXO0g.js.map +1 -0
- package/dist/routes-D21FQyGF.js +51 -0
- package/dist/routes-D21FQyGF.js.map +1 -0
- package/dist/{rpc-CIVU4Ktx.js → rpc-BgYnfg_a.js} +3 -3
- package/dist/{rpc-CIVU4Ktx.js.map → rpc-BgYnfg_a.js.map} +1 -1
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/client.d.ts +2 -2
- package/dist/runtime/client.js +3 -3
- package/dist/runtime/devtools.d.ts +1 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/routes.js +1 -51
- package/dist/runtime/server.d.ts +2 -2
- package/dist/runtime/server.js +3 -3
- package/dist/runtime/signals.d.ts +2 -140
- package/dist/runtime/signals.js +4 -1
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.d.ts +24 -4
- package/dist/runtime/testing.js +66 -2
- package/dist/runtime/testing.js.map +1 -1
- package/dist/{produce-Cq6KKi7b.js → search-params-CM1RWR2P.js} +25 -3
- package/dist/search-params-CM1RWR2P.js.map +1 -0
- package/dist/{server-Doy5HR7r.js → server-BcT9icQ4.js} +107 -40
- package/dist/server-BcT9icQ4.js.map +1 -0
- package/dist/{server-CAwIqrXl.d.ts → server-dP_ucRiJ.d.ts} +42 -3
- package/dist/signals-BwD4u22K.d.ts +165 -0
- package/dist/{static-loader-9Nc1GvF0.d.ts → static-loader-CGthkX0s.d.ts} +2 -2
- package/dist/{static-loader-Bdet7g76.js → static-loader-DCxASuzA.js} +3 -3
- package/dist/{static-loader-Bdet7g76.js.map → static-loader-DCxASuzA.js.map} +1 -1
- package/dist/{stream-BdhzvPQO.js → stream-DRjx0keF.js} +2 -2
- package/dist/{stream-BdhzvPQO.js.map → stream-DRjx0keF.js.map} +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +17 -12
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +231 -35
- package/package.json +6 -1
- package/skills/brumate/references/errors.md +32 -12
- package/skills/brumate/references/signals.md +27 -25
- package/skills/brumate/references/syntax.md +1 -1
- package/dist/client-BYHGusTe.js.map +0 -1
- package/dist/features-D5kLyihb.js.map +0 -1
- package/dist/inspect-BLPt-dZZ.js.map +0 -1
- package/dist/loader-DKxhLjJw.js.map +0 -1
- package/dist/produce-Cq6KKi7b.js.map +0 -1
- package/dist/runtime/routes.js.map +0 -1
- package/dist/server-Doy5HR7r.js.map +0 -1
|
@@ -26,6 +26,7 @@ const MACROS = /* @__PURE__ */ new Set([
|
|
|
26
26
|
"$setContext",
|
|
27
27
|
"$getContext",
|
|
28
28
|
"$route",
|
|
29
|
+
"$searchParam",
|
|
29
30
|
"$navigation",
|
|
30
31
|
"$id",
|
|
31
32
|
"$title",
|
|
@@ -292,7 +293,7 @@ const REACTIVE = /* @__PURE__ */ new Set([
|
|
|
292
293
|
/** The module of the wrappers of event handlers, which the compiler reads. */
|
|
293
294
|
const EVENTS_MODULE = "brumate/events";
|
|
294
295
|
/** The wrappers that `brumate/events` exports. */
|
|
295
|
-
const WRAPPERS$
|
|
296
|
+
const WRAPPERS$3 = /* @__PURE__ */ new Set([
|
|
296
297
|
"prevent",
|
|
297
298
|
"stop",
|
|
298
299
|
"once",
|
|
@@ -511,6 +512,7 @@ var Analyzer = class {
|
|
|
511
512
|
this.markPromiseProps();
|
|
512
513
|
for (const site of this.sites) new Resolver(this, site).run();
|
|
513
514
|
this.addPendingReads();
|
|
515
|
+
this.addSearchParamReads();
|
|
514
516
|
this.checkLoadingHeaders();
|
|
515
517
|
this.resolveRefs();
|
|
516
518
|
this.check();
|
|
@@ -526,6 +528,29 @@ var Analyzer = class {
|
|
|
526
528
|
pendingCalls: this.pendingCalls
|
|
527
529
|
};
|
|
528
530
|
}
|
|
531
|
+
/**
|
|
532
|
+
* The effect of a `$searchParam` reads its signal, so it runs again when the signal changes.
|
|
533
|
+
* The range is empty, so no identifier starts there.
|
|
534
|
+
*/
|
|
535
|
+
addSearchParamReads() {
|
|
536
|
+
for (const declaration of this.declarations) {
|
|
537
|
+
if (!declaration.searchParam) continue;
|
|
538
|
+
for (const site of this.sites) if (site.node === declaration.searchParam && site.kind === "effect") {
|
|
539
|
+
const read = {
|
|
540
|
+
range: {
|
|
541
|
+
start: site.node.end,
|
|
542
|
+
end: site.node.end
|
|
543
|
+
},
|
|
544
|
+
declaration,
|
|
545
|
+
site,
|
|
546
|
+
tracked: true,
|
|
547
|
+
inFunction: false
|
|
548
|
+
};
|
|
549
|
+
declaration.reads.push(read);
|
|
550
|
+
site.reads.push(read);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
529
554
|
/** `$isPending(memo)` calls, which also read the memos that the memo reads. */
|
|
530
555
|
pendingCalls = [];
|
|
531
556
|
/**
|
|
@@ -688,14 +713,9 @@ var Analyzer = class {
|
|
|
688
713
|
/**
|
|
689
714
|
* Reads the wrappers of `brumate/events` around a handler, such as
|
|
690
715
|
* `prevent(move, 'Enter')`, into the modifiers that `b-on` holds, so the
|
|
691
|
-
* loader applies them before the handler's code loads.
|
|
692
|
-
* attribute name, such as `onSubmit:prevent`, still works, with a warning.
|
|
716
|
+
* loader applies them before the handler's code loads.
|
|
693
717
|
*/
|
|
694
718
|
readWrappers(site, attribute, scope) {
|
|
695
|
-
if (attribute.modifiers.length > 0) {
|
|
696
|
-
const [first] = attribute.modifiers;
|
|
697
|
-
this.report("warning", `${attribute.name}:${first} is replaced by ${attribute.name}=(${first === "passive" ? "handler" : `${first}(handler)`}) from brumate/events${first === "passive" ? ", since listeners are passive unless a handler prevents" : ""}`, attribute);
|
|
698
|
-
}
|
|
699
719
|
const modifiers = [];
|
|
700
720
|
let node = attribute.handler.ast;
|
|
701
721
|
for (;;) {
|
|
@@ -707,7 +727,7 @@ var Analyzer = class {
|
|
|
707
727
|
node = node.arguments[0];
|
|
708
728
|
continue;
|
|
709
729
|
}
|
|
710
|
-
if (name === void 0 || !WRAPPERS$
|
|
730
|
+
if (name === void 0 || !WRAPPERS$3.has(name)) break;
|
|
711
731
|
const [handler, ...rest] = node.arguments;
|
|
712
732
|
if (!handler || name !== "prevent" && rest.length > 0) {
|
|
713
733
|
this.report("error", `${name} takes a handler`, node);
|
|
@@ -890,6 +910,31 @@ var Analyzer = class {
|
|
|
890
910
|
declaration.passedKey = prop.propKey;
|
|
891
911
|
return;
|
|
892
912
|
}
|
|
913
|
+
if (name === "$searchParam") {
|
|
914
|
+
const expected = "let";
|
|
915
|
+
if (kind !== expected) this.report("error", `Declare ${name} with ${expected}`, declarator);
|
|
916
|
+
if (id.type !== "Identifier") {
|
|
917
|
+
this.report("error", `${name} cannot be destructured`, id);
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
const [first, options] = call.arguments;
|
|
921
|
+
if (first?.type !== "Literal" || typeof first.value !== "string" || call.arguments.length > 2 || options && options.type !== "ObjectExpression") {
|
|
922
|
+
this.report("error", `${name} needs a value`, call);
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
for (const other of this.declarations) {
|
|
926
|
+
const [earlier] = other.searchParam?.arguments ?? [];
|
|
927
|
+
if (other.scope === scope && earlier?.type === "Literal" && earlier.value === first.value) {
|
|
928
|
+
this.report("error", `"${id.name}" is already declared`, id);
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
const declaration = this.addDeclaration(scope, id.name, "signal", id);
|
|
933
|
+
declaration.searchParam = call;
|
|
934
|
+
this.createSite("effect", scope, call, "search param");
|
|
935
|
+
this.createSite("client", scope, call, "search param", { trigger: "load" });
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
893
938
|
if (name === "$route" || name === "$navigation") {
|
|
894
939
|
if (kind !== "const" || id.type !== "Identifier") {
|
|
895
940
|
this.report("error", MISPLACED[name], declarator);
|
|
@@ -1076,7 +1121,7 @@ var Analyzer = class {
|
|
|
1076
1121
|
node = handler;
|
|
1077
1122
|
continue;
|
|
1078
1123
|
}
|
|
1079
|
-
if (name === void 0 || !WRAPPERS$
|
|
1124
|
+
if (name === void 0 || !WRAPPERS$3.has(name) || !handler) break;
|
|
1080
1125
|
const names = [];
|
|
1081
1126
|
let unnamed = false;
|
|
1082
1127
|
for (const key of keys) {
|
|
@@ -1677,6 +1722,10 @@ var Resolver = class {
|
|
|
1677
1722
|
for (const argument of recipe ? [recipe, ...rest] : rest) this.visit(argument);
|
|
1678
1723
|
return;
|
|
1679
1724
|
}
|
|
1725
|
+
if (name === "$searchParam" && this.site.node === node) {
|
|
1726
|
+
for (const argument of node.arguments) this.visit(argument);
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1680
1729
|
if (name === "$bind") {
|
|
1681
1730
|
this.declareBinding(node);
|
|
1682
1731
|
for (const argument of node.arguments) this.visit(argument);
|
|
@@ -1884,7 +1933,7 @@ const SYNTAX = [
|
|
|
1884
1933
|
entry("BRM019", "Only event handlers are allowed here", "`<window>` and `<document>` take event handlers and nothing else.", "<document onKeyDown=(handler) />"),
|
|
1885
1934
|
entry("BRM020", "Expected a spread or a shorthand attribute", "A `{` in a tag holds something other than `...rest` or a name.", "<a {href} {...rest}>Open</a>"),
|
|
1886
1935
|
entry("BRM021", "Expected an attribute name", "A tag has a character where an attribute name belongs.", "<input disabled>"),
|
|
1887
|
-
entry("BRM022", "
|
|
1936
|
+
entry("BRM022", "Event modifiers in the attribute name were removed. Write {fix}", "A modifier follows the event name, as in `onSubmit:prevent=send`. Wrappers of `brumate/events` write modifiers now, and `:passive` is the default, since listeners are passive unless a handler prevents.", "import { prevent } from 'brumate/events';\n\n<form onSubmit=(prevent(send))></form>"),
|
|
1888
1937
|
entry("BRM180", "\"{name}\" is not an event name. Write \"{camel}\"", "An event of more than one word is written in camel case. The lower-case form is an error.", "<input onKeyDown=(handle) onFocusOut=(handle) />"),
|
|
1889
1938
|
entry("BRM186", "\"{name}\" in the #loading header is not a memo that markup in the body reads. Name a $memo of the component or of a block script around the block", "The header of `#loading (…)` names something other than a memo, or a memo that no markup in the body reads, so its loads would not show the fallback for that body.", "const posts = $memo(loadPosts(id));\n#loading (posts) {\n <p>{posts.length} posts</p>\n} #else {\n <p>Loading</p>\n}"),
|
|
1890
1939
|
entry("BRM182", "The handler reads \"{name}\", a memo that can lack a value. Wait for it with await $resolve({name}), or check $isPending({name}) first", "A handler, a handler prop or a `$client` callback reads an async memo that may still be loading, with no `$isPending` check or `await $resolve` before the read.", "<script>\n const user = $memo(getUser(id));\n async function save() {\n await $resolve(user);\n send(user.name);\n }\n<\/script>"),
|
|
@@ -1893,7 +1942,6 @@ const SYNTAX = [
|
|
|
1893
1942
|
entry("BRM185", "<{tag}> cannot be inside <{parent}>: the HTML parser closes or moves it before the page runs. Move it out of the <{parent}>, or use a <span> or as=\"span\"", "The HTML parser does not keep this nesting. A `<p>` ends at a block element such as `<div>`, an `<a>` or a `<form>` inside the same tag starts again, and a table keeps only table parts. The browser builds a page that differs from the markup, and the start and end markers of a block can land in different parents.", "<p>Total: <span>{total}</span></p>\n<div>\n <p>Total</p>\n</div>"),
|
|
1894
1943
|
entry("BRM187", "The {kind} {name} of {component} did not settle: it writes a value that it reads, and runs again without end. Wrap the read or the write in $untrack, or write only when the value changes", "In the browser, an effect or an update writes a value that it reads, so each run schedules the next. Past 1000 rounds of effects, or 10000 rounds of updates, in one change, the page stops the loop and sends this error to the nearest `#try` in place of hanging the tab. A production build sends the short form `Update loop {scope}:{name} [BRM187]`.", "<script>\n import { $effect, $signal, $untrack } from 'brumate/signals';\n\n let query = $signal('');\n let saves = $signal(0);\n\n $effect(() => {\n void query;\n $untrack(saves++);\n });\n<\/script>"),
|
|
1895
1944
|
entry("BRM188", "\"{name}\" gives a promise, and {place} cannot wait for one. Await it in the code that runs, or read its value with $memo", "Markup waits for a promise in text and in attribute values only. An event handler, the key of a `#for`, a `ref` and a `$bind` need the value at once, and the compiler sees that this expression gives a promise: `new Promise(…)`, a call of a server function or of an async function, or a prop typed as a promise.", "<button onClick=(() => save(draft))>Save</button>\n#for (user of users by user.id) {\n <p>{user.name}</p>\n}"),
|
|
1896
|
-
entry("BRM023", "Modifiers apply to elements. Put \":{modifier}\" on the element that the component renders", "An event modifier is on a component, which only passes the handler on.", "<form onSubmit=(prevent(send))></form>"),
|
|
1897
1945
|
entry("BRM024", "Expected an event handler", "An event attribute has no `=` and no value.", "<button onClick=(() => count++)>Add</button>"),
|
|
1898
1946
|
entry("BRM025", "An event handler must be an expression, not a string", "The value of an event attribute is a quoted string.", "<button onClick=(() => count++)>Add</button>"),
|
|
1899
1947
|
entry("BRM026", "An attribute name can have one \":\" namespace", "An attribute name has two or more `:`.", "<svg xlink:href=\"#icon\"></svg>"),
|
|
@@ -1909,6 +1957,8 @@ const SYNTAX = [
|
|
|
1909
1957
|
entry("BRM036", "A file can have one <script module>", "A file has two module scripts.", "<script module>\n export const MAX = 10;\n export const MIN = 1;\n<\/script>"),
|
|
1910
1958
|
entry("BRM037", "A file can have one <script>", "A file has two instance scripts.", "<script>\n let a = $signal(1);\n let b = $signal(2);\n<\/script>"),
|
|
1911
1959
|
entry("BRM038", "lang must be \"css\", \"scss\" or \"less\"", "A `<style>` names another language.", "<style lang=\"scss\">\n p {\n a {\n color: red;\n }\n }\n</style>"),
|
|
1960
|
+
entry("BRM189", "Unknown <style> attribute \"{name}\"", "A `<style>` has an attribute other than `lang` and `global`.", "<style scoped>\n p {\n color: red;\n }\n</style>"),
|
|
1961
|
+
entry("BRM190", "global takes no value, as in <style global>", "A `<style global>` gives `global` a value.", "<style global=\"true\">\n p {\n color: red;\n }\n</style>"),
|
|
1912
1962
|
entry("BRM039", "#reveal takes an order, 'sequential', 'backwards', 'together' or 'natural', and collapsed, such as #reveal ('sequential', collapsed)", "`#reveal` has an option that it does not know.", "#reveal ('sequential', collapsed) {\n …\n}"),
|
|
1913
1963
|
entry("BRM040", "collapsed shows the fallback of the next body to show, so it needs the order 'sequential', not '{order}'", "`collapsed` goes with `sequential` only.", "#reveal ('sequential', collapsed) {\n …\n}"),
|
|
1914
1964
|
entry("BRM041", "#reveal has no script of its own", "A `#reveal` body starts with a `<script>`.", "<script>\n let open = $signal(false);\n<\/script>\n#reveal {\n …\n}"),
|
|
@@ -2206,6 +2256,38 @@ const SOURCE_KINDS = /* @__PURE__ */ new Set([
|
|
|
2206
2256
|
"error",
|
|
2207
2257
|
"template-param"
|
|
2208
2258
|
]);
|
|
2259
|
+
/** True if the read is inside the compute of one of the memos; a read in its inner function counts. */
|
|
2260
|
+
function isReadIn(read, memos) {
|
|
2261
|
+
const site = read.site;
|
|
2262
|
+
return site.kind === "memo" && site.declaration !== void 0 && memos.has(site.declaration);
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Finds the memos that no browser code reads: no read at all, or reads only in the compute of
|
|
2266
|
+
* other such memos. The server computes a memo when something reads it, so the browser does not
|
|
2267
|
+
* compute these either. A memo that is awaited where it is declared, a debounced or throttled
|
|
2268
|
+
* value, an optimistic value, a search parameter, a bound value and a ref target stay.
|
|
2269
|
+
*/
|
|
2270
|
+
function findUnread(model) {
|
|
2271
|
+
const unread = /* @__PURE__ */ new Set();
|
|
2272
|
+
const candidates = [];
|
|
2273
|
+
for (const declaration of model.declarations) if (isMemoKind(declaration.kind) && declaration.site?.kind === "memo" && !declaration.awaited && !declaration.timing && !declaration.optimistic && !declaration.writable && !declaration.searchParam && !declaration.bound && declaration.refs.length === 0 && declaration.writes.length === 0) candidates.push(declaration);
|
|
2274
|
+
for (let changed = true; changed;) {
|
|
2275
|
+
changed = false;
|
|
2276
|
+
for (const declaration of candidates) {
|
|
2277
|
+
if (unread.has(declaration)) continue;
|
|
2278
|
+
let read = false;
|
|
2279
|
+
for (const item of declaration.reads) if (!isReadIn(item, unread)) {
|
|
2280
|
+
read = true;
|
|
2281
|
+
break;
|
|
2282
|
+
}
|
|
2283
|
+
if (!read) {
|
|
2284
|
+
unread.add(declaration);
|
|
2285
|
+
changed = true;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
return unread;
|
|
2290
|
+
}
|
|
2209
2291
|
/** True if a prop or the rest of the props can change on the client. */
|
|
2210
2292
|
function isLiveProp(declaration, liveProps) {
|
|
2211
2293
|
if (!liveProps || liveProps.has("*")) return true;
|
|
@@ -2455,6 +2537,7 @@ function buildGraph(model, options = {}) {
|
|
|
2455
2537
|
const live = /* @__PURE__ */ new Set();
|
|
2456
2538
|
const reached = /* @__PURE__ */ new Set();
|
|
2457
2539
|
const created = /* @__PURE__ */ new Set();
|
|
2540
|
+
const unread = findUnread(model);
|
|
2458
2541
|
function reach(site) {
|
|
2459
2542
|
if (reached.has(site)) return;
|
|
2460
2543
|
reached.add(site);
|
|
@@ -2471,7 +2554,7 @@ function buildGraph(model, options = {}) {
|
|
|
2471
2554
|
const templateUsed = scope.kind === "template" && templateCallChanges(scope);
|
|
2472
2555
|
if (parentCreated || blockLive || templateUsed) created.add(scope);
|
|
2473
2556
|
}
|
|
2474
|
-
for (const site of model.sites) if (site.kind === "event" || site.kind === "client" || site.kind === "prop" && isFunctionValue(site) || site.kind === "block" && site.block?.kind === "for" && site.block.window !== void 0 || site.kind === "effect" && live.has(siteNodes.get(site)) || created.has(site.scope)) reach(site);
|
|
2557
|
+
for (const site of model.sites) if ((site.kind === "event" || site.kind === "client" || site.kind === "prop" && isFunctionValue(site) || site.kind === "block" && site.block?.kind === "for" && site.block.window !== void 0 || site.kind === "effect" && live.has(siteNodes.get(site)) || created.has(site.scope)) && !(site.kind === "memo" && unread.has(site.declaration))) reach(site);
|
|
2475
2558
|
for (const [declaration, node] of declarationNodes) {
|
|
2476
2559
|
if (live.has(node)) continue;
|
|
2477
2560
|
if ((declaration.kind === "prop" || declaration.kind === "props-rest") && isLiveProp(declaration, options.liveProps) || declaration.kind === "prop" && declaration.writable === true && anyReached(declaration.writes, reached) || declaration.kind === "context" || declaration.kind === "action" || isMemoKind(declaration.kind) && callsRefreshed(declaration) || declaration.kind === "memo" && isPropValue(declaration.site) || declaration.optimistic !== void 0 && anyReached(declaration.writes, reached) || declaration.kind === "signal" && (anyReached(declaration.writes, reached) || hasRefIn(declaration, created)) || declaration.kind === "error" && declaration.block?.kind === "try" && tryChanges(declaration.block) || declaration.bound === true || declaration.kind === "template-param" && templateCallChanges(declaration.scope)) live.add(node);
|
|
@@ -2483,6 +2566,7 @@ function buildGraph(model, options = {}) {
|
|
|
2483
2566
|
propagated = true;
|
|
2484
2567
|
}
|
|
2485
2568
|
}
|
|
2569
|
+
for (const declaration of unread) live.delete(declarationNodes.get(declaration));
|
|
2486
2570
|
if (live.size + reached.size + created.size !== before) changed = true;
|
|
2487
2571
|
}
|
|
2488
2572
|
function templateCallChanges(scope) {
|
|
@@ -2531,6 +2615,7 @@ function buildGraph(model, options = {}) {
|
|
|
2531
2615
|
live,
|
|
2532
2616
|
reached,
|
|
2533
2617
|
created,
|
|
2618
|
+
unread,
|
|
2534
2619
|
diagnostics
|
|
2535
2620
|
};
|
|
2536
2621
|
}
|
|
@@ -2812,6 +2897,12 @@ function findTopLevel(code, word, fail) {
|
|
|
2812
2897
|
}
|
|
2813
2898
|
//#endregion
|
|
2814
2899
|
//#region src/parser.ts
|
|
2900
|
+
const WRAPPERS$2 = /* @__PURE__ */ new Set([
|
|
2901
|
+
"prevent",
|
|
2902
|
+
"stop",
|
|
2903
|
+
"once",
|
|
2904
|
+
"capture"
|
|
2905
|
+
]);
|
|
2815
2906
|
const VOID_ELEMENTS$1 = /* @__PURE__ */ new Set([
|
|
2816
2907
|
"area",
|
|
2817
2908
|
"base",
|
|
@@ -2851,13 +2942,6 @@ const BRANCH_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
2851
2942
|
"case",
|
|
2852
2943
|
"default"
|
|
2853
2944
|
]);
|
|
2854
|
-
const MODIFIERS = /* @__PURE__ */ new Set([
|
|
2855
|
-
"prevent",
|
|
2856
|
-
"stop",
|
|
2857
|
-
"passive",
|
|
2858
|
-
"once",
|
|
2859
|
-
"capture"
|
|
2860
|
-
]);
|
|
2861
2945
|
const CLIENT_TRIGGERS = /* @__PURE__ */ new Set([
|
|
2862
2946
|
"visible",
|
|
2863
2947
|
"idle",
|
|
@@ -3162,7 +3246,6 @@ var Parser = class {
|
|
|
3162
3246
|
end: this.pos,
|
|
3163
3247
|
name,
|
|
3164
3248
|
event: name.slice(2).toLowerCase(),
|
|
3165
|
-
modifiers: [],
|
|
3166
3249
|
handler: this.expression(inner.start, inner.end)
|
|
3167
3250
|
};
|
|
3168
3251
|
}
|
|
@@ -3198,10 +3281,23 @@ var Parser = class {
|
|
|
3198
3281
|
const parts = fullName.split(":");
|
|
3199
3282
|
if (/^on[A-Z]/.test(fullName)) {
|
|
3200
3283
|
const name = parts[0];
|
|
3201
|
-
const modifiers = parts.slice(1);
|
|
3202
3284
|
this.checkEventName(name, owner, start);
|
|
3203
|
-
|
|
3204
|
-
|
|
3285
|
+
if (parts.length > 1) {
|
|
3286
|
+
const rest = parts.slice(1);
|
|
3287
|
+
const wrappers = [];
|
|
3288
|
+
let unknown;
|
|
3289
|
+
for (const modifier of rest) if (WRAPPERS$2.has(modifier)) wrappers.push(modifier);
|
|
3290
|
+
else if (modifier !== "passive") unknown ??= modifier;
|
|
3291
|
+
let fix;
|
|
3292
|
+
if (unknown !== void 0) fix = `${name}=(handler) with the wrappers of brumate/events, since ":${unknown}" is not a modifier`;
|
|
3293
|
+
else if (wrappers.length === 0) fix = `${name}=(handler), since listeners are passive unless a handler prevents`;
|
|
3294
|
+
else {
|
|
3295
|
+
let call = "handler";
|
|
3296
|
+
for (const wrapper of wrappers.toReversed()) call = `${wrapper}(${call})`;
|
|
3297
|
+
fix = `${name}=(${call}) with ${wrappers.join(" and ")} from brumate/events`;
|
|
3298
|
+
}
|
|
3299
|
+
this.fail(`Event modifiers in the attribute name were removed. Write ${fix}`, start);
|
|
3300
|
+
}
|
|
3205
3301
|
if (this.peek() !== "=") this.fail("Expected an event handler", this.pos);
|
|
3206
3302
|
this.pos++;
|
|
3207
3303
|
const value = this.parseValue();
|
|
@@ -3212,7 +3308,6 @@ var Parser = class {
|
|
|
3212
3308
|
end: this.pos,
|
|
3213
3309
|
name,
|
|
3214
3310
|
event: name.slice(2).toLowerCase(),
|
|
3215
|
-
modifiers,
|
|
3216
3311
|
handler: value
|
|
3217
3312
|
};
|
|
3218
3313
|
}
|
|
@@ -3372,6 +3467,8 @@ var Parser = class {
|
|
|
3372
3467
|
const start = this.pos;
|
|
3373
3468
|
const { attributes, contentStart } = this.parseBlockTag("style");
|
|
3374
3469
|
const { contentEnd } = this.readBlockContent("style", contentStart);
|
|
3470
|
+
for (const name of Object.keys(attributes)) if (name !== "lang" && name !== "global") this.fail(`Unknown <style> attribute "${name}"`, start);
|
|
3471
|
+
if (attributes.global !== void 0 && attributes.global !== true) this.fail("global takes no value, as in <style global>", start);
|
|
3375
3472
|
const lang = attributes.lang ?? "css";
|
|
3376
3473
|
if (lang !== "css" && lang !== "scss" && lang !== "less") return this.fail("lang must be \"css\", \"scss\" or \"less\"", start);
|
|
3377
3474
|
const variables = [];
|
|
@@ -3389,6 +3486,7 @@ var Parser = class {
|
|
|
3389
3486
|
start,
|
|
3390
3487
|
end: this.pos,
|
|
3391
3488
|
lang,
|
|
3489
|
+
global: attributes.global === true,
|
|
3392
3490
|
content: this.source.slice(contentStart, contentEnd),
|
|
3393
3491
|
variables
|
|
3394
3492
|
};
|
|
@@ -5285,6 +5383,11 @@ function addValueEdits(patch, file, sites, mode = "server", inline = /* @__PURE_
|
|
|
5285
5383
|
patch.replace(node.start, node.end, mode === "server" && argument?.type === "Identifier" ? `$$b.actionResult($$ctx, ${argument.name})` : "undefined");
|
|
5286
5384
|
return;
|
|
5287
5385
|
}
|
|
5386
|
+
if (name === "$searchParam" && argument) {
|
|
5387
|
+
patch.replace(node.start, argument.start, mode === "server" ? "$$b.searchParam($$ctx, " : "$$b.searchParam(");
|
|
5388
|
+
for (const rest of node.arguments) visit(rest);
|
|
5389
|
+
return;
|
|
5390
|
+
}
|
|
5288
5391
|
if (name === "$isBound") {
|
|
5289
5392
|
patch.replace(node.start, node.end, "false");
|
|
5290
5393
|
return;
|
|
@@ -5787,9 +5890,10 @@ function scopeTarget(compound) {
|
|
|
5787
5890
|
}
|
|
5788
5891
|
/**
|
|
5789
5892
|
* Adds the scope attribute to every compound selector, except inside
|
|
5790
|
-
* `:global(…)`. Each scoped compound goes into `targets`.
|
|
5893
|
+
* `:global(…)`. Each scoped compound goes into `targets`. With `unscoped`, no
|
|
5894
|
+
* compound is scoped, and `:global(…)` is only unwrapped.
|
|
5791
5895
|
*/
|
|
5792
|
-
function scopeSelector(attribute, targets) {
|
|
5896
|
+
function scopeSelector(attribute, targets, unscoped) {
|
|
5793
5897
|
return selectorParser((selectors) => {
|
|
5794
5898
|
for (let index = 0; index < selectors.nodes.length; index++) {
|
|
5795
5899
|
const selector = selectors.nodes[index];
|
|
@@ -5833,7 +5937,7 @@ function scopeSelector(attribute, targets) {
|
|
|
5833
5937
|
global.replaceWith(...clones);
|
|
5834
5938
|
continue;
|
|
5835
5939
|
}
|
|
5836
|
-
if (compound.length === 0) continue;
|
|
5940
|
+
if (compound.length === 0 || unscoped) continue;
|
|
5837
5941
|
targets.push(scopeTarget(compound));
|
|
5838
5942
|
let last;
|
|
5839
5943
|
for (let at = compound.length - 1; at >= 0; at--) {
|
|
@@ -5854,8 +5958,8 @@ function scopeSelector(attribute, targets) {
|
|
|
5854
5958
|
});
|
|
5855
5959
|
});
|
|
5856
5960
|
}
|
|
5857
|
-
function scopeRules(root, attribute, targets) {
|
|
5858
|
-
const processor = scopeSelector(attribute, targets);
|
|
5961
|
+
function scopeRules(root, attribute, targets, unscoped) {
|
|
5962
|
+
const processor = scopeSelector(attribute, targets, unscoped);
|
|
5859
5963
|
root.walkRules((rule) => {
|
|
5860
5964
|
if (rule.parent?.type === "atrule" && /keyframes$/i.test(rule.parent.name)) return;
|
|
5861
5965
|
rule.selector = processor.processSync(rule.selector);
|
|
@@ -5982,7 +6086,7 @@ function compileStyles(file, scope, filePath) {
|
|
|
5982
6086
|
content += style.content.slice(position);
|
|
5983
6087
|
try {
|
|
5984
6088
|
const root = parse(style.lang === "css" ? content : preprocess(style.lang, content, filePath, dependencies));
|
|
5985
|
-
scopeRules(root, attribute, targets);
|
|
6089
|
+
scopeRules(root, attribute, targets, style.global);
|
|
5986
6090
|
parts.push(root.toString().trim());
|
|
5987
6091
|
} catch (error) {
|
|
5988
6092
|
diagnostics.push({
|
|
@@ -6536,6 +6640,50 @@ function holderArguments(plan, block) {
|
|
|
6536
6640
|
}
|
|
6537
6641
|
//#endregion
|
|
6538
6642
|
//#region src/codegen/template.ts
|
|
6643
|
+
const contexts = /* @__PURE__ */ new WeakMap();
|
|
6644
|
+
/**
|
|
6645
|
+
* `svg` or `math` when the elements around a body, or around the children of a component, put
|
|
6646
|
+
* its markup in SVG or MathML, which HTML that the browser parses there would find at run time.
|
|
6647
|
+
* `owner` is the body, or the component or dynamic tag that the children belong to.
|
|
6648
|
+
*/
|
|
6649
|
+
function foreignContext(file, owner) {
|
|
6650
|
+
if (!owner) return;
|
|
6651
|
+
let found = contexts.get(file);
|
|
6652
|
+
if (!found) {
|
|
6653
|
+
found = /* @__PURE__ */ new Map();
|
|
6654
|
+
contexts.set(file, found);
|
|
6655
|
+
const map = found;
|
|
6656
|
+
const walk = (nodes, around) => {
|
|
6657
|
+
for (const node of nodes) switch (node.kind) {
|
|
6658
|
+
case "element": {
|
|
6659
|
+
const tag = node.tag.toLowerCase();
|
|
6660
|
+
let inside = around;
|
|
6661
|
+
if (tag === "svg" || tag === "math") inside = tag;
|
|
6662
|
+
else if (tag === "foreignobject") inside = void 0;
|
|
6663
|
+
walk(node.children, inside);
|
|
6664
|
+
break;
|
|
6665
|
+
}
|
|
6666
|
+
case "component":
|
|
6667
|
+
case "dynamic":
|
|
6668
|
+
map.set(node, around);
|
|
6669
|
+
walk(node.children, around);
|
|
6670
|
+
break;
|
|
6671
|
+
case "fragment":
|
|
6672
|
+
walk(node.children, around);
|
|
6673
|
+
break;
|
|
6674
|
+
case "text":
|
|
6675
|
+
case "insert":
|
|
6676
|
+
case "listener": break;
|
|
6677
|
+
default: for (const body of blockBodies(node)) {
|
|
6678
|
+
map.set(body, around);
|
|
6679
|
+
walk(body.children, around);
|
|
6680
|
+
}
|
|
6681
|
+
}
|
|
6682
|
+
};
|
|
6683
|
+
walk(file.children, void 0);
|
|
6684
|
+
}
|
|
6685
|
+
return found.get(owner);
|
|
6686
|
+
}
|
|
6539
6687
|
const ATTRIBUTE = /^\$\$b\.attribute\(("(?:[^"\\]|\\.)*"), ([\s\S]*)\)$/;
|
|
6540
6688
|
const CLASS_TOKEN = /^\(\(([\s\S]*)\) \? " ([^"\\&<>]+)" : ""\)$/;
|
|
6541
6689
|
/**
|
|
@@ -6728,8 +6876,9 @@ var Reader = class {
|
|
|
6728
6876
|
}
|
|
6729
6877
|
};
|
|
6730
6878
|
/** The template of a render's parts, or undefined when its markup needs HTML. */
|
|
6731
|
-
function clonedTemplate(parts) {
|
|
6879
|
+
function clonedTemplate(parts, filled, around) {
|
|
6732
6880
|
const reader = new Reader();
|
|
6881
|
+
reader.foreign = around;
|
|
6733
6882
|
const writes = [];
|
|
6734
6883
|
/** The index of each marked element, by its number in the order of the markup. */
|
|
6735
6884
|
const marks = /* @__PURE__ */ new Map();
|
|
@@ -6858,7 +7007,7 @@ function clonedTemplate(parts) {
|
|
|
6858
7007
|
continue;
|
|
6859
7008
|
}
|
|
6860
7009
|
const blockEnd = nextStatic === void 0 ? null : BLOCK_END.exec(nextStatic);
|
|
6861
|
-
if (SCOPE.test(code) && reader.html.endsWith(BLOCK_START) && blockEnd) {
|
|
7010
|
+
if (SCOPE.test(code) && reader.html.endsWith(BLOCK_START) && blockEnd && (!filled || filled(code, Number(blockEnd[1])))) {
|
|
6862
7011
|
reader.takeBack(BLOCK_START, "text");
|
|
6863
7012
|
const mark = writes.length;
|
|
6864
7013
|
writes.push([{
|
|
@@ -6980,7 +7129,7 @@ function clonedTemplate(parts) {
|
|
|
6980
7129
|
}
|
|
6981
7130
|
return;
|
|
6982
7131
|
}
|
|
6983
|
-
|
|
7132
|
+
const indexed = reader.html.replace(/<!--x\d+-->|<!--\/[biP]-->/g, "").includes("<!--") || /<template\b/i.test(reader.html) || void 0;
|
|
6984
7133
|
function getAnchor(element) {
|
|
6985
7134
|
for (const write of writes[marks.get(element) ?? -1] ?? []) if (write.kind === "anchor") return write;
|
|
6986
7135
|
}
|
|
@@ -6998,7 +7147,8 @@ function clonedTemplate(parts) {
|
|
|
6998
7147
|
return {
|
|
6999
7148
|
html: reader.html,
|
|
7000
7149
|
writes,
|
|
7001
|
-
foreign: reader.foreign
|
|
7150
|
+
foreign: reader.foreign,
|
|
7151
|
+
indexed
|
|
7002
7152
|
};
|
|
7003
7153
|
}
|
|
7004
7154
|
/**
|
|
@@ -7016,7 +7166,7 @@ function promised(scope, key, value, write) {
|
|
|
7016
7166
|
* The lines between the first and the last `$$html +=` can only declare the values of the
|
|
7017
7167
|
* writes, which run after them. Plain `{` blocks around them go, so the writes see them.
|
|
7018
7168
|
*/
|
|
7019
|
-
function cloneLines(emitter, hoist, fn = 0) {
|
|
7169
|
+
function cloneLines(emitter, hoist, fn = 0, owner) {
|
|
7020
7170
|
const { lines: source, levels } = emitter;
|
|
7021
7171
|
function isTop(at) {
|
|
7022
7172
|
return levels[at].fn === fn && !levels[at].control;
|
|
@@ -7063,12 +7213,13 @@ function cloneLines(emitter, hoist, fn = 0) {
|
|
|
7063
7213
|
if (previous && "static" in previous && "static" in part) parts[parts.length - 1] = { static: previous.static + part.static };
|
|
7064
7214
|
else parts.push({ ...part });
|
|
7065
7215
|
}
|
|
7066
|
-
const found = clonedTemplate(parts);
|
|
7216
|
+
const found = clonedTemplate(parts, (scope, anchor) => emitter.fills?.has(`${scope}:${anchor}`) ?? false, emitter.foreignAround(owner));
|
|
7067
7217
|
if (!found) return false;
|
|
7068
7218
|
const flush = tops[0];
|
|
7069
7219
|
const indent = /^ */.exec(emitter.lines[flush.line])[0];
|
|
7070
|
-
|
|
7071
|
-
|
|
7220
|
+
let options = found.foreign ? `, ${JSON.stringify(found.foreign)}` : "";
|
|
7221
|
+
if (found.indexed) options += `${found.foreign ? "" : ", undefined"}, 1`;
|
|
7222
|
+
const lines = [`${indent}const $$e = $$b.clone(${hoist(`$$b.template(${JSON.stringify(found.html)}, ${found.writes.length}${options})`)}), $$f = $$e[${found.writes.length}];`];
|
|
7072
7223
|
const fills = [];
|
|
7073
7224
|
const settled = /* @__PURE__ */ new Map();
|
|
7074
7225
|
function addLine(line, memos) {
|
|
@@ -8091,6 +8242,10 @@ var Emitter = class {
|
|
|
8091
8242
|
this.braces.push({ kind: "control" });
|
|
8092
8243
|
}
|
|
8093
8244
|
}
|
|
8245
|
+
/** `svg` or `math` when the elements around `owner`, a body or children, put its markup there. */
|
|
8246
|
+
foreignAround(owner) {
|
|
8247
|
+
return foreignContext(this.file, owner);
|
|
8248
|
+
}
|
|
8094
8249
|
/**
|
|
8095
8250
|
* The return of a render function of the browser: its clone, its HTML, or an empty string
|
|
8096
8251
|
* for a function with no markup, which is not HTML that the core must parse.
|
|
@@ -8511,8 +8666,21 @@ var Emitter = class {
|
|
|
8511
8666
|
if (!this.options.functions && this.isFunctionStatement(statement)) continue;
|
|
8512
8667
|
}
|
|
8513
8668
|
let code = this.patch.slice(statement.start, statement.end);
|
|
8669
|
+
let partial = false;
|
|
8670
|
+
if (this.options.mode === "client" && statement.type === "VariableDeclaration") {
|
|
8671
|
+
const kept = [];
|
|
8672
|
+
for (const declarator of statement.declarations) {
|
|
8673
|
+
const declaration = declarator.id.type === "Identifier" ? scope.declarations.get(declarator.id.name) : void 0;
|
|
8674
|
+
if (!declaration || !this.plan.graph.unread.has(declaration)) kept.push(this.patch.slice(declarator.start, declarator.end));
|
|
8675
|
+
}
|
|
8676
|
+
if (kept.length === 0) continue;
|
|
8677
|
+
if (kept.length < statement.declarations.length) {
|
|
8678
|
+
code = `${statement.kind} ${kept.join(", ")};`;
|
|
8679
|
+
partial = true;
|
|
8680
|
+
}
|
|
8681
|
+
}
|
|
8514
8682
|
if (index < lastAwait && statement.type === "VariableDeclaration") {
|
|
8515
|
-
if (statement.kind === "const") code = `let${this.patch.slice(statement.start + 5, statement.end)}`;
|
|
8683
|
+
if (statement.kind === "const") code = partial ? `let${code.slice(5)}` : `let${this.patch.slice(statement.start + 5, statement.end)}`;
|
|
8516
8684
|
for (const declaration of scope.declarations.values()) if (declaration.range.start >= statement.start && declaration.range.end <= statement.end) this.reassignable.add(declaration);
|
|
8517
8685
|
}
|
|
8518
8686
|
this.raw(code, statement.start);
|
|
@@ -8630,18 +8798,19 @@ var Emitter = class {
|
|
|
8630
8798
|
}
|
|
8631
8799
|
}
|
|
8632
8800
|
/**
|
|
8633
|
-
* In the browser, a memo that
|
|
8634
|
-
*
|
|
8635
|
-
*
|
|
8636
|
-
*
|
|
8637
|
-
*
|
|
8638
|
-
* same promise.
|
|
8801
|
+
* In the browser, a memo that only `await` reads has no slot, so no load takes its promise.
|
|
8802
|
+
* The server waits at the `await` and throws the error there, so the rejection goes to the
|
|
8803
|
+
* nearest `#try`, which is where a memo that throws sends its error. A memo that always gives a
|
|
8804
|
+
* primitive, such as `count * 2`, is never a promise, unless it has `await` inside. `await memo`
|
|
8805
|
+
* compiles to a plain read of the promise, which drops it, unless the read is the whole value of
|
|
8806
|
+
* another memo, as in `$memo(await memo)`, which then holds the same promise. A memo that
|
|
8807
|
+
* nothing reads is not declared (`Graph.unread`), and neither is one that only such a memo reads.
|
|
8639
8808
|
*/
|
|
8640
8809
|
watchUnreadMemos(statement, scope, splits) {
|
|
8641
8810
|
const awaited = splits ? this.markupAwaits(scope) : [];
|
|
8642
8811
|
for (const declarator of statement.declarations) {
|
|
8643
8812
|
const declaration = declarator.id.type === "Identifier" ? scope.declarations.get(declarator.id.name) : void 0;
|
|
8644
|
-
if (declaration && !awaited.includes(declaration) && (declaration.kind === "memo" || declaration.kind === "async-memo") && declaration.reads.every((read) => read.await && (read.site.kind !== "memo" || read.site.node.start !== read.await.start || read.site.node.end !== read.await.end)) && slotIndex(this.plan, declaration) === -1 && !isNeverPromise(declaration)) {
|
|
8813
|
+
if (declaration && !awaited.includes(declaration) && (declaration.kind === "memo" || declaration.kind === "async-memo") && !this.plan.graph.unread.has(declaration) && declaration.reads.every((read) => read.site.kind === "memo" && this.plan.graph.unread.has(read.site.declaration) || read.await && (read.site.kind !== "memo" || read.site.node.start !== read.await.start || read.site.node.end !== read.await.end)) && slotIndex(this.plan, declaration) === -1 && !isNeverPromise(declaration)) {
|
|
8645
8814
|
const target = this.scopeVar(instanceScope(this.plan, scope));
|
|
8646
8815
|
this.line(`$$b.unreadMemo(${target}, ${declaration.name});`);
|
|
8647
8816
|
}
|
|
@@ -8945,9 +9114,9 @@ var Emitter = class {
|
|
|
8945
9114
|
if (setter) return `${event}=$set:${this.plan.id}#${setter}`;
|
|
8946
9115
|
return `${event}=$bind#${hops}.${slotIndex(this.plan, binding.declaration)}`;
|
|
8947
9116
|
}
|
|
8948
|
-
eventEntry({ event,
|
|
9117
|
+
eventEntry({ event, handler }) {
|
|
8949
9118
|
const site = this.sitesByNode.get(handler.ast);
|
|
8950
|
-
return `${[event, ...[
|
|
9119
|
+
return `${[event, ...[...new Set(site.modifiers ?? [])]].join(":")}=${this.plan.id}#${this.plan.symbols.get(site)}`;
|
|
8951
9120
|
}
|
|
8952
9121
|
emitRef(target, attribute, anchor, when) {
|
|
8953
9122
|
const declaration = this.refTargets.get(attribute);
|
|
@@ -9248,7 +9417,7 @@ var Emitter = class {
|
|
|
9248
9417
|
this.line(`let $$html = '';`);
|
|
9249
9418
|
this.atTopLevel(() => this.emitNodes(nodes, scope));
|
|
9250
9419
|
this.flush();
|
|
9251
|
-
const cloned = this.options.hoist !== void 0 && cloneLines(this, this.options.hoist, fn);
|
|
9420
|
+
const cloned = this.options.hoist !== void 0 && cloneLines(this, this.options.hoist, fn, node);
|
|
9252
9421
|
this.line(this.returnLine(fn, cloned));
|
|
9253
9422
|
this.close("});");
|
|
9254
9423
|
return name;
|
|
@@ -9449,7 +9618,7 @@ var Emitter = class {
|
|
|
9449
9618
|
this.headBlocks -= block.kind === "head" ? 1 : 0;
|
|
9450
9619
|
this.html("<!--/P-->");
|
|
9451
9620
|
this.flush();
|
|
9452
|
-
const cloned = this.options.mode === "client" && this.options.hoist !== void 0 && cloneLines(this, this.options.hoist, fn);
|
|
9621
|
+
const cloned = this.options.mode === "client" && this.options.hoist !== void 0 && cloneLines(this, this.options.hoist, fn, block.body);
|
|
9453
9622
|
this.line(cloned ? "return $$f;" : "return $$html;");
|
|
9454
9623
|
this.close("})();");
|
|
9455
9624
|
this.line(`${this.helper(block.kind === "head" ? "head" : "portal")}(${name});`);
|
|
@@ -9624,7 +9793,7 @@ var Emitter = class {
|
|
|
9624
9793
|
this.line(`let $$html = '';`);
|
|
9625
9794
|
this.splitBody(scope, content, () => {
|
|
9626
9795
|
this.flush();
|
|
9627
|
-
const cloned = this.options.hoist !== void 0 && cloneLines(this, this.options.hoist, fn);
|
|
9796
|
+
const cloned = this.options.hoist !== void 0 && cloneLines(this, this.options.hoist, fn, scope?.body);
|
|
9628
9797
|
this.line(this.returnLine(fn, cloned));
|
|
9629
9798
|
});
|
|
9630
9799
|
this.close("};");
|
|
@@ -10318,6 +10487,8 @@ var Rewriter = class {
|
|
|
10318
10487
|
shared;
|
|
10319
10488
|
/** The sites of `$handler` calls, by call. */
|
|
10320
10489
|
handlers = /* @__PURE__ */ new Map();
|
|
10490
|
+
/** The signals of `$searchParam` calls, by call. */
|
|
10491
|
+
searches = /* @__PURE__ */ new Map();
|
|
10321
10492
|
/** The declarations of the names of `$bind` calls, by call. */
|
|
10322
10493
|
bindings = /* @__PURE__ */ new Map();
|
|
10323
10494
|
constructor(file, plan, diagnostics, shared) {
|
|
@@ -10326,6 +10497,7 @@ var Rewriter = class {
|
|
|
10326
10497
|
this.diagnostics = diagnostics;
|
|
10327
10498
|
this.shared = shared;
|
|
10328
10499
|
for (const site of plan.graph.model.sites) if (site.handler) this.handlers.set(site.handler, site);
|
|
10500
|
+
for (const declaration of plan.graph.model.declarations) if (declaration.searchParam) this.searches.set(declaration.searchParam, declaration);
|
|
10329
10501
|
for (const binding of plan.graph.model.bindings) this.bindings.set(binding.call, binding);
|
|
10330
10502
|
}
|
|
10331
10503
|
/**
|
|
@@ -10572,6 +10744,13 @@ var Rewriter = class {
|
|
|
10572
10744
|
for (const argument of node.arguments) visit(argument);
|
|
10573
10745
|
return;
|
|
10574
10746
|
}
|
|
10747
|
+
const searched = this.searches.get(node);
|
|
10748
|
+
if (searched && node.arguments[0]) {
|
|
10749
|
+
const slot = slotIndex(this.plan, searched);
|
|
10750
|
+
patch.replace(node.start, node.arguments[0].start, `$$b.paramEffect(${path(searched)}, ${slot}, `);
|
|
10751
|
+
for (const argument of node.arguments) visit(argument);
|
|
10752
|
+
return;
|
|
10753
|
+
}
|
|
10575
10754
|
if (node.callee.type === "Identifier" && node.callee.name === "$isBound" && !references.has(node.callee.start)) {
|
|
10576
10755
|
const prop = node.arguments[0];
|
|
10577
10756
|
const declaration = prop && references.get(prop.start)?.declaration;
|
|
@@ -11351,7 +11530,7 @@ var ClientGenerator = class {
|
|
|
11351
11530
|
}
|
|
11352
11531
|
}
|
|
11353
11532
|
if (attribute.kind === "event" && site) {
|
|
11354
|
-
const all = [
|
|
11533
|
+
const all = [...new Set(site.modifiers ?? [])];
|
|
11355
11534
|
const entry = `${[attribute.event, ...all].join(":")}=${this.plan.id}#${this.plan.symbols.get(site)}@`;
|
|
11356
11535
|
entries.push(`${JSON.stringify(entry)} + $$s.id`);
|
|
11357
11536
|
}
|
|
@@ -11593,8 +11772,8 @@ var ClientGenerator = class {
|
|
|
11593
11772
|
* Replaces the one `$$html +=` line of a render with a clone of a template and the writes on
|
|
11594
11773
|
* its elements. Returns false when the markup needs HTML.
|
|
11595
11774
|
*/
|
|
11596
|
-
cloneRender(emitter) {
|
|
11597
|
-
return cloneLines(emitter, (code) => this.hoist(code));
|
|
11775
|
+
cloneRender(emitter, body) {
|
|
11776
|
+
return cloneLines(emitter, (code) => this.hoist(code), 0, body);
|
|
11598
11777
|
}
|
|
11599
11778
|
/**
|
|
11600
11779
|
* The code of the render function of a body. With `fill`, the body fills its nested blocks
|
|
@@ -11632,7 +11811,7 @@ var ClientGenerator = class {
|
|
|
11632
11811
|
else emitter.emitBody(body);
|
|
11633
11812
|
}, () => {
|
|
11634
11813
|
emitter.flush();
|
|
11635
|
-
cloned =
|
|
11814
|
+
cloned = this.cloneRender(emitter, body);
|
|
11636
11815
|
emitter.line(emitter.returnLine(0, cloned));
|
|
11637
11816
|
});
|
|
11638
11817
|
if (fill && !cloned) return;
|
|
@@ -11760,7 +11939,7 @@ var ClientGenerator = class {
|
|
|
11760
11939
|
for (const template of this.declared(inside)) if (template.kind === "template") emitter.emitTemplate(template.template);
|
|
11761
11940
|
emitter.emitChildrenBody(node, scope);
|
|
11762
11941
|
emitter.flush();
|
|
11763
|
-
const cloned = cloneLines(emitter, (code) => this.hoist(code));
|
|
11942
|
+
const cloned = cloneLines(emitter, (code) => this.hoist(code), 0, node);
|
|
11764
11943
|
emitter.line(emitter.returnLine(0, cloned));
|
|
11765
11944
|
emitter.close();
|
|
11766
11945
|
this.emit(emitter.lines.join("\n"));
|
|
@@ -12392,4 +12571,4 @@ function inspect(source, options = {}) {
|
|
|
12392
12571
|
//#endregion
|
|
12393
12572
|
export { analyzeProject as A, getLocation as B, isReactiveModule as C, unmarked as D, originalPosition as E, summarize as F, isWithin as G, findError as H, parse$1 as I, walk as J, lookup as K, buildGraph as L, importSource as M, importedComponents as N, entryClasses as O, resolveRelative as P, forEachNode as R, sharedSites as S, builtin as T, analyze$1 as U, errorLink as V, getPatternNames as W, functionId as _, scopeLabel as a, SHARED_QUERY as b, DEFAULT_MERGE as c, generateServer as d, instanceScope as f, createPlan as g, clientState as h, report as i, analyzeProjectProps as j, refreshedNames as k, generateClient as l, blockBodies as m, formatReport as n, CompileError as o, slotIndex as p, resolveMacros as q, inspect as r, compile as s, anchorLabel as t, generateRender as u, getComponentName as v, resolveFromDisk as w, generateShared as x, hash as y, BrumateError as z };
|
|
12394
12573
|
|
|
12395
|
-
//# sourceMappingURL=inspect-
|
|
12574
|
+
//# sourceMappingURL=inspect-ddfGeww0.js.map
|