@barefootjs/jsx 0.38.0 → 0.39.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/action-accessor.d.ts +159 -0
- package/dist/action-accessor.d.ts.map +1 -0
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/analyzer.d.ts +30 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/async-action-refusal.d.ts +45 -0
- package/dist/async-action-refusal.d.ts.map +1 -0
- package/dist/compiler.d.ts.map +1 -1
- package/dist/debug.d.ts +61 -5
- package/dist/debug.d.ts.map +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/format-date-refusal.d.ts +2 -6
- package/dist/format-date-refusal.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1056 -344
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +4 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +41 -2
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/signal-initializer.d.ts +24 -0
- package/dist/signal-initializer.d.ts.map +1 -0
- package/dist/template-position-walk.d.ts +68 -0
- package/dist/template-position-walk.d.ts.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +191 -1
- package/src/__tests__/action-accessor.test.ts +166 -0
- package/src/__tests__/create-mutation.test.ts +220 -0
- package/src/__tests__/create-query.test.ts +644 -0
- package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
- package/src/__tests__/debug.test.ts +222 -0
- package/src/__tests__/doc-examples.test.ts +66 -3
- package/src/__tests__/props-destructuring.test.ts +79 -4
- package/src/__tests__/reactive-factory-arity.test.ts +311 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +5 -3
- package/src/action-accessor.ts +289 -0
- package/src/adapters/jsx-adapter.ts +17 -0
- package/src/analyzer.ts +558 -33
- package/src/async-action-refusal.ts +254 -0
- package/src/compiler.ts +3 -0
- package/src/debug.ts +318 -103
- package/src/errors.ts +39 -0
- package/src/format-date-refusal.ts +6 -125
- package/src/index.ts +2 -1
- package/src/ir-to-client-js/build-references.ts +6 -2
- package/src/ir-to-client-js/collect-elements.ts +1 -0
- package/src/ir-to-client-js/compute-inlinability.ts +2 -1
- package/src/ir-to-client-js/compute-scope.ts +3 -1
- package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
- package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
- package/src/ir-to-client-js/csr-substitute.ts +11 -3
- package/src/ir-to-client-js/declaration-sort.ts +7 -3
- package/src/ir-to-client-js/emit-module-level.ts +7 -4
- package/src/ir-to-client-js/emit-registration.ts +5 -10
- package/src/ir-to-client-js/index.ts +7 -2
- package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
- package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
- package/src/ir-to-client-js/prop-handling.ts +4 -0
- package/src/ir-to-client-js/reactivity.ts +1 -0
- package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
- package/src/ir-to-client-js/types.ts +4 -0
- package/src/ir-to-client-js/utils.ts +55 -7
- package/src/jsx-to-ir.ts +36 -2
- package/src/signal-initializer.ts +36 -0
- package/src/template-position-walk.ts +203 -0
- package/src/types.ts +52 -0
package/dist/index.js
CHANGED
|
@@ -2461,7 +2461,8 @@ import {
|
|
|
2461
2461
|
loopEndMarker,
|
|
2462
2462
|
loopItemMarker,
|
|
2463
2463
|
toHTMLAttrName as toHtmlAttrName,
|
|
2464
|
-
keyAttrName as sharedKeyAttrName
|
|
2464
|
+
keyAttrName as sharedKeyAttrName,
|
|
2465
|
+
BF_PORTAL_OWNER
|
|
2465
2466
|
} from "@barefootjs/shared";
|
|
2466
2467
|
|
|
2467
2468
|
// src/ir-to-client-js/imports.ts
|
|
@@ -2813,7 +2814,18 @@ function initFunctionName(componentName) {
|
|
|
2813
2814
|
return RESERVED_RUNTIME_NAMES.has(name) ? `${name}$` : name;
|
|
2814
2815
|
}
|
|
2815
2816
|
function isCommentScopedRoot(root) {
|
|
2816
|
-
return root
|
|
2817
|
+
return isScopeCommentFragmentRoot(root) || root.type === "component";
|
|
2818
|
+
}
|
|
2819
|
+
function isScopeCommentFragmentRoot(root) {
|
|
2820
|
+
return root.type === "fragment" && !!root.needsScopeComment;
|
|
2821
|
+
}
|
|
2822
|
+
function componentDefScopeFlags(root) {
|
|
2823
|
+
const flags = [];
|
|
2824
|
+
if (isCommentScopedRoot(root))
|
|
2825
|
+
flags.push("comment: true");
|
|
2826
|
+
if (isScopeCommentFragmentRoot(root))
|
|
2827
|
+
flags.push("fragmentRoot: true");
|
|
2828
|
+
return flags;
|
|
2817
2829
|
}
|
|
2818
2830
|
var keyAttrName = sharedKeyAttrName;
|
|
2819
2831
|
function mapArrayKeyArgs(bfIdArg, keyed, loopDepth) {
|
|
@@ -2917,13 +2929,13 @@ function wrapHandlerForTurn(handler, handlerId, loc) {
|
|
|
2917
2929
|
const idArg = loc ? `${JSON.stringify(handlerId)}, ${JSON.stringify(loc)}` : JSON.stringify(handlerId);
|
|
2918
2930
|
return `(...__bfa) => { beginTurn(${idArg}); try { return (${handler.trim()})(...__bfa) } finally { endTurn() } }`;
|
|
2919
2931
|
}
|
|
2920
|
-
function emitRefCall(callback, elementVar) {
|
|
2932
|
+
function emitRefCall(callback, elementVar, ssrPortalOwner = false) {
|
|
2921
2933
|
const trimmed = callback.trim();
|
|
2922
2934
|
const isBareIdent = /^[a-zA-Z_$][\w$]*$/.test(trimmed);
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
return `
|
|
2935
|
+
const call = isBareIdent ? `(${callback})(${elementVar})` : `(${callback})?.(${elementVar})`;
|
|
2936
|
+
if (!ssrPortalOwner)
|
|
2937
|
+
return call;
|
|
2938
|
+
return `{ ${call}; if (__scopeId) ${elementVar}.setAttribute('${BF_PORTAL_OWNER}', __scopeId) }`;
|
|
2927
2939
|
}
|
|
2928
2940
|
function inferDefaultValue(type) {
|
|
2929
2941
|
if (type.kind === "primitive") {
|
|
@@ -3728,6 +3740,75 @@ function resolveRestSpreadOriginCore(bindings, constantValues, name) {
|
|
|
3728
3740
|
});
|
|
3729
3741
|
}
|
|
3730
3742
|
|
|
3743
|
+
// src/adapters/env-signal.ts
|
|
3744
|
+
var ENV_SIGNAL_CLIENT_FACTORY = {
|
|
3745
|
+
search: "createSearchParams"
|
|
3746
|
+
};
|
|
3747
|
+
var ENV_SIGNAL_READERS = new Map([
|
|
3748
|
+
["search", { key: "search", canonicalName: "searchParams", methods: new Set(["get"]) }]
|
|
3749
|
+
]);
|
|
3750
|
+
function envSignalReaderFor(key) {
|
|
3751
|
+
if (key === undefined)
|
|
3752
|
+
return null;
|
|
3753
|
+
return ENV_SIGNAL_READERS.get(key) ?? null;
|
|
3754
|
+
}
|
|
3755
|
+
function envSignalLocalNames(metadata, key) {
|
|
3756
|
+
const names = new Set;
|
|
3757
|
+
for (const s of metadata.signals) {
|
|
3758
|
+
if (s.envReader !== undefined && (key === undefined || s.envReader === key)) {
|
|
3759
|
+
names.add(s.getter);
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
return names;
|
|
3763
|
+
}
|
|
3764
|
+
function searchParamsLocalNames(metadata) {
|
|
3765
|
+
return envSignalLocalNames(metadata, "search");
|
|
3766
|
+
}
|
|
3767
|
+
function importsSearchParams(metadata) {
|
|
3768
|
+
return searchParamsLocalNames(metadata).size > 0;
|
|
3769
|
+
}
|
|
3770
|
+
function queryHrefLocalNames(metadata) {
|
|
3771
|
+
const names = new Set;
|
|
3772
|
+
for (const imp of metadata.imports) {
|
|
3773
|
+
if (!CLIENT_HELPER_SOURCES.has(imp.source) || imp.isTypeOnly)
|
|
3774
|
+
continue;
|
|
3775
|
+
for (const s of imp.specifiers) {
|
|
3776
|
+
if (s.isTypeOnly || s.isNamespace || s.isDefault)
|
|
3777
|
+
continue;
|
|
3778
|
+
if (s.name === "queryHref")
|
|
3779
|
+
names.add(s.alias ?? s.name);
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
return names;
|
|
3783
|
+
}
|
|
3784
|
+
var CLIENT_HELPER_SOURCES = new Set([
|
|
3785
|
+
"@barefootjs/client",
|
|
3786
|
+
"@barefootjs/client/runtime"
|
|
3787
|
+
]);
|
|
3788
|
+
function matchSearchParamsMethodCall(callee, args, localNames) {
|
|
3789
|
+
if (callee.kind !== "member" || callee.computed)
|
|
3790
|
+
return null;
|
|
3791
|
+
const recv = callee.object;
|
|
3792
|
+
if (recv.kind !== "call" || recv.args.length !== 0 || recv.callee.kind !== "identifier" || !localNames.has(recv.callee.name)) {
|
|
3793
|
+
return null;
|
|
3794
|
+
}
|
|
3795
|
+
return { method: callee.property, args };
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
// src/signal-initializer.ts
|
|
3799
|
+
function signalFactoryInitializer(signal) {
|
|
3800
|
+
if (signal.factory)
|
|
3801
|
+
return `${signal.factory.callee}(${signal.factory.argsText})`;
|
|
3802
|
+
if (signal.envReader) {
|
|
3803
|
+
const factory = signal.envFactory ?? ENV_SIGNAL_CLIENT_FACTORY[signal.envReader];
|
|
3804
|
+
return factory ? `${factory}()` : null;
|
|
3805
|
+
}
|
|
3806
|
+
return null;
|
|
3807
|
+
}
|
|
3808
|
+
function signalSecondBinding(signal) {
|
|
3809
|
+
return signal.setter ?? signal.factory?.action ?? null;
|
|
3810
|
+
}
|
|
3811
|
+
|
|
3731
3812
|
// src/ir-to-client-js/csr-substitute.ts
|
|
3732
3813
|
function csrSubstitute(value, env, enclosingScope) {
|
|
3733
3814
|
if (!value || value.trim().length === 0) {
|
|
@@ -3959,8 +4040,9 @@ function buildSignalMemoEnv(signals, memos, propsObjectName, localConstants = []
|
|
|
3959
4040
|
replacement: normalizeSignalInitial(s, propsObjectName),
|
|
3960
4041
|
freeIdentifiers: s.initialFreeIdentifiers ?? new Set
|
|
3961
4042
|
});
|
|
3962
|
-
|
|
3963
|
-
|
|
4043
|
+
const second = signalSecondBinding(s);
|
|
4044
|
+
if (second) {
|
|
4045
|
+
substitutions.set(second, { kind: "identifier", replacement: "() => {}", freeIdentifiers: new Set });
|
|
3964
4046
|
}
|
|
3965
4047
|
}
|
|
3966
4048
|
for (const m of memos) {
|
|
@@ -3979,7 +4061,7 @@ function normalizeSignalInitial(signal, propsObjectName) {
|
|
|
3979
4061
|
const initialValue = signal.initialValue;
|
|
3980
4062
|
const propsName = propsObjectName ?? "props";
|
|
3981
4063
|
const propsPrefix = `${propsName}.`;
|
|
3982
|
-
if (initialValue.startsWith(propsPrefix) && !initialValue.includes("??")) {
|
|
4064
|
+
if (!signal.factory && initialValue.startsWith(propsPrefix) && !initialValue.includes("??")) {
|
|
3983
4065
|
return `${initialValue} ?? ${inferDefaultValue(signal.type)}`;
|
|
3984
4066
|
}
|
|
3985
4067
|
return signal.templateInitialValue ?? initialValue;
|
|
@@ -6779,7 +6861,11 @@ var ErrorCodes = {
|
|
|
6779
6861
|
REACTIVE_FACTORY_RENAME_UNSUPPORTED: "BF111",
|
|
6780
6862
|
REACTIVE_FACTORY_MODULE_CAPTURE: "BF112",
|
|
6781
6863
|
REACTIVE_FACTORY_IMPORT_COLLISION: "BF113",
|
|
6782
|
-
REACTIVE_FACTORY_PARAM_SHADOWED: "BF114"
|
|
6864
|
+
REACTIVE_FACTORY_PARAM_SHADOWED: "BF114",
|
|
6865
|
+
REACTIVE_FACTORY_ARITY_MISMATCH: "BF115",
|
|
6866
|
+
REACTIVE_FACTORY_EXTRA_ARGUMENTS: "BF116",
|
|
6867
|
+
ASYNC_ACTION_READ_IN_TEMPLATE: "BF117",
|
|
6868
|
+
MUTATION_INITIAL_OPTION: "BF118"
|
|
6783
6869
|
};
|
|
6784
6870
|
var errorMessages = {
|
|
6785
6871
|
[ErrorCodes.MISSING_USE_CLIENT]: "'use client' directive required for components with createSignal or event handlers",
|
|
@@ -6814,7 +6900,11 @@ var errorMessages = {
|
|
|
6814
6900
|
[ErrorCodes.REACTIVE_FACTORY_RENAME_UNSUPPORTED]: "Reactive factory object return/destructure must use shorthand properties only. " + "Property renames (`{ lists: myLists }`), defaults, and rest elements are not " + "supported — destructure with the factory's own property names.",
|
|
6815
6901
|
[ErrorCodes.REACTIVE_FACTORY_MODULE_CAPTURE]: "Imported reactive factory references bindings from its own module scope, so its " + "body cannot be inlined into the component file. Move those helpers into the " + "component file, pass them to the factory as parameters, or define the factory " + "in the component file.",
|
|
6816
6902
|
[ErrorCodes.REACTIVE_FACTORY_IMPORT_COLLISION]: "Inlining an imported reactive factory requires re-importing one of its helper " + "imports into this file, but that name is already bound here to something else. " + "Rename the conflicting binding in this file, or alias the import in the factory's own file.",
|
|
6817
|
-
[ErrorCodes.REACTIVE_FACTORY_PARAM_SHADOWED]: "Reactive factory parameter is shadowed by a nested declaration inside the factory body, so argument substitution at the inline site would be ambiguous. Rename the inner binding so it does not collide with the parameter."
|
|
6903
|
+
[ErrorCodes.REACTIVE_FACTORY_PARAM_SHADOWED]: "Reactive factory parameter is shadowed by a nested declaration inside the factory body, so argument substitution at the inline site would be ambiguous. Rename the inner binding so it does not collide with the parameter.",
|
|
6904
|
+
[ErrorCodes.REACTIVE_FACTORY_ARITY_MISMATCH]: "Tuple destructure of 'createSignal'/'createMemo' does not match the number of " + "elements the factory returns. `createSignal` returns `[getter, setter]` (destructure " + "1 or 2 elements); `createMemo` returns a single getter (do not destructure it as an " + "array at all).",
|
|
6905
|
+
[ErrorCodes.REACTIVE_FACTORY_EXTRA_ARGUMENTS]: "'createSignal'/'createMemo' call passes more arguments than the primitive accepts " + "(`createSignal(initialValue?)`, `createMemo(computeFn)`, `createSearchParams()`). The extra argument(s) are " + "silently dropped from the compiled client JS.",
|
|
6906
|
+
[ErrorCodes.ASYNC_ACTION_READ_IN_TEMPLATE]: "An async action's accessors (`isPending()` / `error()`) cannot be read in this template position — " + "the request function never runs on the server, so there is no value to render.",
|
|
6907
|
+
[ErrorCodes.MUTATION_INITIAL_OPTION]: "`createMutation` takes no `initial` option — a mutation has no initial request to seed its value from. " + "Use `createQuery` for a value that needs an initial state."
|
|
6818
6908
|
};
|
|
6819
6909
|
function createError(code, loc, options) {
|
|
6820
6910
|
if (code === undefined || !(code in errorMessages)) {
|
|
@@ -7072,10 +7162,12 @@ function findBrandPackageImportLoc(sourceFile, filePath) {
|
|
|
7072
7162
|
}
|
|
7073
7163
|
return null;
|
|
7074
7164
|
}
|
|
7075
|
-
function createProgramForFile(source, filePath) {
|
|
7165
|
+
function createProgramForFile(source, filePath, hostOptions = {}) {
|
|
7076
7166
|
incrementCounter("programCreations");
|
|
7077
7167
|
try {
|
|
7078
|
-
const
|
|
7168
|
+
const { currentDirectory } = hostOptions;
|
|
7169
|
+
const resolveFrom = (fileName) => currentDirectory === undefined ? path_default.resolve(fileName) : path_default.resolve(currentDirectory, fileName);
|
|
7170
|
+
const normalizedPath = resolveFrom(filePath);
|
|
7079
7171
|
const compilerOptions = {
|
|
7080
7172
|
target: ts15.ScriptTarget.Latest,
|
|
7081
7173
|
module: ts15.ModuleKind.ESNext,
|
|
@@ -7089,19 +7181,20 @@ function createProgramForFile(source, filePath) {
|
|
|
7089
7181
|
const defaultHost = ts15.createCompilerHost(compilerOptions);
|
|
7090
7182
|
const virtualHost = {
|
|
7091
7183
|
...defaultHost,
|
|
7184
|
+
...currentDirectory === undefined ? {} : { getCurrentDirectory: () => currentDirectory },
|
|
7092
7185
|
getSourceFile(fileName, languageVersion) {
|
|
7093
|
-
if (
|
|
7186
|
+
if (resolveFrom(fileName) === normalizedPath) {
|
|
7094
7187
|
return ts15.createSourceFile(fileName, source, languageVersion, true, ts15.ScriptKind.TSX);
|
|
7095
7188
|
}
|
|
7096
7189
|
return defaultHost.getSourceFile(fileName, languageVersion);
|
|
7097
7190
|
},
|
|
7098
7191
|
fileExists(fileName) {
|
|
7099
|
-
if (
|
|
7192
|
+
if (resolveFrom(fileName) === normalizedPath)
|
|
7100
7193
|
return true;
|
|
7101
7194
|
return defaultHost.fileExists(fileName);
|
|
7102
7195
|
},
|
|
7103
7196
|
readFile(fileName) {
|
|
7104
|
-
if (
|
|
7197
|
+
if (resolveFrom(fileName) === normalizedPath)
|
|
7105
7198
|
return source;
|
|
7106
7199
|
return defaultHost.readFile(fileName);
|
|
7107
7200
|
}
|
|
@@ -7115,6 +7208,11 @@ function createProgramForFile(source, filePath) {
|
|
|
7115
7208
|
return null;
|
|
7116
7209
|
}
|
|
7117
7210
|
}
|
|
7211
|
+
function createAnchoredProgram(source, filename, anchorDir) {
|
|
7212
|
+
if (!needsTypeBasedDetection(source))
|
|
7213
|
+
return;
|
|
7214
|
+
return createProgramForFile(source, filename, { currentDirectory: anchorDir })?.program;
|
|
7215
|
+
}
|
|
7118
7216
|
function analyzeComponent(source, filePath, targetComponentName, program, acceptsCallbackBody, programIsShared) {
|
|
7119
7217
|
incrementCounter("filesAnalyzed");
|
|
7120
7218
|
const hadSharedProgram = programIsShared ?? program !== undefined;
|
|
@@ -7587,7 +7685,13 @@ var PRIMITIVE_CANONICAL_NAMES = {
|
|
|
7587
7685
|
createEffect: "effect",
|
|
7588
7686
|
onMount: "onMount",
|
|
7589
7687
|
onCleanup: "onCleanup",
|
|
7590
|
-
createSearchParams: "signal"
|
|
7688
|
+
createSearchParams: "signal",
|
|
7689
|
+
createQuery: "signal",
|
|
7690
|
+
createMutation: "signal"
|
|
7691
|
+
};
|
|
7692
|
+
var SIGNAL_FACTORY_KINDS = {
|
|
7693
|
+
createQuery: "query",
|
|
7694
|
+
createMutation: "mutation"
|
|
7591
7695
|
};
|
|
7592
7696
|
var ENV_SIGNAL_FACTORIES = {
|
|
7593
7697
|
createSearchParams: "search"
|
|
@@ -7642,17 +7746,23 @@ function resolveCanonicalClientExportName(ident, ctx) {
|
|
|
7642
7746
|
return null;
|
|
7643
7747
|
}
|
|
7644
7748
|
function resolveEnvSignalKey(callExpr, ctx) {
|
|
7749
|
+
return resolveClientFactoryEntry(callExpr, ENV_SIGNAL_FACTORIES, ctx);
|
|
7750
|
+
}
|
|
7751
|
+
function resolveSignalFactoryKind(callExpr, ctx) {
|
|
7752
|
+
return resolveClientFactoryEntry(callExpr, SIGNAL_FACTORY_KINDS, ctx);
|
|
7753
|
+
}
|
|
7754
|
+
function resolveClientFactoryEntry(callExpr, table, ctx) {
|
|
7645
7755
|
if (ts15.isIdentifier(callExpr.expression)) {
|
|
7646
|
-
const
|
|
7647
|
-
if (
|
|
7648
|
-
return
|
|
7756
|
+
const hit = table[callExpr.expression.text];
|
|
7757
|
+
if (hit)
|
|
7758
|
+
return hit;
|
|
7649
7759
|
const canonical = resolveCanonicalClientExportName(callExpr.expression, ctx);
|
|
7650
|
-
return canonical ?
|
|
7760
|
+
return canonical ? table[canonical] ?? null : null;
|
|
7651
7761
|
}
|
|
7652
7762
|
if (ts15.isPropertyAccessExpression(callExpr.expression)) {
|
|
7653
|
-
const
|
|
7654
|
-
if (
|
|
7655
|
-
return
|
|
7763
|
+
const hit = table[callExpr.expression.name.text];
|
|
7764
|
+
if (hit && isBarefootClientNamespace(callExpr.expression.expression, ctx))
|
|
7765
|
+
return hit;
|
|
7656
7766
|
}
|
|
7657
7767
|
return null;
|
|
7658
7768
|
}
|
|
@@ -7692,6 +7802,11 @@ function isSignalDeclaration(node, ctx) {
|
|
|
7692
7802
|
function collectSignal(node, ctx) {
|
|
7693
7803
|
const pattern = node.name;
|
|
7694
7804
|
const callExpr = node.initializer;
|
|
7805
|
+
const factoryKind = resolveSignalFactoryKind(callExpr, ctx);
|
|
7806
|
+
if (factoryKind) {
|
|
7807
|
+
collectFactorySignal(node, pattern, callExpr, factoryKind, ctx);
|
|
7808
|
+
return;
|
|
7809
|
+
}
|
|
7695
7810
|
const elements = pattern.elements;
|
|
7696
7811
|
const getterElided = elements.length === 2 && ts15.isOmittedExpression(elements[0]);
|
|
7697
7812
|
if (elements.length < 1 || elements.length > 2 || !getterElided && (!ts15.isBindingElement(elements[0]) || !ts15.isIdentifier(elements[0].name))) {
|
|
@@ -7736,6 +7851,88 @@ function collectSignal(node, ctx) {
|
|
|
7736
7851
|
envFactory
|
|
7737
7852
|
});
|
|
7738
7853
|
}
|
|
7854
|
+
function collectFactorySignal(node, pattern, callExpr, kind, ctx) {
|
|
7855
|
+
const elements = pattern.elements;
|
|
7856
|
+
const bindingName = (el) => el && ts15.isBindingElement(el) && ts15.isIdentifier(el.name) ? el.name.text : null;
|
|
7857
|
+
if (elements.length < 1 || elements.length > 2)
|
|
7858
|
+
return;
|
|
7859
|
+
const getterElided = ts15.isOmittedExpression(elements[0]);
|
|
7860
|
+
const valueName = getterElided ? null : bindingName(elements[0]);
|
|
7861
|
+
if (!getterElided && valueName === null)
|
|
7862
|
+
return;
|
|
7863
|
+
const action = elements.length === 2 ? bindingName(elements[1]) : null;
|
|
7864
|
+
if (elements.length === 2 && action === null)
|
|
7865
|
+
return;
|
|
7866
|
+
if (getterElided && action === null)
|
|
7867
|
+
return;
|
|
7868
|
+
const initialNode = kind === "mutation" ? { kind: "absent" } : factoryInitialNode(callExpr.arguments[1]);
|
|
7869
|
+
const initialValue = initialNode.kind === "expression" ? ctx.getJS(initialNode.node) : initialNode.kind === "member-read" ? `(${ctx.getJS(initialNode.options)}).initial` : "undefined";
|
|
7870
|
+
const typedInitialValue = initialNode.kind === "expression" ? initialNode.node.getText(ctx.sourceFile) : initialNode.kind === "member-read" ? `(${initialNode.options.getText(ctx.sourceFile)}).initial` : undefined;
|
|
7871
|
+
const initialFreeIdentifiers = initialNode.kind === "expression" ? extractFreeIdentifiersFromNode(initialNode.node) : initialNode.kind === "member-read" ? extractFreeIdentifiersFromNode(initialNode.options) : new Set;
|
|
7872
|
+
let type = { kind: "unknown", raw: "unknown" };
|
|
7873
|
+
if (callExpr.typeArguments && callExpr.typeArguments.length > 0) {
|
|
7874
|
+
type = typeNodeToTypeInfo(callExpr.typeArguments[0], ctx.sourceFile) ?? type;
|
|
7875
|
+
} else if (initialNode.kind !== "absent") {
|
|
7876
|
+
type = inferTypeFromValue(initialValue);
|
|
7877
|
+
}
|
|
7878
|
+
let templateInitialValue;
|
|
7879
|
+
if (!ctx.propsObjectName && initialNode.kind === "expression") {
|
|
7880
|
+
const propNames = new Set(ctx.propsParams.map((p) => p.name));
|
|
7881
|
+
if (propNames.size > 0) {
|
|
7882
|
+
const propAliases = buildPropAliasMap(ctx.propsParams);
|
|
7883
|
+
templateInitialValue = rewriteBarePropRefs(initialValue, initialNode.node, propNames, undefined, propAliases);
|
|
7884
|
+
}
|
|
7885
|
+
}
|
|
7886
|
+
const argTexts = callExpr.arguments.map((arg) => ctx.getJS(arg));
|
|
7887
|
+
const requestArg = callExpr.arguments[0];
|
|
7888
|
+
ctx.signals.push({
|
|
7889
|
+
getter: valueName ?? `__bfGet_${action}`,
|
|
7890
|
+
setter: null,
|
|
7891
|
+
getterElided: getterElided || undefined,
|
|
7892
|
+
initialValue,
|
|
7893
|
+
typedInitialValue: typedInitialValue !== undefined && typedInitialValue !== initialValue ? typedInitialValue : undefined,
|
|
7894
|
+
templateInitialValue,
|
|
7895
|
+
type,
|
|
7896
|
+
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
7897
|
+
initialFreeIdentifiers,
|
|
7898
|
+
factory: {
|
|
7899
|
+
kind,
|
|
7900
|
+
callee: callExpr.expression.getText(ctx.sourceFile),
|
|
7901
|
+
argsText: argTexts.join(", "),
|
|
7902
|
+
requestText: argTexts[0] ?? "",
|
|
7903
|
+
requestFreeIdentifiers: requestArg ? extractFreeIdentifiersFromNode(requestArg) : new Set,
|
|
7904
|
+
action
|
|
7905
|
+
}
|
|
7906
|
+
});
|
|
7907
|
+
}
|
|
7908
|
+
function factoryInitialNode(options) {
|
|
7909
|
+
if (!options)
|
|
7910
|
+
return { kind: "absent" };
|
|
7911
|
+
let unwrapped = options;
|
|
7912
|
+
while (ts15.isParenthesizedExpression(unwrapped) || ts15.isAsExpression(unwrapped) || ts15.isSatisfiesExpression(unwrapped)) {
|
|
7913
|
+
unwrapped = unwrapped.expression;
|
|
7914
|
+
}
|
|
7915
|
+
if (!ts15.isObjectLiteralExpression(unwrapped))
|
|
7916
|
+
return { kind: "member-read", options };
|
|
7917
|
+
let found = null;
|
|
7918
|
+
for (const prop of unwrapped.properties) {
|
|
7919
|
+
if (ts15.isSpreadAssignment(prop))
|
|
7920
|
+
return { kind: "member-read", options };
|
|
7921
|
+
const name = prop.name;
|
|
7922
|
+
if (name === undefined || ts15.isComputedPropertyName(name))
|
|
7923
|
+
return { kind: "member-read", options };
|
|
7924
|
+
const key = ts15.isIdentifier(name) || ts15.isStringLiteral(name) || ts15.isNumericLiteral(name) ? name.text : null;
|
|
7925
|
+
if (key !== "initial")
|
|
7926
|
+
continue;
|
|
7927
|
+
if (ts15.isPropertyAssignment(prop))
|
|
7928
|
+
found = prop.initializer;
|
|
7929
|
+
else if (ts15.isShorthandPropertyAssignment(prop))
|
|
7930
|
+
found = prop.name;
|
|
7931
|
+
else
|
|
7932
|
+
return { kind: "member-read", options };
|
|
7933
|
+
}
|
|
7934
|
+
return found ? { kind: "expression", node: found } : { kind: "absent" };
|
|
7935
|
+
}
|
|
7739
7936
|
function isSignalTupleDeclaration(node) {
|
|
7740
7937
|
if (!ts15.isIdentifier(node.name))
|
|
7741
7938
|
return false;
|
|
@@ -8189,6 +8386,10 @@ var CLIENT_EXPORTS = new Set([
|
|
|
8189
8386
|
"isSSRPortal",
|
|
8190
8387
|
"findSiblingSlot",
|
|
8191
8388
|
"createSearchParams",
|
|
8389
|
+
"http",
|
|
8390
|
+
"HttpError",
|
|
8391
|
+
"createQuery",
|
|
8392
|
+
"createMutation",
|
|
8192
8393
|
"queryHref",
|
|
8193
8394
|
"formatDate",
|
|
8194
8395
|
"Async",
|
|
@@ -8625,6 +8826,7 @@ function collectFunction(node, ctx, _isModule, isExported = false) {
|
|
|
8625
8826
|
declarationKind: "function",
|
|
8626
8827
|
isModule: _isModule || undefined,
|
|
8627
8828
|
isJsxFunction: isJsxFunction || undefined,
|
|
8829
|
+
freeIdentifiers: extractFreeIdentifiersFromNode(node),
|
|
8628
8830
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath)
|
|
8629
8831
|
});
|
|
8630
8832
|
}
|
|
@@ -8959,6 +9161,11 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
8959
9161
|
}
|
|
8960
9162
|
const freeIdentifiers2 = node.initializer ? extractFreeIdentifiersFromNode(node.initializer) : undefined;
|
|
8961
9163
|
const containsArrow = node.initializer ? nodeContainsArrow(node.initializer) : false;
|
|
9164
|
+
let unwrappedInitializer = node.initializer;
|
|
9165
|
+
while (unwrappedInitializer && (ts15.isParenthesizedExpression(unwrappedInitializer) || ts15.isAsExpression(unwrappedInitializer) || ts15.isSatisfiesExpression(unwrappedInitializer))) {
|
|
9166
|
+
unwrappedInitializer = unwrappedInitializer.expression;
|
|
9167
|
+
}
|
|
9168
|
+
const isFunctionValue = unwrappedInitializer !== undefined && (ts15.isArrowFunction(unwrappedInitializer) || ts15.isFunctionExpression(unwrappedInitializer));
|
|
8962
9169
|
const systemConstructKind = node.initializer ? getSystemConstructKind(node.initializer) : undefined;
|
|
8963
9170
|
let templateValue;
|
|
8964
9171
|
if (value && ctx.propsParams.length > 0 && node.initializer) {
|
|
@@ -8971,8 +9178,9 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
8971
9178
|
const shadowedByNonAlias = new Set;
|
|
8972
9179
|
for (const s of ctx.signals) {
|
|
8973
9180
|
shadowedByNonAlias.add(s.getter);
|
|
8974
|
-
|
|
8975
|
-
|
|
9181
|
+
const second = signalSecondBinding(s);
|
|
9182
|
+
if (second)
|
|
9183
|
+
shadowedByNonAlias.add(second);
|
|
8976
9184
|
}
|
|
8977
9185
|
for (const m of ctx.memos)
|
|
8978
9186
|
shadowedByNonAlias.add(m.name);
|
|
@@ -9013,6 +9221,7 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
9013
9221
|
isJsx,
|
|
9014
9222
|
isJsxFunction: isJsxFunction || undefined,
|
|
9015
9223
|
containsArrow: containsArrow || undefined,
|
|
9224
|
+
isFunctionValue: isFunctionValue || undefined,
|
|
9016
9225
|
systemConstructKind,
|
|
9017
9226
|
templateValue,
|
|
9018
9227
|
origin: {
|
|
@@ -9099,28 +9308,75 @@ function collectKeysFromMembers(members, ctx) {
|
|
|
9099
9308
|
}
|
|
9100
9309
|
return keys;
|
|
9101
9310
|
}
|
|
9102
|
-
function isResolvableMemberType(info) {
|
|
9311
|
+
function isResolvableMemberType(info, localObjectMembers, visiting = new Set) {
|
|
9312
|
+
const recurse = (t) => isResolvableMemberType(t, localObjectMembers, visiting);
|
|
9103
9313
|
switch (info.kind) {
|
|
9104
9314
|
case "primitive":
|
|
9105
9315
|
return info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean";
|
|
9106
|
-
case "interface":
|
|
9107
|
-
|
|
9316
|
+
case "interface": {
|
|
9317
|
+
if (CATALOGUED_RICH_TYPE_NAMES.has(baseTypeName(info.raw)))
|
|
9318
|
+
return true;
|
|
9319
|
+
if (!localObjectMembers || visiting.has(info.raw))
|
|
9320
|
+
return false;
|
|
9321
|
+
const members = localObjectMembers(info.raw);
|
|
9322
|
+
if (!members)
|
|
9323
|
+
return false;
|
|
9324
|
+
const inner = new Set(visiting).add(info.raw);
|
|
9325
|
+
return members.every((t) => isResolvableMemberType(t, localObjectMembers, inner));
|
|
9326
|
+
}
|
|
9108
9327
|
case "array":
|
|
9109
|
-
return !!info.elementType &&
|
|
9328
|
+
return !!info.elementType && recurse(info.elementType);
|
|
9110
9329
|
case "object":
|
|
9111
|
-
return info.properties !== undefined && info.properties.every((prop) =>
|
|
9330
|
+
return info.properties !== undefined && info.properties.every((prop) => recurse(prop.type));
|
|
9112
9331
|
default:
|
|
9113
9332
|
return false;
|
|
9114
9333
|
}
|
|
9115
9334
|
}
|
|
9335
|
+
function localObjectMemberTypesFor(ctx) {
|
|
9336
|
+
const cache = new Map;
|
|
9337
|
+
const lookup = (name) => {
|
|
9338
|
+
const decls = findTypeDeclarations(name, ctx.sourceFile);
|
|
9339
|
+
if (decls.length !== 1)
|
|
9340
|
+
return null;
|
|
9341
|
+
const decl = decls[0];
|
|
9342
|
+
if (decl.typeParameters?.length)
|
|
9343
|
+
return null;
|
|
9344
|
+
let members;
|
|
9345
|
+
if (ts15.isInterfaceDeclaration(decl)) {
|
|
9346
|
+
if (decl.heritageClauses?.length)
|
|
9347
|
+
return null;
|
|
9348
|
+
members = decl.members;
|
|
9349
|
+
} else if (ts15.isTypeLiteralNode(decl.type)) {
|
|
9350
|
+
members = decl.type.members;
|
|
9351
|
+
} else {
|
|
9352
|
+
return null;
|
|
9353
|
+
}
|
|
9354
|
+
const types = [];
|
|
9355
|
+
for (const member of members) {
|
|
9356
|
+
if (!ts15.isPropertySignature(member) || !member.type)
|
|
9357
|
+
return null;
|
|
9358
|
+
const info = typeNodeToTypeInfo(member.type, ctx.sourceFile);
|
|
9359
|
+
if (!info)
|
|
9360
|
+
return null;
|
|
9361
|
+
types.push(info);
|
|
9362
|
+
}
|
|
9363
|
+
return types;
|
|
9364
|
+
};
|
|
9365
|
+
return (name) => {
|
|
9366
|
+
if (!cache.has(name))
|
|
9367
|
+
cache.set(name, lookup(name));
|
|
9368
|
+
return cache.get(name) ?? null;
|
|
9369
|
+
};
|
|
9370
|
+
}
|
|
9116
9371
|
function collectMemberTypes(typeNode, ctx) {
|
|
9372
|
+
const localObjectMembers = localObjectMemberTypesFor(ctx);
|
|
9117
9373
|
const fromMembers = (members) => {
|
|
9118
9374
|
const map = new Map;
|
|
9119
9375
|
for (const member of members) {
|
|
9120
9376
|
if (ts15.isPropertySignature(member) && member.name) {
|
|
9121
9377
|
const info = member.type ? typeNodeToTypeInfo(member.type, ctx.sourceFile) : null;
|
|
9122
9378
|
map.set(member.name.getText(ctx.sourceFile), {
|
|
9123
|
-
type: info && isResolvableMemberType(info) ? info : null,
|
|
9379
|
+
type: info && isResolvableMemberType(info, localObjectMembers) ? info : null,
|
|
9124
9380
|
optional: !!member.questionToken
|
|
9125
9381
|
});
|
|
9126
9382
|
}
|
|
@@ -9176,15 +9432,11 @@ function extractPropsFromTypeMembers(members, ctx) {
|
|
|
9176
9432
|
}
|
|
9177
9433
|
}
|
|
9178
9434
|
}
|
|
9179
|
-
function
|
|
9180
|
-
|
|
9435
|
+
function findTypeDeclarations(typeName, sourceFile) {
|
|
9436
|
+
const result = [];
|
|
9181
9437
|
function visit3(node) {
|
|
9182
|
-
if (ts15.isInterfaceDeclaration(node) && node.name.text === typeName) {
|
|
9183
|
-
result
|
|
9184
|
-
return;
|
|
9185
|
-
}
|
|
9186
|
-
if (ts15.isTypeAliasDeclaration(node) && node.name.text === typeName) {
|
|
9187
|
-
result = node;
|
|
9438
|
+
if ((ts15.isInterfaceDeclaration(node) || ts15.isTypeAliasDeclaration(node)) && node.name.text === typeName) {
|
|
9439
|
+
result.push(node);
|
|
9188
9440
|
return;
|
|
9189
9441
|
}
|
|
9190
9442
|
ts15.forEachChild(node, visit3);
|
|
@@ -9192,6 +9444,9 @@ function findTypeDeclaration(typeName, sourceFile) {
|
|
|
9192
9444
|
ts15.forEachChild(sourceFile, visit3);
|
|
9193
9445
|
return result;
|
|
9194
9446
|
}
|
|
9447
|
+
function findTypeDeclaration(typeName, sourceFile) {
|
|
9448
|
+
return findTypeDeclarations(typeName, sourceFile).at(-1);
|
|
9449
|
+
}
|
|
9195
9450
|
function inferTypeFromValue(value) {
|
|
9196
9451
|
const trimmed = value.trim();
|
|
9197
9452
|
const nullishMatch = trimmed.match(/^.+\?\?\s*(.+)$/);
|
|
@@ -9274,6 +9529,7 @@ function validateContext(ctx) {
|
|
|
9274
9529
|
markMutatedConstants(ctx);
|
|
9275
9530
|
validateInitStatementReferences(ctx);
|
|
9276
9531
|
validateReactiveFactoryCalls(ctx);
|
|
9532
|
+
validateReactiveFactoryArity(ctx);
|
|
9277
9533
|
validateNamespaceQualifiedPrimitives(ctx);
|
|
9278
9534
|
validateClientImports(ctx);
|
|
9279
9535
|
}
|
|
@@ -9481,8 +9737,9 @@ function collectResolvedNames(ctx) {
|
|
|
9481
9737
|
names.add(f.name);
|
|
9482
9738
|
for (const s of ctx.signals) {
|
|
9483
9739
|
names.add(s.getter);
|
|
9484
|
-
|
|
9485
|
-
|
|
9740
|
+
const second = signalSecondBinding(s);
|
|
9741
|
+
if (second)
|
|
9742
|
+
names.add(second);
|
|
9486
9743
|
}
|
|
9487
9744
|
for (const m of ctx.memos)
|
|
9488
9745
|
names.add(m.name);
|
|
@@ -10460,6 +10717,8 @@ function validateReactiveFactoryCalls(ctx) {
|
|
|
10460
10717
|
continue;
|
|
10461
10718
|
if (resolveEnvSignalKey(decl.initializer, ctx))
|
|
10462
10719
|
continue;
|
|
10720
|
+
if (resolveSignalFactoryKind(decl.initializer, ctx))
|
|
10721
|
+
continue;
|
|
10463
10722
|
const declinedEntry = ctx.declinedReactiveFactories.get(callee);
|
|
10464
10723
|
if (declinedEntry) {
|
|
10465
10724
|
ctx.errors.push(createError(declinedFactoryErrorCode(declinedEntry.code), loc, { severity: "error", message: declinedFactoryMessage(callee, declinedEntry) }));
|
|
@@ -10488,6 +10747,92 @@ function validateReactiveFactoryCalls(ctx) {
|
|
|
10488
10747
|
}
|
|
10489
10748
|
}
|
|
10490
10749
|
}
|
|
10750
|
+
function validateReactiveFactoryArity(ctx) {
|
|
10751
|
+
if (!ctx.componentNode)
|
|
10752
|
+
return;
|
|
10753
|
+
const body = ts15.isFunctionDeclaration(ctx.componentNode) ? ctx.componentNode.body : ts15.isBlock(ctx.componentNode.body) ? ctx.componentNode.body : null;
|
|
10754
|
+
if (!body)
|
|
10755
|
+
return;
|
|
10756
|
+
checkStatementsForReactiveFactoryArity(body.statements, ctx);
|
|
10757
|
+
for (const stmt of body.statements) {
|
|
10758
|
+
if (!ts15.isIfStatement(stmt))
|
|
10759
|
+
continue;
|
|
10760
|
+
if (!findJsxReturnInBlock(stmt.thenStatement))
|
|
10761
|
+
continue;
|
|
10762
|
+
if (!ts15.isBlock(stmt.thenStatement))
|
|
10763
|
+
continue;
|
|
10764
|
+
checkStatementsForReactiveFactoryArity(stmt.thenStatement.statements, ctx);
|
|
10765
|
+
}
|
|
10766
|
+
}
|
|
10767
|
+
function checkStatementsForReactiveFactoryArity(statements, ctx) {
|
|
10768
|
+
for (const stmt of statements) {
|
|
10769
|
+
if (!ts15.isVariableStatement(stmt))
|
|
10770
|
+
continue;
|
|
10771
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
10772
|
+
if (!decl.initializer || !ts15.isCallExpression(decl.initializer))
|
|
10773
|
+
continue;
|
|
10774
|
+
const callExpr = decl.initializer;
|
|
10775
|
+
const kind = resolvePrimitiveKind(callExpr, ctx);
|
|
10776
|
+
if (kind !== "signal" && kind !== "memo")
|
|
10777
|
+
continue;
|
|
10778
|
+
const loc = getSourceLocation(stmt, ctx.sourceFile, ctx.filePath);
|
|
10779
|
+
const calleeText = callExpr.expression.getText(ctx.sourceFile);
|
|
10780
|
+
const factoryKind = kind === "signal" ? resolveSignalFactoryKind(callExpr, ctx) : null;
|
|
10781
|
+
if (factoryKind !== null) {
|
|
10782
|
+
checkAsyncFactoryArity(decl, callExpr, calleeText, loc, ctx);
|
|
10783
|
+
if (factoryKind === "mutation")
|
|
10784
|
+
checkMutationInitialOption(callExpr, calleeText, ctx);
|
|
10785
|
+
continue;
|
|
10786
|
+
}
|
|
10787
|
+
if (ts15.isArrayBindingPattern(decl.name)) {
|
|
10788
|
+
const elementCount = decl.name.elements.length;
|
|
10789
|
+
const maxArity = kind === "signal" ? 2 : 0;
|
|
10790
|
+
if (elementCount < 1 || elementCount > maxArity) {
|
|
10791
|
+
ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_ARITY_MISMATCH, loc, {
|
|
10792
|
+
severity: "error",
|
|
10793
|
+
message: kind === "signal" ? elementCount === 0 ? `'${calleeText}(...)' returns a 2-element tuple '[getter, setter]' — this ` + `destructure binds 0 elements, so neither the getter nor the setter is ` + `reachable. Use 'const [get, set] = ${calleeText}(...)' or ` + `'const [get] = ${calleeText}(...)'.` : `'${calleeText}(...)' returns a 2-element tuple '[getter, setter]' (a ` + `1-element destructure keeps just the getter) — this destructure has ` + `${elementCount} elements. The extra binding(s) are silently dropped from ` + `the compiled output today. Use 'const [get, set] = ${calleeText}(...)' or ` + `'const [get] = ${calleeText}(...)'.` : `'${calleeText}(...)' returns a single getter function, not a tuple — this ` + `destructures ${elementCount} element${elementCount === 1 ? "" : "s"} from it. ` + `Use 'const value = ${calleeText}(...)' instead.`
|
|
10794
|
+
}));
|
|
10795
|
+
continue;
|
|
10796
|
+
}
|
|
10797
|
+
}
|
|
10798
|
+
const isEnvSignal = kind === "signal" && resolveEnvSignalKey(callExpr, ctx) !== null;
|
|
10799
|
+
const maxArgs = isEnvSignal ? 0 : 1;
|
|
10800
|
+
if (callExpr.arguments.length > maxArgs) {
|
|
10801
|
+
ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_EXTRA_ARGUMENTS, loc, {
|
|
10802
|
+
severity: "error",
|
|
10803
|
+
message: isEnvSignal ? `'${calleeText}()' takes no arguments (its value is read from the request ` + `environment), but this call passes ${callExpr.arguments.length}. The ` + `argument(s) are silently dropped from the compiled client JS today; remove them.` : `'${calleeText}(...)' accepts at most 1 argument (${kind === "signal" ? "the initial value" : "the compute function"}), ` + `but this call passes ${callExpr.arguments.length}. The extra argument(s) are ` + `silently dropped from the compiled client JS today; remove them, or fold ` + `whatever they configure into the ${kind === "signal" ? "initial value expression" : "compute function body"}.`
|
|
10804
|
+
}));
|
|
10805
|
+
}
|
|
10806
|
+
}
|
|
10807
|
+
}
|
|
10808
|
+
}
|
|
10809
|
+
function checkAsyncFactoryArity(decl, callExpr, calleeText, loc, ctx) {
|
|
10810
|
+
if (ts15.isArrayBindingPattern(decl.name)) {
|
|
10811
|
+
const elementCount = decl.name.elements.length;
|
|
10812
|
+
if (elementCount < 1 || elementCount > 2) {
|
|
10813
|
+
ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_ARITY_MISMATCH, loc, {
|
|
10814
|
+
severity: "error",
|
|
10815
|
+
message: `'${calleeText}(...)' returns a 2-element tuple '[value, action]' — this destructure has ` + `${elementCount} elements. Use 'const [value, action] = ${calleeText}(...)', ` + `'const [value] = ${calleeText}(...)' or 'const [, action] = ${calleeText}(...)'.`
|
|
10816
|
+
}));
|
|
10817
|
+
return;
|
|
10818
|
+
}
|
|
10819
|
+
}
|
|
10820
|
+
if (callExpr.arguments.length > 2) {
|
|
10821
|
+
ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_EXTRA_ARGUMENTS, loc, {
|
|
10822
|
+
severity: "error",
|
|
10823
|
+
message: `'${calleeText}(...)' accepts at most 2 arguments (the request function and the options), ` + `but this call passes ${callExpr.arguments.length}. The extra argument(s) are dropped from the ` + `compiled client JS; remove them.`
|
|
10824
|
+
}));
|
|
10825
|
+
}
|
|
10826
|
+
}
|
|
10827
|
+
function checkMutationInitialOption(callExpr, calleeText, ctx) {
|
|
10828
|
+
const initialNode = factoryInitialNode(callExpr.arguments[1]);
|
|
10829
|
+
if (initialNode.kind !== "expression")
|
|
10830
|
+
return;
|
|
10831
|
+
ctx.errors.push(createError(ErrorCodes.MUTATION_INITIAL_OPTION, getSourceLocation(initialNode.node, ctx.sourceFile, ctx.filePath), {
|
|
10832
|
+
severity: "error",
|
|
10833
|
+
message: `'${calleeText}(...)' takes no 'initial' option: a mutation's value is undefined until its action is ` + `called, so this value would never be used. Use 'createQuery' for a value that needs an initial state.`
|
|
10834
|
+
}));
|
|
10835
|
+
}
|
|
10491
10836
|
function validateNamespaceQualifiedPrimitives(ctx) {
|
|
10492
10837
|
if (!ctx.componentNode)
|
|
10493
10838
|
return;
|
|
@@ -11427,6 +11772,248 @@ var toLocaleDatePlugin = {
|
|
|
11427
11772
|
|
|
11428
11773
|
// src/jsx-to-ir.ts
|
|
11429
11774
|
import { toHTMLAttrName, decodeEntities, BF_KEY as BF_KEY2, keyAttrName as keyAttrName2 } from "@barefootjs/shared";
|
|
11775
|
+
|
|
11776
|
+
// src/template-position-walk.ts
|
|
11777
|
+
function walkTemplatePositions(root, visit3) {
|
|
11778
|
+
walkNode(root, visit3);
|
|
11779
|
+
}
|
|
11780
|
+
function walkTemplateParts(parts, loc, attrName, visit3) {
|
|
11781
|
+
const visitText = (text) => {
|
|
11782
|
+
const trimmed = text.trim();
|
|
11783
|
+
if (!trimmed)
|
|
11784
|
+
return;
|
|
11785
|
+
visit3({ expr: parseExpression(trimmed), loc, role: "template-part", attrName });
|
|
11786
|
+
};
|
|
11787
|
+
for (const part of parts) {
|
|
11788
|
+
if (part.type === "ternary") {
|
|
11789
|
+
visitText(part.condition);
|
|
11790
|
+
visitText(part.whenTrue);
|
|
11791
|
+
visitText(part.whenFalse);
|
|
11792
|
+
} else if (part.type === "lookup") {
|
|
11793
|
+
visitText(part.key);
|
|
11794
|
+
}
|
|
11795
|
+
}
|
|
11796
|
+
}
|
|
11797
|
+
function walkAttrValue(value, clientOnly, loc, attrName, onElement, visit3) {
|
|
11798
|
+
if (clientOnly)
|
|
11799
|
+
return;
|
|
11800
|
+
if (value.kind === "expression") {
|
|
11801
|
+
if (value.parsed) {
|
|
11802
|
+
visit3(onElement ? { expr: value.parsed, loc, role: "element-attr", attrName, host: { kind: "element-attr", value } } : { expr: value.parsed, loc, role: "prop", attrName });
|
|
11803
|
+
}
|
|
11804
|
+
if (value.parts)
|
|
11805
|
+
walkTemplateParts(value.parts, loc, attrName, visit3);
|
|
11806
|
+
} else if (value.kind === "spread") {
|
|
11807
|
+
if (value.parsed)
|
|
11808
|
+
visit3({ expr: value.parsed, loc, role: "spread", attrName });
|
|
11809
|
+
} else if (value.kind === "template") {
|
|
11810
|
+
walkTemplateParts(value.parts, loc, attrName, visit3);
|
|
11811
|
+
}
|
|
11812
|
+
}
|
|
11813
|
+
function walkNode(node, visit3) {
|
|
11814
|
+
if (node.type === "expression") {
|
|
11815
|
+
if (!node.clientOnly && node.parsed)
|
|
11816
|
+
visit3({ expr: node.parsed, loc: node.loc, role: "text" });
|
|
11817
|
+
} else if (node.type === "conditional") {
|
|
11818
|
+
if (!node.clientOnly && node.parsedCondition) {
|
|
11819
|
+
visit3({ expr: node.parsedCondition, loc: node.loc, role: "condition", host: { kind: "condition", node } });
|
|
11820
|
+
}
|
|
11821
|
+
} else if (node.type === "if-statement") {
|
|
11822
|
+
if (node.parsedCondition) {
|
|
11823
|
+
visit3({ expr: node.parsedCondition, loc: node.loc, role: "condition", host: { kind: "condition", node } });
|
|
11824
|
+
}
|
|
11825
|
+
}
|
|
11826
|
+
if (node.type === "element") {
|
|
11827
|
+
for (const attr of node.attrs)
|
|
11828
|
+
walkAttrValue(attr.value, attr.clientOnly, attr.loc, attr.name, true, visit3);
|
|
11829
|
+
} else if (node.type === "component") {
|
|
11830
|
+
for (const prop of node.props)
|
|
11831
|
+
walkAttrValue(prop.value, prop.clientOnly, prop.loc, prop.name, false, visit3);
|
|
11832
|
+
} else if (node.type === "provider") {
|
|
11833
|
+
walkAttrValue(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, "value", false, visit3);
|
|
11834
|
+
}
|
|
11835
|
+
switch (node.type) {
|
|
11836
|
+
case "element":
|
|
11837
|
+
case "component":
|
|
11838
|
+
case "fragment":
|
|
11839
|
+
case "provider":
|
|
11840
|
+
for (const child of node.children)
|
|
11841
|
+
walkNode(child, visit3);
|
|
11842
|
+
break;
|
|
11843
|
+
case "async":
|
|
11844
|
+
walkNode(node.fallback, visit3);
|
|
11845
|
+
for (const child of node.children)
|
|
11846
|
+
walkNode(child, visit3);
|
|
11847
|
+
break;
|
|
11848
|
+
case "loop": {
|
|
11849
|
+
if (node.clientOnly)
|
|
11850
|
+
break;
|
|
11851
|
+
if (node.arrayParsed)
|
|
11852
|
+
visit3({ expr: node.arrayParsed, loc: node.loc, role: "loop-array" });
|
|
11853
|
+
for (const child of node.children)
|
|
11854
|
+
walkNode(child, visit3);
|
|
11855
|
+
if (node.childComponent) {
|
|
11856
|
+
for (const child of node.childComponent.children)
|
|
11857
|
+
walkNode(child, visit3);
|
|
11858
|
+
}
|
|
11859
|
+
for (const nested of node.nestedComponents ?? []) {
|
|
11860
|
+
for (const child of nested.children)
|
|
11861
|
+
walkNode(child, visit3);
|
|
11862
|
+
}
|
|
11863
|
+
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
11864
|
+
if (seg.kind === "jsx")
|
|
11865
|
+
walkNode(seg.ir, visit3);
|
|
11866
|
+
}
|
|
11867
|
+
for (const seg of node.preamble?.segments ?? []) {
|
|
11868
|
+
if (seg.kind === "jsx")
|
|
11869
|
+
walkNode(seg.ir, visit3);
|
|
11870
|
+
}
|
|
11871
|
+
break;
|
|
11872
|
+
}
|
|
11873
|
+
case "conditional":
|
|
11874
|
+
if (node.clientOnly)
|
|
11875
|
+
break;
|
|
11876
|
+
walkNode(node.whenTrue, visit3);
|
|
11877
|
+
walkNode(node.whenFalse, visit3);
|
|
11878
|
+
break;
|
|
11879
|
+
case "if-statement":
|
|
11880
|
+
walkNode(node.consequent, visit3);
|
|
11881
|
+
if (node.alternate)
|
|
11882
|
+
walkNode(node.alternate, visit3);
|
|
11883
|
+
break;
|
|
11884
|
+
}
|
|
11885
|
+
}
|
|
11886
|
+
|
|
11887
|
+
// src/action-accessor.ts
|
|
11888
|
+
var ACTION_ACCESSOR_NAMES = new Set(["isPending", "error"]);
|
|
11889
|
+
function collectActionNames(signals) {
|
|
11890
|
+
const actions = new Set;
|
|
11891
|
+
for (const signal of signals) {
|
|
11892
|
+
if (signal.factory?.action)
|
|
11893
|
+
actions.add(signal.factory.action);
|
|
11894
|
+
}
|
|
11895
|
+
return actions;
|
|
11896
|
+
}
|
|
11897
|
+
function matchActionAccessorCall(expr, actions) {
|
|
11898
|
+
if (expr.kind !== "call" || expr.args.length !== 0)
|
|
11899
|
+
return null;
|
|
11900
|
+
const callee = expr.callee;
|
|
11901
|
+
if (callee.kind !== "member" || callee.computed)
|
|
11902
|
+
return null;
|
|
11903
|
+
if (callee.object.kind !== "identifier")
|
|
11904
|
+
return null;
|
|
11905
|
+
if (!actions.has(callee.object.name))
|
|
11906
|
+
return null;
|
|
11907
|
+
if (!ACTION_ACCESSOR_NAMES.has(callee.property))
|
|
11908
|
+
return null;
|
|
11909
|
+
return { action: callee.object.name, accessor: callee.property };
|
|
11910
|
+
}
|
|
11911
|
+
function parsedExprChildren(expr) {
|
|
11912
|
+
const all = (...exprs) => exprs.map((e) => ({ expr: e }));
|
|
11913
|
+
switch (expr.kind) {
|
|
11914
|
+
case "member":
|
|
11915
|
+
return all(expr.object);
|
|
11916
|
+
case "call":
|
|
11917
|
+
return all(expr.callee, ...expr.args);
|
|
11918
|
+
case "index-access":
|
|
11919
|
+
return all(expr.object, expr.index);
|
|
11920
|
+
case "binary":
|
|
11921
|
+
case "logical":
|
|
11922
|
+
return all(expr.left, expr.right);
|
|
11923
|
+
case "unary":
|
|
11924
|
+
return all(expr.argument);
|
|
11925
|
+
case "conditional":
|
|
11926
|
+
return all(expr.test, expr.consequent, expr.alternate);
|
|
11927
|
+
case "template-literal":
|
|
11928
|
+
return all(...expr.parts.flatMap((p) => p.type === "expression" ? [p.expr] : []));
|
|
11929
|
+
case "array-literal":
|
|
11930
|
+
return all(...expr.elements);
|
|
11931
|
+
case "object-literal":
|
|
11932
|
+
return all(...expr.properties.map((p) => p.kind === "spread" ? p.expr : p.value));
|
|
11933
|
+
case "array-method":
|
|
11934
|
+
return all(expr.object, ...expr.args, ...expr.method === "flat" && expr.depthExpr ? [expr.depthExpr] : []);
|
|
11935
|
+
case "arrow":
|
|
11936
|
+
return [{ expr: expr.body, params: expr.params }];
|
|
11937
|
+
case "identifier":
|
|
11938
|
+
case "literal":
|
|
11939
|
+
case "regex":
|
|
11940
|
+
case "unsupported":
|
|
11941
|
+
return [];
|
|
11942
|
+
}
|
|
11943
|
+
}
|
|
11944
|
+
function collectActionAccessorReads(expr, actions, isBound = () => false) {
|
|
11945
|
+
const reads = [];
|
|
11946
|
+
if (actions.size === 0)
|
|
11947
|
+
return reads;
|
|
11948
|
+
const visit3 = (e, bound) => {
|
|
11949
|
+
const read = matchActionAccessorCall(e, actions);
|
|
11950
|
+
if (read && !bound.has(read.action) && !isBound(read.action)) {
|
|
11951
|
+
if (!reads.some((r) => r.action === read.action && r.accessor === read.accessor))
|
|
11952
|
+
reads.push(read);
|
|
11953
|
+
return;
|
|
11954
|
+
}
|
|
11955
|
+
for (const child of parsedExprChildren(e)) {
|
|
11956
|
+
visit3(child.expr, child.params ? new Set([...bound, ...child.params]) : bound);
|
|
11957
|
+
}
|
|
11958
|
+
};
|
|
11959
|
+
visit3(expr, new Set);
|
|
11960
|
+
return reads;
|
|
11961
|
+
}
|
|
11962
|
+
var ARIA_BOOLEAN_STATE_ATTRS = new Set([
|
|
11963
|
+
"aria-atomic",
|
|
11964
|
+
"aria-busy",
|
|
11965
|
+
"aria-checked",
|
|
11966
|
+
"aria-disabled",
|
|
11967
|
+
"aria-expanded",
|
|
11968
|
+
"aria-hidden",
|
|
11969
|
+
"aria-modal",
|
|
11970
|
+
"aria-multiline",
|
|
11971
|
+
"aria-multiselectable",
|
|
11972
|
+
"aria-pressed",
|
|
11973
|
+
"aria-readonly",
|
|
11974
|
+
"aria-required",
|
|
11975
|
+
"aria-selected"
|
|
11976
|
+
]);
|
|
11977
|
+
function seedableActionAccessorRead(position, actions) {
|
|
11978
|
+
const read = matchActionAccessorCall(position.expr, actions);
|
|
11979
|
+
if (!read)
|
|
11980
|
+
return null;
|
|
11981
|
+
switch (position.role) {
|
|
11982
|
+
case "condition":
|
|
11983
|
+
return read;
|
|
11984
|
+
case "element-attr":
|
|
11985
|
+
return read.accessor === "isPending" && position.attrName !== undefined && (ARIA_BOOLEAN_STATE_ATTRS.has(position.attrName) || isBooleanAttr(position.attrName)) ? read : null;
|
|
11986
|
+
default:
|
|
11987
|
+
return null;
|
|
11988
|
+
}
|
|
11989
|
+
}
|
|
11990
|
+
function seedActionAccessorReads(root, signals) {
|
|
11991
|
+
const actions = collectActionNames(signals);
|
|
11992
|
+
if (actions.size === 0)
|
|
11993
|
+
return;
|
|
11994
|
+
walkTemplatePositions(root, (position) => {
|
|
11995
|
+
const read = seedableActionAccessorRead(position, actions);
|
|
11996
|
+
if (!read || !position.host)
|
|
11997
|
+
return;
|
|
11998
|
+
const parsed = actionAccessorSeedParsed(read.accessor);
|
|
11999
|
+
const text = actionAccessorSeedText(read.accessor);
|
|
12000
|
+
if (position.host.kind === "condition") {
|
|
12001
|
+
position.host.node.parsedCondition = parsed;
|
|
12002
|
+
position.host.node.templateCondition = text;
|
|
12003
|
+
} else {
|
|
12004
|
+
position.host.value.parsed = parsed;
|
|
12005
|
+
position.host.value.templateExpr = text;
|
|
12006
|
+
}
|
|
12007
|
+
});
|
|
12008
|
+
}
|
|
12009
|
+
function actionAccessorSeedParsed(_accessor) {
|
|
12010
|
+
return { kind: "literal", value: false, literalType: "boolean" };
|
|
12011
|
+
}
|
|
12012
|
+
function actionAccessorSeedText(accessor) {
|
|
12013
|
+
return accessor === "isPending" ? "false" : "undefined";
|
|
12014
|
+
}
|
|
12015
|
+
|
|
12016
|
+
// src/jsx-to-ir.ts
|
|
11430
12017
|
var BLOCK_COMMENT_RE2 = /\/\*([\s\S]*?)\*\//g;
|
|
11431
12018
|
function hasLeadingClientDirective(expr, sourceFile) {
|
|
11432
12019
|
const trivia = sourceFile.text.slice(expr.pos, expr.getStart(sourceFile));
|
|
@@ -11953,6 +12540,7 @@ function jsxToIR(analyzer) {
|
|
|
11953
12540
|
if (root) {
|
|
11954
12541
|
reportRefAttrsAbsentAtSsr(root, ctx);
|
|
11955
12542
|
attachParsedExpressions(root, analyzer);
|
|
12543
|
+
seedActionAccessorReads(root, analyzer.signals);
|
|
11956
12544
|
resolveRootKeyAttr(root);
|
|
11957
12545
|
}
|
|
11958
12546
|
return root;
|
|
@@ -12523,6 +13111,11 @@ function markCarrierIn(node) {
|
|
|
12523
13111
|
return null;
|
|
12524
13112
|
return { ...cond, whenTrue: whenTrue ?? cond.whenTrue, whenFalse: whenFalse ?? cond.whenFalse };
|
|
12525
13113
|
}
|
|
13114
|
+
if (node.type === "fragment") {
|
|
13115
|
+
const frag = node;
|
|
13116
|
+
const children = markDataKeyCarrier(frag.children);
|
|
13117
|
+
return children === frag.children ? null : { ...frag, children };
|
|
13118
|
+
}
|
|
12526
13119
|
return null;
|
|
12527
13120
|
}
|
|
12528
13121
|
function transformFragment(node, ctx) {
|
|
@@ -15864,8 +16457,19 @@ function shouldAutoDeferReactiveBrand(expr, ctx) {
|
|
|
15864
16457
|
return false;
|
|
15865
16458
|
if (leaves.some((leaf) => isSignalOrMemoReference(ctx.getJS(leaf), ctx)))
|
|
15866
16459
|
return false;
|
|
16460
|
+
if (leaves.some((leaf) => isAsyncActionLeaf(leaf, ctx)))
|
|
16461
|
+
return false;
|
|
15867
16462
|
return true;
|
|
15868
16463
|
}
|
|
16464
|
+
function isAsyncActionLeaf(leaf, ctx) {
|
|
16465
|
+
let node = leaf;
|
|
16466
|
+
while (ts18.isCallExpression(node) || ts18.isPropertyAccessExpression(node))
|
|
16467
|
+
node = node.expression;
|
|
16468
|
+
if (!ts18.isIdentifier(node))
|
|
16469
|
+
return false;
|
|
16470
|
+
const name = node.text;
|
|
16471
|
+
return ctx.analyzer.signals.some((s) => s.factory?.action === name);
|
|
16472
|
+
}
|
|
15869
16473
|
function isSignalOrMemoReference(expr, ctx, visited) {
|
|
15870
16474
|
for (const { pattern } of ctx.patterns.signals) {
|
|
15871
16475
|
if (pattern.test(expr))
|
|
@@ -16230,6 +16834,8 @@ function expandConstantForReactivity(expr, ctx, originalFreeIds, scope) {
|
|
|
16230
16834
|
return { expr, freeIds: originalFreeIds };
|
|
16231
16835
|
}
|
|
16232
16836
|
function getControlledPropName(signal, propsParams, propsObjectName = null) {
|
|
16837
|
+
if (signal.factory)
|
|
16838
|
+
return null;
|
|
16233
16839
|
const initialValue = signal.initialValue.trim();
|
|
16234
16840
|
const isDefaultProp = (propName) => propName.startsWith("default");
|
|
16235
16841
|
const propsName = propsObjectName ?? "props";
|
|
@@ -16414,7 +17020,8 @@ function collectConditionalBranchRefs(node) {
|
|
|
16414
17020
|
if (el.slotId && el.ref) {
|
|
16415
17021
|
refs.push({
|
|
16416
17022
|
slotId: el.slotId,
|
|
16417
|
-
callback: el.ref
|
|
17023
|
+
callback: el.ref,
|
|
17024
|
+
...el.ssrPortalOwnerScope && { ssrPortalOwner: true }
|
|
16418
17025
|
});
|
|
16419
17026
|
}
|
|
16420
17027
|
}, true);
|
|
@@ -17312,7 +17919,8 @@ function collectFromElement(element, ctx, insideConditional = false) {
|
|
|
17312
17919
|
if (element.ref && element.slotId) {
|
|
17313
17920
|
ctx.refElements.push({
|
|
17314
17921
|
slotId: element.slotId,
|
|
17315
|
-
callback: element.ref
|
|
17922
|
+
callback: element.ref,
|
|
17923
|
+
...element.ssrPortalOwnerScope && { ssrPortalOwner: true }
|
|
17316
17924
|
});
|
|
17317
17925
|
}
|
|
17318
17926
|
if (element.slotId) {
|
|
@@ -17586,8 +18194,9 @@ function buildReferencesGraph(ctx, irRoot) {
|
|
|
17586
18194
|
declaredNames.add(f.name);
|
|
17587
18195
|
for (const s of ctx.signals) {
|
|
17588
18196
|
declaredNames.add(s.getter);
|
|
17589
|
-
|
|
17590
|
-
|
|
18197
|
+
const second = signalSecondBinding(s);
|
|
18198
|
+
if (second)
|
|
18199
|
+
declaredNames.add(second);
|
|
17591
18200
|
}
|
|
17592
18201
|
for (const m of ctx.memos)
|
|
17593
18202
|
declaredNames.add(m.name);
|
|
@@ -17674,7 +18283,7 @@ function buildReferencesGraph(ctx, irRoot) {
|
|
|
17674
18283
|
}
|
|
17675
18284
|
}
|
|
17676
18285
|
for (const signal of ctx.signals) {
|
|
17677
|
-
addExprEdges({ kind: "signal", name: signal.getter }, signal.initialValue, "init-body");
|
|
18286
|
+
addExprEdges({ kind: "signal", name: signal.getter }, signal.factory?.argsText ?? signal.initialValue, "init-body");
|
|
17678
18287
|
}
|
|
17679
18288
|
for (const memo of ctx.memos) {
|
|
17680
18289
|
addExprEdges({ kind: "memo", name: memo.name }, memo.computation, "init-body");
|
|
@@ -17885,8 +18494,9 @@ function computeDeclarationScopes(ctx, graph) {
|
|
|
17885
18494
|
const initRequired = new Set;
|
|
17886
18495
|
for (const s of ctx.signals) {
|
|
17887
18496
|
initRequired.add(s.getter);
|
|
17888
|
-
|
|
17889
|
-
|
|
18497
|
+
const second = signalSecondBinding(s);
|
|
18498
|
+
if (second)
|
|
18499
|
+
initRequired.add(second);
|
|
17890
18500
|
}
|
|
17891
18501
|
for (const m of ctx.memos)
|
|
17892
18502
|
initRequired.add(m.name);
|
|
@@ -18503,7 +19113,7 @@ function computeInlinability(ctx, graph, irRoot) {
|
|
|
18503
19113
|
functions.set(fn.name, functionScope.get(fn.name) === "module" ? { kind: "module-scope-safe" } : { kind: "references-component-scope" });
|
|
18504
19114
|
}
|
|
18505
19115
|
const signalGetters = new Set(ctx.signals.map((s) => s.getter));
|
|
18506
|
-
const signalSetters = new Set(ctx.signals.
|
|
19116
|
+
const signalSetters = new Set(ctx.signals.flatMap((s) => signalSecondBinding(s) ?? []));
|
|
18507
19117
|
const memoNames = new Set(ctx.memos.map((m) => m.name));
|
|
18508
19118
|
const getterAliases = resolveGetterAliases(ctx.localConstants, (n) => signalGetters.has(n) || memoNames.has(n));
|
|
18509
19119
|
const env = buildEnvFromCtx(ctx);
|
|
@@ -18822,8 +19432,6 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
|
|
|
18822
19432
|
const propNamesForStaticCheck = new Set(ctx.propsParams.map((p) => p.name));
|
|
18823
19433
|
const { inlinableConstants, unsafeLocalNames } = inlinability ?? buildInlinableConstants(ctx, graph, _ir.root);
|
|
18824
19434
|
const restSpreadNames = resolveRestSpreadNames(ctx);
|
|
18825
|
-
const isFragmentRoot = _ir.root.type === "fragment" && !!_ir.root.needsScopeComment;
|
|
18826
|
-
const isCommentScope = isCommentScopedRoot(_ir.root);
|
|
18827
19435
|
const defParts = [`init: ${initFunctionName(name)}`];
|
|
18828
19436
|
if (canGenerateStaticTemplate(_ir.root, propNamesForStaticCheck, inlinableConstants, unsafeLocalNames)) {
|
|
18829
19437
|
const markupSlotIds = markupSlotIdsOf(ctx);
|
|
@@ -18838,12 +19446,7 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
|
|
|
18838
19446
|
defParts.push(buildTemplateDefPart(ctx, templateHtml));
|
|
18839
19447
|
}
|
|
18840
19448
|
}
|
|
18841
|
-
|
|
18842
|
-
defParts.push("comment: true");
|
|
18843
|
-
}
|
|
18844
|
-
if (isFragmentRoot) {
|
|
18845
|
-
defParts.push("fragmentRoot: true");
|
|
18846
|
-
}
|
|
19449
|
+
defParts.push(...componentDefScopeFlags(_ir.root));
|
|
18847
19450
|
const registryKey = nameForRegistryRef(name);
|
|
18848
19451
|
if (registryKey !== name) {
|
|
18849
19452
|
defParts.push(`name: '${name}'`);
|
|
@@ -18930,8 +19533,10 @@ function providedNames(decl) {
|
|
|
18930
19533
|
switch (decl.kind) {
|
|
18931
19534
|
case "constant":
|
|
18932
19535
|
return [decl.info.name];
|
|
18933
|
-
case "signal":
|
|
18934
|
-
|
|
19536
|
+
case "signal": {
|
|
19537
|
+
const second = signalSecondBinding(decl.info);
|
|
19538
|
+
return second ? [decl.info.getter, second] : [decl.info.getter];
|
|
19539
|
+
}
|
|
18935
19540
|
case "memo":
|
|
18936
19541
|
return [decl.info.name];
|
|
18937
19542
|
case "function":
|
|
@@ -19030,61 +19635,6 @@ function sortDeclarations(declarations, declNameSet, graph) {
|
|
|
19030
19635
|
return result;
|
|
19031
19636
|
}
|
|
19032
19637
|
|
|
19033
|
-
// src/adapters/env-signal.ts
|
|
19034
|
-
var ENV_SIGNAL_CLIENT_FACTORY = {
|
|
19035
|
-
search: "createSearchParams"
|
|
19036
|
-
};
|
|
19037
|
-
var ENV_SIGNAL_READERS = new Map([
|
|
19038
|
-
["search", { key: "search", canonicalName: "searchParams", methods: new Set(["get"]) }]
|
|
19039
|
-
]);
|
|
19040
|
-
function envSignalReaderFor(key) {
|
|
19041
|
-
if (key === undefined)
|
|
19042
|
-
return null;
|
|
19043
|
-
return ENV_SIGNAL_READERS.get(key) ?? null;
|
|
19044
|
-
}
|
|
19045
|
-
function envSignalLocalNames(metadata, key) {
|
|
19046
|
-
const names = new Set;
|
|
19047
|
-
for (const s of metadata.signals) {
|
|
19048
|
-
if (s.envReader !== undefined && (key === undefined || s.envReader === key)) {
|
|
19049
|
-
names.add(s.getter);
|
|
19050
|
-
}
|
|
19051
|
-
}
|
|
19052
|
-
return names;
|
|
19053
|
-
}
|
|
19054
|
-
function searchParamsLocalNames(metadata) {
|
|
19055
|
-
return envSignalLocalNames(metadata, "search");
|
|
19056
|
-
}
|
|
19057
|
-
function importsSearchParams(metadata) {
|
|
19058
|
-
return searchParamsLocalNames(metadata).size > 0;
|
|
19059
|
-
}
|
|
19060
|
-
function queryHrefLocalNames(metadata) {
|
|
19061
|
-
const names = new Set;
|
|
19062
|
-
for (const imp of metadata.imports) {
|
|
19063
|
-
if (!CLIENT_HELPER_SOURCES.has(imp.source) || imp.isTypeOnly)
|
|
19064
|
-
continue;
|
|
19065
|
-
for (const s of imp.specifiers) {
|
|
19066
|
-
if (s.isTypeOnly || s.isNamespace || s.isDefault)
|
|
19067
|
-
continue;
|
|
19068
|
-
if (s.name === "queryHref")
|
|
19069
|
-
names.add(s.alias ?? s.name);
|
|
19070
|
-
}
|
|
19071
|
-
}
|
|
19072
|
-
return names;
|
|
19073
|
-
}
|
|
19074
|
-
var CLIENT_HELPER_SOURCES = new Set([
|
|
19075
|
-
"@barefootjs/client",
|
|
19076
|
-
"@barefootjs/client/runtime"
|
|
19077
|
-
]);
|
|
19078
|
-
function matchSearchParamsMethodCall(callee, args, localNames) {
|
|
19079
|
-
if (callee.kind !== "member" || callee.computed)
|
|
19080
|
-
return null;
|
|
19081
|
-
const recv = callee.object;
|
|
19082
|
-
if (recv.kind !== "call" || recv.args.length !== 0 || recv.callee.kind !== "identifier" || !localNames.has(recv.callee.name)) {
|
|
19083
|
-
return null;
|
|
19084
|
-
}
|
|
19085
|
-
return { method: callee.property, args };
|
|
19086
|
-
}
|
|
19087
|
-
|
|
19088
19638
|
// src/ir-to-client-js/plan/build-declaration-emit.ts
|
|
19089
19639
|
function buildDeclarationEmitLookups(ctx, controlledSignals) {
|
|
19090
19640
|
const controlledBySignal = new Map;
|
|
@@ -19131,19 +19681,18 @@ function buildDeclarationEmitPlan(decl, ctx, lookups) {
|
|
|
19131
19681
|
}
|
|
19132
19682
|
}
|
|
19133
19683
|
function buildSignalPlan(signal, ctx, lookups) {
|
|
19134
|
-
|
|
19135
|
-
|
|
19136
|
-
|
|
19137
|
-
|
|
19138
|
-
|
|
19139
|
-
|
|
19140
|
-
|
|
19141
|
-
|
|
19142
|
-
|
|
19143
|
-
|
|
19144
|
-
|
|
19145
|
-
|
|
19146
|
-
}
|
|
19684
|
+
const initializerOverride = signalFactoryInitializer(signal);
|
|
19685
|
+
if (initializerOverride) {
|
|
19686
|
+
return {
|
|
19687
|
+
kind: "signal",
|
|
19688
|
+
getter: signal.getter,
|
|
19689
|
+
setter: signalSecondBinding(signal),
|
|
19690
|
+
getterElided: signal.getterElided,
|
|
19691
|
+
initialValueExpr: "",
|
|
19692
|
+
controlledEffect: null,
|
|
19693
|
+
initializerOverride,
|
|
19694
|
+
branchCondition: signal.factory ? signal.branchCondition : undefined
|
|
19695
|
+
};
|
|
19147
19696
|
}
|
|
19148
19697
|
const controlledEffect = buildControlledSignalEffect(signal, lookups);
|
|
19149
19698
|
if (controlledEffect && ctx.profile) {
|
|
@@ -19227,11 +19776,15 @@ function bfIdArg(bfId) {
|
|
|
19227
19776
|
function emitSignal(lines, plan) {
|
|
19228
19777
|
const getterSlot = plan.getterElided ? "" : plan.getter;
|
|
19229
19778
|
if (plan.initializerOverride) {
|
|
19230
|
-
|
|
19231
|
-
|
|
19232
|
-
|
|
19233
|
-
lines.push(`
|
|
19779
|
+
const bindings = plan.setter ? `${getterSlot}, ${plan.setter}` : plan.getter;
|
|
19780
|
+
if (plan.branchCondition) {
|
|
19781
|
+
lines.push(plan.setter ? plan.getterElided ? ` let ${plan.setter}` : ` let ${plan.getter}, ${plan.setter}` : ` let ${plan.getter}`);
|
|
19782
|
+
lines.push(` if (${plan.branchCondition}) {`);
|
|
19783
|
+
lines.push(` ;[${bindings}] = ${plan.initializerOverride}`);
|
|
19784
|
+
lines.push(` }`);
|
|
19785
|
+
return;
|
|
19234
19786
|
}
|
|
19787
|
+
lines.push(` const [${bindings}] = ${plan.initializerOverride}`);
|
|
19235
19788
|
return;
|
|
19236
19789
|
}
|
|
19237
19790
|
const id = bfIdArg(plan.bfId);
|
|
@@ -19427,13 +19980,15 @@ function emitModuleLevelDeclarations(moduleLevelConstants, moduleLevelFunctions,
|
|
|
19427
19980
|
}
|
|
19428
19981
|
for (const signal of moduleLevelSignals) {
|
|
19429
19982
|
const tupleVar = `__bf_m_${signal.getter}_tuple`;
|
|
19983
|
+
const initializer = signalFactoryInitializer(signal) ?? `createSignal(${signal.initialValue})`;
|
|
19984
|
+
const second = signalSecondBinding(signal);
|
|
19430
19985
|
if (signal.isExported) {
|
|
19431
|
-
lines.push(`export const [${signal.getter}${
|
|
19986
|
+
lines.push(`export const [${signal.getter}${second ? `, ${second}` : ""}] = ${initializer}`);
|
|
19432
19987
|
} else {
|
|
19433
|
-
lines.push(`var ${tupleVar} = ${tupleVar} ??
|
|
19988
|
+
lines.push(`var ${tupleVar} = ${tupleVar} ?? ${initializer}`);
|
|
19434
19989
|
lines.push(`var ${signal.getter} = ${tupleVar}[0]`);
|
|
19435
|
-
if (
|
|
19436
|
-
lines.push(`var ${
|
|
19990
|
+
if (second) {
|
|
19991
|
+
lines.push(`var ${second} = ${tupleVar}[1]`);
|
|
19437
19992
|
}
|
|
19438
19993
|
}
|
|
19439
19994
|
}
|
|
@@ -21346,7 +21901,7 @@ function emitRefCallbacks(lines, ctx, conditionalSlotIds) {
|
|
|
21346
21901
|
if (conditionalSlotIds.has(elem.slotId))
|
|
21347
21902
|
continue;
|
|
21348
21903
|
const v = varSlotId(elem.slotId);
|
|
21349
|
-
lines.push(` if (_${v}) ${emitRefCall(elem.callback, `_${v}
|
|
21904
|
+
lines.push(` if (_${v}) ${emitRefCall(elem.callback, `_${v}`, elem.ssrPortalOwner)}`);
|
|
21350
21905
|
}
|
|
21351
21906
|
}
|
|
21352
21907
|
|
|
@@ -23297,7 +23852,8 @@ function buildArmBody(branch, options) {
|
|
|
23297
23852
|
})),
|
|
23298
23853
|
refs: branch.refs.map((r) => ({
|
|
23299
23854
|
slotId: r.slotId,
|
|
23300
|
-
callback: r.callback
|
|
23855
|
+
callback: r.callback,
|
|
23856
|
+
...r.ssrPortalOwner && { ssrPortalOwner: true }
|
|
23301
23857
|
})),
|
|
23302
23858
|
childComponents: branch.childComponents.map((c) => ({
|
|
23303
23859
|
name: c.name,
|
|
@@ -23649,7 +24205,7 @@ function emitArmBody(lines, body, mode, indent, profileComponentName) {
|
|
|
23649
24205
|
}
|
|
23650
24206
|
for (const ref of body.refs) {
|
|
23651
24207
|
const v = varSlotId(ref.slotId);
|
|
23652
|
-
lines.push(`${indent}if (_${v}) ${emitRefCall(ref.callback, `_${v}
|
|
24208
|
+
lines.push(`${indent}if (_${v}) ${emitRefCall(ref.callback, `_${v}`, ref.ssrPortalOwner)}`);
|
|
23653
24209
|
}
|
|
23654
24210
|
for (let i = 0;i < body.childComponents.length; i++) {
|
|
23655
24211
|
const comp = body.childComponents[i];
|
|
@@ -24453,7 +25009,8 @@ function generateTemplateOnlyMount(ir, ctx) {
|
|
|
24453
25009
|
lines.push(`function ${initName}() {}`);
|
|
24454
25010
|
lines.push("");
|
|
24455
25011
|
const nameField = registryKey !== name ? `, name: '${name}'` : "";
|
|
24456
|
-
|
|
25012
|
+
const scopeFlags = componentDefScopeFlags(ir.root).map((f) => `, ${f}`).join("");
|
|
25013
|
+
lines.push(`hydrate('${registryKey}', { init: ${initName}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${scopeFlags}${nameField} })`);
|
|
24457
25014
|
lines.push(`export function ${name}(${PROPS_PARAM}, __bfKey) { return createComponent('${registryKey}', ${PROPS_PARAM}, __bfKey) }`);
|
|
24458
25015
|
const generatedCode = lines.join(`
|
|
24459
25016
|
`);
|
|
@@ -24469,9 +25026,9 @@ ${externalImports.join(`
|
|
|
24469
25026
|
|
|
24470
25027
|
// src/ir-to-client-js/client-only-elision.ts
|
|
24471
25028
|
function decideClientOnlyElision(root) {
|
|
24472
|
-
|
|
25029
|
+
walkNode2(root, [], new Set, { bailed: false });
|
|
24473
25030
|
}
|
|
24474
|
-
function
|
|
25031
|
+
function walkNode2(node, path, forceCloseAncestors, state) {
|
|
24475
25032
|
if (state.bailed)
|
|
24476
25033
|
return;
|
|
24477
25034
|
if (node.type === "element") {
|
|
@@ -24533,7 +25090,7 @@ function walkChildren(children, parentPath, forceCloseAncestors, state) {
|
|
|
24533
25090
|
return;
|
|
24534
25091
|
}
|
|
24535
25092
|
if (!frozen) {
|
|
24536
|
-
|
|
25093
|
+
walkNode2(child, [...parentPath, idx], forceCloseAncestors, state);
|
|
24537
25094
|
}
|
|
24538
25095
|
idx += 1;
|
|
24539
25096
|
pendingText = false;
|
|
@@ -26045,7 +26602,7 @@ function checkRichTypeMethodCalls(root, metadata, errors) {
|
|
|
26045
26602
|
return;
|
|
26046
26603
|
const matchers = prepareLoweringMatchers(metadata);
|
|
26047
26604
|
const seen = new Set;
|
|
26048
|
-
|
|
26605
|
+
walkNode3(root, metadata, EMPTY_BINDINGS2, matchers, errors, seen);
|
|
26049
26606
|
}
|
|
26050
26607
|
function checkRichTypePropSerialization(root, metadata, errors, declLoc) {
|
|
26051
26608
|
if (!metadata.propsType || !metadata.clientAnalysis?.needsInit)
|
|
@@ -26204,7 +26761,7 @@ function checkExpr(expr, loc, meta, bindings, matchers, errors, seen) {
|
|
|
26204
26761
|
break;
|
|
26205
26762
|
}
|
|
26206
26763
|
}
|
|
26207
|
-
function
|
|
26764
|
+
function walkTemplateParts2(parts, loc, meta, bindings, matchers, errors, seen) {
|
|
26208
26765
|
for (const part of parts) {
|
|
26209
26766
|
if (part.type === "ternary") {
|
|
26210
26767
|
const trimmed = part.condition.trim();
|
|
@@ -26217,22 +26774,22 @@ function walkTemplateParts(parts, loc, meta, bindings, matchers, errors, seen) {
|
|
|
26217
26774
|
}
|
|
26218
26775
|
}
|
|
26219
26776
|
}
|
|
26220
|
-
function
|
|
26777
|
+
function walkAttrValue2(value, clientOnly, loc, meta, bindings, matchers, errors, seen) {
|
|
26221
26778
|
if (clientOnly)
|
|
26222
26779
|
return;
|
|
26223
26780
|
if (value.kind === "expression") {
|
|
26224
26781
|
if (value.parsed)
|
|
26225
26782
|
checkExpr(value.parsed, loc, meta, bindings, matchers, errors, seen);
|
|
26226
26783
|
if (value.parts)
|
|
26227
|
-
|
|
26784
|
+
walkTemplateParts2(value.parts, loc, meta, bindings, matchers, errors, seen);
|
|
26228
26785
|
} else if (value.kind === "spread") {
|
|
26229
26786
|
if (value.parsed)
|
|
26230
26787
|
checkExpr(value.parsed, loc, meta, bindings, matchers, errors, seen);
|
|
26231
26788
|
} else if (value.kind === "template") {
|
|
26232
|
-
|
|
26789
|
+
walkTemplateParts2(value.parts, loc, meta, bindings, matchers, errors, seen);
|
|
26233
26790
|
}
|
|
26234
26791
|
}
|
|
26235
|
-
function
|
|
26792
|
+
function walkNode3(node, meta, bindings, matchers, errors, seen) {
|
|
26236
26793
|
if (node.type === "expression") {
|
|
26237
26794
|
if (!node.clientOnly && node.parsed)
|
|
26238
26795
|
checkExpr(node.parsed, node.loc, meta, bindings, matchers, errors, seen);
|
|
@@ -26245,12 +26802,12 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
|
|
|
26245
26802
|
}
|
|
26246
26803
|
if (node.type === "element") {
|
|
26247
26804
|
for (const attr of node.attrs)
|
|
26248
|
-
|
|
26805
|
+
walkAttrValue2(attr.value, attr.clientOnly, attr.loc, meta, bindings, matchers, errors, seen);
|
|
26249
26806
|
} else if (node.type === "component") {
|
|
26250
26807
|
for (const prop of node.props)
|
|
26251
|
-
|
|
26808
|
+
walkAttrValue2(prop.value, prop.clientOnly, prop.loc, meta, bindings, matchers, errors, seen);
|
|
26252
26809
|
} else if (node.type === "provider") {
|
|
26253
|
-
|
|
26810
|
+
walkAttrValue2(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, meta, bindings, matchers, errors, seen);
|
|
26254
26811
|
}
|
|
26255
26812
|
switch (node.type) {
|
|
26256
26813
|
case "element":
|
|
@@ -26258,12 +26815,12 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
|
|
|
26258
26815
|
case "fragment":
|
|
26259
26816
|
case "provider":
|
|
26260
26817
|
for (const child of node.children)
|
|
26261
|
-
|
|
26818
|
+
walkNode3(child, meta, bindings, matchers, errors, seen);
|
|
26262
26819
|
break;
|
|
26263
26820
|
case "async":
|
|
26264
|
-
|
|
26821
|
+
walkNode3(node.fallback, meta, bindings, matchers, errors, seen);
|
|
26265
26822
|
for (const child of node.children)
|
|
26266
|
-
|
|
26823
|
+
walkNode3(child, meta, bindings, matchers, errors, seen);
|
|
26267
26824
|
break;
|
|
26268
26825
|
case "loop": {
|
|
26269
26826
|
if (node.clientOnly)
|
|
@@ -26276,35 +26833,35 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
|
|
|
26276
26833
|
if (node.index)
|
|
26277
26834
|
loopBindings.set(node.index, null);
|
|
26278
26835
|
for (const child of node.children)
|
|
26279
|
-
|
|
26836
|
+
walkNode3(child, meta, loopBindings, matchers, errors, seen);
|
|
26280
26837
|
if (node.childComponent) {
|
|
26281
26838
|
for (const child of node.childComponent.children)
|
|
26282
|
-
|
|
26839
|
+
walkNode3(child, meta, loopBindings, matchers, errors, seen);
|
|
26283
26840
|
}
|
|
26284
26841
|
for (const nested of node.nestedComponents ?? []) {
|
|
26285
26842
|
for (const child of nested.children)
|
|
26286
|
-
|
|
26843
|
+
walkNode3(child, meta, loopBindings, matchers, errors, seen);
|
|
26287
26844
|
}
|
|
26288
26845
|
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
26289
26846
|
if (seg.kind === "jsx")
|
|
26290
|
-
|
|
26847
|
+
walkNode3(seg.ir, meta, loopBindings, matchers, errors, seen);
|
|
26291
26848
|
}
|
|
26292
26849
|
for (const seg of node.preamble?.segments ?? []) {
|
|
26293
26850
|
if (seg.kind === "jsx")
|
|
26294
|
-
|
|
26851
|
+
walkNode3(seg.ir, meta, loopBindings, matchers, errors, seen);
|
|
26295
26852
|
}
|
|
26296
26853
|
break;
|
|
26297
26854
|
}
|
|
26298
26855
|
case "conditional":
|
|
26299
26856
|
if (node.clientOnly)
|
|
26300
26857
|
break;
|
|
26301
|
-
|
|
26302
|
-
|
|
26858
|
+
walkNode3(node.whenTrue, meta, bindings, matchers, errors, seen);
|
|
26859
|
+
walkNode3(node.whenFalse, meta, bindings, matchers, errors, seen);
|
|
26303
26860
|
break;
|
|
26304
26861
|
case "if-statement":
|
|
26305
|
-
|
|
26862
|
+
walkNode3(node.consequent, meta, bindings, matchers, errors, seen);
|
|
26306
26863
|
if (node.alternate)
|
|
26307
|
-
|
|
26864
|
+
walkNode3(node.alternate, meta, bindings, matchers, errors, seen);
|
|
26308
26865
|
break;
|
|
26309
26866
|
}
|
|
26310
26867
|
}
|
|
@@ -26333,7 +26890,10 @@ function checkAuthoredFormatDateCalls(root, metadata, errors) {
|
|
|
26333
26890
|
if (names.size === 0)
|
|
26334
26891
|
return;
|
|
26335
26892
|
const seen = new Set;
|
|
26336
|
-
|
|
26893
|
+
walkTemplatePositions(root, ({ expr, loc }) => {
|
|
26894
|
+
if (exprCallsName(expr, names))
|
|
26895
|
+
pushDiagnostic2(errors, seen, loc, anyName(names));
|
|
26896
|
+
});
|
|
26337
26897
|
}
|
|
26338
26898
|
function pushDiagnostic2(errors, seen, loc, name) {
|
|
26339
26899
|
const key = `${loc.start.line}:${loc.start.column}`;
|
|
@@ -26400,112 +26960,144 @@ function anyName(names) {
|
|
|
26400
26960
|
return n;
|
|
26401
26961
|
return "formatDate";
|
|
26402
26962
|
}
|
|
26403
|
-
|
|
26404
|
-
|
|
26405
|
-
|
|
26406
|
-
|
|
26407
|
-
|
|
26408
|
-
|
|
26409
|
-
|
|
26410
|
-
|
|
26411
|
-
|
|
26412
|
-
|
|
26413
|
-
|
|
26414
|
-
|
|
26415
|
-
|
|
26416
|
-
|
|
26417
|
-
|
|
26963
|
+
|
|
26964
|
+
// src/async-action-refusal.ts
|
|
26965
|
+
function checkAsyncActionReads(root, metadata, errors) {
|
|
26966
|
+
const directActions = collectActionNames(metadata.signals);
|
|
26967
|
+
if (directActions.size === 0)
|
|
26968
|
+
return;
|
|
26969
|
+
const actions = new Set(directActions);
|
|
26970
|
+
for (let grew = true;grew; ) {
|
|
26971
|
+
grew = false;
|
|
26972
|
+
for (const constant of metadata.localConstants) {
|
|
26973
|
+
const target = aliasTarget(constant);
|
|
26974
|
+
if (target !== undefined && actions.has(target) && !actions.has(constant.name)) {
|
|
26975
|
+
actions.add(constant.name);
|
|
26976
|
+
grew = true;
|
|
26977
|
+
}
|
|
26418
26978
|
}
|
|
26419
26979
|
}
|
|
26980
|
+
const readers = localsReadingActions(metadata, actions);
|
|
26981
|
+
const seen = new Set;
|
|
26982
|
+
walkTemplatePositions(root, (position) => {
|
|
26983
|
+
const { expr, loc, attrName } = position;
|
|
26984
|
+
if (attrName !== undefined && isEventHandlerName(attrName))
|
|
26985
|
+
return;
|
|
26986
|
+
if (seedableActionAccessorRead(position, directActions))
|
|
26987
|
+
return;
|
|
26988
|
+
const read = findActionRead(expr, actions, readers, new Set);
|
|
26989
|
+
if (read)
|
|
26990
|
+
pushDiagnostic3(errors, seen, loc, read);
|
|
26991
|
+
});
|
|
26420
26992
|
}
|
|
26421
|
-
function
|
|
26422
|
-
|
|
26423
|
-
|
|
26424
|
-
|
|
26425
|
-
|
|
26426
|
-
|
|
26427
|
-
if (value.parts)
|
|
26428
|
-
walkTemplateParts2(value.parts, loc, names, errors, seen);
|
|
26429
|
-
} else if (value.kind === "spread") {
|
|
26430
|
-
if (value.parsed && exprCallsName(value.parsed, names))
|
|
26431
|
-
pushDiagnostic2(errors, seen, loc, anyName(names));
|
|
26432
|
-
} else if (value.kind === "template") {
|
|
26433
|
-
walkTemplateParts2(value.parts, loc, names, errors, seen);
|
|
26993
|
+
function localsReadingActions(metadata, actions) {
|
|
26994
|
+
const values = new Map;
|
|
26995
|
+
const callables = new Map;
|
|
26996
|
+
const candidates = [];
|
|
26997
|
+
for (const memo of metadata.memos) {
|
|
26998
|
+
candidates.push({ name: memo.name, declaration: "memo", callable: false, freeIds: memo.computationFreeIdentifiers ?? [] });
|
|
26434
26999
|
}
|
|
26435
|
-
|
|
26436
|
-
|
|
26437
|
-
|
|
26438
|
-
|
|
26439
|
-
|
|
26440
|
-
|
|
26441
|
-
|
|
26442
|
-
|
|
26443
|
-
|
|
26444
|
-
}
|
|
26445
|
-
} else if (node.type === "if-statement") {
|
|
26446
|
-
if (node.parsedCondition && exprCallsName(node.parsedCondition, names)) {
|
|
26447
|
-
pushDiagnostic2(errors, seen, node.loc, anyName(names));
|
|
26448
|
-
}
|
|
27000
|
+
for (const constant of metadata.localConstants) {
|
|
27001
|
+
if (constant.isJsx || constant.isJsxFunction || actions.has(constant.name))
|
|
27002
|
+
continue;
|
|
27003
|
+
candidates.push({
|
|
27004
|
+
name: constant.name,
|
|
27005
|
+
declaration: "constant",
|
|
27006
|
+
callable: constant.isFunctionValue === true,
|
|
27007
|
+
freeIds: constant.freeIdentifiers ?? [],
|
|
27008
|
+
aliasOf: aliasTarget(constant)
|
|
27009
|
+
});
|
|
26449
27010
|
}
|
|
26450
|
-
|
|
26451
|
-
|
|
26452
|
-
|
|
26453
|
-
|
|
26454
|
-
for (const prop of node.props)
|
|
26455
|
-
walkAttrValue2(prop.value, prop.clientOnly, prop.loc, names, errors, seen);
|
|
26456
|
-
} else if (node.type === "provider") {
|
|
26457
|
-
walkAttrValue2(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, names, errors, seen);
|
|
27011
|
+
for (const fn of metadata.localFunctions) {
|
|
27012
|
+
if (fn.isJsxFunction)
|
|
27013
|
+
continue;
|
|
27014
|
+
candidates.push({ name: fn.name, declaration: "function", callable: true, freeIds: fn.freeIdentifiers ?? [] });
|
|
26458
27015
|
}
|
|
26459
|
-
|
|
26460
|
-
|
|
26461
|
-
|
|
26462
|
-
|
|
26463
|
-
|
|
26464
|
-
|
|
26465
|
-
|
|
26466
|
-
|
|
26467
|
-
|
|
26468
|
-
|
|
26469
|
-
|
|
26470
|
-
|
|
26471
|
-
|
|
26472
|
-
|
|
26473
|
-
|
|
26474
|
-
|
|
26475
|
-
|
|
26476
|
-
pushDiagnostic2(errors, seen, node.loc, anyName(names));
|
|
26477
|
-
for (const child of node.children)
|
|
26478
|
-
walkNode3(child, names, errors, seen);
|
|
26479
|
-
if (node.childComponent) {
|
|
26480
|
-
for (const child of node.childComponent.children)
|
|
26481
|
-
walkNode3(child, names, errors, seen);
|
|
26482
|
-
}
|
|
26483
|
-
for (const nested of node.nestedComponents ?? []) {
|
|
26484
|
-
for (const child of nested.children)
|
|
26485
|
-
walkNode3(child, names, errors, seen);
|
|
26486
|
-
}
|
|
26487
|
-
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
26488
|
-
if (seg.kind === "jsx")
|
|
26489
|
-
walkNode3(seg.ir, names, errors, seen);
|
|
27016
|
+
let changed = true;
|
|
27017
|
+
while (changed) {
|
|
27018
|
+
changed = false;
|
|
27019
|
+
for (const candidate of candidates) {
|
|
27020
|
+
if (values.has(candidate.name) || callables.has(candidate.name))
|
|
27021
|
+
continue;
|
|
27022
|
+
if (candidate.aliasOf !== undefined) {
|
|
27023
|
+
const target = values.get(candidate.aliasOf) ?? callables.get(candidate.aliasOf);
|
|
27024
|
+
if (target === undefined)
|
|
27025
|
+
continue;
|
|
27026
|
+
const reader = { declaration: candidate.declaration, action: target.action };
|
|
27027
|
+
if (callables.has(candidate.aliasOf))
|
|
27028
|
+
callables.set(candidate.name, reader);
|
|
27029
|
+
else
|
|
27030
|
+
values.set(candidate.name, reader);
|
|
27031
|
+
changed = true;
|
|
27032
|
+
continue;
|
|
26490
27033
|
}
|
|
26491
|
-
for (const
|
|
26492
|
-
if (
|
|
26493
|
-
|
|
27034
|
+
for (const id of candidate.freeIds) {
|
|
27035
|
+
if (id === candidate.name)
|
|
27036
|
+
continue;
|
|
27037
|
+
const action = actions.has(id) ? id : (values.get(id) ?? callables.get(id))?.action;
|
|
27038
|
+
if (action === undefined)
|
|
27039
|
+
continue;
|
|
27040
|
+
const reader = { declaration: candidate.declaration, action };
|
|
27041
|
+
if (candidate.callable)
|
|
27042
|
+
callables.set(candidate.name, reader);
|
|
27043
|
+
else
|
|
27044
|
+
values.set(candidate.name, reader);
|
|
27045
|
+
changed = true;
|
|
27046
|
+
break;
|
|
26494
27047
|
}
|
|
26495
|
-
break;
|
|
26496
27048
|
}
|
|
26497
|
-
|
|
26498
|
-
|
|
26499
|
-
|
|
26500
|
-
|
|
26501
|
-
|
|
27049
|
+
}
|
|
27050
|
+
return { values, callables };
|
|
27051
|
+
}
|
|
27052
|
+
function aliasTarget(constant) {
|
|
27053
|
+
return constant.parsed?.kind === "identifier" ? constant.parsed.name : undefined;
|
|
27054
|
+
}
|
|
27055
|
+
function findActionRead(expr, actions, readers, bound) {
|
|
27056
|
+
switch (expr.kind) {
|
|
27057
|
+
case "identifier": {
|
|
27058
|
+
if (bound.has(expr.name))
|
|
27059
|
+
return null;
|
|
27060
|
+
const reader = readers.values.get(expr.name);
|
|
27061
|
+
return reader ? { kind: "local", name: expr.name, ...reader } : null;
|
|
27062
|
+
}
|
|
27063
|
+
case "member":
|
|
27064
|
+
if (expr.object.kind === "identifier" && actions.has(expr.object.name) && !bound.has(expr.object.name) && ACTION_ACCESSOR_NAMES.has(expr.property)) {
|
|
27065
|
+
return { kind: "accessor", action: expr.object.name, accessor: expr.property };
|
|
27066
|
+
}
|
|
26502
27067
|
break;
|
|
26503
|
-
case "
|
|
26504
|
-
|
|
26505
|
-
|
|
26506
|
-
|
|
27068
|
+
case "call":
|
|
27069
|
+
if (expr.callee.kind === "identifier" && !bound.has(expr.callee.name)) {
|
|
27070
|
+
if (actions.has(expr.callee.name))
|
|
27071
|
+
return { kind: "call", action: expr.callee.name };
|
|
27072
|
+
const reader = readers.callables.get(expr.callee.name);
|
|
27073
|
+
if (reader)
|
|
27074
|
+
return { kind: "local", name: expr.callee.name, ...reader };
|
|
27075
|
+
}
|
|
26507
27076
|
break;
|
|
26508
27077
|
}
|
|
27078
|
+
for (const child of parsedExprChildren(expr)) {
|
|
27079
|
+
const read = findActionRead(child.expr, actions, readers, child.params ? new Set([...bound, ...child.params]) : bound);
|
|
27080
|
+
if (read)
|
|
27081
|
+
return read;
|
|
27082
|
+
}
|
|
27083
|
+
return null;
|
|
27084
|
+
}
|
|
27085
|
+
function pushDiagnostic3(errors, seen, loc, read) {
|
|
27086
|
+
const key = `${loc.start.line}:${loc.start.column}`;
|
|
27087
|
+
if (seen.has(key))
|
|
27088
|
+
return;
|
|
27089
|
+
seen.add(key);
|
|
27090
|
+
const what = read.kind === "accessor" ? `'${read.action}.${read.accessor}' reads an async action's accessor` : read.kind === "call" ? `'${read.action}()' calls an async action, which sends a request,` : `${read.declaration} '${read.name}' reads the async action '${read.action}' and is used`;
|
|
27091
|
+
errors.push({
|
|
27092
|
+
code: ErrorCodes.ASYNC_ACTION_READ_IN_TEMPLATE,
|
|
27093
|
+
severity: "error",
|
|
27094
|
+
message: `${what} in a template position. The request function never runs on the server, so ` + `'${read.action}.isPending()' and '${read.action}.error()' have no value to render there yet.`,
|
|
27095
|
+
loc,
|
|
27096
|
+
suggestion: {
|
|
27097
|
+
message: "Defer the read to the client with /* @client */, or read it inside an event handler or " + "effect, which only run on the client.",
|
|
27098
|
+
escape: [{ kind: "client-directive" }]
|
|
27099
|
+
}
|
|
27100
|
+
});
|
|
26509
27101
|
}
|
|
26510
27102
|
|
|
26511
27103
|
// src/compiler.ts
|
|
@@ -26596,6 +27188,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
26596
27188
|
checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors);
|
|
26597
27189
|
checkRichTypePropSerialization(componentIR.root, componentIR.metadata, errors, ctx.propsDestructuring?.loc);
|
|
26598
27190
|
checkAuthoredFormatDateCalls(componentIR.root, componentIR.metadata, errors);
|
|
27191
|
+
checkAsyncActionReads(componentIR.root, componentIR.metadata, errors);
|
|
26599
27192
|
decideComponentRootScopeComment(componentIR);
|
|
26600
27193
|
decideClientOnlyElision(componentIR.root);
|
|
26601
27194
|
entries.push({ componentIR, ctx });
|
|
@@ -26952,6 +27545,7 @@ function compileJSX(source, filePath, options) {
|
|
|
26952
27545
|
checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors);
|
|
26953
27546
|
checkRichTypePropSerialization(componentIR.root, componentIR.metadata, errors, ctx.propsDestructuring?.loc);
|
|
26954
27547
|
checkAuthoredFormatDateCalls(componentIR.root, componentIR.metadata, errors);
|
|
27548
|
+
checkAsyncActionReads(componentIR.root, componentIR.metadata, errors);
|
|
26955
27549
|
decideComponentRootScopeComment(componentIR);
|
|
26956
27550
|
decideClientOnlyElision(componentIR.root);
|
|
26957
27551
|
if (ctx.importedClientSignalNames.size > 0) {
|
|
@@ -27191,6 +27785,10 @@ class JsxAdapter extends BaseAdapter {
|
|
|
27191
27785
|
} else {
|
|
27192
27786
|
lines.push(` const ${signal.getter} = () => ${initialValue}`);
|
|
27193
27787
|
}
|
|
27788
|
+
const action = signal.factory?.action;
|
|
27789
|
+
if (action && identifierPattern(action).test(setterRefText)) {
|
|
27790
|
+
lines.push(preserveTypes ? ` const ${action}: any = Object.assign(() => {}, { isPending: () => false, error: () => undefined })` : ` const ${action} = Object.assign(() => {}, { isPending: () => false, error: () => undefined })`);
|
|
27791
|
+
}
|
|
27194
27792
|
if (signal.setter) {
|
|
27195
27793
|
const setterUsed = identifierPattern(signal.setter).test(setterRefText);
|
|
27196
27794
|
if (setterUsed) {
|
|
@@ -28468,6 +29066,8 @@ function buildComponentGraph(source, filePath, componentName) {
|
|
|
28468
29066
|
memos: [],
|
|
28469
29067
|
effects: [],
|
|
28470
29068
|
props: [],
|
|
29069
|
+
factories: [],
|
|
29070
|
+
accessors: [],
|
|
28471
29071
|
domBindings: []
|
|
28472
29072
|
};
|
|
28473
29073
|
}
|
|
@@ -28480,6 +29080,8 @@ function buildComponentGraph(source, filePath, componentName) {
|
|
|
28480
29080
|
memos: [],
|
|
28481
29081
|
effects: [],
|
|
28482
29082
|
props: [],
|
|
29083
|
+
factories: [],
|
|
29084
|
+
accessors: [],
|
|
28483
29085
|
domBindings: []
|
|
28484
29086
|
};
|
|
28485
29087
|
}
|
|
@@ -28550,89 +29152,107 @@ function buildGraphFromIR(ir) {
|
|
|
28550
29152
|
}
|
|
28551
29153
|
return [...out];
|
|
28552
29154
|
};
|
|
29155
|
+
const actions = collectActionNames(meta.signals);
|
|
29156
|
+
const accessorNames = new Set;
|
|
29157
|
+
for (const action of actions)
|
|
29158
|
+
for (const accessor of ACTION_ACCESSOR_NAMES)
|
|
29159
|
+
accessorNames.add(`${action}.${accessor}`);
|
|
29160
|
+
const accessorDepsOf = (expr, isShadowed) => [...actions].some((action) => tokenContainsIdent(expr, action)) ? collectActionAccessorReads(parseExpression(expr), actions, isShadowed).map((r) => `${r.action}.${r.accessor}`) : [];
|
|
28553
29161
|
const domBindings = [];
|
|
28554
|
-
collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined, BindingScope.EMPTY, propDepsOf);
|
|
28555
|
-
const
|
|
28556
|
-
|
|
28557
|
-
|
|
28558
|
-
|
|
28559
|
-
for (const dep of memo.deps) {
|
|
28560
|
-
signalConsumers.get(dep)?.push(`memo:${memo.name}`);
|
|
28561
|
-
}
|
|
28562
|
-
}
|
|
28563
|
-
for (let i = 0;i < meta.effects.length; i++) {
|
|
28564
|
-
const effect = meta.effects[i];
|
|
28565
|
-
for (const dep of effect.deps) {
|
|
28566
|
-
signalConsumers.get(dep)?.push(`effect:e${i}`);
|
|
28567
|
-
}
|
|
28568
|
-
}
|
|
28569
|
-
for (const dom of domBindings) {
|
|
28570
|
-
for (const dep of dom.deps) {
|
|
28571
|
-
signalConsumers.get(dep)?.push(`dom:${dom.label}`);
|
|
28572
|
-
}
|
|
28573
|
-
}
|
|
28574
|
-
const memoConsumers = new Map;
|
|
28575
|
-
for (const m of meta.memos)
|
|
28576
|
-
memoConsumers.set(m.name, []);
|
|
28577
|
-
for (let i = 0;i < meta.effects.length; i++) {
|
|
28578
|
-
const effect = meta.effects[i];
|
|
28579
|
-
for (const dep of effect.deps) {
|
|
28580
|
-
memoConsumers.get(dep)?.push(`effect:e${i}`);
|
|
28581
|
-
}
|
|
28582
|
-
}
|
|
28583
|
-
for (const dom of domBindings) {
|
|
28584
|
-
for (const dep of dom.deps) {
|
|
28585
|
-
memoConsumers.get(dep)?.push(`dom:${dom.label}`);
|
|
28586
|
-
}
|
|
28587
|
-
}
|
|
28588
|
-
for (const memo of meta.memos) {
|
|
28589
|
-
for (const dep of memo.deps) {
|
|
28590
|
-
memoConsumers.get(dep)?.push(`memo:${memo.name}`);
|
|
28591
|
-
}
|
|
28592
|
-
}
|
|
28593
|
-
const propConsumers = new Map;
|
|
28594
|
-
for (const dom of domBindings) {
|
|
28595
|
-
if (dom.type === "event")
|
|
29162
|
+
collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined, BindingScope.EMPTY, propDepsOf, accessorDepsOf);
|
|
29163
|
+
const factories = [];
|
|
29164
|
+
const factoryOf = new Map;
|
|
29165
|
+
for (const s of meta.signals) {
|
|
29166
|
+
if (!s.factory)
|
|
28596
29167
|
continue;
|
|
28597
|
-
|
|
28598
|
-
|
|
28599
|
-
|
|
28600
|
-
|
|
28601
|
-
|
|
28602
|
-
|
|
28603
|
-
|
|
28604
|
-
|
|
28605
|
-
|
|
28606
|
-
|
|
29168
|
+
const value = s.getterElided ? null : s.getter;
|
|
29169
|
+
const ids = s.factory.requestFreeIdentifiers;
|
|
29170
|
+
const info = {
|
|
29171
|
+
key: value ?? s.factory.action ?? s.getter,
|
|
29172
|
+
kind: s.factory.kind,
|
|
29173
|
+
callee: s.factory.callee,
|
|
29174
|
+
action: s.factory.action,
|
|
29175
|
+
value,
|
|
29176
|
+
requestDeps: s.factory.kind === "query" ? [
|
|
29177
|
+
...[...ids].filter((id) => id !== s.getter && (signalGetters.has(id) || memoNames.has(id))),
|
|
29178
|
+
...propDepsOf(s.factory.requestText, ids)
|
|
29179
|
+
] : []
|
|
29180
|
+
};
|
|
29181
|
+
factories.push(info);
|
|
29182
|
+
factoryOf.set(s, info);
|
|
28607
29183
|
}
|
|
28608
|
-
const signals = meta.signals.map((s) => ({
|
|
28609
|
-
kind: "signal",
|
|
28610
|
-
name: s.getter,
|
|
28611
|
-
setter: s.setter,
|
|
28612
|
-
initialValue: s.initialValue,
|
|
28613
|
-
consumers: signalConsumers.get(s.getter) ?? [],
|
|
28614
|
-
loc: { file: s.loc.file, line: s.loc.start.line }
|
|
28615
|
-
}));
|
|
28616
29184
|
const memos = meta.memos.map((m) => ({
|
|
28617
29185
|
kind: "memo",
|
|
28618
29186
|
name: m.name,
|
|
28619
|
-
deps: m.deps,
|
|
28620
|
-
consumers:
|
|
29187
|
+
deps: [...m.deps, ...bodyAccessorDeps(m.computation, actions)],
|
|
29188
|
+
consumers: [],
|
|
28621
29189
|
computation: m.computation,
|
|
28622
29190
|
loc: { file: m.loc.file, line: m.loc.start.line }
|
|
28623
29191
|
}));
|
|
28624
29192
|
const effects = meta.effects.map((e, i) => ({
|
|
28625
29193
|
kind: "effect",
|
|
28626
29194
|
label: `e${i}`,
|
|
28627
|
-
deps: e.deps,
|
|
29195
|
+
deps: [...e.deps, ...bodyAccessorDeps(e.body, actions)],
|
|
28628
29196
|
body: e.body,
|
|
28629
29197
|
loc: { file: e.loc.file, line: e.loc.start.line }
|
|
28630
29198
|
}));
|
|
29199
|
+
const signalConsumers = new Map(meta.signals.map((s) => [s.getter, []]));
|
|
29200
|
+
const memoConsumers = new Map(meta.memos.map((m) => [m.name, []]));
|
|
29201
|
+
const accessorConsumers = new Map([...accessorNames].map((name) => [name, []]));
|
|
29202
|
+
const propConsumers = new Map;
|
|
29203
|
+
const addConsumer = (dep, consumer, props2) => {
|
|
29204
|
+
const consumers = signalConsumers.get(dep) ?? memoConsumers.get(dep) ?? accessorConsumers.get(dep);
|
|
29205
|
+
if (consumers) {
|
|
29206
|
+
consumers.push(consumer);
|
|
29207
|
+
} else if (props2) {
|
|
29208
|
+
const list = propConsumers.get(dep) ?? [];
|
|
29209
|
+
propConsumers.set(dep, list);
|
|
29210
|
+
list.push(consumer);
|
|
29211
|
+
}
|
|
29212
|
+
};
|
|
29213
|
+
for (const m of memos)
|
|
29214
|
+
for (const dep of m.deps)
|
|
29215
|
+
addConsumer(dep, `memo:${m.name}`, false);
|
|
29216
|
+
for (const e of effects)
|
|
29217
|
+
for (const dep of e.deps)
|
|
29218
|
+
addConsumer(dep, `effect:${e.label}`, false);
|
|
29219
|
+
for (const dom of domBindings) {
|
|
29220
|
+
for (const dep of dom.deps)
|
|
29221
|
+
addConsumer(dep, `dom:${dom.label}`, dom.type !== "event");
|
|
29222
|
+
}
|
|
29223
|
+
for (const f of factories)
|
|
29224
|
+
for (const dep of f.requestDeps)
|
|
29225
|
+
addConsumer(dep, `query:${f.key}`, true);
|
|
29226
|
+
for (const m of memos)
|
|
29227
|
+
m.consumers = memoConsumers.get(m.name) ?? [];
|
|
29228
|
+
const signals = meta.signals.filter((s) => !(s.factory && s.getterElided)).map((s) => {
|
|
29229
|
+
const factory = factoryOf.get(s);
|
|
29230
|
+
return {
|
|
29231
|
+
kind: "signal",
|
|
29232
|
+
name: s.getter,
|
|
29233
|
+
setter: s.setter,
|
|
29234
|
+
initialValue: s.initialValue,
|
|
29235
|
+
consumers: signalConsumers.get(s.getter) ?? [],
|
|
29236
|
+
loc: { file: s.loc.file, line: s.loc.start.line },
|
|
29237
|
+
...factory && { factory }
|
|
29238
|
+
};
|
|
29239
|
+
});
|
|
28631
29240
|
const props = [...propConsumers].map(([name, consumers]) => ({
|
|
28632
29241
|
kind: "prop",
|
|
28633
29242
|
name,
|
|
28634
29243
|
consumers
|
|
28635
29244
|
}));
|
|
29245
|
+
const accessors = factories.flatMap((f) => f.action === null ? [] : [...ACTION_ACCESSOR_NAMES].map((accessor) => {
|
|
29246
|
+
const name = `${f.action}.${accessor}`;
|
|
29247
|
+
return {
|
|
29248
|
+
kind: "accessor",
|
|
29249
|
+
name,
|
|
29250
|
+
action: f.action,
|
|
29251
|
+
accessor,
|
|
29252
|
+
factory: f.key,
|
|
29253
|
+
consumers: accessorConsumers.get(name) ?? []
|
|
29254
|
+
};
|
|
29255
|
+
}));
|
|
28636
29256
|
return {
|
|
28637
29257
|
componentName: meta.componentName,
|
|
28638
29258
|
sourceFile: findSourceFile2(meta) ?? "",
|
|
@@ -28640,9 +29260,32 @@ function buildGraphFromIR(ir) {
|
|
|
28640
29260
|
memos,
|
|
28641
29261
|
effects,
|
|
28642
29262
|
props,
|
|
29263
|
+
factories,
|
|
29264
|
+
accessors,
|
|
28643
29265
|
domBindings
|
|
28644
29266
|
};
|
|
28645
29267
|
}
|
|
29268
|
+
function bodyAccessorDeps(body, actions) {
|
|
29269
|
+
if (![...actions].some((action) => tokenContainsIdent(body, action)))
|
|
29270
|
+
return [];
|
|
29271
|
+
const found = new Set;
|
|
29272
|
+
const visit3 = (node) => {
|
|
29273
|
+
if (ts30.isExpression(node)) {
|
|
29274
|
+
const parsed = tsNodeToParsedExpr(node);
|
|
29275
|
+
if (!containsUnsupported(parsed)) {
|
|
29276
|
+
for (const r of collectActionAccessorReads(parsed, actions))
|
|
29277
|
+
found.add(`${r.action}.${r.accessor}`);
|
|
29278
|
+
return;
|
|
29279
|
+
}
|
|
29280
|
+
}
|
|
29281
|
+
ts30.forEachChild(node, visit3);
|
|
29282
|
+
};
|
|
29283
|
+
visit3(ts30.createSourceFile("__body.tsx", `(${body})`, ts30.ScriptTarget.Latest, true, ts30.ScriptKind.TSX));
|
|
29284
|
+
return [...found];
|
|
29285
|
+
}
|
|
29286
|
+
function containsUnsupported(expr) {
|
|
29287
|
+
return expr.kind === "unsupported" || parsedExprChildren(expr).some((child) => containsUnsupported(child.expr));
|
|
29288
|
+
}
|
|
28646
29289
|
function buildComponentAnalysis(source, filePath, componentName, program) {
|
|
28647
29290
|
const ctx = analyzeComponent(source, filePath, componentName, program);
|
|
28648
29291
|
const emptyIR = {
|
|
@@ -29143,8 +29786,19 @@ function traceUpdatePath(graph, targetName) {
|
|
|
29143
29786
|
const prop = graph.props.find((p) => p.name === targetName);
|
|
29144
29787
|
if (prop)
|
|
29145
29788
|
return { target: targetName, kind: "prop", dependents: traceConsumers(prop.consumers, graph) };
|
|
29789
|
+
const accessor = graph.accessors.find((a) => a.name === targetName);
|
|
29790
|
+
if (accessor)
|
|
29791
|
+
return { target: targetName, kind: "accessor", dependents: traceConsumers(accessor.consumers, graph) };
|
|
29146
29792
|
return null;
|
|
29147
29793
|
}
|
|
29794
|
+
function traceableNames(graph) {
|
|
29795
|
+
return [
|
|
29796
|
+
...graph.signals.map((s) => s.name),
|
|
29797
|
+
...graph.memos.map((m) => m.name),
|
|
29798
|
+
...graph.props.map((p) => p.name),
|
|
29799
|
+
...graph.accessors.map((a) => a.name)
|
|
29800
|
+
];
|
|
29801
|
+
}
|
|
29148
29802
|
function traceConsumers(consumers, graph) {
|
|
29149
29803
|
return consumers.map((consumer) => buildUpdateEntry(consumer, graph, new Set));
|
|
29150
29804
|
}
|
|
@@ -29173,6 +29827,15 @@ function buildUpdateEntry(consumer, graph, visited) {
|
|
|
29173
29827
|
if (type === "dom") {
|
|
29174
29828
|
return { name, kind: "dom", label: name, children: [] };
|
|
29175
29829
|
}
|
|
29830
|
+
if (type === "query") {
|
|
29831
|
+
const value = graph.signals.find((s) => s.name === name);
|
|
29832
|
+
const readers = [
|
|
29833
|
+
...value?.consumers ?? [],
|
|
29834
|
+
...graph.accessors.filter((a) => a.factory === name).flatMap((a) => a.consumers)
|
|
29835
|
+
];
|
|
29836
|
+
const children = [...new Set(readers)].map((c) => buildUpdateEntry(c, graph, new Set(visited)));
|
|
29837
|
+
return { name, kind: "query", label: `${name} (query)`, children };
|
|
29838
|
+
}
|
|
29176
29839
|
return { name: consumer, kind: "effect", label: consumer, children: [] };
|
|
29177
29840
|
}
|
|
29178
29841
|
function buildWhyUpdate(source, filePath, bindingLabel, componentName) {
|
|
@@ -29194,15 +29857,29 @@ function buildWhyUpdate(source, filePath, bindingLabel, componentName) {
|
|
|
29194
29857
|
if (s.setter)
|
|
29195
29858
|
setterToSignal.set(s.setter, s.getter);
|
|
29196
29859
|
}
|
|
29860
|
+
for (const f of graph.factories) {
|
|
29861
|
+
if (f.action)
|
|
29862
|
+
setterToSignal.set(f.action, f.key);
|
|
29863
|
+
}
|
|
29197
29864
|
const fnSetters = buildLocalFunctionSetterMap(ir.metadata, setterToSignal);
|
|
29198
29865
|
const events = collectEventBindings(ir.root, setterToSignal, fnSetters);
|
|
29866
|
+
const changedByOf = (key) => events.flatMap((ev) => ev.setterCalls.filter((sc) => sc.signal === key).map((sc) => ({ handler: ev.eventName, setter: sc.setter, elementContext: ev.elementContext, via: sc.via })));
|
|
29867
|
+
const factoryByKey = new Map(graph.factories.map((f) => [f.key, f]));
|
|
29199
29868
|
const deps = [];
|
|
29200
29869
|
const visited = new Set;
|
|
29201
29870
|
function traceDep(name) {
|
|
29202
29871
|
if (visited.has(name))
|
|
29203
29872
|
return;
|
|
29204
29873
|
visited.add(name);
|
|
29205
|
-
const
|
|
29874
|
+
const accessor = graph.accessors.find((a) => a.name === name);
|
|
29875
|
+
const signal = accessor ? undefined : graph.signals.find((s) => s.name === name);
|
|
29876
|
+
const factory = factoryByKey.get(accessor?.factory ?? signal?.factory?.key ?? "");
|
|
29877
|
+
if (factory) {
|
|
29878
|
+
deps.push({ name, kind: accessor ? "accessor" : "signal", dependsOn: factory.requestDeps, changedBy: changedByOf(factory.key) });
|
|
29879
|
+
for (const dep of factory.requestDeps)
|
|
29880
|
+
traceDep(dep);
|
|
29881
|
+
return;
|
|
29882
|
+
}
|
|
29206
29883
|
if (signal) {
|
|
29207
29884
|
const changedBy = [];
|
|
29208
29885
|
for (const ev of events) {
|
|
@@ -29264,7 +29941,9 @@ function formatWhyUpdate(result) {
|
|
|
29264
29941
|
lines.push(" (prop — the parent component passes a new value)");
|
|
29265
29942
|
} else {
|
|
29266
29943
|
lines.push(`${dep.name} changes from:`);
|
|
29267
|
-
|
|
29944
|
+
for (const d of dep.dependsOn)
|
|
29945
|
+
lines.push(` ${d} (re-sends the request)`);
|
|
29946
|
+
if (dep.changedBy.length === 0 && dep.dependsOn.length === 0) {
|
|
29268
29947
|
lines.push(" (no event handlers found)");
|
|
29269
29948
|
}
|
|
29270
29949
|
for (const src of dep.changedBy) {
|
|
@@ -29282,7 +29961,17 @@ function formatComponentGraph(graph) {
|
|
|
29282
29961
|
if (graph.signals.length > 0) {
|
|
29283
29962
|
lines.push(` signals:`);
|
|
29284
29963
|
for (const s of graph.signals) {
|
|
29285
|
-
|
|
29964
|
+
const factory = s.factory ? ` [${s.factory.callee}${s.factory.action ? `, action ${s.factory.action}` : ""}]` + (s.factory.requestDeps.length > 0 ? ` <- ${s.factory.requestDeps.join(", ")}` : "") : "";
|
|
29965
|
+
lines.push(` ${s.name} (initial: ${s.initialValue})${factory}`);
|
|
29966
|
+
}
|
|
29967
|
+
}
|
|
29968
|
+
if (graph.accessors.length > 0) {
|
|
29969
|
+
const factoryByKey = new Map(graph.factories.map((f) => [f.key, f]));
|
|
29970
|
+
lines.push(` accessors:`);
|
|
29971
|
+
for (const a of graph.accessors) {
|
|
29972
|
+
const f = factoryByKey.get(a.factory);
|
|
29973
|
+
const owner = f?.value ? `of ${f.value}` : `${f?.callee}, value not destructured`;
|
|
29974
|
+
lines.push(` ${a.name}() (${owner})`);
|
|
29286
29975
|
}
|
|
29287
29976
|
}
|
|
29288
29977
|
if (graph.memos.length > 0) {
|
|
@@ -29332,7 +30021,7 @@ function formatComponentGraph(graph) {
|
|
|
29332
30021
|
}
|
|
29333
30022
|
}
|
|
29334
30023
|
}
|
|
29335
|
-
if (graph.signals.length > 0 || graph.memos.length > 0 || graph.props.length > 0) {
|
|
30024
|
+
if (graph.signals.length > 0 || graph.memos.length > 0 || graph.props.length > 0 || graph.accessors.length > 0) {
|
|
29336
30025
|
lines.push(` dependency graph:`);
|
|
29337
30026
|
for (const s of graph.signals) {
|
|
29338
30027
|
for (const consumer of s.consumers) {
|
|
@@ -29349,6 +30038,11 @@ function formatComponentGraph(graph) {
|
|
|
29349
30038
|
lines.push(` ${p.name} -> ${consumer}`);
|
|
29350
30039
|
}
|
|
29351
30040
|
}
|
|
30041
|
+
for (const a of graph.accessors) {
|
|
30042
|
+
for (const consumer of a.consumers) {
|
|
30043
|
+
lines.push(` ${a.name} -> ${consumer}`);
|
|
30044
|
+
}
|
|
30045
|
+
}
|
|
29352
30046
|
}
|
|
29353
30047
|
return lines.join(`
|
|
29354
30048
|
`);
|
|
@@ -29384,7 +30078,8 @@ function graphToJSON(graph) {
|
|
|
29384
30078
|
setter: s.setter,
|
|
29385
30079
|
initialValue: s.initialValue,
|
|
29386
30080
|
consumers: s.consumers,
|
|
29387
|
-
loc: s.loc
|
|
30081
|
+
loc: s.loc,
|
|
30082
|
+
...s.factory && { factory: s.factory }
|
|
29388
30083
|
})),
|
|
29389
30084
|
memos: graph.memos.map((m) => ({
|
|
29390
30085
|
name: m.name,
|
|
@@ -29403,6 +30098,14 @@ function graphToJSON(graph) {
|
|
|
29403
30098
|
name: p.name,
|
|
29404
30099
|
consumers: p.consumers
|
|
29405
30100
|
})),
|
|
30101
|
+
factories: graph.factories,
|
|
30102
|
+
accessors: graph.accessors.map((a) => ({
|
|
30103
|
+
name: a.name,
|
|
30104
|
+
action: a.action,
|
|
30105
|
+
accessor: a.accessor,
|
|
30106
|
+
factory: a.factory,
|
|
30107
|
+
consumers: a.consumers
|
|
30108
|
+
})),
|
|
29406
30109
|
domBindings: graph.domBindings.map((d) => ({
|
|
29407
30110
|
label: d.label,
|
|
29408
30111
|
slotId: d.slotId,
|
|
@@ -29625,7 +30328,7 @@ function inferWrapReasonForAttrLike(hasStringReactive, hasPropsRef, flags) {
|
|
|
29625
30328
|
const decision = decideWrapFromAstFlags(flags);
|
|
29626
30329
|
return decision.wrap ? decision.reason : undefined;
|
|
29627
30330
|
}
|
|
29628
|
-
function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag, scope = BindingScope.EMPTY, propDepsOf = () => []) {
|
|
30331
|
+
function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag, scope = BindingScope.EMPTY, propDepsOf = () => [], accessorDepsOf = () => []) {
|
|
29629
30332
|
const boundNames = scope.valueBoundNames();
|
|
29630
30333
|
const isShadowed = scope.asShadowPredicate();
|
|
29631
30334
|
const setSomeIn = (names, other) => {
|
|
@@ -29647,7 +30350,10 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
29647
30350
|
const expr = attrValueToString2(attr.value);
|
|
29648
30351
|
if (!expr)
|
|
29649
30352
|
continue;
|
|
29650
|
-
const signalDeps =
|
|
30353
|
+
const signalDeps = [
|
|
30354
|
+
...extractReactiveDeps(expr, signalGetters, memoNames),
|
|
30355
|
+
...accessorDepsOf(expr, isShadowed)
|
|
30356
|
+
];
|
|
29651
30357
|
const isReactive = signalDeps.length > 0 || attrReadsLoopParam(attr.freeIdentifiers);
|
|
29652
30358
|
const propDeps = propDepsOf(expr, attr.freeIdentifiers, isShadowed);
|
|
29653
30359
|
const hasPropsRef = propDeps.length > 0;
|
|
@@ -29680,16 +30386,18 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
29680
30386
|
});
|
|
29681
30387
|
}
|
|
29682
30388
|
for (const child of node.children) {
|
|
29683
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, node.tag, scope, propDepsOf);
|
|
30389
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, node.tag, scope, propDepsOf, accessorDepsOf);
|
|
29684
30390
|
}
|
|
29685
30391
|
break;
|
|
29686
30392
|
}
|
|
29687
30393
|
case "expression": {
|
|
29688
30394
|
const decision = decideWrapFromAstFlags(node);
|
|
29689
30395
|
const loopReactive = exprReadsLoopParam(node);
|
|
29690
|
-
|
|
30396
|
+
const accessorDeps = accessorDepsOf(node.expr, isShadowed);
|
|
30397
|
+
if ((decision.wrap || loopReactive || accessorDeps.length > 0) && node.slotId) {
|
|
29691
30398
|
const deps = [
|
|
29692
30399
|
...extractReactiveDeps(node.expr, signalGetters, memoNames),
|
|
30400
|
+
...accessorDeps,
|
|
29693
30401
|
...propDepsOf(node.expr, freeIdsOf(node.origin), isShadowed)
|
|
29694
30402
|
];
|
|
29695
30403
|
const preview = parentTag ? `<${parentTag}>{${truncateExpr(node.expr)}}</${parentTag}>` : `{${truncateExpr(node.expr)}}`;
|
|
@@ -29699,9 +30407,9 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
29699
30407
|
slotId: node.slotId,
|
|
29700
30408
|
deps,
|
|
29701
30409
|
type: "text",
|
|
29702
|
-
classification: decision.wrap && decision.reason === "proven-reactive" || loopReactive ? "reactive" : "fallback",
|
|
30410
|
+
classification: decision.wrap && decision.reason === "proven-reactive" || loopReactive || accessorDeps.length > 0 ? "reactive" : "fallback",
|
|
29703
30411
|
expression: node.expr,
|
|
29704
|
-
wrapReason: decision.wrap ? decision.reason : "string-reactive",
|
|
30412
|
+
wrapReason: decision.wrap && accessorDeps.length === 0 ? decision.reason : "string-reactive",
|
|
29705
30413
|
loc: node.loc,
|
|
29706
30414
|
jsxPreview: preview
|
|
29707
30415
|
});
|
|
@@ -29711,9 +30419,11 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
29711
30419
|
case "conditional": {
|
|
29712
30420
|
const decision = decideWrapFromAstFlags(node);
|
|
29713
30421
|
const loopReactive = boundNames.size > 0 && (node.origin?.freeRefs?.some((r) => boundNames.has(r.name)) ?? false);
|
|
29714
|
-
|
|
30422
|
+
const accessorDeps = accessorDepsOf(node.condition, isShadowed);
|
|
30423
|
+
if ((decision.wrap || loopReactive || accessorDeps.length > 0) && node.slotId) {
|
|
29715
30424
|
const deps = [
|
|
29716
30425
|
...extractReactiveDeps(node.condition, signalGetters, memoNames),
|
|
30426
|
+
...accessorDeps,
|
|
29717
30427
|
...propDepsOf(node.condition, freeIdsOf(node.origin), isShadowed)
|
|
29718
30428
|
];
|
|
29719
30429
|
bindings.push({
|
|
@@ -29722,15 +30432,15 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
29722
30432
|
slotId: node.slotId,
|
|
29723
30433
|
deps,
|
|
29724
30434
|
type: "conditional",
|
|
29725
|
-
classification: decision.wrap && decision.reason === "proven-reactive" || loopReactive ? "reactive" : "fallback",
|
|
30435
|
+
classification: decision.wrap && decision.reason === "proven-reactive" || loopReactive || accessorDeps.length > 0 ? "reactive" : "fallback",
|
|
29726
30436
|
expression: node.condition,
|
|
29727
|
-
wrapReason: decision.wrap ? decision.reason : "string-reactive",
|
|
30437
|
+
wrapReason: decision.wrap && accessorDeps.length === 0 ? decision.reason : "string-reactive",
|
|
29728
30438
|
loc: node.loc,
|
|
29729
30439
|
jsxPreview: `{${truncateExpr(node.condition)} ? ... : ...}`
|
|
29730
30440
|
});
|
|
29731
30441
|
}
|
|
29732
|
-
collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
|
|
29733
|
-
collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
|
|
30442
|
+
collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
|
|
30443
|
+
collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
|
|
29734
30444
|
break;
|
|
29735
30445
|
}
|
|
29736
30446
|
case "loop": {
|
|
@@ -29757,7 +30467,7 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
29757
30467
|
}
|
|
29758
30468
|
const childScope = scope.enterLoopRow(node);
|
|
29759
30469
|
for (const child of node.children) {
|
|
29760
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, childScope, propDepsOf);
|
|
30470
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, childScope, propDepsOf, accessorDepsOf);
|
|
29761
30471
|
}
|
|
29762
30472
|
break;
|
|
29763
30473
|
}
|
|
@@ -29791,21 +30501,21 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
29791
30501
|
}
|
|
29792
30502
|
}
|
|
29793
30503
|
for (const child of node.children) {
|
|
29794
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
|
|
30504
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
|
|
29795
30505
|
}
|
|
29796
30506
|
break;
|
|
29797
30507
|
}
|
|
29798
30508
|
case "fragment":
|
|
29799
30509
|
case "provider": {
|
|
29800
30510
|
for (const child of node.children) {
|
|
29801
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
|
|
30511
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
|
|
29802
30512
|
}
|
|
29803
30513
|
break;
|
|
29804
30514
|
}
|
|
29805
30515
|
case "if-statement": {
|
|
29806
|
-
collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
|
|
30516
|
+
collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
|
|
29807
30517
|
if (node.alternate) {
|
|
29808
|
-
collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
|
|
30518
|
+
collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
|
|
29809
30519
|
}
|
|
29810
30520
|
break;
|
|
29811
30521
|
}
|
|
@@ -31136,6 +31846,7 @@ function profileToJSON(profile) {
|
|
|
31136
31846
|
registerBuiltinLoweringPlugins();
|
|
31137
31847
|
export {
|
|
31138
31848
|
tsNodeToParsedExpr,
|
|
31849
|
+
traceableNames,
|
|
31139
31850
|
traceUpdatePath,
|
|
31140
31851
|
testAdapter,
|
|
31141
31852
|
stringifyParsedExpr,
|
|
@@ -31257,6 +31968,7 @@ export {
|
|
|
31257
31968
|
createProgramForFile,
|
|
31258
31969
|
createProgramForCorpus,
|
|
31259
31970
|
createError,
|
|
31971
|
+
createAnchoredProgram,
|
|
31260
31972
|
containsHigherOrder,
|
|
31261
31973
|
computeSsrSeedPlan,
|
|
31262
31974
|
compileJSX,
|