brumate 0.2.0 → 0.3.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-D-IdPy7B.d.ts → boot-C25Sa6vq.d.ts} +5 -2
- package/dist/cli.js +2 -2
- package/dist/{client-C0UCNL3J.js → client-BD6XT-s5.js} +435 -110
- package/dist/client-BD6XT-s5.js.map +1 -0
- package/dist/{client-MD0ZmcFR.d.ts → client-D0CqSxoO.d.ts} +114 -8
- package/dist/{cookies-Av5WFmcf.js → cookies-BzllthiF.js} +2 -1
- package/dist/cookies-BzllthiF.js.map +1 -0
- package/dist/{defer-D0bo1Gqx.js → defer-BbD7JQhj.js} +6 -2
- package/dist/defer-BbD7JQhj.js.map +1 -0
- package/dist/devtools-CQgD7NPB.js +623 -0
- package/dist/devtools-CQgD7NPB.js.map +1 -0
- package/dist/devtools-panel-BVB-W5q4.js +1930 -0
- package/dist/devtools-panel-BVB-W5q4.js.map +1 -0
- package/dist/events-CSs7OwIC.js +85 -0
- package/dist/events-CSs7OwIC.js.map +1 -0
- package/dist/{files-Bnn1JqHx.js → files-BXSSrQgc.js} +18 -5
- package/dist/files-BXSSrQgc.js.map +1 -0
- package/dist/forms-Bg-CwGqX.js +406 -0
- package/dist/forms-Bg-CwGqX.js.map +1 -0
- package/dist/forms-Cl21hkHt.d.ts +281 -0
- package/dist/highlight.d.ts +17 -0
- package/dist/highlight.js +269 -0
- package/dist/highlight.js.map +1 -0
- package/dist/{html-y1q7-t7D.d.ts → html-Bq1rFxX_.d.ts} +36 -4
- package/dist/{html-bHZbkK-h.js → html-mNTKzaDD.js} +79 -8
- package/dist/html-mNTKzaDD.js.map +1 -0
- package/dist/index.d.ts +47 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BJtACnQp.js → inspect-BHpOw1LF.js} +625 -48
- package/dist/inspect-BHpOw1LF.js.map +1 -0
- package/dist/{loader-B18i3_-T.js → loader-Dos_3NP0.js} +5 -4
- package/dist/loader-Dos_3NP0.js.map +1 -0
- package/dist/{navigate-BwuZveDF.js → navigate-O78d_zGN.js} +45 -2
- package/dist/navigate-O78d_zGN.js.map +1 -0
- package/dist/{produce-D4K7qpaL.d.ts → produce-D0V0ICkz.d.ts} +45 -3
- package/dist/{produce-CWfJ4byV.js → produce-Doc91GkX.js} +113 -6
- package/dist/produce-Doc91GkX.js.map +1 -0
- package/dist/{rpc-B-Zkn6Ch.js → rpc-ygMRPmN4.js} +20 -10
- package/dist/rpc-ygMRPmN4.js.map +1 -0
- package/dist/runtime/client.d.ts +4 -4
- package/dist/runtime/client.js +4 -4
- package/dist/runtime/devtools.d.ts +188 -3
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/events.d.ts +15 -0
- package/dist/runtime/events.js +1 -1
- package/dist/runtime/forms.d.ts +2 -0
- package/dist/runtime/forms.js +1 -0
- package/dist/runtime/gather.d.ts +25 -0
- package/dist/runtime/gather.js +33 -0
- package/dist/runtime/gather.js.map +1 -0
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.d.ts +2 -2
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/server.d.ts +5 -4
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +38 -2
- package/dist/runtime/signals.js +12 -2
- 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 +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/runtime/values.d.ts +2 -0
- package/dist/runtime/values.js +24 -0
- package/dist/runtime/values.js.map +1 -0
- package/dist/{server-BqfM95r1.js → server-CxVDYE_V.js} +776 -121
- package/dist/server-CxVDYE_V.js.map +1 -0
- package/dist/{server-BA9SJ2Vm.d.ts → server-DuFYRXrd.d.ts} +284 -15
- package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-Drpr0AzI.d.ts} +2 -2
- package/dist/{static-loader-DOygOFj5.js → static-loader-nZssh66R.js} +168 -51
- package/dist/static-loader-nZssh66R.js.map +1 -0
- package/dist/{stream-JaMHMdBD.js → stream-DCYZO4IF.js} +89 -10
- package/dist/stream-DCYZO4IF.js.map +1 -0
- package/dist/values-B8C7CLvG.d.ts +63 -0
- package/dist/vite.d.ts +8 -1
- package/dist/vite.js +170 -20
- package/dist/vite.js.map +1 -1
- package/forms/forms.brm.ts +141 -0
- package/package.json +31 -2
- package/dist/client-C0UCNL3J.js.map +0 -1
- package/dist/cookies-Av5WFmcf.js.map +0 -1
- package/dist/defer-D0bo1Gqx.js.map +0 -1
- package/dist/devtools-C50VH8gZ.js +0 -113
- package/dist/devtools-C50VH8gZ.js.map +0 -1
- package/dist/devtools-panel-AYjfwPhj.js +0 -435
- package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
- package/dist/events-BKWRqtMg.js +0 -52
- package/dist/events-BKWRqtMg.js.map +0 -1
- package/dist/files-Bnn1JqHx.js.map +0 -1
- package/dist/html-bHZbkK-h.js.map +0 -1
- package/dist/inspect-BJtACnQp.js.map +0 -1
- package/dist/loader-B18i3_-T.js.map +0 -1
- package/dist/navigate-BwuZveDF.js.map +0 -1
- package/dist/produce-CWfJ4byV.js.map +0 -1
- package/dist/rpc-B-Zkn6Ch.js.map +0 -1
- package/dist/server-BqfM95r1.js.map +0 -1
- package/dist/static-loader-DOygOFj5.js.map +0 -1
- package/dist/stream-JaMHMdBD.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as KEY_NAMES } from "./events-
|
|
2
|
-
import {
|
|
1
|
+
import { t as KEY_NAMES } from "./events-CSs7OwIC.js";
|
|
2
|
+
import { f as insertValue } from "./html-mNTKzaDD.js";
|
|
3
3
|
import { parseSync } from "oxc-parser";
|
|
4
4
|
import { parse } from "postcss";
|
|
5
5
|
import selectorParser from "postcss-selector-parser";
|
|
@@ -25,7 +25,9 @@ const MACROS = /* @__PURE__ */ new Set([
|
|
|
25
25
|
"$navigation",
|
|
26
26
|
"$id",
|
|
27
27
|
"$title",
|
|
28
|
-
"$action"
|
|
28
|
+
"$action",
|
|
29
|
+
"$handler",
|
|
30
|
+
"$bind"
|
|
29
31
|
]);
|
|
30
32
|
/** Compile-time functions that have a new name, by old name. */
|
|
31
33
|
const RENAMED_MACROS = /* @__PURE__ */ new Map([["$provide", "$setContext"], ["$context", "$getContext"]]);
|
|
@@ -344,6 +346,27 @@ function range(node) {
|
|
|
344
346
|
end: node.end
|
|
345
347
|
};
|
|
346
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* The names of the props that a type marks `Bindable`, such as `open` in
|
|
351
|
+
* `{ open?: Bindable<boolean> }`. A name of a type is looked up among the
|
|
352
|
+
* interfaces and the type aliases of the scripts.
|
|
353
|
+
*/
|
|
354
|
+
function bindableNames(type, file) {
|
|
355
|
+
let members;
|
|
356
|
+
if (type.type === "TSTypeLiteral") members = type.members;
|
|
357
|
+
else if (type.type === "TSTypeReference" && type.typeName.type === "Identifier") {
|
|
358
|
+
const name = type.typeName.name;
|
|
359
|
+
const statements = [...file.moduleScript?.program.body ?? [], ...file.instanceScript?.program.body ?? []].map((statement) => statement.type === "ExportNamedDeclaration" && statement.declaration ? statement.declaration : statement);
|
|
360
|
+
for (const statement of statements) if (statement.type === "TSInterfaceDeclaration" && statement.id.name === name) members = statement.body.body;
|
|
361
|
+
else if (statement.type === "TSTypeAliasDeclaration" && statement.id.name === name) return bindableNames(statement.typeAnnotation, file);
|
|
362
|
+
}
|
|
363
|
+
return (members ?? []).flatMap((member) => {
|
|
364
|
+
const annotation = member.type === "TSPropertySignature" ? member.typeAnnotation?.typeAnnotation : void 0;
|
|
365
|
+
if (!(annotation?.type === "TSTypeReference" && annotation.typeName.type === "Identifier" && annotation.typeName.name === "Bindable") || member.type !== "TSPropertySignature" || member.computed) return [];
|
|
366
|
+
if (member.key.type === "Identifier") return [member.key.name];
|
|
367
|
+
return member.key.type === "Literal" ? [String(member.key.value)] : [];
|
|
368
|
+
});
|
|
369
|
+
}
|
|
347
370
|
function analyze$1(file) {
|
|
348
371
|
return new Analyzer(file).run();
|
|
349
372
|
}
|
|
@@ -352,8 +375,11 @@ var Analyzer = class {
|
|
|
352
375
|
scopes = [];
|
|
353
376
|
declarations = [];
|
|
354
377
|
sites = [];
|
|
378
|
+
bindings = [];
|
|
355
379
|
diagnostics = [];
|
|
356
380
|
refs = [];
|
|
381
|
+
/** The type arguments of the `$props<T>()` calls. */
|
|
382
|
+
propsTypes = [];
|
|
357
383
|
module;
|
|
358
384
|
component;
|
|
359
385
|
constructor(file) {
|
|
@@ -370,6 +396,7 @@ var Analyzer = class {
|
|
|
370
396
|
for (const style of this.file.styles) for (const variable of style.variables) this.createExpressionSite("style", this.component, variable, "style");
|
|
371
397
|
this.visitNodes(this.file.children, this.component);
|
|
372
398
|
this.addProvidedFunctions();
|
|
399
|
+
this.checkBindableProps();
|
|
373
400
|
for (const site of this.sites) new Resolver(this, site).run();
|
|
374
401
|
this.addPendingReads();
|
|
375
402
|
this.resolveRefs();
|
|
@@ -380,6 +407,7 @@ var Analyzer = class {
|
|
|
380
407
|
scopes: this.scopes,
|
|
381
408
|
declarations: this.declarations,
|
|
382
409
|
sites: this.sites,
|
|
410
|
+
bindings: this.bindings,
|
|
383
411
|
diagnostics: this.diagnostics
|
|
384
412
|
};
|
|
385
413
|
}
|
|
@@ -403,6 +431,20 @@ var Analyzer = class {
|
|
|
403
431
|
reference.site.reads.push(read);
|
|
404
432
|
}
|
|
405
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Warns about a prop that the type of `$props<T>()` marks `Bindable`, but
|
|
436
|
+
* that the component reads only with `const`, so a binding of it never
|
|
437
|
+
* changes the parent's value. It reads the type in the file: a type
|
|
438
|
+
* literal, or an interface or a type alias of the scripts.
|
|
439
|
+
*/
|
|
440
|
+
checkBindableProps() {
|
|
441
|
+
const bindable = /* @__PURE__ */ new Set();
|
|
442
|
+
for (const type of this.propsTypes) for (const name of bindableNames(type, this.file)) bindable.add(name);
|
|
443
|
+
if (bindable.size === 0) return;
|
|
444
|
+
const props = this.declarations.filter((declaration) => declaration.kind === "prop" && declaration.scope === this.component && declaration.propKey !== void 0 && bindable.has(declaration.propKey));
|
|
445
|
+
const written = new Set(props.filter((declaration) => declaration.writable).map((declaration) => declaration.propKey));
|
|
446
|
+
for (const declaration of props) if (!written.has(declaration.propKey)) this.report("warning", `The prop "${declaration.propKey}" is Bindable, but the component reads it with const and never writes it. Destructure it with let`, declaration.range);
|
|
447
|
+
}
|
|
406
448
|
report(severity, message, at) {
|
|
407
449
|
this.diagnostics.push({
|
|
408
450
|
severity,
|
|
@@ -481,6 +523,10 @@ var Analyzer = class {
|
|
|
481
523
|
if (node.type !== "CallExpression" || node.callee.type !== "Identifier") break;
|
|
482
524
|
const imported = lookup(scope, node.callee.name)?.imported;
|
|
483
525
|
const name = imported?.source === EVENTS_MODULE ? imported.name : void 0;
|
|
526
|
+
if (name === "transition" && node.arguments[0]) {
|
|
527
|
+
node = node.arguments[0];
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
484
530
|
if (name === void 0 || !WRAPPERS$1.has(name)) break;
|
|
485
531
|
const [handler, ...rest] = node.arguments;
|
|
486
532
|
if (!handler || name !== "prevent" && rest.length > 0) {
|
|
@@ -543,7 +589,8 @@ var Analyzer = class {
|
|
|
543
589
|
if (specifier.type === "ImportSpecifier" && specifier.importKind === "type") continue;
|
|
544
590
|
const declaration = this.addDeclaration(scope, specifier.local.name, "import", specifier.local);
|
|
545
591
|
if (specifier.type !== "ImportNamespaceSpecifier") {
|
|
546
|
-
|
|
592
|
+
let imported = "default";
|
|
593
|
+
if (specifier.type !== "ImportDefaultSpecifier") imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
|
|
547
594
|
declaration.imported = {
|
|
548
595
|
source: statement.source.value,
|
|
549
596
|
name: imported
|
|
@@ -610,15 +657,19 @@ var Analyzer = class {
|
|
|
610
657
|
const call = init;
|
|
611
658
|
if (name === "$props") {
|
|
612
659
|
if (!isComponent) this.report("error", "$props() can only be called in the component script", declarator);
|
|
613
|
-
if (kind !== "const") this.report("error", "Assign $props() to a const", declarator);
|
|
660
|
+
if (kind !== "const" && kind !== "let") this.report("error", "Assign $props() to a const or a let", declarator);
|
|
614
661
|
if (call.arguments.length > 0) this.report("error", "$props() takes no arguments", call);
|
|
662
|
+
const type = call.typeArguments?.params[0];
|
|
663
|
+
if (type) this.propsTypes.push(type);
|
|
615
664
|
if (id.type === "ObjectPattern") {
|
|
616
665
|
for (const property of id.properties) if (property.type === "RestElement") for (const binding of getPatternNames(property.argument)) this.addDeclaration(scope, binding.name, "props-rest", binding);
|
|
617
666
|
else {
|
|
618
|
-
|
|
667
|
+
let key;
|
|
668
|
+
if (!property.computed) key = property.key.type === "Identifier" ? property.key.name : String(property.key.value);
|
|
619
669
|
for (const binding of getPatternNames(property.value)) {
|
|
620
670
|
const declaration = this.addDeclaration(scope, binding.name, "prop", binding);
|
|
621
671
|
declaration.propKey = key;
|
|
672
|
+
if (kind === "let") declaration.writable = true;
|
|
622
673
|
}
|
|
623
674
|
}
|
|
624
675
|
this.createDefaultSites(id, scope);
|
|
@@ -766,6 +817,78 @@ var Analyzer = class {
|
|
|
766
817
|
for (const part of parts) if (isFunction$2(part) || part.type === "Identifier" && ["function", "server-function"].includes(lookup(site.scope, part.name)?.kind ?? "")) this.createSite("prop", site.scope, part, "provided function");
|
|
767
818
|
}
|
|
768
819
|
}
|
|
820
|
+
/**
|
|
821
|
+
* `$handler(fn, ...args)`: `fn` is a client root, as a function prop is, and
|
|
822
|
+
* its reference goes with the arguments. `isLocal` tells a name that a
|
|
823
|
+
* function around the call declares: `fn` cannot read one, since only the
|
|
824
|
+
* values of the scope and the arguments reach the browser.
|
|
825
|
+
*/
|
|
826
|
+
declareHandler(call, scope, isLocal) {
|
|
827
|
+
const [fn] = call.arguments;
|
|
828
|
+
if (!fn || fn.type === "SpreadElement" || !this.isHandlerFunction(fn, scope)) {
|
|
829
|
+
this.report("error", "$handler needs a function as its first argument: a function expression, a function of the script, or one of them in a wrapper of brumate/events", call);
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
for (const name of freeNames(fn)) if (isLocal(name)) {
|
|
833
|
+
this.report("error", `The handler reads "${name}", a value of the function around $handler, which the browser does not have. Pass it as an argument: $handler(fn, ${name})`, fn);
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
if (call.arguments.slice(1).some((argument) => argument.type === "SpreadElement")) this.report("error", "The arguments of $handler cannot be spread", call);
|
|
837
|
+
this.createSite("prop", scope, fn, "handler", {
|
|
838
|
+
handler: call,
|
|
839
|
+
modifiers: this.handlerModifiers(fn, scope)
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* The function of `$bind(name, fn)`, which a write of the binding calls
|
|
844
|
+
* with the new value in place of writing the name. It compiles as a
|
|
845
|
+
* handler does, with its own part.
|
|
846
|
+
*/
|
|
847
|
+
declareSetter(call, scope, isLocal) {
|
|
848
|
+
const fn = call.arguments[1];
|
|
849
|
+
if (fn.type === "SpreadElement" || !this.isHandlerFunction(fn, scope)) {
|
|
850
|
+
this.report("error", "The second argument of $bind is a function that takes the new value: a function expression, or a function of the script", fn);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
for (const name of freeNames(fn)) if (isLocal(name)) {
|
|
854
|
+
this.report("error", `The setter reads "${name}", a value of the function around $bind, which the browser does not have`, fn);
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
return this.createSite("prop", scope, fn, "setter", { setter: call });
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* The modifiers of the wrappers around the function of `$handler`, such as
|
|
861
|
+
* `prevent`, as `b-on` holds them. Markup that the browser renders writes
|
|
862
|
+
* them without loading the code of the handler.
|
|
863
|
+
*/
|
|
864
|
+
handlerModifiers(node, scope) {
|
|
865
|
+
const modifiers = [];
|
|
866
|
+
while (node.type === "CallExpression" && node.callee.type === "Identifier") {
|
|
867
|
+
const imported = lookup(scope, node.callee.name)?.imported;
|
|
868
|
+
const name = imported?.source === EVENTS_MODULE ? imported.name : void 0;
|
|
869
|
+
const [handler, ...keys] = node.arguments;
|
|
870
|
+
if (name === "transition" && handler) {
|
|
871
|
+
node = handler;
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
if (name === void 0 || !WRAPPERS$1.has(name) || !handler) break;
|
|
875
|
+
const names = keys.map((key) => key.type === "Literal" && typeof key.value === "string" ? key.value : void 0);
|
|
876
|
+
if (names.some((key) => key === void 0)) this.report("error", "Name each key of prevent as a string, such as 'Enter'", node);
|
|
877
|
+
modifiers.push(names.length > 0 ? `${name}(${names.join(",")})` : name);
|
|
878
|
+
node = handler;
|
|
879
|
+
}
|
|
880
|
+
return modifiers.length > 0 ? modifiers : void 0;
|
|
881
|
+
}
|
|
882
|
+
/** A function, a function of the script, or one of them in wrappers of `brumate/events`. */
|
|
883
|
+
isHandlerFunction(node, scope) {
|
|
884
|
+
while (node.type === "CallExpression" && node.callee.type === "Identifier" && lookup(scope, node.callee.name)?.imported?.source === EVENTS_MODULE && node.arguments[0]) node = node.arguments[0];
|
|
885
|
+
if (isFunction$2(node)) return true;
|
|
886
|
+
if (node.type === "Identifier") {
|
|
887
|
+
const kind = lookup(scope, node.name)?.kind;
|
|
888
|
+
return kind === "function" || kind === "server-function";
|
|
889
|
+
}
|
|
890
|
+
return false;
|
|
891
|
+
}
|
|
769
892
|
declareProvide(call, scope) {
|
|
770
893
|
const [context, value] = call.arguments;
|
|
771
894
|
if (!context || !value || call.arguments.length !== 2) {
|
|
@@ -857,7 +980,9 @@ var Analyzer = class {
|
|
|
857
980
|
}
|
|
858
981
|
visitAttributes(node, scope) {
|
|
859
982
|
const isComponent = node.kind === "component";
|
|
860
|
-
|
|
983
|
+
let tag = "dynamic";
|
|
984
|
+
if (node.kind === "element") tag = node.tag;
|
|
985
|
+
else if (node.kind === "component") tag = node.name;
|
|
861
986
|
for (const attribute of node.attributes) {
|
|
862
987
|
if (!isComponent && (attribute.kind === "static" || attribute.kind === "value") && attribute.name.startsWith("b-")) this.report("error", `"${attribute.name}" is reserved. Brumate writes the attributes that start with "b-"`, attribute);
|
|
863
988
|
switch (attribute.kind) {
|
|
@@ -1064,6 +1189,44 @@ var Resolver = class {
|
|
|
1064
1189
|
}
|
|
1065
1190
|
return reference;
|
|
1066
1191
|
}
|
|
1192
|
+
/**
|
|
1193
|
+
* `$bind(name)` passes a child a reference to a signal, or to a prop that
|
|
1194
|
+
* the component writes, so the child's writes reach it. It is the whole
|
|
1195
|
+
* value of a prop of a component. The name gets a slot, which the
|
|
1196
|
+
* reference points to.
|
|
1197
|
+
*/
|
|
1198
|
+
declareBinding(call) {
|
|
1199
|
+
let node = this.site.node;
|
|
1200
|
+
while (node.type === "ParenthesizedExpression") node = node.expression;
|
|
1201
|
+
const owner = this.site.owner;
|
|
1202
|
+
const element = this.site.kind === "attribute" && owner?.kind === "element" ? owner.attributes.find((attribute) => attribute.kind === "value" && attribute.value.ast === this.site.node) : void 0;
|
|
1203
|
+
const onElement = element?.kind === "value" && (element.name === "value" || element.name === "checked") && [
|
|
1204
|
+
"input",
|
|
1205
|
+
"select",
|
|
1206
|
+
"textarea"
|
|
1207
|
+
].includes(owner.tag.toLowerCase());
|
|
1208
|
+
if (!(this.site.kind === "prop" || onElement) || node !== call) {
|
|
1209
|
+
this.analyzer.report("error", "Pass $bind(name) as the value of a prop of a component, or of value or checked of an input, a select or a textarea", call);
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
const [target, fn, ...rest] = call.arguments;
|
|
1213
|
+
if (!target || target.type !== "Identifier" || rest.length > 0) {
|
|
1214
|
+
this.analyzer.report("error", "$bind takes the name of a signal, and a function that writes it, such as $bind(open) or $bind(open, (next) => (open = next))", call);
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const declaration = this.isLocal(target.name) ? void 0 : lookup(this.site.scope, target.name);
|
|
1218
|
+
if (!declaration || !(declaration.kind === "signal" || declaration.kind === "prop" && declaration.writable)) {
|
|
1219
|
+
this.analyzer.report("error", `$bind takes a signal, or a prop that the component destructures with let, and "${target.name}" is not one`, target);
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
declaration.bound = true;
|
|
1223
|
+
const setter = fn === void 0 ? void 0 : this.analyzer.declareSetter(call, this.site.scope, (local) => this.isLocal(local));
|
|
1224
|
+
this.analyzer.bindings.push({
|
|
1225
|
+
call,
|
|
1226
|
+
declaration,
|
|
1227
|
+
setter
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1067
1230
|
visitChildren(node) {
|
|
1068
1231
|
for (const [key, child] of children(node)) if (!TYPE_KEYS.has(key)) this.visit(child);
|
|
1069
1232
|
}
|
|
@@ -1204,6 +1367,16 @@ var Resolver = class {
|
|
|
1204
1367
|
for (const argument of recipe ? [recipe, ...rest] : rest) this.visit(argument);
|
|
1205
1368
|
return;
|
|
1206
1369
|
}
|
|
1370
|
+
if (name === "$bind") {
|
|
1371
|
+
this.declareBinding(node);
|
|
1372
|
+
for (const argument of node.arguments) this.visit(argument);
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
if (name === "$handler") {
|
|
1376
|
+
this.analyzer.declareHandler(node, this.site.scope, (local) => this.isLocal(local));
|
|
1377
|
+
for (const argument of node.arguments.slice(1)) this.visit(argument);
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1207
1380
|
if (COMPILE_TIME_FUNCTIONS.has(name)) this.analyzer.report("error", MISPLACED[name] ?? `${name} cannot be used here`, node);
|
|
1208
1381
|
else if (name in REMOVED) this.analyzer.report("error", REMOVED[name], node);
|
|
1209
1382
|
}
|
|
@@ -1309,6 +1482,40 @@ function varNames(node, names = []) {
|
|
|
1309
1482
|
}
|
|
1310
1483
|
return names;
|
|
1311
1484
|
}
|
|
1485
|
+
/**
|
|
1486
|
+
* The names that code reads and does not declare itself, such as what a
|
|
1487
|
+
* function reads from around it. Property names are not reads.
|
|
1488
|
+
*/
|
|
1489
|
+
function freeNames(node) {
|
|
1490
|
+
const free = /* @__PURE__ */ new Set();
|
|
1491
|
+
const visit = (current, bound) => {
|
|
1492
|
+
if (isFunction$2(current)) {
|
|
1493
|
+
const inner = new Set(bound);
|
|
1494
|
+
for (const param of current.params) for (const name of getPatternNames(param)) inner.add(name.name);
|
|
1495
|
+
if (current.type === "FunctionExpression" && current.id) inner.add(current.id.name);
|
|
1496
|
+
const body = current.body;
|
|
1497
|
+
if (body?.type === "BlockStatement") for (const name of [...lexicalNames(body.body), ...varNames(body)]) inner.add(name);
|
|
1498
|
+
for (const param of current.params) visit(param, inner);
|
|
1499
|
+
if (body) visit(body, inner);
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
if (current.type === "Identifier") {
|
|
1503
|
+
if (!bound.has(current.name)) free.add(current.name);
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
if (current.type === "MemberExpression" && !current.computed) {
|
|
1507
|
+
visit(current.object, bound);
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
if (current.type === "Property" && !current.computed) {
|
|
1511
|
+
visit(current.value, bound);
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
for (const [, child] of children(current)) visit(child, bound);
|
|
1515
|
+
};
|
|
1516
|
+
visit(node, /* @__PURE__ */ new Set());
|
|
1517
|
+
return free;
|
|
1518
|
+
}
|
|
1312
1519
|
//#endregion
|
|
1313
1520
|
//#region src/error.ts
|
|
1314
1521
|
function getLocation(source, offset) {
|
|
@@ -1537,7 +1744,7 @@ function buildGraph(model, options = {}) {
|
|
|
1537
1744
|
for (const site of model.sites) if (site.kind === "event" || site.kind === "client" || site.kind === "prop" && isFunctionValue(site) || site.kind === "effect" && live.has(siteNodes.get(site)) || created.has(site.scope)) reach(site);
|
|
1538
1745
|
for (const [declaration, node] of declarationNodes) {
|
|
1539
1746
|
if (live.has(node)) continue;
|
|
1540
|
-
if ((declaration.kind === "prop" || declaration.kind === "props-rest") && isLiveProp(declaration, options.liveProps) || declaration.kind === "context" || declaration.kind === "action" || isMemoKind(declaration.kind) && [...declaration.site?.calls ?? []].some((callee) => callee.refreshed) || declaration.optimistic !== void 0 && declaration.writes.some((write) => reached.has(write.site)) || declaration.kind === "signal" && (declaration.writes.some((write) => reached.has(write.site)) || declaration.refs.some((ref) => created.has(ref.scope))) || declaration.kind === "error" && declaration.block?.kind === "try" && tryChanges(declaration.block) || declaration.kind === "template-param" && templateCallChanges(declaration.scope)) live.add(node);
|
|
1747
|
+
if ((declaration.kind === "prop" || declaration.kind === "props-rest") && isLiveProp(declaration, options.liveProps) || declaration.kind === "context" || declaration.kind === "action" || isMemoKind(declaration.kind) && [...declaration.site?.calls ?? []].some((callee) => callee.refreshed) || declaration.optimistic !== void 0 && declaration.writes.some((write) => reached.has(write.site)) || declaration.kind === "signal" && (declaration.writes.some((write) => reached.has(write.site)) || declaration.refs.some((ref) => created.has(ref.scope))) || declaration.kind === "error" && declaration.block?.kind === "try" && tryChanges(declaration.block) || declaration.bound === true || declaration.kind === "template-param" && templateCallChanges(declaration.scope)) live.add(node);
|
|
1541
1748
|
}
|
|
1542
1749
|
for (let propagated = true; propagated;) {
|
|
1543
1750
|
propagated = false;
|
|
@@ -1797,6 +2004,7 @@ const BLOCK_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
1797
2004
|
"head",
|
|
1798
2005
|
"client",
|
|
1799
2006
|
"offscreen",
|
|
2007
|
+
"reveal",
|
|
1800
2008
|
"defer",
|
|
1801
2009
|
"template"
|
|
1802
2010
|
]);
|
|
@@ -2343,6 +2551,39 @@ var Parser = class {
|
|
|
2343
2551
|
};
|
|
2344
2552
|
}
|
|
2345
2553
|
/** Parses `( … )` at the current position, after optional whitespace. */
|
|
2554
|
+
/**
|
|
2555
|
+
* `#reveal ('sequential', collapsed) { … }`: an order as a string, and
|
|
2556
|
+
* `collapsed`, both optional. The body is the children of a fragment.
|
|
2557
|
+
*/
|
|
2558
|
+
parseReveal(start) {
|
|
2559
|
+
const header = this.parseHeader("reveal", false);
|
|
2560
|
+
const reveal = {
|
|
2561
|
+
order: "sequential",
|
|
2562
|
+
collapsed: false
|
|
2563
|
+
};
|
|
2564
|
+
if (header) {
|
|
2565
|
+
const code = this.source.slice(header.start, header.end);
|
|
2566
|
+
let offset = header.start;
|
|
2567
|
+
for (const part of code.split(",")) {
|
|
2568
|
+
const word = part.trim();
|
|
2569
|
+
const string = /^(['"])(sequential|backwards|together|natural)\1$/.exec(word);
|
|
2570
|
+
if (string) reveal.order = string[2];
|
|
2571
|
+
else if (word === "collapsed") reveal.collapsed = true;
|
|
2572
|
+
else this.fail("#reveal takes an order, 'sequential', 'backwards', 'together' or 'natural', and collapsed, such as #reveal ('sequential', collapsed)", offset + part.length - part.trimStart().length);
|
|
2573
|
+
offset += part.length + 1;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
if (reveal.collapsed && reveal.order !== "sequential") this.fail(`collapsed shows the fallback of the next body to show, so it needs the order 'sequential', not '${reveal.order}'`, header.start);
|
|
2577
|
+
const body = this.parseBody("reveal");
|
|
2578
|
+
if (body.script) this.fail("#reveal has no script of its own", body.script.start);
|
|
2579
|
+
return {
|
|
2580
|
+
kind: "fragment",
|
|
2581
|
+
start,
|
|
2582
|
+
end: this.pos,
|
|
2583
|
+
children: body.children,
|
|
2584
|
+
reveal
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2346
2587
|
parseHeader(keyword, required) {
|
|
2347
2588
|
this.skipWhitespace();
|
|
2348
2589
|
if (this.peek() !== "(") {
|
|
@@ -2500,6 +2741,7 @@ var Parser = class {
|
|
|
2500
2741
|
end: this.pos,
|
|
2501
2742
|
body: this.parseBody("head")
|
|
2502
2743
|
};
|
|
2744
|
+
case "reveal": return this.parseReveal(start);
|
|
2503
2745
|
case "portal": {
|
|
2504
2746
|
const header = this.parseHeader("portal", false);
|
|
2505
2747
|
const target = header ? this.expression(header.start, header.end) : void 0;
|
|
@@ -2901,6 +3143,34 @@ function checkAccessibility(file) {
|
|
|
2901
3143
|
roots.forEach((nodes) => visit(nodes, false));
|
|
2902
3144
|
return diagnostics;
|
|
2903
3145
|
}
|
|
3146
|
+
const NAME = "[A-Za-z_$][\\w$]*";
|
|
3147
|
+
const REFRESH = new RegExp(`\\.refresh\\(\\s*(${NAME}(?:\\s*\\.\\s*${NAME})*)?\\s*([,)])`, "g");
|
|
3148
|
+
const IMPORT = /import\s+(?:type\s+)?\{([^}]*)\}\s*from/g;
|
|
3149
|
+
/**
|
|
3150
|
+
* The names of the server functions that the sources pass to `refresh`, by
|
|
3151
|
+
* the name that their file exports. A local name of an import, such as `ln`
|
|
3152
|
+
* of `import { listNotes as ln }`, counts as the name that it imports. A
|
|
3153
|
+
* call that the scan cannot read, such as `refresh(pick())`, adds `ANY`.
|
|
3154
|
+
*/
|
|
3155
|
+
function refreshedNames(sources) {
|
|
3156
|
+
const names = /* @__PURE__ */ new Set();
|
|
3157
|
+
for (const source of sources) {
|
|
3158
|
+
if (!source.includes(".refresh(")) continue;
|
|
3159
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
3160
|
+
for (const [, list] of source.matchAll(IMPORT)) for (const item of list.split(",")) {
|
|
3161
|
+
const [imported, local] = item.trim().replace(/^type\s+/, "").split(/\s+as\s+/);
|
|
3162
|
+
if (imported && local) aliases.set(local.trim(), imported.trim());
|
|
3163
|
+
}
|
|
3164
|
+
for (const match of source.matchAll(REFRESH)) {
|
|
3165
|
+
const target = match[1];
|
|
3166
|
+
if (target === void 0) continue;
|
|
3167
|
+
const last = target.split(".").at(-1).trim();
|
|
3168
|
+
names.add(aliases.get(last) ?? last);
|
|
3169
|
+
}
|
|
3170
|
+
if (source.split(".refresh(").length - 1 > [...source.matchAll(REFRESH)].length) names.add("*");
|
|
3171
|
+
}
|
|
3172
|
+
return names;
|
|
3173
|
+
}
|
|
2904
3174
|
//#endregion
|
|
2905
3175
|
//#region src/captures.ts
|
|
2906
3176
|
/** Classes whose instances brumate can send to the browser. */
|
|
@@ -2969,21 +3239,41 @@ function initializers(file) {
|
|
|
2969
3239
|
if (file.instanceScript) visit(file.instanceScript.program);
|
|
2970
3240
|
return result;
|
|
2971
3241
|
}
|
|
2972
|
-
/** The class of a value made with `new`, unless brumate can send it. */
|
|
2973
|
-
function unsendableClass(node) {
|
|
3242
|
+
/** The class of a value made with `new`, unless brumate or a plugin of the app can send it. */
|
|
3243
|
+
function unsendableClass(node, sendable) {
|
|
2974
3244
|
if (node.type !== "NewExpression") return;
|
|
2975
3245
|
const callee = node.callee;
|
|
2976
|
-
|
|
2977
|
-
|
|
3246
|
+
let name = "class";
|
|
3247
|
+
if (callee.type === "Identifier") name = callee.name;
|
|
3248
|
+
else if (callee.type === "MemberExpression" && callee.property.type === "Identifier") name = callee.property.name;
|
|
3249
|
+
return SENDABLE.has(name) || sendable.includes(name) ? void 0 : name;
|
|
3250
|
+
}
|
|
3251
|
+
/**
|
|
3252
|
+
* The classes that the plugins of a serial entry send: the names on the
|
|
3253
|
+
* right of `instanceof` in the file, such as `Money` in
|
|
3254
|
+
* `test: (value) => value instanceof Money`.
|
|
3255
|
+
*/
|
|
3256
|
+
function entryClasses(program) {
|
|
3257
|
+
const names = /* @__PURE__ */ new Set();
|
|
3258
|
+
const visit = (node) => {
|
|
3259
|
+
if (node.type === "BinaryExpression" && node.operator === "instanceof") {
|
|
3260
|
+
const right = node.right;
|
|
3261
|
+
if (right.type === "Identifier") names.add(right.name);
|
|
3262
|
+
else if (right.type === "MemberExpression" && right.property.type === "Identifier") names.add(right.property.name);
|
|
3263
|
+
}
|
|
3264
|
+
for (const [, child] of children(node)) visit(child);
|
|
3265
|
+
};
|
|
3266
|
+
visit(program);
|
|
3267
|
+
return [...names];
|
|
2978
3268
|
}
|
|
2979
3269
|
/** Errors for values that the browser reads but that cannot be sent to it. */
|
|
2980
|
-
function checkCaptures(file, plan) {
|
|
3270
|
+
function checkCaptures(file, plan, sendable = []) {
|
|
2981
3271
|
const values = initializers(file);
|
|
2982
3272
|
const diagnostics = [];
|
|
2983
3273
|
const reported = /* @__PURE__ */ new Set();
|
|
2984
3274
|
for (const layout of plan.scopes.values()) for (const declaration of layout.slots) {
|
|
2985
3275
|
const init = values.get(declaration.range.start);
|
|
2986
|
-
const kind = init && unsendableClass(init);
|
|
3276
|
+
const kind = init && unsendableClass(init, sendable);
|
|
2987
3277
|
if (!kind || reported.has(declaration)) continue;
|
|
2988
3278
|
reported.add(declaration);
|
|
2989
3279
|
const reader = declaration.reads.find((read) => plan.graph.reached.has(read.site))?.site;
|
|
@@ -3175,6 +3465,57 @@ function finish(code, files, place = (offset) => ({
|
|
|
3175
3465
|
}
|
|
3176
3466
|
};
|
|
3177
3467
|
}
|
|
3468
|
+
/**
|
|
3469
|
+
* The place in a source that a position of generated code came from, by a
|
|
3470
|
+
* source map. Lines and columns count from 1. Undefined when the map has no
|
|
3471
|
+
* mapping on that line at or before the column.
|
|
3472
|
+
*/
|
|
3473
|
+
function originalPosition(map, line, column) {
|
|
3474
|
+
const state = [
|
|
3475
|
+
0,
|
|
3476
|
+
0,
|
|
3477
|
+
0,
|
|
3478
|
+
0
|
|
3479
|
+
];
|
|
3480
|
+
let found;
|
|
3481
|
+
const lines = map.mappings.split(";");
|
|
3482
|
+
for (let index = 0; index < line && index < lines.length; index++) {
|
|
3483
|
+
let generated = 0;
|
|
3484
|
+
for (const segment of lines[index].split(",")) {
|
|
3485
|
+
if (!segment) continue;
|
|
3486
|
+
const fields = [];
|
|
3487
|
+
let value = 0;
|
|
3488
|
+
let shift = 0;
|
|
3489
|
+
for (const char of segment) {
|
|
3490
|
+
const digit = BASE64.indexOf(char);
|
|
3491
|
+
value += (digit & 31) << shift;
|
|
3492
|
+
if (digit & 32) shift += 5;
|
|
3493
|
+
else {
|
|
3494
|
+
fields.push(value & 1 ? -(value >>> 1) : value >>> 1);
|
|
3495
|
+
value = 0;
|
|
3496
|
+
shift = 0;
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
generated += fields[0];
|
|
3500
|
+
if (fields.length >= 4) {
|
|
3501
|
+
state[1] += fields[1];
|
|
3502
|
+
state[2] += fields[2];
|
|
3503
|
+
state[3] += fields[3];
|
|
3504
|
+
}
|
|
3505
|
+
if (index === line - 1 && fields.length >= 4 && generated <= column - 1) found = [
|
|
3506
|
+
state[1],
|
|
3507
|
+
state[2],
|
|
3508
|
+
state[3]
|
|
3509
|
+
];
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
const source = found && map.sources[found[0]];
|
|
3513
|
+
return found && source ? {
|
|
3514
|
+
source,
|
|
3515
|
+
line: found[1] + 1,
|
|
3516
|
+
column: found[2] + 1
|
|
3517
|
+
} : void 0;
|
|
3518
|
+
}
|
|
3178
3519
|
//#endregion
|
|
3179
3520
|
//#region src/node.ts
|
|
3180
3521
|
/** Returns a Node built-in, or undefined outside Node. */
|
|
@@ -3289,10 +3630,16 @@ function parseModule(module) {
|
|
|
3289
3630
|
case "TSEnumDeclaration": if (node.id) declarations.set(node.id.name, exported ? node.id.name : void 0);
|
|
3290
3631
|
}
|
|
3291
3632
|
};
|
|
3292
|
-
for (const statement of program.body) if (statement.type === "ImportDeclaration") for (const specifier of statement.specifiers)
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3633
|
+
for (const statement of program.body) if (statement.type === "ImportDeclaration") for (const specifier of statement.specifiers) {
|
|
3634
|
+
let imported;
|
|
3635
|
+
if (specifier.type === "ImportDefaultSpecifier") imported = "default";
|
|
3636
|
+
else if (specifier.type === "ImportNamespaceSpecifier") imported = "*";
|
|
3637
|
+
else imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
|
|
3638
|
+
imports.set(specifier.local.name, {
|
|
3639
|
+
specifier: statement.source.value,
|
|
3640
|
+
imported
|
|
3641
|
+
});
|
|
3642
|
+
}
|
|
3296
3643
|
else if (statement.type === "ExportNamedDeclaration" && statement.declaration) declare(statement.declaration, true);
|
|
3297
3644
|
else declare(statement, false);
|
|
3298
3645
|
for (const statement of program.body) if (statement.type === "ExportNamedDeclaration" && !statement.declaration && !statement.source) for (const specifier of statement.specifiers) {
|
|
@@ -3465,6 +3812,7 @@ function expandModules(file, path, resolve) {
|
|
|
3465
3812
|
const source = file.source;
|
|
3466
3813
|
const program = file.instanceScript?.program;
|
|
3467
3814
|
if (!program) return;
|
|
3815
|
+
const reactive = (specifier) => isReactiveModule(specifier) || !specifier.startsWith(".") && specifier !== "brumate/signals" && isReactiveModule(resolve(specifier, path)?.path ?? "");
|
|
3468
3816
|
const imported = /* @__PURE__ */ new Map();
|
|
3469
3817
|
const macroNames = /* @__PURE__ */ new Map();
|
|
3470
3818
|
const topNames = /* @__PURE__ */ new Set();
|
|
@@ -3472,7 +3820,7 @@ function expandModules(file, path, resolve) {
|
|
|
3472
3820
|
topNames.add(specifier.local.name);
|
|
3473
3821
|
if (specifier.type !== "ImportSpecifier") continue;
|
|
3474
3822
|
const name = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
|
|
3475
|
-
if (
|
|
3823
|
+
if (reactive(statement.source.value)) imported.set(specifier.local.name, {
|
|
3476
3824
|
specifier: statement.source.value,
|
|
3477
3825
|
name
|
|
3478
3826
|
});
|
|
@@ -3727,7 +4075,12 @@ function expandModules(file, path, resolve) {
|
|
|
3727
4075
|
builder.add(source.slice(0, importsOffset), { offset: 0 }, true);
|
|
3728
4076
|
const lines = [];
|
|
3729
4077
|
if (macrosToImport.size > 0) lines.push(`\nimport { ${[...macrosToImport].join(", ")} } from '${SIGNALS_MODULE}';`);
|
|
3730
|
-
for (const [alias, { specifier, imported: name }] of imports)
|
|
4078
|
+
for (const [alias, { specifier, imported: name }] of imports) if (name === "*") lines.push(`\nimport * as ${alias} from '${specifier}';`);
|
|
4079
|
+
else if (name === "default") lines.push(`\nimport ${alias} from '${specifier}';`);
|
|
4080
|
+
else {
|
|
4081
|
+
const binding = name === alias ? name : `${name} as ${alias}`;
|
|
4082
|
+
lines.push(`\nimport { ${binding} } from '${specifier}';`);
|
|
4083
|
+
}
|
|
3731
4084
|
builder.add(lines.join(""), { offset: importsOffset }, false);
|
|
3732
4085
|
const offset = builder.text.length;
|
|
3733
4086
|
for (const piece of after.pieces) builder.pieces.push({
|
|
@@ -3798,8 +4151,25 @@ function promiseName(name) {
|
|
|
3798
4151
|
* `$$p_<name>`, because it can hold a promise that is awaited where it is read.
|
|
3799
4152
|
* The memos in `inline` are plain values on the server too.
|
|
3800
4153
|
*/
|
|
4154
|
+
/** The name of the key of a property, or undefined for a computed key. */
|
|
4155
|
+
function keyName(property) {
|
|
4156
|
+
if (property.computed) return;
|
|
4157
|
+
if (property.key.type === "Identifier") return property.key.name;
|
|
4158
|
+
return property.key.type === "Literal" ? String(property.key.value) : void 0;
|
|
4159
|
+
}
|
|
3801
4160
|
function addValueEdits(patch, file, sites, mode = "server", inline = /* @__PURE__ */ new Set()) {
|
|
3802
4161
|
const sitesByNode = /* @__PURE__ */ new Map();
|
|
4162
|
+
const propNames = /* @__PURE__ */ new Map();
|
|
4163
|
+
for (const statement of file.instanceScript?.program.body ?? []) {
|
|
4164
|
+
if (statement.type !== "VariableDeclaration") continue;
|
|
4165
|
+
for (const declarator of statement.declarations) {
|
|
4166
|
+
const init = declarator.init;
|
|
4167
|
+
if (init?.type === "CallExpression" && calleeName(init) === "$props" && declarator.id.type === "ObjectPattern") propNames.set(init, declarator.id.properties.flatMap((property) => {
|
|
4168
|
+
const name = property.type === "Property" ? keyName(property) : void 0;
|
|
4169
|
+
return name === void 0 ? [] : [name];
|
|
4170
|
+
}));
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
3803
4173
|
const awaits = /* @__PURE__ */ new Map();
|
|
3804
4174
|
const replaced = /* @__PURE__ */ new Set();
|
|
3805
4175
|
for (const site of sites) {
|
|
@@ -3824,7 +4194,8 @@ function addValueEdits(patch, file, sites, mode = "server", inline = /* @__PURE_
|
|
|
3824
4194
|
const name = node.callee.name;
|
|
3825
4195
|
const argument = node.arguments[0];
|
|
3826
4196
|
if (name === "$props") {
|
|
3827
|
-
|
|
4197
|
+
const names = propNames.get(node);
|
|
4198
|
+
patch.replace(node.start, node.end, names ? `$$b.unbind($$props, ${JSON.stringify(names)})` : "$$b.unbind($$props)");
|
|
3828
4199
|
return;
|
|
3829
4200
|
}
|
|
3830
4201
|
if (name === "$action") {
|
|
@@ -3856,7 +4227,7 @@ function addValueEdits(patch, file, sites, mode = "server", inline = /* @__PURE_
|
|
|
3856
4227
|
replaced.add(read);
|
|
3857
4228
|
}
|
|
3858
4229
|
patch.replace(node.start, argument.start, site.awaits ? "$$b.memo(async () => (" : "$$b.memo(() => (");
|
|
3859
|
-
patch.replace(argument.end, node.end,
|
|
4230
|
+
patch.replace(argument.end, node.end, `), $$ctx, ${JSON.stringify(declaration.name)})`);
|
|
3860
4231
|
} else if (site?.awaits) {
|
|
3861
4232
|
patch.replace(node.start, argument.start, "(async () => (");
|
|
3862
4233
|
patch.replace(argument.end, node.end, "))()");
|
|
@@ -3917,7 +4288,8 @@ const UNSHARED = /* @__PURE__ */ new Set([
|
|
|
3917
4288
|
"$setContext",
|
|
3918
4289
|
"$title",
|
|
3919
4290
|
"$action",
|
|
3920
|
-
"$props"
|
|
4291
|
+
"$props",
|
|
4292
|
+
"$handler"
|
|
3921
4293
|
]);
|
|
3922
4294
|
const analyses = /* @__PURE__ */ new WeakMap();
|
|
3923
4295
|
function isFunction$1(node) {
|
|
@@ -3971,7 +4343,10 @@ function analyze(module) {
|
|
|
3971
4343
|
if (locals.has(identifier.name)) reads.add(identifier.name);
|
|
3972
4344
|
});
|
|
3973
4345
|
const findWrites = (current) => {
|
|
3974
|
-
|
|
4346
|
+
let target;
|
|
4347
|
+
if (current.type === "AssignmentExpression") target = current.left;
|
|
4348
|
+
else if (current.type === "UpdateExpression") target = current.argument;
|
|
4349
|
+
else if (current.type === "CallExpression" && current.callee.type === "Identifier" && macros.get(current.callee.name) === "$produce") target = current.arguments[0];
|
|
3975
4350
|
if (target?.type === "Identifier" && locals.has(target.name)) writes.add(target.name);
|
|
3976
4351
|
for (const [, child] of children(current)) findWrites(child);
|
|
3977
4352
|
};
|
|
@@ -4088,6 +4463,27 @@ function scopeTarget(compound) {
|
|
|
4088
4463
|
* `:global(…)`. Each scoped compound goes into `targets`.
|
|
4089
4464
|
*/
|
|
4090
4465
|
const scopeSelector = (attribute, targets) => selectorParser((selectors) => {
|
|
4466
|
+
for (let index = 0; index < selectors.nodes.length; index++) {
|
|
4467
|
+
const selector = selectors.nodes[index];
|
|
4468
|
+
let list;
|
|
4469
|
+
selector.walkPseudos((pseudo) => {
|
|
4470
|
+
if (!list && pseudo.value === ":global" && pseudo.nodes.length > 1) list = pseudo;
|
|
4471
|
+
});
|
|
4472
|
+
if (!list) continue;
|
|
4473
|
+
const copies = list.nodes.map((_, item) => {
|
|
4474
|
+
const copy = selector.clone();
|
|
4475
|
+
let found;
|
|
4476
|
+
copy.walkPseudos((pseudo) => {
|
|
4477
|
+
if (!found && pseudo.value === ":global" && pseudo.nodes.length > 1) found = pseudo;
|
|
4478
|
+
});
|
|
4479
|
+
const only = found.nodes[item];
|
|
4480
|
+
if (only.first) only.first.spaces.before = "";
|
|
4481
|
+
found.nodes = [only];
|
|
4482
|
+
return copy;
|
|
4483
|
+
});
|
|
4484
|
+
selector.replaceWith(...copies);
|
|
4485
|
+
index--;
|
|
4486
|
+
}
|
|
4091
4487
|
selectors.each((selector) => {
|
|
4092
4488
|
const compounds = [[]];
|
|
4093
4489
|
selector.each((node) => {
|
|
@@ -4266,6 +4662,12 @@ function compileStyles(file, scope, filePath) {
|
|
|
4266
4662
|
}
|
|
4267
4663
|
//#endregion
|
|
4268
4664
|
//#region src/plan.ts
|
|
4665
|
+
/** A node without the parentheses around it. */
|
|
4666
|
+
function unparen(node) {
|
|
4667
|
+
let current = node;
|
|
4668
|
+
while (current.type === "ParenthesizedExpression") current = current.expression;
|
|
4669
|
+
return current;
|
|
4670
|
+
}
|
|
4269
4671
|
/**
|
|
4270
4672
|
* Elements that the HTML parser can end before their end tag, or whose
|
|
4271
4673
|
* content it moves out, when they hold some other elements: a `<p>` ends at
|
|
@@ -4364,7 +4766,7 @@ function clientState(graph) {
|
|
|
4364
4766
|
const slots = /* @__PURE__ */ new Map();
|
|
4365
4767
|
for (const scope of model.scopes) {
|
|
4366
4768
|
if (scope.kind === "module") continue;
|
|
4367
|
-
slots.set(scope, [...scope.declarations.values()].filter((declaration) => !NO_SLOT.has(declaration.kind) && declaration.reads.some((read) => clientSites.has(read.site))));
|
|
4769
|
+
slots.set(scope, [...scope.declarations.values()].filter((declaration) => !NO_SLOT.has(declaration.kind) && (declaration.reads.some((read) => clientSites.has(read.site)) || declaration.bound === true || declaration.kind === "prop" && declaration.writable === true && declaration.writes.some((write) => clientSites.has(write.site)))));
|
|
4368
4770
|
}
|
|
4369
4771
|
return {
|
|
4370
4772
|
isLiveSite,
|
|
@@ -4385,10 +4787,13 @@ function createPlan(file, graph, path, hideNames = false) {
|
|
|
4385
4787
|
needsId: scope.kind === "component",
|
|
4386
4788
|
anchors: 0
|
|
4387
4789
|
});
|
|
4790
|
+
const boundCalls = new Set(model.bindings.map((binding) => binding.call));
|
|
4388
4791
|
const anchors = /* @__PURE__ */ new Map();
|
|
4792
|
+
const anchorScopes = /* @__PURE__ */ new Map();
|
|
4389
4793
|
const anchor = (scope, target) => {
|
|
4390
4794
|
const plan = scopes.get(scope);
|
|
4391
4795
|
anchors.set(target, plan.anchors++);
|
|
4796
|
+
anchorScopes.set(target, scope);
|
|
4392
4797
|
plan.needsId = true;
|
|
4393
4798
|
};
|
|
4394
4799
|
const symbols = /* @__PURE__ */ new Map();
|
|
@@ -4446,10 +4851,12 @@ function createPlan(file, graph, path, hideNames = false) {
|
|
|
4446
4851
|
});
|
|
4447
4852
|
const content = node.kind === "element" ? liveContent(node) : void 0;
|
|
4448
4853
|
const events = sites.some((site) => site.kind === "event");
|
|
4854
|
+
const bound = node.kind === "element" && node.attributes.some((attribute) => attribute.kind === "value" && boundCalls.has(unparen(attribute.value.ast)));
|
|
4449
4855
|
const implied = node.kind === "element" && outer === scope;
|
|
4450
|
-
if (hasRef || content || itemRoots.has(node) || sites.some((site) => isLiveSite(site)) || events && !implied) anchor(scope, node);
|
|
4856
|
+
if (hasRef || bound || content || itemRoots.has(node) || sites.some((site) => isLiveSite(site)) || events && !implied) anchor(scope, node);
|
|
4451
4857
|
if (content) {
|
|
4452
4858
|
anchors.set(content, anchors.get(node));
|
|
4859
|
+
anchorScopes.set(content, scope);
|
|
4453
4860
|
contents.add(content);
|
|
4454
4861
|
if (node.kind === "element" && RAW_TEXT.has(node.tag.toLowerCase())) textContents.add(content);
|
|
4455
4862
|
return;
|
|
@@ -4571,6 +4978,7 @@ function createPlan(file, graph, path, hideNames = false) {
|
|
|
4571
4978
|
scopes,
|
|
4572
4979
|
bodyScopes,
|
|
4573
4980
|
anchors,
|
|
4981
|
+
anchorScopes,
|
|
4574
4982
|
contents,
|
|
4575
4983
|
textContents,
|
|
4576
4984
|
elementItems,
|
|
@@ -4753,7 +5161,9 @@ function mayWait(plan, nodes) {
|
|
|
4753
5161
|
case "text":
|
|
4754
5162
|
case "listener": break;
|
|
4755
5163
|
default: {
|
|
4756
|
-
|
|
5164
|
+
let bodies;
|
|
5165
|
+
if (node.kind === "loading" || node.kind === "defer" || node.kind === "client") bodies = node.fallback ? [node.fallback] : [];
|
|
5166
|
+
else bodies = blockBodies(node);
|
|
4757
5167
|
for (const body of bodies) if (mayWait(plan, body.children)) return true;
|
|
4758
5168
|
}
|
|
4759
5169
|
}
|
|
@@ -4900,6 +5310,8 @@ function specialCall(declarator) {
|
|
|
4900
5310
|
const name = init.callee.name;
|
|
4901
5311
|
return name === "$getContext" || name === "$id" || name === "$route" || name === "$navigation" ? name : void 0;
|
|
4902
5312
|
}
|
|
5313
|
+
/** The attribute that sets the method of a form, by the attribute that sets its action. */
|
|
5314
|
+
const FORM_METHODS = /* @__PURE__ */ new Map([["action", "method"], ["formaction", "formmethod"]]);
|
|
4903
5315
|
/** The contexts that the runtime provides, by the compile-time function that reads them. */
|
|
4904
5316
|
const BUILT_IN_CONTEXTS = {
|
|
4905
5317
|
$route: "$$b.routeContext",
|
|
@@ -4907,6 +5319,8 @@ const BUILT_IN_CONTEXTS = {
|
|
|
4907
5319
|
};
|
|
4908
5320
|
/** Writes code that renders markup to an HTML string, on the server or on the client. */
|
|
4909
5321
|
/** The exports of the core that do on the client what the server's render context does. */
|
|
5322
|
+
/** The `$handler` calls that each patch has edited, since emitters of a file share its patch. */
|
|
5323
|
+
const handlerEdits = /* @__PURE__ */ new WeakMap();
|
|
4910
5324
|
const CLIENT_HELPERS = {
|
|
4911
5325
|
scope: "createScope",
|
|
4912
5326
|
slots: "setSlots",
|
|
@@ -4920,6 +5334,7 @@ const CLIENT_HELPERS = {
|
|
|
4920
5334
|
portal: "addPortal",
|
|
4921
5335
|
style: "addStyle",
|
|
4922
5336
|
fn: "handlerProp",
|
|
5337
|
+
bindings: "bindings",
|
|
4923
5338
|
after: "afterInsert",
|
|
4924
5339
|
title: "title"
|
|
4925
5340
|
};
|
|
@@ -5022,8 +5437,66 @@ var Emitter = class {
|
|
|
5022
5437
|
this.blocking = blockingMemos(plan);
|
|
5023
5438
|
this.inline = options.mode === "server" ? plainValues(plan, this.blocking) : /* @__PURE__ */ new Set();
|
|
5024
5439
|
for (const site of plan.graph.model.sites) this.sitesByNode.set(site.node, site);
|
|
5440
|
+
this.addHandlerEdits();
|
|
5441
|
+
this.addBindEdits();
|
|
5025
5442
|
for (const declaration of plan.graph.model.declarations) for (const ref of declaration.refs) this.refTargets.set(ref.attribute, declaration);
|
|
5026
5443
|
}
|
|
5444
|
+
/**
|
|
5445
|
+
* `$handler(fn, ...args)` marks its function as a client function with its
|
|
5446
|
+
* arguments, `fn(fn, "<id>#<export>", scope, [args])`, so a spread can
|
|
5447
|
+
* pass it on. The calls are edits of the source, wherever they are in a
|
|
5448
|
+
* script. Emitters of one file share its patch, so each call is edited once.
|
|
5449
|
+
*/
|
|
5450
|
+
addHandlerEdits() {
|
|
5451
|
+
let edited = handlerEdits.get(this.patch);
|
|
5452
|
+
if (!edited) handlerEdits.set(this.patch, edited = /* @__PURE__ */ new Set());
|
|
5453
|
+
for (const site of this.plan.graph.model.sites) {
|
|
5454
|
+
const call = site.handler;
|
|
5455
|
+
const fn = call?.arguments[0];
|
|
5456
|
+
if (!call || !fn || edited.has(call)) continue;
|
|
5457
|
+
edited.add(call);
|
|
5458
|
+
const args = call.arguments.slice(1);
|
|
5459
|
+
const symbol = this.plan.symbols.get(site);
|
|
5460
|
+
if (!symbol) {
|
|
5461
|
+
this.patch.replace(call.start, fn.start, "(");
|
|
5462
|
+
this.patch.replace(fn.end, call.end, ")");
|
|
5463
|
+
continue;
|
|
5464
|
+
}
|
|
5465
|
+
const ref = JSON.stringify(`${this.plan.id}#${symbol}`);
|
|
5466
|
+
const scope = this.scopeVar(instanceScope(this.plan, site.scope));
|
|
5467
|
+
this.patch.replace(call.start, fn.start, `${this.helper("fn")}(`);
|
|
5468
|
+
if (args.length === 0) this.patch.replace(fn.end, call.end, `, ${ref}, ${scope})`);
|
|
5469
|
+
else {
|
|
5470
|
+
this.patch.replace(fn.end, args[0].start, `, ${ref}, ${scope}, [`);
|
|
5471
|
+
this.patch.replace(args.at(-1).end, call.end, "])");
|
|
5472
|
+
}
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5475
|
+
/**
|
|
5476
|
+
* `$bind(name)` passes the child the value of the name with its slot,
|
|
5477
|
+
* `binding(name, scope, slot)`, so the child's writes reach it.
|
|
5478
|
+
*/
|
|
5479
|
+
addBindEdits() {
|
|
5480
|
+
let edited = handlerEdits.get(this.patch);
|
|
5481
|
+
if (!edited) handlerEdits.set(this.patch, edited = /* @__PURE__ */ new Set());
|
|
5482
|
+
for (const { call, declaration, setter } of this.plan.graph.model.bindings) {
|
|
5483
|
+
const [target, fn] = call.arguments;
|
|
5484
|
+
if (!target || edited.has(call)) continue;
|
|
5485
|
+
edited.add(call);
|
|
5486
|
+
const scope = this.scopeVar(instanceScope(this.plan, declaration.scope));
|
|
5487
|
+
const slot = slotIndex(this.plan, declaration);
|
|
5488
|
+
this.patch.replace(call.start, target.start, "$$b.binding((");
|
|
5489
|
+
const symbol = setter && this.plan.symbols.get(setter);
|
|
5490
|
+
if (!fn || !setter || !symbol) {
|
|
5491
|
+
this.patch.replace(target.end, call.end, `), ${scope}, ${slot})`);
|
|
5492
|
+
continue;
|
|
5493
|
+
}
|
|
5494
|
+
const ref = JSON.stringify(`${this.plan.id}#${symbol}`);
|
|
5495
|
+
const owner = this.scopeVar(instanceScope(this.plan, setter.scope));
|
|
5496
|
+
this.patch.replace(target.end, fn.start, `), ${scope}, ${slot}, ${this.helper("fn")}(`);
|
|
5497
|
+
this.patch.replace(fn.end, call.end, `, ${ref}, ${owner}))`);
|
|
5498
|
+
}
|
|
5499
|
+
}
|
|
5027
5500
|
line(code) {
|
|
5028
5501
|
this.flush();
|
|
5029
5502
|
this.lines.push(`${" ".repeat(this.depth)}${code}`);
|
|
@@ -5109,6 +5582,10 @@ var Emitter = class {
|
|
|
5109
5582
|
const names = this.options.mode === "server" ? `, ${JSON.stringify(slots.map((slot) => slot.name))}` : "";
|
|
5110
5583
|
this.line(`${this.helper("slots")}(${this.scopeVar(scope)}, [${values.join(", ")}]${names});`);
|
|
5111
5584
|
}
|
|
5585
|
+
if (scope.kind === "component") {
|
|
5586
|
+
const bindable = slots.flatMap((slot, index) => slot.kind === "prop" && slot.writable && slot.propKey !== void 0 ? [`${JSON.stringify(slot.propKey)}: ${index}`] : []);
|
|
5587
|
+
if (bindable.length > 0) this.line(`${this.helper("bindings")}(${this.scopeVar(scope)}, $$props, { ${bindable.join(", ")} });`);
|
|
5588
|
+
}
|
|
5112
5589
|
}
|
|
5113
5590
|
/** True if the server inserts a primitive, such as a memo that it computes as a plain value. */
|
|
5114
5591
|
isPrimitiveInsert(expression) {
|
|
@@ -5227,7 +5704,9 @@ var Emitter = class {
|
|
|
5227
5704
|
this.line(`const ${declaration.name} = ${this.helper("id")}(${target}, ${declaration.idIndex});`);
|
|
5228
5705
|
continue;
|
|
5229
5706
|
}
|
|
5230
|
-
|
|
5707
|
+
let context;
|
|
5708
|
+
if (call && BUILT_IN_CONTEXTS[call]) context = BUILT_IN_CONTEXTS[call];
|
|
5709
|
+
else if (call === "$getContext" && init.arguments[0]) context = this.source(init.arguments[0]);
|
|
5231
5710
|
if (!context || declarator.id.type !== "Identifier") {
|
|
5232
5711
|
this.line(`${statement.kind} ${this.source(declarator)};`);
|
|
5233
5712
|
continue;
|
|
@@ -5394,6 +5873,12 @@ var Emitter = class {
|
|
|
5394
5873
|
this.emitDynamic(node, scope);
|
|
5395
5874
|
return;
|
|
5396
5875
|
case "fragment":
|
|
5876
|
+
if (node.reveal && this.options.mode === "server") {
|
|
5877
|
+
this.line(`$$ctx.revealStart(${JSON.stringify(node.reveal.order)}, ${node.reveal.collapsed});`);
|
|
5878
|
+
this.emitNodes(node.children, scope);
|
|
5879
|
+
this.line("$$ctx.revealEnd();");
|
|
5880
|
+
return;
|
|
5881
|
+
}
|
|
5397
5882
|
this.emitNodes(node.children, scope);
|
|
5398
5883
|
return;
|
|
5399
5884
|
case "listener": {
|
|
@@ -5411,6 +5896,25 @@ var Emitter = class {
|
|
|
5411
5896
|
} else this.emitBlock(node, scope);
|
|
5412
5897
|
}
|
|
5413
5898
|
}
|
|
5899
|
+
/**
|
|
5900
|
+
* The `b-on` entry of `value=$bind(name)` or `checked=$bind(name)` on an
|
|
5901
|
+
* element: `input=$bind#<hops>.<slot>`, where `hops` counts the parents
|
|
5902
|
+
* from the scope of the element to the scope of the name. The core writes
|
|
5903
|
+
* the slot from the element without loading any code of the component.
|
|
5904
|
+
*/
|
|
5905
|
+
bindEntry(node, attribute, scope) {
|
|
5906
|
+
let value = attribute.value.ast;
|
|
5907
|
+
while (value.type === "ParenthesizedExpression") value = value.expression;
|
|
5908
|
+
const binding = this.plan.graph.model.bindings.find((item) => item.call === value);
|
|
5909
|
+
if (!binding) return;
|
|
5910
|
+
const setter = binding.setter && this.plan.symbols.get(binding.setter);
|
|
5911
|
+
const hops = scopePath(this.plan, "$$s", instanceScope(this.plan, scope), instanceScope(this.plan, binding.declaration.scope)).split(".p").length - 1;
|
|
5912
|
+
const type = node.attributes.find((item) => item.kind === "static" && item.name === "type");
|
|
5913
|
+
const box = type && typeof type.value === "string" && /^(checkbox|radio)$/i.test(type.value);
|
|
5914
|
+
const event = attribute.name === "checked" || box || node.tag.toLowerCase() === "select" ? "change" : "input";
|
|
5915
|
+
if (setter) return `${event}=$set:${this.plan.id}#${setter}`;
|
|
5916
|
+
return `${event}=$bind#${hops}.${slotIndex(this.plan, binding.declaration)}`;
|
|
5917
|
+
}
|
|
5414
5918
|
eventEntry({ event, modifiers, handler }) {
|
|
5415
5919
|
const site = this.sitesByNode.get(handler.ast);
|
|
5416
5920
|
return `${[event, ...[.../* @__PURE__ */ new Set([...modifiers, ...site.modifiers ?? []])]].join(":")}=${this.plan.id}#${this.plan.symbols.get(site)}`;
|
|
@@ -5450,11 +5954,11 @@ var Emitter = class {
|
|
|
5450
5954
|
* server function without client code. Returns undefined otherwise.
|
|
5451
5955
|
*/
|
|
5452
5956
|
formAction(node, name, value, scope) {
|
|
5453
|
-
const method = name
|
|
5957
|
+
const method = FORM_METHODS.get(name);
|
|
5454
5958
|
if (!method || value.ast.type !== "Identifier") return;
|
|
5455
5959
|
const declaration = lookup(scope, value.ast.name);
|
|
5456
|
-
if (declaration?.kind !== "server-function") return;
|
|
5457
|
-
const ref = JSON.stringify(serverFunctionId(this.plan, declaration.name));
|
|
5960
|
+
if (declaration?.kind !== "server-function" && declaration?.serverImport === void 0) return;
|
|
5961
|
+
const ref = JSON.stringify(declaration.serverImport ?? serverFunctionId(this.plan, declaration.name));
|
|
5458
5962
|
const hasMethod = node.attributes.some((attribute) => "name" in attribute && attribute.name === method);
|
|
5459
5963
|
const methodArgument = hasMethod ? "" : `, ${JSON.stringify(method)}`;
|
|
5460
5964
|
const result = name === "action" ? this.actionSlot(declaration) : void 0;
|
|
@@ -5472,7 +5976,7 @@ var Emitter = class {
|
|
|
5472
5976
|
const pageTitle = node.tag === "title" && this.headBlocks > 0;
|
|
5473
5977
|
if (pageTitle && this.options.mode === "server") this.line(`${this.helper("title")}(${this.titleText(node)}, true);`);
|
|
5474
5978
|
let spreadHandlers;
|
|
5475
|
-
if (
|
|
5979
|
+
if (node.attributes.some((attribute) => attribute.kind === "spread")) {
|
|
5476
5980
|
spreadHandlers = this.unique("on");
|
|
5477
5981
|
this.line(`const ${spreadHandlers}: string[] = [];`);
|
|
5478
5982
|
}
|
|
@@ -5502,6 +6006,8 @@ var Emitter = class {
|
|
|
5502
6006
|
break;
|
|
5503
6007
|
}
|
|
5504
6008
|
this.code(`$$b.attribute(${JSON.stringify(attribute.name)}, ${this.expression(attribute.value)})`);
|
|
6009
|
+
const bound = this.bindEntry(node, attribute, scope);
|
|
6010
|
+
if (bound) events.unshift(bound);
|
|
5505
6011
|
break;
|
|
5506
6012
|
}
|
|
5507
6013
|
case "spread":
|
|
@@ -5544,7 +6050,7 @@ var Emitter = class {
|
|
|
5544
6050
|
mergedAttribute(node, attribute, scope, parts) {
|
|
5545
6051
|
switch (attribute.kind) {
|
|
5546
6052
|
case "static":
|
|
5547
|
-
parts.push(`{ ${JSON.stringify(attribute.name)}: ${attribute.value === true ? "
|
|
6053
|
+
parts.push(`{ ${JSON.stringify(attribute.name)}: ${attribute.value === true ? "''" : JSON.stringify(decodeAttribute(attribute.value))} }`);
|
|
5548
6054
|
return true;
|
|
5549
6055
|
case "value":
|
|
5550
6056
|
if (this.formAction(node, attribute.name, attribute.value, scope)) return false;
|
|
@@ -5772,7 +6278,7 @@ var Emitter = class {
|
|
|
5772
6278
|
}
|
|
5773
6279
|
this.line(`const ${boundary} = $$ctx.boundary();`);
|
|
5774
6280
|
if (inPlace) {
|
|
5775
|
-
this.line(`if ($$b.settled([${names.join(", ")}])) {`);
|
|
6281
|
+
this.line(`if ($$b.settled([${names.join(", ")}]) && $$ctx.mayShow()) {`);
|
|
5776
6282
|
this.line(`$$ctx.enter(${boundary});`);
|
|
5777
6283
|
for (const declaration of memos) this.line(`const ${declaration.name} = $$b.read(${promiseName(declaration.name)});`);
|
|
5778
6284
|
this.emitBody(block.body);
|
|
@@ -5784,9 +6290,11 @@ var Emitter = class {
|
|
|
5784
6290
|
this.code(boundary);
|
|
5785
6291
|
this.html("-->");
|
|
5786
6292
|
if (block.fallback) {
|
|
6293
|
+
this.code(`$$ctx.fallbackStart(${boundary})`);
|
|
5787
6294
|
this.line("{");
|
|
5788
6295
|
this.emitBody(block.fallback);
|
|
5789
6296
|
this.close();
|
|
6297
|
+
this.code(`$$ctx.fallbackEnd(${boundary})`);
|
|
5790
6298
|
}
|
|
5791
6299
|
this.html("<!--/l-->");
|
|
5792
6300
|
this.end(block);
|
|
@@ -5991,9 +6499,15 @@ function staticClasses(attributes) {
|
|
|
5991
6499
|
}
|
|
5992
6500
|
return classes;
|
|
5993
6501
|
}
|
|
6502
|
+
/** The entities that escape the characters of a class in an attribute. */
|
|
6503
|
+
const CLASS_ESCAPES = {
|
|
6504
|
+
"&": "&",
|
|
6505
|
+
"<": "<",
|
|
6506
|
+
"\"": """
|
|
6507
|
+
};
|
|
5994
6508
|
/** Escapes a class for an attribute, as the runtime does. */
|
|
5995
6509
|
function escapeClass(name) {
|
|
5996
|
-
return name.replace(/[&<"]/g, (char) => char
|
|
6510
|
+
return name.replace(/[&<"]/g, (char) => CLASS_ESCAPES[char]);
|
|
5997
6511
|
}
|
|
5998
6512
|
/**
|
|
5999
6513
|
* The classes of a literal `class` value, such as `{ done: todo.done }` or
|
|
@@ -6017,7 +6531,9 @@ function literalClasses(value, slice) {
|
|
|
6017
6531
|
for (const property of node.properties) {
|
|
6018
6532
|
if (property.type !== "Property" || property.kind !== "init" || property.method || property.computed) return false;
|
|
6019
6533
|
const { key } = property;
|
|
6020
|
-
|
|
6534
|
+
let name;
|
|
6535
|
+
if (key.type === "Identifier") name = key.name;
|
|
6536
|
+
else if (key.type === "Literal" && typeof key.value === "string") name = key.value;
|
|
6021
6537
|
if (!name || /^\d+$/.test(name) || name === "__proto__" || names.has(name)) return false;
|
|
6022
6538
|
names.add(name);
|
|
6023
6539
|
const constant = property.value;
|
|
@@ -6320,11 +6836,17 @@ var Rewriter = class {
|
|
|
6320
6836
|
plan;
|
|
6321
6837
|
diagnostics;
|
|
6322
6838
|
shared;
|
|
6839
|
+
/** The sites of `$handler` calls, by call. */
|
|
6840
|
+
handlers = /* @__PURE__ */ new Map();
|
|
6841
|
+
/** The declarations of the names of `$bind` calls, by call. */
|
|
6842
|
+
bindings = /* @__PURE__ */ new Map();
|
|
6323
6843
|
constructor(file, plan, diagnostics, shared) {
|
|
6324
6844
|
this.file = file;
|
|
6325
6845
|
this.plan = plan;
|
|
6326
6846
|
this.diagnostics = diagnostics;
|
|
6327
6847
|
this.shared = shared;
|
|
6848
|
+
for (const site of plan.graph.model.sites) if (site.handler) this.handlers.set(site.handler, site);
|
|
6849
|
+
for (const binding of plan.graph.model.bindings) this.bindings.set(binding.call, binding);
|
|
6328
6850
|
}
|
|
6329
6851
|
/**
|
|
6330
6852
|
* The call of the shared code of a site that a module function gave the
|
|
@@ -6520,6 +7042,38 @@ var Rewriter = class {
|
|
|
6520
7042
|
break;
|
|
6521
7043
|
}
|
|
6522
7044
|
case "CallExpression": {
|
|
7045
|
+
const bound = this.bindings.get(node);
|
|
7046
|
+
const [name, setterFn] = node.arguments;
|
|
7047
|
+
if (bound && name) {
|
|
7048
|
+
const { declaration, setter } = bound;
|
|
7049
|
+
const path = scopePath(this.plan, scopeVar, base, declaration.scope);
|
|
7050
|
+
const slot = slotIndex(this.plan, declaration);
|
|
7051
|
+
const symbol = setter && this.plan.symbols.get(setter);
|
|
7052
|
+
patch.replace(node.start, name.start, "$$b.binding((");
|
|
7053
|
+
if (setterFn && setter && symbol) {
|
|
7054
|
+
const ref = JSON.stringify(`${this.plan.id}#${symbol}`);
|
|
7055
|
+
const owner = scopePath(this.plan, scopeVar, base, instanceScope(this.plan, setter.scope));
|
|
7056
|
+
patch.replace(name.end, node.end, `), ${path}, ${slot}, $$b.handlerProp(() => {}, ${ref}, ${owner}))`);
|
|
7057
|
+
} else patch.replace(name.end, node.end, `), ${path}, ${slot})`);
|
|
7058
|
+
visit(name);
|
|
7059
|
+
return;
|
|
7060
|
+
}
|
|
7061
|
+
const handler = this.handlers.get(node);
|
|
7062
|
+
if (handler) {
|
|
7063
|
+
const [fn, ...args] = node.arguments;
|
|
7064
|
+
const symbol = this.plan.symbols.get(handler);
|
|
7065
|
+
const ref = JSON.stringify(`${this.plan.id}#${symbol}`);
|
|
7066
|
+
const owner = scopePath(this.plan, scopeVar, base, instanceScope(this.plan, handler.scope));
|
|
7067
|
+
const modifiers = JSON.stringify(handler.modifiers ?? []);
|
|
7068
|
+
patch.replace(node.start, fn.end, `$$b.handlerProp(() => {}, ${ref}, ${owner}`);
|
|
7069
|
+
if (args.length === 0) patch.replace(fn.end, node.end, `, [], ${modifiers})`);
|
|
7070
|
+
else {
|
|
7071
|
+
patch.replace(fn.end, args[0].start, ", [");
|
|
7072
|
+
patch.replace(args.at(-1).end, node.end, `], ${modifiers})`);
|
|
7073
|
+
}
|
|
7074
|
+
for (const argument of args) visit(argument);
|
|
7075
|
+
return;
|
|
7076
|
+
}
|
|
6523
7077
|
const fn = target(node.callee)?.declaration;
|
|
6524
7078
|
if (fn?.kind === "function" && slotIndex(this.plan, fn) === -1) {
|
|
6525
7079
|
const owner = scopePath(this.plan, scopeVar, base, instanceScope(this.plan, fn.scope));
|
|
@@ -6536,7 +7090,10 @@ var Rewriter = class {
|
|
|
6536
7090
|
const slot = slotIndex(this.plan, item);
|
|
6537
7091
|
return slot === -1 ? [] : [`$$b.pending(${path(item)}, ${slot})`];
|
|
6538
7092
|
});
|
|
6539
|
-
|
|
7093
|
+
let value;
|
|
7094
|
+
if (checks.length === 0) value = "false";
|
|
7095
|
+
else if (checks.length === 1) value = checks[0];
|
|
7096
|
+
else value = `(${checks.join(" || ")})`;
|
|
6540
7097
|
patch.replace(node.start, node.end, value);
|
|
6541
7098
|
return;
|
|
6542
7099
|
}
|
|
@@ -6788,7 +7345,7 @@ var ClientGenerator = class {
|
|
|
6788
7345
|
reads(sites) {
|
|
6789
7346
|
const result = /* @__PURE__ */ new Set();
|
|
6790
7347
|
for (const site of sites) {
|
|
6791
|
-
const shared = this.
|
|
7348
|
+
const shared = this.rewriter.sharedCall(site, "$$s", instanceScope(this.plan, site.scope)) !== void 0;
|
|
6792
7349
|
for (const read of site.reads) if (!shared || read.declaration.kind !== "import") result.add(read.declaration);
|
|
6793
7350
|
}
|
|
6794
7351
|
return result;
|
|
@@ -7046,7 +7603,9 @@ var ClientGenerator = class {
|
|
|
7046
7603
|
const insert = this.findInsert(site);
|
|
7047
7604
|
const anchor = insert && this.plan.anchors.get(insert);
|
|
7048
7605
|
if (anchor !== void 0) {
|
|
7049
|
-
|
|
7606
|
+
let fn = "text";
|
|
7607
|
+
if (this.plan.textContents.has(insert)) fn = "writeText";
|
|
7608
|
+
else if (this.plan.contents.has(insert)) fn = "content";
|
|
7050
7609
|
this.emit(`export function ${name("u")}($$s) {\n $$b.${fn}($$s, ${anchor}, ${expression()});\n}`);
|
|
7051
7610
|
}
|
|
7052
7611
|
return;
|
|
@@ -7075,7 +7634,8 @@ var ClientGenerator = class {
|
|
|
7075
7634
|
}
|
|
7076
7635
|
if (owner.kind === "component") {
|
|
7077
7636
|
if (attribute.kind === "spread") {
|
|
7078
|
-
|
|
7637
|
+
const after = owner.attributes.slice(owner.attributes.indexOf(attribute) + 1).flatMap((item) => item.kind === "static" || item.kind === "value" || item.kind === "event" ? [item.name] : []);
|
|
7638
|
+
this.emit(`export function ${name("u")}($$s) {\n $$b.spreadProps($$s, ${anchor}, ${expression()}, ${JSON.stringify(after)});\n}`);
|
|
7079
7639
|
return;
|
|
7080
7640
|
}
|
|
7081
7641
|
this.emit(`export function ${name("u")}($$s) {\n $$b.prop($$s, ${anchor}, ${JSON.stringify(attribute.name)}, ${expression()});\n}`);
|
|
@@ -7086,7 +7646,7 @@ var ClientGenerator = class {
|
|
|
7086
7646
|
if (this.plan.styles.css) own.push(this.plan.styles.attribute, "style");
|
|
7087
7647
|
const parts = owner.attributes.flatMap((item) => {
|
|
7088
7648
|
if (item === attribute) return [expression()];
|
|
7089
|
-
return item.kind === "static" ? [`{ ${JSON.stringify(item.name)}: ${item.value === true ? "
|
|
7649
|
+
return item.kind === "static" ? [`{ ${JSON.stringify(item.name)}: ${item.value === true ? "''" : JSON.stringify(decodeAttribute(item.value))} }`] : [];
|
|
7090
7650
|
});
|
|
7091
7651
|
const value = parts.length > 1 ? `$$b.mergeAttributes([${parts.join(", ")}])` : expression();
|
|
7092
7652
|
this.emit(`export function ${name("u")}($$s) {\n $$b.attrs($$s, ${anchor}, ${value}, ${JSON.stringify(own)});\n}`);
|
|
@@ -7131,7 +7691,7 @@ var ClientGenerator = class {
|
|
|
7131
7691
|
}
|
|
7132
7692
|
case "for":
|
|
7133
7693
|
case "repeat": {
|
|
7134
|
-
const items = block.kind === "for" ?
|
|
7694
|
+
const items = block.kind === "for" ? `$$b.listOf(${header(0)})` : `Array.from({ length: ${header(0)} }, (_, index) => index)`;
|
|
7135
7695
|
const key = this.keyFunction(block, base);
|
|
7136
7696
|
const fallback = block.fallback ? this.renderName(block.fallback) : "undefined";
|
|
7137
7697
|
const fallbackKinds = block.fallback ? this.kinds([block.fallback]) : [];
|
|
@@ -7222,7 +7782,9 @@ var ClientGenerator = class {
|
|
|
7222
7782
|
});
|
|
7223
7783
|
const isItem = (block.kind === "for" || block.kind === "repeat") && block.body === body;
|
|
7224
7784
|
const isCatch = block.kind === "try" && block.fallback === body;
|
|
7225
|
-
|
|
7785
|
+
let params = "";
|
|
7786
|
+
if (isItem) params = ", $$item, $$index";
|
|
7787
|
+
else if (isCatch) params = ", $$error";
|
|
7226
7788
|
emitter.line(`export function r${scope.id}($$p${params}) {`);
|
|
7227
7789
|
emitter.line(`let $$html = '';`);
|
|
7228
7790
|
if (block.kind === "try" && isCatch) {
|
|
@@ -7528,7 +8090,8 @@ function compile(source, options = {}) {
|
|
|
7528
8090
|
for (const declaration of model.declarations) if (declaration.imported && options.serverImport) {
|
|
7529
8091
|
declaration.serverImport = options.serverImport(declaration.imported.source, declaration.imported.name);
|
|
7530
8092
|
if (declaration.serverImport !== void 0) {
|
|
7531
|
-
|
|
8093
|
+
const name = declaration.imported.name;
|
|
8094
|
+
declaration.refreshed = !options.refreshed || options.refreshed.has("*") || options.refreshed.has(name);
|
|
7532
8095
|
for (const read of declaration.reads) read.site.calls.add(declaration);
|
|
7533
8096
|
}
|
|
7534
8097
|
}
|
|
@@ -7543,7 +8106,7 @@ function compile(source, options = {}) {
|
|
|
7543
8106
|
const plan = createPlan(file, graph, options.path, options.hideNames);
|
|
7544
8107
|
const styleErrors = [...plan.styles.diagnostics, ...plan.diagnostics].filter((diagnostic) => diagnostic.severity === "error");
|
|
7545
8108
|
if (styleErrors.length > 0) fail(styleErrors);
|
|
7546
|
-
const captures = [...checkCaptures(file, plan), ...options.envImport ? checkEnv(file, plan, options.envImport) : []];
|
|
8109
|
+
const captures = [...checkCaptures(file, plan, options.sendableClasses), ...options.envImport ? checkEnv(file, plan, options.envImport) : []];
|
|
7547
8110
|
if (captures.length > 0) fail(captures);
|
|
7548
8111
|
const shared = sharedContext(origin, modules, calls, options.path ?? filename);
|
|
7549
8112
|
const client = generateClient(file, plan, options.merge, shared);
|
|
@@ -7609,6 +8172,18 @@ function siteLabel(source, site) {
|
|
|
7609
8172
|
return `${site.label} (${at(source, site.range)})`;
|
|
7610
8173
|
}
|
|
7611
8174
|
/** A short name for a scope, such as `body of #for (12:3)`. */
|
|
8175
|
+
/** A short name of an anchor for the devtools: its tag, its block, or `$client`. */
|
|
8176
|
+
function anchorLabel(target) {
|
|
8177
|
+
if ("range" in target) return target.kind === "client" ? "$client" : target.label;
|
|
8178
|
+
switch (target.kind) {
|
|
8179
|
+
case "element": return `<${target.tag}>`;
|
|
8180
|
+
case "component": return `<${target.name}>`;
|
|
8181
|
+
case "dynamic": return "<dynamic tag>";
|
|
8182
|
+
case "listener": return `#${target.target} listener`;
|
|
8183
|
+
case "insert": return "insert";
|
|
8184
|
+
default: return `#${target.kind}`;
|
|
8185
|
+
}
|
|
8186
|
+
}
|
|
7612
8187
|
function scopeLabel(source, scope) {
|
|
7613
8188
|
if (scope.kind === "body" && scope.block) return `body of #${scope.block.kind} (${at(source, scope.block)})`;
|
|
7614
8189
|
if (scope.kind === "template" && scope.template) return `#template ${scope.template.name}`;
|
|
@@ -7635,7 +8210,9 @@ function report(source, result, liveProps, parents) {
|
|
|
7635
8210
|
}
|
|
7636
8211
|
};
|
|
7637
8212
|
visit(site);
|
|
7638
|
-
|
|
8213
|
+
let kind = "runs on the event";
|
|
8214
|
+
if (site.kind === "client") kind = `runs when the browser is ${site.trigger === "load" ? "loaded" : site.trigger}`;
|
|
8215
|
+
else if (site.kind === "prop") kind = "a function passed to a component";
|
|
7639
8216
|
roots.push({
|
|
7640
8217
|
label: `${symbol}: ${site.label}`,
|
|
7641
8218
|
at: at(source, site.range),
|
|
@@ -7758,6 +8335,6 @@ function inspect(source, options = {}) {
|
|
|
7758
8335
|
};
|
|
7759
8336
|
}
|
|
7760
8337
|
//#endregion
|
|
7761
|
-
export {
|
|
8338
|
+
export { analyzeProject as A, isWithin as B, isReactiveModule as C, unmarked as D, originalPosition as E, parse$1 as F, buildGraph as I, BrumateError as L, forEachNode as M, resolveRelative as N, entryClasses as O, summarize as P, getLocation as R, sharedSites as S, builtin as T, lookup as V, 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, inspect as r, compile as s, anchorLabel as t, generateRender as u, getComponentName as v, resolveFromDisk as w, generateShared as x, hash as y, analyze$1 as z };
|
|
7762
8339
|
|
|
7763
|
-
//# sourceMappingURL=inspect-
|
|
8340
|
+
//# sourceMappingURL=inspect-BHpOw1LF.js.map
|