brumate 0.6.0 → 0.6.1
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-CMvhoWRu.d.ts → boot-DkbcqdUz.d.ts} +2 -2
- package/dist/cli.js +2 -2
- package/dist/{client-eVI8Wc95.js → client-C3vRNuLi.js} +186 -78
- package/dist/client-C3vRNuLi.js.map +1 -0
- package/dist/{client-C4kNKGwH.d.ts → client-CqGDbWd_.d.ts} +29 -5
- package/dist/{defer-pKO0S6UT.js → defer-M18UKyfG.js} +2 -2
- package/dist/{defer-pKO0S6UT.js.map → defer-M18UKyfG.js.map} +1 -1
- package/dist/{devtools-DqqqdI4b.js → devtools-YnvrZ6D8.js} +4 -4
- package/dist/{devtools-DqqqdI4b.js.map → devtools-YnvrZ6D8.js.map} +1 -1
- package/dist/{devtools-panel--GYjFZ35.js → devtools-panel-DRcKclEG.js} +2 -2
- package/dist/{devtools-panel--GYjFZ35.js.map → devtools-panel-DRcKclEG.js.map} +1 -1
- package/dist/{files-CR-V05xd.js → files-HzPDUyTY.js} +2 -2
- package/dist/{files-CR-V05xd.js.map → files-HzPDUyTY.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/{inspect-ddfGeww0.js → inspect-Q5W0A66e.js} +241 -66
- package/dist/inspect-Q5W0A66e.js.map +1 -0
- package/dist/{loader-CQkAXO0g.js → loader-C-S3yzep.js} +4 -4
- package/dist/{loader-CQkAXO0g.js.map → loader-C-S3yzep.js.map} +1 -1
- package/dist/{navigate-BcV1qkkx.js → navigate-r23FFR6e.js} +5 -2
- package/dist/{navigate-BcV1qkkx.js.map → navigate-r23FFR6e.js.map} +1 -1
- package/dist/{rpc-BgYnfg_a.js → rpc-C_znDZ_w.js} +2 -2
- package/dist/{rpc-BgYnfg_a.js.map → rpc-C_znDZ_w.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 +2 -2
- 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/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.d.ts +1 -1
- package/dist/runtime/testing.js +1 -1
- package/dist/{static-loader-DCxASuzA.js → static-loader-Bt2WDkY1.js} +2 -2
- package/dist/{static-loader-DCxASuzA.js.map → static-loader-Bt2WDkY1.js.map} +1 -1
- package/dist/{static-loader-CGthkX0s.d.ts → static-loader-DysAET-w.d.ts} +2 -2
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +3 -3
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +8 -2
- package/package.json +1 -1
- package/skills/brumate/references/errors.md +14 -0
- package/dist/client-eVI8Wc95.js.map +0 -1
- package/dist/inspect-ddfGeww0.js.map +0 -1
|
@@ -1935,6 +1935,7 @@ const SYNTAX = [
|
|
|
1935
1935
|
entry("BRM021", "Expected an attribute name", "A tag has a character where an attribute name belongs.", "<input disabled>"),
|
|
1936
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>"),
|
|
1937
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) />"),
|
|
1938
|
+
entry("BRM201", "\"{name}\" cannot be a handler. {fix}", "The event has capitals in its name, or the browser fires another name for it, and a handler name is lower-cased to the event. `onDOMContentLoaded` would listen to `domcontentloaded`, which the browser never fires, and page code loads after the HTML, mostly after `DOMContentLoaded`. Use the event that the message names, or `$client(fn, 'load')` to run code at load.", "<script>\n $client(() => {\n start();\n }, 'load');\n<\/script>"),
|
|
1938
1939
|
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}"),
|
|
1939
1940
|
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>"),
|
|
1940
1941
|
entry("BRM183", "$resolve needs a $memo and, as an option, a timeout or a signal", "`$resolve` takes the name of a memo, and one object of options at most.", "async function save() {\n const profile = await $resolve(user, { timeout: 5000 });\n}"),
|
|
@@ -2315,6 +2316,18 @@ function callsRefreshed(declaration) {
|
|
|
2315
2316
|
for (const callee of declaration.site?.calls ?? []) if (callee.refreshed) return true;
|
|
2316
2317
|
return false;
|
|
2317
2318
|
}
|
|
2319
|
+
/**
|
|
2320
|
+
* True for a `$searchParam` that the browser can change without a request: the URL is the source
|
|
2321
|
+
* when the page loads, and the history writes it. One with `server: true` navigates instead. A spread in the options may hold `server`, and
|
|
2322
|
+
* such a signal stays live, which costs a slot and breaks nothing.
|
|
2323
|
+
*/
|
|
2324
|
+
function followsUrl(declaration) {
|
|
2325
|
+
const options = declaration.searchParam?.arguments[1];
|
|
2326
|
+
if (!declaration.searchParam) return false;
|
|
2327
|
+
if (options?.type !== "ObjectExpression") return true;
|
|
2328
|
+
for (const property of options.properties) if (property.type === "Property" && property.key.type === "Identifier" && property.key.name === "server") return false;
|
|
2329
|
+
return true;
|
|
2330
|
+
}
|
|
2318
2331
|
/** True if the declaration is referenced from one of the scopes. */
|
|
2319
2332
|
function hasRefIn(declaration, scopes) {
|
|
2320
2333
|
for (const ref of declaration.refs) if (scopes.has(ref.scope)) return true;
|
|
@@ -2557,7 +2570,7 @@ function buildGraph(model, options = {}) {
|
|
|
2557
2570
|
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);
|
|
2558
2571
|
for (const [declaration, node] of declarationNodes) {
|
|
2559
2572
|
if (live.has(node)) continue;
|
|
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);
|
|
2573
|
+
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) || followsUrl(declaration)) || declaration.kind === "error" && declaration.block?.kind === "try" && tryChanges(declaration.block) || declaration.bound === true || declaration.kind === "template-param" && templateCallChanges(declaration.scope)) live.add(node);
|
|
2561
2574
|
}
|
|
2562
2575
|
for (let propagated = true; propagated;) {
|
|
2563
2576
|
propagated = false;
|
|
@@ -2722,6 +2735,31 @@ function camelEventName(attribute) {
|
|
|
2722
2735
|
const camel = BY_LOWER.get(attribute.toLowerCase());
|
|
2723
2736
|
return camel === attribute ? void 0 : camel;
|
|
2724
2737
|
}
|
|
2738
|
+
const NO_HANDLER = /* @__PURE__ */ new Map([
|
|
2739
|
+
["domcontentloaded", "The page code loads after the HTML, mostly after this event, and a client navigation never fires it. Run code at load with $client(fn, 'load')"],
|
|
2740
|
+
["domactivate", "The event is deprecated. Write onClick"],
|
|
2741
|
+
["domfocusin", "The event is deprecated. Write onFocusIn"],
|
|
2742
|
+
["domfocusout", "The event is deprecated. Write onFocusOut"],
|
|
2743
|
+
["dommousescroll", "The event is not standard. Write onWheel"],
|
|
2744
|
+
["mozmousepixelscroll", "The event is not standard. Write onWheel"],
|
|
2745
|
+
["webkitanimationstart", "The browser fires the prefixed name only. Write onAnimationStart"],
|
|
2746
|
+
["webkitanimationiteration", "The browser fires the prefixed name only. Write onAnimationIteration"],
|
|
2747
|
+
["webkitanimationend", "The browser fires the prefixed name only. Write onAnimationEnd"],
|
|
2748
|
+
["webkittransitionend", "The browser fires the prefixed name only. Write onTransitionEnd"]
|
|
2749
|
+
]);
|
|
2750
|
+
for (const mutation of [
|
|
2751
|
+
"DOMAttrModified",
|
|
2752
|
+
"DOMCharacterDataModified",
|
|
2753
|
+
"DOMNodeInserted",
|
|
2754
|
+
"DOMNodeInsertedIntoDocument",
|
|
2755
|
+
"DOMNodeRemoved",
|
|
2756
|
+
"DOMNodeRemovedFromDocument",
|
|
2757
|
+
"DOMSubtreeModified"
|
|
2758
|
+
]) NO_HANDLER.set(mutation.toLowerCase(), "The event is removed. Observe the DOM with a MutationObserver");
|
|
2759
|
+
/** What to write instead of a handler for an event that has none, such as `onDOMContentLoaded`. */
|
|
2760
|
+
function noHandlerFix(attribute) {
|
|
2761
|
+
return NO_HANDLER.get(attribute.slice(2).toLowerCase());
|
|
2762
|
+
}
|
|
2725
2763
|
//#endregion
|
|
2726
2764
|
//#region src/scan.ts
|
|
2727
2765
|
function isWhitespace(char) {
|
|
@@ -3222,8 +3260,11 @@ var Parser = class {
|
|
|
3222
3260
|
}
|
|
3223
3261
|
/** A handler of an element is written in camel case: `onKeyDown`, not `onKeydown`. */
|
|
3224
3262
|
checkEventName(name, owner, start) {
|
|
3225
|
-
|
|
3263
|
+
if (owner === "component" || owner === "dynamic") return;
|
|
3264
|
+
const camel = camelEventName(name);
|
|
3226
3265
|
if (camel) this.fail(`"${name}" is not an event name. Write "${camel}"`, start);
|
|
3266
|
+
const fix = noHandlerFix(name);
|
|
3267
|
+
if (fix) this.fail(`"${name}" cannot be a handler. ${fix}`, start);
|
|
3227
3268
|
}
|
|
3228
3269
|
parseAttribute(owner) {
|
|
3229
3270
|
const start = this.pos;
|
|
@@ -5221,6 +5262,38 @@ function expandModules(file, path, resolve) {
|
|
|
5221
5262
|
};
|
|
5222
5263
|
}
|
|
5223
5264
|
//#endregion
|
|
5265
|
+
//#region src/codegen/primitive.ts
|
|
5266
|
+
/**
|
|
5267
|
+
* True if an expression always gives a primitive, so it is never a promise
|
|
5268
|
+
* or an async iterable. A name is a primitive when `plain` says that it reads
|
|
5269
|
+
* a declaration that holds one.
|
|
5270
|
+
*/
|
|
5271
|
+
function isPrimitive(node, plain = () => false) {
|
|
5272
|
+
switch (node.type) {
|
|
5273
|
+
case "Identifier": return plain(node);
|
|
5274
|
+
case "Literal": return !("regex" in node && node.regex);
|
|
5275
|
+
case "TemplateLiteral":
|
|
5276
|
+
case "BinaryExpression":
|
|
5277
|
+
case "UnaryExpression": return true;
|
|
5278
|
+
case "LogicalExpression": return isPrimitive(node.left, plain) && isPrimitive(node.right, plain);
|
|
5279
|
+
case "ConditionalExpression": return isPrimitive(node.consequent, plain) && isPrimitive(node.alternate, plain);
|
|
5280
|
+
case "TSAsExpression":
|
|
5281
|
+
case "TSSatisfiesExpression":
|
|
5282
|
+
case "TSNonNullExpression": return isPrimitive(node.expression, plain);
|
|
5283
|
+
default: return false;
|
|
5284
|
+
}
|
|
5285
|
+
}
|
|
5286
|
+
/** Expressions whose value is never a promise, as the memo of a list or a function. */
|
|
5287
|
+
const NEVER_PROMISE = /* @__PURE__ */ new Set([
|
|
5288
|
+
"ArrayExpression",
|
|
5289
|
+
"ArrowFunctionExpression",
|
|
5290
|
+
"FunctionExpression"
|
|
5291
|
+
]);
|
|
5292
|
+
/** True for an expression that gives a primitive, an array or a function, never a promise. */
|
|
5293
|
+
function neverPromise(node) {
|
|
5294
|
+
return isPrimitive(node) || NEVER_PROMISE.has(node.type);
|
|
5295
|
+
}
|
|
5296
|
+
//#endregion
|
|
5224
5297
|
//#region src/codegen/patch.ts
|
|
5225
5298
|
/** Rewrites ranges of the source with edits that do not overlap. */
|
|
5226
5299
|
var Patch = class {
|
|
@@ -5268,6 +5341,16 @@ const MEMOS = /* @__PURE__ */ new Set([
|
|
|
5268
5341
|
"$debounced",
|
|
5269
5342
|
"$throttled"
|
|
5270
5343
|
]);
|
|
5344
|
+
/**
|
|
5345
|
+
* The code of an arrow function body, given the source offset where the user's expression starts.
|
|
5346
|
+
* An expression that starts with `{` is wrapped in parentheses, or the arrow reads it as a block.
|
|
5347
|
+
* This covers an object literal under `as`, `satisfies`, `!` and a `<T>` cast, and a sequence or
|
|
5348
|
+
* member access that starts with one. The source is checked, not the code, because the code can
|
|
5349
|
+
* start with a marker of the compiler.
|
|
5350
|
+
*/
|
|
5351
|
+
function arrowBody(code, source, start) {
|
|
5352
|
+
return source[start] === "{" ? `(${code})` : code;
|
|
5353
|
+
}
|
|
5271
5354
|
function promiseName(name) {
|
|
5272
5355
|
return `$$p_${name}`;
|
|
5273
5356
|
}
|
|
@@ -5339,11 +5422,18 @@ function addValueEdits(patch, file, sites, mode = "server", inline = /* @__PURE_
|
|
|
5339
5422
|
for (const read of site.reads) if (read.range.start !== read.range.end && read.range.start >= node.start && read.range.end <= node.end && !targets.has(read.range.start) && !isFolded(read) && read.declaration !== own && !inline.has(read.declaration) && (!only || only.has(read.declaration)) && !replaced.has(read) && !replacedAt.has((read.await ?? read.range).start) && (read.declaration.kind === "memo" || read.declaration.kind === "async-memo")) {
|
|
5340
5423
|
const range = read.await ?? read.range;
|
|
5341
5424
|
const key = shorthands.has(range.start) ? `${read.declaration.name}: ` : "";
|
|
5342
|
-
patch.replace(range.start, range.end, `${key}$$b.read(${promiseName(read.declaration.name)})`);
|
|
5425
|
+
patch.replace(range.start, range.end, mode === "render" ? `${key}$$b.readMemo(${read.declaration.name})` : `${key}$$b.read(${promiseName(read.declaration.name)})`);
|
|
5343
5426
|
replaced.add(read);
|
|
5344
5427
|
replacedAt.add(range.start);
|
|
5345
5428
|
}
|
|
5346
5429
|
}
|
|
5430
|
+
if (mode === "render") {
|
|
5431
|
+
const held = /* @__PURE__ */ new Set();
|
|
5432
|
+
for (const site of sites) if (site.kind === "memo" && site.declaration && !inline.has(site.declaration)) {
|
|
5433
|
+
if (site.awaits || !neverPromise(site.node)) held.add(site.declaration);
|
|
5434
|
+
}
|
|
5435
|
+
for (const site of sites) readMemos(site, site.node, site.declaration, held);
|
|
5436
|
+
}
|
|
5347
5437
|
if (mode === "server") {
|
|
5348
5438
|
for (const site of sites) if (site.kind === "function") readMemos(site, site.node);
|
|
5349
5439
|
if (lazy.size > 0) {
|
|
@@ -5420,6 +5510,9 @@ function addValueEdits(patch, file, sites, mode = "server", inline = /* @__PURE_
|
|
|
5420
5510
|
readMemos(site, argument, declaration);
|
|
5421
5511
|
patch.replace(node.start, argument.start, site.awaits ? "$$b.memo(async () => (" : "$$b.memo(() => (");
|
|
5422
5512
|
patch.replace(argument.end, node.end, `), $$ctx, ${JSON.stringify(declaration.name)})`);
|
|
5513
|
+
} else if (mode === "render" && declaration && (site.awaits || !neverPromise(argument))) {
|
|
5514
|
+
patch.replace(node.start, argument.start, site.awaits ? "$$b.renderMemo(async () => (" : "$$b.renderMemo(() => (");
|
|
5515
|
+
patch.replace(argument.end, node.end, "))");
|
|
5423
5516
|
} else if (site?.awaits) {
|
|
5424
5517
|
patch.replace(node.start, argument.start, "(async () => (");
|
|
5425
5518
|
patch.replace(argument.end, node.end, "))()");
|
|
@@ -6688,7 +6781,8 @@ const ATTRIBUTE = /^\$\$b\.attribute\(("(?:[^"\\]|\\.)*"), ([\s\S]*)\)$/;
|
|
|
6688
6781
|
const CLASS_TOKEN = /^\(\(([\s\S]*)\) \? " ([^"\\&<>]+)" : ""\)$/;
|
|
6689
6782
|
/**
|
|
6690
6783
|
* The static classes of a `class` with code in its quotes, and the calls that add the classes
|
|
6691
|
-
* that conditions add, when each piece of code is such a condition
|
|
6784
|
+
* that conditions add, when each piece of code is such a condition and no static class follows
|
|
6785
|
+
* one, so the classes keep their order. `parts` are the parts of
|
|
6692
6786
|
* the value after its static `prefix`, up to its closing quote.
|
|
6693
6787
|
*/
|
|
6694
6788
|
function classTokens(parts, prefix) {
|
|
@@ -6696,6 +6790,7 @@ function classTokens(parts, prefix) {
|
|
|
6696
6790
|
const calls = [];
|
|
6697
6791
|
for (const part of parts) {
|
|
6698
6792
|
if ("static" in part) {
|
|
6793
|
+
if (calls.length > 0 && part.static.trim() !== "") return;
|
|
6699
6794
|
text += part.static;
|
|
6700
6795
|
continue;
|
|
6701
6796
|
}
|
|
@@ -7508,6 +7603,50 @@ function scopePath(plan, base, from, target) {
|
|
|
7508
7603
|
}
|
|
7509
7604
|
return expression;
|
|
7510
7605
|
}
|
|
7606
|
+
/**
|
|
7607
|
+
* The parameters of a template of the file, and the `[slot, value]` pairs of its arguments, so a
|
|
7608
|
+
* call that comes again writes its new arguments into the scope that it rendered. `params` are
|
|
7609
|
+
* the parameters as written, `exported` have no default values (the call passes the values with
|
|
7610
|
+
* them), and `names` are the arguments when each parameter is a name and one has a default.
|
|
7611
|
+
* Nothing if the template has no scope of its own, or a destructured parameter has a default
|
|
7612
|
+
* value: it then renders again. An argument that no slot holds is never read in the browser.
|
|
7613
|
+
*/
|
|
7614
|
+
function templateArgs(plan, source, scope) {
|
|
7615
|
+
const template = scope.template;
|
|
7616
|
+
if (!template || !plan.scopes.get(scope)?.needsId) return;
|
|
7617
|
+
const first = template.params[0];
|
|
7618
|
+
const last = template.params.at(-1);
|
|
7619
|
+
const params = first && last ? copy(source, first.start, last.end) : "";
|
|
7620
|
+
const exported = [];
|
|
7621
|
+
const names = [];
|
|
7622
|
+
let simple = true;
|
|
7623
|
+
let defaults = false;
|
|
7624
|
+
for (const param of template.params) {
|
|
7625
|
+
const target = param.type === "AssignmentPattern" ? param.left : param;
|
|
7626
|
+
defaults ||= target !== param;
|
|
7627
|
+
if (target.type === "Identifier") names.push(target.name);
|
|
7628
|
+
else simple = false;
|
|
7629
|
+
if (target.type !== "Identifier" && hasDefault(target)) return;
|
|
7630
|
+
exported.push(copy(source, target.start, target.end));
|
|
7631
|
+
}
|
|
7632
|
+
const pairs = [];
|
|
7633
|
+
for (const declaration of scope.declarations.values()) {
|
|
7634
|
+
if (declaration.kind !== "template-param") continue;
|
|
7635
|
+
const slot = slotIndex(plan, declaration);
|
|
7636
|
+
if (slot !== -1) pairs.push(`[${slot}, ${declaration.name}]`);
|
|
7637
|
+
}
|
|
7638
|
+
return {
|
|
7639
|
+
params,
|
|
7640
|
+
exported: exported.join(", "),
|
|
7641
|
+
names: simple && defaults ? names : void 0,
|
|
7642
|
+
pairs
|
|
7643
|
+
};
|
|
7644
|
+
}
|
|
7645
|
+
function hasDefault(node) {
|
|
7646
|
+
if (node.type === "AssignmentPattern") return true;
|
|
7647
|
+
for (const [, child] of children(node)) if (hasDefault(child)) return true;
|
|
7648
|
+
return false;
|
|
7649
|
+
}
|
|
7511
7650
|
/** Returns the slot index of a declaration, or -1. */
|
|
7512
7651
|
function slotIndex(plan, declaration) {
|
|
7513
7652
|
return plan.scopes.get(declaration.scope)?.slots.indexOf(declaration) ?? -1;
|
|
@@ -7761,26 +7900,6 @@ const UNSAFE_NODES = /* @__PURE__ */ new Set([
|
|
|
7761
7900
|
"ArrowFunctionExpression",
|
|
7762
7901
|
"ClassExpression"
|
|
7763
7902
|
]);
|
|
7764
|
-
/**
|
|
7765
|
-
* True if an expression always gives a primitive, so it is never a promise
|
|
7766
|
-
* or an async iterable. A name is a primitive when `plain` says that it reads
|
|
7767
|
-
* a declaration that holds one.
|
|
7768
|
-
*/
|
|
7769
|
-
function isPrimitive(node, plain = () => false) {
|
|
7770
|
-
switch (node.type) {
|
|
7771
|
-
case "Identifier": return plain(node);
|
|
7772
|
-
case "Literal": return !("regex" in node && node.regex);
|
|
7773
|
-
case "TemplateLiteral":
|
|
7774
|
-
case "BinaryExpression":
|
|
7775
|
-
case "UnaryExpression": return true;
|
|
7776
|
-
case "LogicalExpression": return isPrimitive(node.left, plain) && isPrimitive(node.right, plain);
|
|
7777
|
-
case "ConditionalExpression": return isPrimitive(node.consequent, plain) && isPrimitive(node.alternate, plain);
|
|
7778
|
-
case "TSAsExpression":
|
|
7779
|
-
case "TSSatisfiesExpression":
|
|
7780
|
-
case "TSNonNullExpression": return isPrimitive(node.expression, plain);
|
|
7781
|
-
default: return false;
|
|
7782
|
-
}
|
|
7783
|
-
}
|
|
7784
7903
|
/** True if an expression calls no code and, unless `members`, reads no property. */
|
|
7785
7904
|
function isSafe(node, members) {
|
|
7786
7905
|
if (UNSAFE_NODES.has(node.type)) return false;
|
|
@@ -7885,12 +8004,6 @@ const TYPE_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
|
7885
8004
|
"TSDeclareFunction",
|
|
7886
8005
|
"TSModuleDeclaration"
|
|
7887
8006
|
]);
|
|
7888
|
-
/** Expressions whose value is never a promise, as the memo of a list or a function. */
|
|
7889
|
-
const NEVER_PROMISE = /* @__PURE__ */ new Set([
|
|
7890
|
-
"ArrayExpression",
|
|
7891
|
-
"ArrowFunctionExpression",
|
|
7892
|
-
"FunctionExpression"
|
|
7893
|
-
]);
|
|
7894
8007
|
/**
|
|
7895
8008
|
* True for a memo whose value is never a promise in the browser, such as `count * 2`, an array or
|
|
7896
8009
|
* a function. A memo with `await` inside is an async function, so its value is a promise whatever
|
|
@@ -7908,7 +8021,7 @@ const MARKUP_SITES = /* @__PURE__ */ new Set([
|
|
|
7908
8021
|
]);
|
|
7909
8022
|
function isNeverPromise(declaration) {
|
|
7910
8023
|
const node = declaration.site?.node;
|
|
7911
|
-
return declaration.kind === "memo" && node !== void 0 && (
|
|
8024
|
+
return declaration.kind === "memo" && node !== void 0 && neverPromise(node);
|
|
7912
8025
|
}
|
|
7913
8026
|
/**
|
|
7914
8027
|
* True for a memo that can hold a promise in the browser: an `await` in it makes one, and others
|
|
@@ -9000,11 +9113,20 @@ var Emitter = class {
|
|
|
9000
9113
|
const last = template.params.at(-1);
|
|
9001
9114
|
const params = first && last ? copy(this.file.source, first.start, last.end) : "";
|
|
9002
9115
|
const type = this.options.mode === "server" ? ": Promise<$$b.Raw>" : "";
|
|
9003
|
-
this.
|
|
9116
|
+
const scope = this.plan.bodyScopes.get(template.body);
|
|
9117
|
+
const call = this.options.mode === "client" && templateArgs(this.plan, this.file.source, scope);
|
|
9118
|
+
const name = call ? `${template.name}$` : template.name;
|
|
9119
|
+
if (call) {
|
|
9120
|
+
const own = call.names ? call.params : "...$$a";
|
|
9121
|
+
const given = call.names ? `[${call.names.join(", ")}]` : "$$a";
|
|
9122
|
+
const owner = this.scopeVar(instanceScope(this.plan, scope.parent));
|
|
9123
|
+
const ref = JSON.stringify(`${this.plan.id}#T${scope.id}`);
|
|
9124
|
+
this.line(`function ${template.name}(${own}) { return $$b.templateCall(${ref}, ${owner}, ${name}, ${given}); }`);
|
|
9125
|
+
}
|
|
9126
|
+
this.line(`${this.async}function ${name}(${params})${type} {`);
|
|
9004
9127
|
this.line(`let $$html = '';`);
|
|
9005
9128
|
this.atTopLevel(() => this.emitBody(template.body));
|
|
9006
9129
|
this.flush();
|
|
9007
|
-
const scope = this.plan.bodyScopes.get(template.body);
|
|
9008
9130
|
const at = this.plan.scopes.get(scope).needsId ? `, ${this.scopeVar(scope)}` : "";
|
|
9009
9131
|
this.line(`return $$b.raw($$html${at});`);
|
|
9010
9132
|
this.close();
|
|
@@ -10296,6 +10418,36 @@ function renderImport(file, statement, names) {
|
|
|
10296
10418
|
const target = source.endsWith(".brm") ? `${source}?brumate-render` : source;
|
|
10297
10419
|
return `import ${parts.join(", ")} from ${JSON.stringify(target)};`;
|
|
10298
10420
|
}
|
|
10421
|
+
/** The exports of the module script, from its declarations and its export lists. */
|
|
10422
|
+
function moduleExports(file, plan) {
|
|
10423
|
+
const result = [];
|
|
10424
|
+
for (const statement of file.moduleScript?.program.body ?? []) {
|
|
10425
|
+
if (statement.type !== "ExportNamedDeclaration" || statement.source) continue;
|
|
10426
|
+
if (statement.declaration) {
|
|
10427
|
+
for (const declaration of plan.graph.model.module.declarations.values()) if (declaration.kind === "module" && declaration.range.start >= statement.start && declaration.range.end <= statement.end) result.push({
|
|
10428
|
+
local: declaration.name,
|
|
10429
|
+
name: declaration.name
|
|
10430
|
+
});
|
|
10431
|
+
continue;
|
|
10432
|
+
}
|
|
10433
|
+
for (const specifier of statement.specifiers) {
|
|
10434
|
+
const local = file.source.slice(specifier.local.start, specifier.local.end);
|
|
10435
|
+
const name = file.source.slice(specifier.exported.start, specifier.exported.end);
|
|
10436
|
+
if (plan.graph.model.module.declarations.get(local)?.kind === "module") result.push({
|
|
10437
|
+
local,
|
|
10438
|
+
name
|
|
10439
|
+
});
|
|
10440
|
+
}
|
|
10441
|
+
}
|
|
10442
|
+
return result;
|
|
10443
|
+
}
|
|
10444
|
+
/** True if the render module imports names of the module script from the shared part. */
|
|
10445
|
+
function rendersModule(plan) {
|
|
10446
|
+
for (const site of plan.graph.model.sites) if (!SKIPPED_SITES.has(site.kind)) {
|
|
10447
|
+
for (const read of site.reads) if (read.declaration.kind === "module") return true;
|
|
10448
|
+
}
|
|
10449
|
+
return false;
|
|
10450
|
+
}
|
|
10299
10451
|
/** Returns the module script for client code. Server functions become `rpc` stubs. */
|
|
10300
10452
|
function clientModuleScript(file, plan) {
|
|
10301
10453
|
const result = [];
|
|
@@ -10325,14 +10477,16 @@ function awaitsPromise(plan) {
|
|
|
10325
10477
|
function generateRender(file, plan, getFill) {
|
|
10326
10478
|
const model = plan.graph.model;
|
|
10327
10479
|
const patch = new Patch(file.source);
|
|
10328
|
-
addValueEdits(patch, file, model.sites, "
|
|
10480
|
+
addValueEdits(patch, file, model.sites, "render", void 0, void 0, model.component.id);
|
|
10329
10481
|
const names = componentNames(file.children);
|
|
10330
10482
|
for (const template of file.templates) bodyNames(template.body, names);
|
|
10331
10483
|
for (const site of model.sites) if (!SKIPPED_SITES.has(site.kind)) for (const read of site.reads) names.add(read.declaration.name);
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10484
|
+
const moduleNames = [];
|
|
10485
|
+
const serverNames = [];
|
|
10486
|
+
for (const name of names) {
|
|
10487
|
+
const found = model.module.declarations.get(name);
|
|
10488
|
+
if (found?.kind === "module") moduleNames.push(name);
|
|
10489
|
+
else if (found?.kind === "server-function") serverNames.push(name);
|
|
10336
10490
|
}
|
|
10337
10491
|
const header = ["import * as $$b from 'brumate/client';"];
|
|
10338
10492
|
const moduleBody = [];
|
|
@@ -10343,16 +10497,19 @@ function generateRender(file, plan, getFill) {
|
|
|
10343
10497
|
for (const program of programs) {
|
|
10344
10498
|
const isModule = program === file.moduleScript?.program;
|
|
10345
10499
|
for (const statement of program.body) if (statement.type === "ImportDeclaration") {
|
|
10346
|
-
|
|
10347
|
-
if (isModule && usesModule) {
|
|
10348
|
-
const own = /* @__PURE__ */ new Set();
|
|
10349
|
-
for (const specifier of statement.specifiers) own.add(specifier.local.name);
|
|
10350
|
-
code = renderImport(file, statement, own);
|
|
10351
|
-
} else code = renderImport(file, statement, names);
|
|
10500
|
+
const code = renderImport(file, statement, names);
|
|
10352
10501
|
if (code) header.push(code);
|
|
10353
10502
|
} else if (!isModule && TYPE_DECLARATIONS.has(statement.type)) moduleBody.push(copy(file.source, statement.start, statement.end));
|
|
10354
10503
|
}
|
|
10355
|
-
|
|
10504
|
+
const exported = moduleNames.length > 0 ? moduleExports(file, plan) : [];
|
|
10505
|
+
const imports = new Set(moduleNames);
|
|
10506
|
+
for (const item of exported) imports.add(item.name);
|
|
10507
|
+
if (imports.size > 0) {
|
|
10508
|
+
const base = file.filename.split(/[\\/]/).pop();
|
|
10509
|
+
header.push(`import { ${[...imports].join(", ")} } from ${JSON.stringify(`./${base}?brumate-client&part=shared`)};`);
|
|
10510
|
+
}
|
|
10511
|
+
if (exported.length > 0) moduleBody.push(`export { ${exported.map((item) => item.name).join(", ")} };`);
|
|
10512
|
+
for (const name of serverNames) if (model.module.declarations.get(name)?.scope === model.module) moduleBody.push(`const ${name} = (...$$a) => $$b.rpc(${JSON.stringify(serverFunctionId(plan, name))}, $$a);`);
|
|
10356
10513
|
for (const declaration of model.declarations) if (declaration.kind === "server-function" && declaration.scope !== model.module) {
|
|
10357
10514
|
const ref = serverFunctionId(plan, declaration.name);
|
|
10358
10515
|
moduleBody.push(`const ${declaration.name} = (...$$a) => $$b.rpc(${JSON.stringify(ref)}, $$a);`);
|
|
@@ -10931,6 +11088,7 @@ var ClientGenerator = class {
|
|
|
10931
11088
|
this.emitFunctions();
|
|
10932
11089
|
this.emitRoots();
|
|
10933
11090
|
this.part = "update";
|
|
11091
|
+
this.emitTemplateExports();
|
|
10934
11092
|
this.emitUpdates();
|
|
10935
11093
|
this.emitWindowStarts();
|
|
10936
11094
|
this.emitRenders();
|
|
@@ -11142,7 +11300,7 @@ var ClientGenerator = class {
|
|
|
11142
11300
|
if (item.kind === "import") names.add(item.name);
|
|
11143
11301
|
if (item.kind === "function" && this.placement.get(item) === "shared" || item.kind === "module" && item.scope === this.model.module) shared.push(item.kind === "function" ? `${item.name}$` : item.name);
|
|
11144
11302
|
}
|
|
11145
|
-
const lines = ["import * as $$b from 'brumate/client';", ...this.importsFor(names, name === "update"
|
|
11303
|
+
const lines = ["import * as $$b from 'brumate/client';", ...this.importsFor(names, this.partScopes(name), name === "update")];
|
|
11146
11304
|
if (shared.length > 0) lines.push(`import { ${[...new Set(shared)].join(", ")} } from ${JSON.stringify(this.partPath("shared"))};`);
|
|
11147
11305
|
lines.push("", ...this.serverStubs([name]), ...this.out.get(name) ?? [], "");
|
|
11148
11306
|
return lines.join("\n");
|
|
@@ -11152,7 +11310,7 @@ var ClientGenerator = class {
|
|
|
11152
11310
|
const imports = /* @__PURE__ */ new Set();
|
|
11153
11311
|
for (const name of names) for (const item of this.reads(this.partSites(name))) if (item.kind === "import") imports.add(item.name);
|
|
11154
11312
|
const scopes = [...this.renderedScopes()];
|
|
11155
|
-
for (const name of names)
|
|
11313
|
+
for (const name of names) for (const scope of this.partScopes(name)) if (!scopes.includes(scope)) scopes.push(scope);
|
|
11156
11314
|
const lines = [
|
|
11157
11315
|
"import * as $$b from 'brumate/client';",
|
|
11158
11316
|
...this.importsFor(imports, scopes, names.includes("update")),
|
|
@@ -11172,9 +11330,7 @@ var ClientGenerator = class {
|
|
|
11172
11330
|
for (const statement of this.file.moduleScript.program.body) if (statement.type === "ImportDeclaration" && !isMacroImport(statement)) lines.push(copy(this.file.source, statement.start, statement.end));
|
|
11173
11331
|
lines.push(...clientModuleScript(this.file, this.plan));
|
|
11174
11332
|
const exported = /* @__PURE__ */ new Set();
|
|
11175
|
-
for (const
|
|
11176
|
-
for (const declaration of this.model.module.declarations.values()) if (declaration.range.start >= statement.start && declaration.range.end <= statement.end) exported.add(declaration.name);
|
|
11177
|
-
}
|
|
11333
|
+
for (const item of moduleExports(this.file, this.plan)) if (item.local === item.name) exported.add(item.name);
|
|
11178
11334
|
const rest = [];
|
|
11179
11335
|
for (const declaration of this.model.module.declarations.values()) if (declaration.kind === "module" && !exported.has(declaration.name)) rest.push(declaration.name);
|
|
11180
11336
|
if (rest.length > 0) lines.push(`export { ${rest.join(", ")} };`);
|
|
@@ -11202,6 +11358,7 @@ var ClientGenerator = class {
|
|
|
11202
11358
|
return reads;
|
|
11203
11359
|
}
|
|
11204
11360
|
usesModuleScript() {
|
|
11361
|
+
if (rendersModule(this.plan)) return true;
|
|
11205
11362
|
for (const declaration of this.clientReads()) if (declaration.kind === "module") return true;
|
|
11206
11363
|
return false;
|
|
11207
11364
|
}
|
|
@@ -11220,6 +11377,23 @@ var ClientGenerator = class {
|
|
|
11220
11377
|
}
|
|
11221
11378
|
return result;
|
|
11222
11379
|
}
|
|
11380
|
+
/**
|
|
11381
|
+
* The scopes whose components and imports a part needs: the scopes that the update part
|
|
11382
|
+
* renders, the templates of a template part, and the templates that the code of the part
|
|
11383
|
+
* copies into itself, such as a call `row(item)` in an update.
|
|
11384
|
+
*/
|
|
11385
|
+
partScopes(part) {
|
|
11386
|
+
const result = part === "update" ? this.renderedScopes() : this.templateScopes(part);
|
|
11387
|
+
for (const site of this.partSites(part)) {
|
|
11388
|
+
const used = [...site.calls];
|
|
11389
|
+
for (const read of site.reads) used.push(read.declaration);
|
|
11390
|
+
for (const callee of used) {
|
|
11391
|
+
const template = callee.kind === "template" ? this.findTemplateScope(callee) : void 0;
|
|
11392
|
+
for (const item of template ? this.inside(template) : []) if (!result.includes(item)) result.push(item);
|
|
11393
|
+
}
|
|
11394
|
+
}
|
|
11395
|
+
return result;
|
|
11396
|
+
}
|
|
11223
11397
|
/** Every scope that a render function of this module renders, including templates. */
|
|
11224
11398
|
renderedScopes() {
|
|
11225
11399
|
const result = /* @__PURE__ */ new Set();
|
|
@@ -11396,8 +11570,7 @@ var ClientGenerator = class {
|
|
|
11396
11570
|
case "memo": {
|
|
11397
11571
|
const slot = slotIndex(this.plan, node.declaration);
|
|
11398
11572
|
if (slot !== -1) {
|
|
11399
|
-
const
|
|
11400
|
-
const value = site.node.type === "ObjectExpression" ? `(${code})` : code;
|
|
11573
|
+
const value = arrowBody(site.awaits ? `(async () => (${expression()}))()` : expression(), this.file.source, site.node.start);
|
|
11401
11574
|
const timing = node.declaration.timing;
|
|
11402
11575
|
const call = timing ? `$$b.timed($$s, ${slot}, ${timing.ms}, ${timing.kind === "throttled"}, () => ${value})` : `$$b.memo($$s, ${slot}, () => ${value})`;
|
|
11403
11576
|
this.emit(`export function ${name("m")}($$s) {\n ${call};\n}`);
|
|
@@ -11961,21 +12134,23 @@ var ClientGenerator = class {
|
|
|
11961
12134
|
break;
|
|
11962
12135
|
}
|
|
11963
12136
|
const scope = callee && this.findTemplateScope(callee);
|
|
11964
|
-
|
|
11965
|
-
|
|
11966
|
-
|
|
11967
|
-
|
|
11968
|
-
const
|
|
11969
|
-
|
|
11970
|
-
|
|
11971
|
-
if (declaration.kind !== "template-param") continue;
|
|
11972
|
-
const slot = slotIndex(this.plan, declaration);
|
|
11973
|
-
if (slot === -1) return;
|
|
11974
|
-
pairs.push(`[${slot}, ${declaration.name}]`);
|
|
11975
|
-
}
|
|
11976
|
-
this.emit(`export const ${symbol}a = (${params}) => [${pairs.join(", ")}];`);
|
|
12137
|
+
if (scope) this.emitArgsExports(symbol, scope);
|
|
12138
|
+
}
|
|
12139
|
+
/** The `a` and `k` exports of a template, which `symbol` names. */
|
|
12140
|
+
emitArgsExports(symbol, scope) {
|
|
12141
|
+
const args = templateArgs(this.plan, this.file.source, scope);
|
|
12142
|
+
if (!args) return;
|
|
12143
|
+
this.emit(`export const ${symbol}a = (${args.exported}) => [${args.pairs.join(", ")}];`);
|
|
11977
12144
|
this.emit(`export const ${symbol}k = ${scope.id};`);
|
|
11978
12145
|
}
|
|
12146
|
+
/**
|
|
12147
|
+
* The exports of the templates of the file that a call in markup can update in place: the
|
|
12148
|
+
* template is `T` and its scope ID, as `templateCall` of the template's code names it.
|
|
12149
|
+
*/
|
|
12150
|
+
emitTemplateExports() {
|
|
12151
|
+
this.part = "update";
|
|
12152
|
+
for (const scope of this.model.scopes) if (scope.template) this.emitArgsExports(`T${scope.id}`, scope);
|
|
12153
|
+
}
|
|
11979
12154
|
withTemplates(site, code) {
|
|
11980
12155
|
const templates = [];
|
|
11981
12156
|
const used = [...site.calls];
|
|
@@ -12571,4 +12746,4 @@ function inspect(source, options = {}) {
|
|
|
12571
12746
|
//#endregion
|
|
12572
12747
|
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 };
|
|
12573
12748
|
|
|
12574
|
-
//# sourceMappingURL=inspect-
|
|
12749
|
+
//# sourceMappingURL=inspect-Q5W0A66e.js.map
|