@barefootjs/client 0.31.1 → 0.31.3
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/csr-adapter.js +353 -38
- package/package.json +2 -2
package/dist/csr-adapter.js
CHANGED
|
@@ -168753,8 +168753,11 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
|
|
|
168753
168753
|
} });
|
|
168754
168754
|
});
|
|
168755
168755
|
|
|
168756
|
+
// ../jsx/src/compiler.ts
|
|
168757
|
+
var import_typescript23 = __toESM(require_typescript(), 1);
|
|
168758
|
+
|
|
168756
168759
|
// ../jsx/src/analyzer.ts
|
|
168757
|
-
var
|
|
168760
|
+
var import_typescript9 = __toESM(require_typescript(), 1);
|
|
168758
168761
|
|
|
168759
168762
|
// ../jsx/src/expression-parser.ts
|
|
168760
168763
|
var import_typescript = __toESM(require_typescript(), 1);
|
|
@@ -168835,6 +168838,29 @@ var import_typescript5 = __toESM(require_typescript(), 1);
|
|
|
168835
168838
|
// ../jsx/src/ir-to-client-js/utils.ts
|
|
168836
168839
|
var import_typescript3 = __toESM(require_typescript(), 1);
|
|
168837
168840
|
|
|
168841
|
+
// ../jsx/src/template-parts.ts
|
|
168842
|
+
function lookupPartToJsExpr(part, opts) {
|
|
168843
|
+
const key = opts?.useTemplate && part.templateKey ? part.templateKey : part.key;
|
|
168844
|
+
const obj = "{" + Object.entries(part.cases).map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`).join(", ") + "}";
|
|
168845
|
+
const typed = opts?.typed ? " as Record<string, string>" : "";
|
|
168846
|
+
return `(${obj}${typed})[${key}]`;
|
|
168847
|
+
}
|
|
168848
|
+
function templatePartsToJsExpr(parts, opts) {
|
|
168849
|
+
let result = "`";
|
|
168850
|
+
for (const part of parts) {
|
|
168851
|
+
if (part.type === "string") {
|
|
168852
|
+
result += opts?.useTemplate && part.templateValue ? part.templateValue : part.value;
|
|
168853
|
+
} else if (part.type === "ternary") {
|
|
168854
|
+
const cond = opts?.useTemplate && part.templateCondition ? part.templateCondition : part.condition;
|
|
168855
|
+
result += `\${${cond} ? '${part.whenTrue}' : '${part.whenFalse}'}`;
|
|
168856
|
+
} else if (part.type === "lookup") {
|
|
168857
|
+
result += `\${${lookupPartToJsExpr(part, opts)}}`;
|
|
168858
|
+
}
|
|
168859
|
+
}
|
|
168860
|
+
result += "`";
|
|
168861
|
+
return result;
|
|
168862
|
+
}
|
|
168863
|
+
|
|
168838
168864
|
// ../jsx/src/scanner/js-scanner.ts
|
|
168839
168865
|
var import_typescript2 = __toESM(require_typescript(), 1);
|
|
168840
168866
|
|
|
@@ -168928,6 +168954,16 @@ var SVG_XML_CAMEL_ATTRS = new Set([
|
|
|
168928
168954
|
]);
|
|
168929
168955
|
// ../jsx/src/ir-to-client-js/csr-substitute.ts
|
|
168930
168956
|
var import_typescript4 = __toESM(require_typescript(), 1);
|
|
168957
|
+
function extractFreeIdentifiersFromText(text) {
|
|
168958
|
+
if (!text || text.trim().length === 0)
|
|
168959
|
+
return new Set;
|
|
168960
|
+
const sf = import_typescript4.default.createSourceFile("__free_ids__.ts", `(${text});`, import_typescript4.default.ScriptTarget.Latest, true, import_typescript4.default.ScriptKind.TS);
|
|
168961
|
+
const stmt = sf.statements[0];
|
|
168962
|
+
if (!stmt || !import_typescript4.default.isExpressionStatement(stmt))
|
|
168963
|
+
return new Set;
|
|
168964
|
+
const expr = import_typescript4.default.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
168965
|
+
return extractFreeIdentifiersFromNode(expr);
|
|
168966
|
+
}
|
|
168931
168967
|
|
|
168932
168968
|
// ../jsx/src/ir-to-client-js/html-template.ts
|
|
168933
168969
|
var VOID_ELEMENTS = new Set([
|
|
@@ -168973,6 +169009,27 @@ var SKELETON_PATH_FORCE_CLOSE_GROUPS = [
|
|
|
168973
169009
|
new Set(["li"])
|
|
168974
169010
|
];
|
|
168975
169011
|
|
|
169012
|
+
// ../jsx/src/props-binding.ts
|
|
169013
|
+
var import_typescript6 = __toESM(require_typescript(), 1);
|
|
169014
|
+
function isIdentifierName(key) {
|
|
169015
|
+
if (key.length === 0)
|
|
169016
|
+
return false;
|
|
169017
|
+
for (let i = 0;i < key.length; ) {
|
|
169018
|
+
const cp = key.codePointAt(i);
|
|
169019
|
+
const ok = i === 0 ? import_typescript6.default.isIdentifierStart(cp, import_typescript6.default.ScriptTarget.Latest) : import_typescript6.default.isIdentifierPart(cp, import_typescript6.default.ScriptTarget.Latest);
|
|
169020
|
+
if (!ok)
|
|
169021
|
+
return false;
|
|
169022
|
+
i += cp > 65535 ? 2 : 1;
|
|
169023
|
+
}
|
|
169024
|
+
return true;
|
|
169025
|
+
}
|
|
169026
|
+
function propsDestructureBinding(p) {
|
|
169027
|
+
const callerKey = p.sourceName ?? p.name;
|
|
169028
|
+
const localName = p.name;
|
|
169029
|
+
const binding = callerKey === localName ? localName : `${isIdentifierName(callerKey) ? callerKey : JSON.stringify(callerKey)}: ${localName}`;
|
|
169030
|
+
return p.defaultValue ? `${binding} = ${p.defaultValue}` : binding;
|
|
169031
|
+
}
|
|
169032
|
+
|
|
168976
169033
|
// ../jsx/src/instrumentation.ts
|
|
168977
169034
|
var _counters = freshCounters();
|
|
168978
169035
|
function freshCounters() {
|
|
@@ -168986,14 +169043,14 @@ function freshCounters() {
|
|
|
168986
169043
|
}
|
|
168987
169044
|
|
|
168988
169045
|
// ../jsx/src/analyzer-context.ts
|
|
168989
|
-
var
|
|
169046
|
+
var import_typescript8 = __toESM(require_typescript(), 1);
|
|
168990
169047
|
|
|
168991
169048
|
// ../jsx/src/strip-types.ts
|
|
168992
|
-
var
|
|
169049
|
+
var import_typescript7 = __toESM(require_typescript(), 1);
|
|
168993
169050
|
|
|
168994
169051
|
// ../jsx/src/analyzer-context.ts
|
|
168995
|
-
var _typePrinter =
|
|
168996
|
-
var _blankTypeSourceFile =
|
|
169052
|
+
var _typePrinter = import_typescript8.default.createPrinter({ removeComments: true, omitTrailingSemicolon: true });
|
|
169053
|
+
var _blankTypeSourceFile = import_typescript8.default.createSourceFile("__bf_types__.ts", "", import_typescript8.default.ScriptTarget.Latest);
|
|
168997
169054
|
|
|
168998
169055
|
// ../jsx/src/errors.ts
|
|
168999
169056
|
var ErrorCodes = {
|
|
@@ -169009,6 +169066,7 @@ var ErrorCodes = {
|
|
|
169009
169066
|
JSX_IN_LOCAL_FUNCTION: "BF045",
|
|
169010
169067
|
COMPONENT_REQUIRED_PROP_MISSING: "BF046",
|
|
169011
169068
|
JSX_BRANCH_LOCAL_IN_CALLBACK: "BF047",
|
|
169069
|
+
SIBLING_COMPONENT_NOT_COMPILED: "BF048",
|
|
169012
169070
|
SHARED_PROGRAM_REQUIRED: "BF050",
|
|
169013
169071
|
WRONG_PACKAGE_IMPORT: "BF051",
|
|
169014
169072
|
BUILTIN_REQUIRES_IMPORT: "BF054",
|
|
@@ -169038,6 +169096,7 @@ var errorMessages = {
|
|
|
169038
169096
|
[ErrorCodes.JSX_IN_LOCAL_FUNCTION]: "Local function returns JSX but cannot be inlined. Extract it as a top-level PascalCase component or use a single return statement.",
|
|
169039
169097
|
[ErrorCodes.COMPONENT_REQUIRED_PROP_MISSING]: "Built-in component is missing a required prop.",
|
|
169040
169098
|
[ErrorCodes.JSX_BRANCH_LOCAL_IN_CALLBACK]: "JSX-typed local declared inside an `if`-block cannot be referenced from a callback body (ref / event handler). " + "Render it as a child instead: `<div ref={...}>{local}</div>`.",
|
|
169099
|
+
[ErrorCodes.SIBLING_COMPONENT_NOT_COMPILED]: "Referenced component did not compile to a template, so this reference would throw " + "`ReferenceError` at render time. Multi-return JSX dispatch (a `switch` or `if`/`else` " + "chain across multiple JSX-returning branches) cannot compile as a component in a " + `'use client' file. Extract it to a separate non-"use client" file (where it is preserved ` + "verbatim, see #932), or rewrite it as a single-return ternary/conditional chain so the " + "component pipeline can compile it.",
|
|
169041
169100
|
[ErrorCodes.SHARED_PROGRAM_REQUIRED]: "Shared ts.Program required for type-based reactivity classification. This source imports a Reactive<T>-branded library (e.g. @barefootjs/form) whose getters cannot be classified by regex alone. Pass `options.program` (built via `createProgramForCorpus`) so the analyzer can resolve the brand through the TypeChecker.",
|
|
169042
169101
|
[ErrorCodes.WRONG_PACKAGE_IMPORT]: "Import from wrong package.",
|
|
169043
169102
|
[ErrorCodes.BUILTIN_REQUIRES_IMPORT]: "Built-in <Async> / <Region> must be imported from '@barefootjs/client'. " + "The compiler recognises these tags by their import (not by tag name), " + "so an unimported tag with this name is treated as an undeclared component.",
|
|
@@ -169211,6 +169270,54 @@ var CLIENT_EXPORTS = new Set([
|
|
|
169211
169270
|
"Async",
|
|
169212
169271
|
"Region"
|
|
169213
169272
|
]);
|
|
169273
|
+
function extractFreeIdentifiersFromNode(node) {
|
|
169274
|
+
const ids = new Set;
|
|
169275
|
+
const boundNames = new Set;
|
|
169276
|
+
function addBindingNames(name, out) {
|
|
169277
|
+
if (import_typescript9.default.isIdentifier(name))
|
|
169278
|
+
out.push(name.text);
|
|
169279
|
+
else if (import_typescript9.default.isObjectBindingPattern(name))
|
|
169280
|
+
name.elements.forEach((e) => addBindingNames(e.name, out));
|
|
169281
|
+
else if (import_typescript9.default.isArrayBindingPattern(name))
|
|
169282
|
+
name.elements.forEach((e) => {
|
|
169283
|
+
if (!import_typescript9.default.isOmittedExpression(e))
|
|
169284
|
+
addBindingNames(e.name, out);
|
|
169285
|
+
});
|
|
169286
|
+
}
|
|
169287
|
+
function visit(n) {
|
|
169288
|
+
if (import_typescript9.default.isTypeNode(n))
|
|
169289
|
+
return;
|
|
169290
|
+
if (import_typescript9.default.isIdentifier(n)) {
|
|
169291
|
+
const parent = n.parent;
|
|
169292
|
+
if (parent && import_typescript9.default.isPropertyAccessExpression(parent) && parent.name === n)
|
|
169293
|
+
return;
|
|
169294
|
+
if (parent && import_typescript9.default.isPropertyAssignment(parent) && parent.name === n)
|
|
169295
|
+
return;
|
|
169296
|
+
if (parent && import_typescript9.default.isParameter(parent) && parent.name === n)
|
|
169297
|
+
return;
|
|
169298
|
+
if (parent && import_typescript9.default.isVariableDeclaration(parent) && parent.name === n)
|
|
169299
|
+
return;
|
|
169300
|
+
if (boundNames.has(n.text))
|
|
169301
|
+
return;
|
|
169302
|
+
ids.add(n.text);
|
|
169303
|
+
return;
|
|
169304
|
+
}
|
|
169305
|
+
if (import_typescript9.default.isArrowFunction(n)) {
|
|
169306
|
+
const params = [];
|
|
169307
|
+
for (const p of n.parameters)
|
|
169308
|
+
addBindingNames(p.name, params);
|
|
169309
|
+
for (const name of params)
|
|
169310
|
+
boundNames.add(name);
|
|
169311
|
+
import_typescript9.default.forEachChild(n, visit);
|
|
169312
|
+
for (const name of params)
|
|
169313
|
+
boundNames.delete(name);
|
|
169314
|
+
return;
|
|
169315
|
+
}
|
|
169316
|
+
import_typescript9.default.forEachChild(n, visit);
|
|
169317
|
+
}
|
|
169318
|
+
visit(node);
|
|
169319
|
+
return ids;
|
|
169320
|
+
}
|
|
169214
169321
|
var BROWSER_ONLY_CLIENT_APIS = new Set([
|
|
169215
169322
|
"useContext",
|
|
169216
169323
|
"provideContext",
|
|
@@ -169229,7 +169336,7 @@ var REACTIVE_PRIMITIVES = new Set([
|
|
|
169229
169336
|
]);
|
|
169230
169337
|
|
|
169231
169338
|
// ../jsx/src/jsx-to-ir.ts
|
|
169232
|
-
var
|
|
169339
|
+
var import_typescript12 = __toESM(require_typescript(), 1);
|
|
169233
169340
|
|
|
169234
169341
|
// ../jsx/src/types.ts
|
|
169235
169342
|
var SCOPE_FORBIDDEN = {
|
|
@@ -169297,10 +169404,10 @@ function findReachableNames(primaryRefs, declarations) {
|
|
|
169297
169404
|
}
|
|
169298
169405
|
|
|
169299
169406
|
// ../jsx/src/reactivity-checker.ts
|
|
169300
|
-
var
|
|
169407
|
+
var import_typescript10 = __toESM(require_typescript(), 1);
|
|
169301
169408
|
|
|
169302
169409
|
// ../jsx/src/free-refs.ts
|
|
169303
|
-
var
|
|
169410
|
+
var import_typescript11 = __toESM(require_typescript(), 1);
|
|
169304
169411
|
var _bindingMapCache = new WeakMap;
|
|
169305
169412
|
|
|
169306
169413
|
// ../jsx/src/to-locale-date-lowering.ts
|
|
@@ -169618,6 +169725,83 @@ var toLocaleDatePlugin = {
|
|
|
169618
169725
|
}
|
|
169619
169726
|
};
|
|
169620
169727
|
|
|
169728
|
+
// ../jsx/src/scope/binding-scope.ts
|
|
169729
|
+
class BindingScope {
|
|
169730
|
+
frames;
|
|
169731
|
+
static EMPTY = new BindingScope([]);
|
|
169732
|
+
constructor(frames) {
|
|
169733
|
+
this.frames = frames;
|
|
169734
|
+
}
|
|
169735
|
+
enterLoopRow(loop) {
|
|
169736
|
+
const bindings = new Map;
|
|
169737
|
+
if (loop.paramBindings && loop.paramBindings.length > 0) {
|
|
169738
|
+
for (const b of loop.paramBindings)
|
|
169739
|
+
bindings.set(b.name, { source: "destructure" });
|
|
169740
|
+
} else {
|
|
169741
|
+
bindings.set(loop.param, { source: "item" });
|
|
169742
|
+
}
|
|
169743
|
+
if (loop.index != null)
|
|
169744
|
+
bindings.set(loop.index, { source: "index" });
|
|
169745
|
+
for (const name of loop.preamble?.declaredNames ?? [])
|
|
169746
|
+
bindings.set(name, { source: "preamble" });
|
|
169747
|
+
const frame = { kind: "loop-row", bindings };
|
|
169748
|
+
return new BindingScope([frame, ...this.frames]);
|
|
169749
|
+
}
|
|
169750
|
+
enterCallback(params) {
|
|
169751
|
+
const bindings = new Map;
|
|
169752
|
+
for (const name of params)
|
|
169753
|
+
bindings.set(name, { source: "param" });
|
|
169754
|
+
const frame = { kind: "callback", bindings };
|
|
169755
|
+
return new BindingScope([frame, ...this.frames]);
|
|
169756
|
+
}
|
|
169757
|
+
isBound(name) {
|
|
169758
|
+
for (const frame of this.frames) {
|
|
169759
|
+
if (frame.bindings.has(name))
|
|
169760
|
+
return true;
|
|
169761
|
+
}
|
|
169762
|
+
return false;
|
|
169763
|
+
}
|
|
169764
|
+
lookup(name) {
|
|
169765
|
+
for (let depth = 0;depth < this.frames.length; depth++) {
|
|
169766
|
+
const frame = this.frames[depth];
|
|
169767
|
+
const binding = frame.bindings.get(name);
|
|
169768
|
+
if (binding)
|
|
169769
|
+
return { depth, frame, binding };
|
|
169770
|
+
}
|
|
169771
|
+
return null;
|
|
169772
|
+
}
|
|
169773
|
+
boundNames() {
|
|
169774
|
+
if (this.boundNamesCache)
|
|
169775
|
+
return this.boundNamesCache;
|
|
169776
|
+
const names = new Set;
|
|
169777
|
+
for (const frame of this.frames) {
|
|
169778
|
+
for (const name of frame.bindings.keys())
|
|
169779
|
+
names.add(name);
|
|
169780
|
+
}
|
|
169781
|
+
this.boundNamesCache = names;
|
|
169782
|
+
return names;
|
|
169783
|
+
}
|
|
169784
|
+
boundNamesCache;
|
|
169785
|
+
valueBoundNamesCache;
|
|
169786
|
+
valueBoundNames() {
|
|
169787
|
+
if (this.valueBoundNamesCache)
|
|
169788
|
+
return this.valueBoundNamesCache;
|
|
169789
|
+
const names = new Set;
|
|
169790
|
+
for (const frame of this.frames) {
|
|
169791
|
+
for (const [name, binding] of frame.bindings) {
|
|
169792
|
+
if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
|
|
169793
|
+
names.add(name);
|
|
169794
|
+
}
|
|
169795
|
+
}
|
|
169796
|
+
}
|
|
169797
|
+
this.valueBoundNamesCache = names;
|
|
169798
|
+
return names;
|
|
169799
|
+
}
|
|
169800
|
+
asShadowPredicate() {
|
|
169801
|
+
return (name) => this.isBound(name);
|
|
169802
|
+
}
|
|
169803
|
+
}
|
|
169804
|
+
|
|
169621
169805
|
// ../jsx/src/jsx-to-ir.ts
|
|
169622
169806
|
var EMPTY_BOUND = new Set;
|
|
169623
169807
|
var constInitializerCache = new WeakMap;
|
|
@@ -169714,13 +169898,13 @@ var KEYWORDS_AND_GLOBALS = new Set([
|
|
|
169714
169898
|
]);
|
|
169715
169899
|
|
|
169716
169900
|
// ../jsx/src/ir-to-client-js/walk-prop-accesses.ts
|
|
169717
|
-
var
|
|
169901
|
+
var import_typescript13 = __toESM(require_typescript(), 1);
|
|
169718
169902
|
|
|
169719
169903
|
// ../jsx/src/value-references.ts
|
|
169720
|
-
var
|
|
169904
|
+
var import_typescript14 = __toESM(require_typescript(), 1);
|
|
169721
169905
|
|
|
169722
169906
|
// ../jsx/src/relocate.ts
|
|
169723
|
-
var
|
|
169907
|
+
var import_typescript15 = __toESM(require_typescript(), 1);
|
|
169724
169908
|
|
|
169725
169909
|
// ../jsx/src/lowering-registry.ts
|
|
169726
169910
|
var plugins = [];
|
|
@@ -169899,10 +170083,10 @@ function formatDateLocalNames(metadata) {
|
|
|
169899
170083
|
}
|
|
169900
170084
|
|
|
169901
170085
|
// ../jsx/src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
169902
|
-
var
|
|
170086
|
+
var import_typescript16 = __toESM(require_typescript(), 1);
|
|
169903
170087
|
|
|
169904
170088
|
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
169905
|
-
var
|
|
170089
|
+
var import_typescript17 = __toESM(require_typescript(), 1);
|
|
169906
170090
|
var NO_PREAMBLE = {
|
|
169907
170091
|
lazySafe: true,
|
|
169908
170092
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -169952,7 +170136,7 @@ var INERT_BINDING_GLOBALS = new Set([
|
|
|
169952
170136
|
]);
|
|
169953
170137
|
|
|
169954
170138
|
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
169955
|
-
var
|
|
170139
|
+
var import_typescript18 = __toESM(require_typescript(), 1);
|
|
169956
170140
|
|
|
169957
170141
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/event-delegation.ts
|
|
169958
170142
|
var NON_BUBBLING_EVENTS = new Set([
|
|
@@ -169967,7 +170151,7 @@ var NON_BUBBLING_EVENTS = new Set([
|
|
|
169967
170151
|
]);
|
|
169968
170152
|
|
|
169969
170153
|
// ../jsx/src/ir-to-client-js/rewrite-props-object.ts
|
|
169970
|
-
var
|
|
170154
|
+
var import_typescript19 = __toESM(require_typescript(), 1);
|
|
169971
170155
|
|
|
169972
170156
|
// ../jsx/src/ir-to-client-js/source-map.ts
|
|
169973
170157
|
var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -170058,20 +170242,20 @@ class SourceMapGenerator {
|
|
|
170058
170242
|
}
|
|
170059
170243
|
|
|
170060
170244
|
// ../jsx/src/preprocess-inline-jsx-callbacks.ts
|
|
170061
|
-
var
|
|
170245
|
+
var import_typescript20 = __toESM(require_typescript(), 1);
|
|
170062
170246
|
|
|
170063
170247
|
// ../jsx/src/ssr-defaults.ts
|
|
170064
|
-
var
|
|
170248
|
+
var import_typescript21 = __toESM(require_typescript(), 1);
|
|
170065
170249
|
var UNRESOLVED = Symbol("unresolved");
|
|
170066
170250
|
var NO_RETURN = Symbol("no-return");
|
|
170067
170251
|
|
|
170068
170252
|
// ../jsx/src/augment-inherited-props.ts
|
|
170069
|
-
var
|
|
170253
|
+
var import_typescript22 = __toESM(require_typescript(), 1);
|
|
170070
170254
|
|
|
170071
170255
|
// ../jsx/src/rich-type-refusal.ts
|
|
170072
170256
|
var EMPTY_BINDINGS2 = new Map;
|
|
170073
170257
|
// ../jsx/src/shared-program.ts
|
|
170074
|
-
var
|
|
170258
|
+
var import_typescript24 = __toESM(require_typescript(), 1);
|
|
170075
170259
|
// ../jsx/src/adapters/interface.ts
|
|
170076
170260
|
class BaseAdapter {
|
|
170077
170261
|
renderChildren(children) {
|
|
@@ -170147,7 +170331,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170147
170331
|
}
|
|
170148
170332
|
const rawInitialValue = preserveTypes ? signal.typedInitialValue ?? signal.initialValue : signal.initialValue;
|
|
170149
170333
|
const initialValue = rawInitialValue.trim().startsWith("{") ? `(${rawInitialValue})` : rawInitialValue;
|
|
170150
|
-
const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive";
|
|
170334
|
+
const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive" && signal.type.raw !== "object";
|
|
170151
170335
|
if (needsTypeAssertion) {
|
|
170152
170336
|
lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`);
|
|
170153
170337
|
} else {
|
|
@@ -170166,12 +170350,16 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170166
170350
|
const computation = preserveTypes ? memo.typedComputation ?? memo.computation : memo.computation;
|
|
170167
170351
|
lines.push(` const ${memo.name} = ${computation}`);
|
|
170168
170352
|
}
|
|
170353
|
+
const moduleScopeNames = this.moduleScopeDeclarationNames(ir);
|
|
170169
170354
|
for (const constant of ir.metadata.localConstants) {
|
|
170170
170355
|
if (constant.isExported)
|
|
170171
170356
|
continue;
|
|
170357
|
+
if (moduleScopeNames.has(constant.name))
|
|
170358
|
+
continue;
|
|
170172
170359
|
const keyword = constant.declarationKind ?? "const";
|
|
170173
170360
|
if (!constant.value) {
|
|
170174
|
-
|
|
170361
|
+
const typeAnnotation = preserveTypes && (constant.typeAnnotation ?? constant.type) ? `: ${constant.typeAnnotation ?? constant.type?.raw}` : "";
|
|
170362
|
+
lines.push(` ${keyword} ${constant.name}${typeAnnotation}`);
|
|
170175
170363
|
continue;
|
|
170176
170364
|
}
|
|
170177
170365
|
const value = constant.value.trim();
|
|
@@ -170180,9 +170368,12 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170180
170368
|
if (!reachable.has(constant.name))
|
|
170181
170369
|
continue;
|
|
170182
170370
|
const constValue = preserveTypes ? constant.typedValue ?? constant.value : constant.value;
|
|
170183
|
-
|
|
170371
|
+
const letTypeAnnotation = preserveTypes && keyword === "let" && constant.typeAnnotation ? `: ${constant.typeAnnotation}` : "";
|
|
170372
|
+
lines.push(` ${keyword} ${constant.name}${letTypeAnnotation} = ${constValue}`);
|
|
170184
170373
|
}
|
|
170185
170374
|
for (const func of localFunctions) {
|
|
170375
|
+
if (moduleScopeNames.has(func.name))
|
|
170376
|
+
continue;
|
|
170186
170377
|
if (!reachable.has(func.name))
|
|
170187
170378
|
continue;
|
|
170188
170379
|
const params = preserveTypes && func.typedParams !== undefined ? func.typedParams : func.params.map(formatParamWithType).join(", ");
|
|
@@ -170192,6 +170383,127 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170192
170383
|
lines.push(` ${asyncKw}function ${func.name}(${params})${returnAnnotation} ${body}`);
|
|
170193
170384
|
}
|
|
170194
170385
|
return lines.join(`
|
|
170386
|
+
`);
|
|
170387
|
+
}
|
|
170388
|
+
moduleScopeNamesCache = new WeakMap;
|
|
170389
|
+
moduleScopeDeclarationNames(ir) {
|
|
170390
|
+
const cached = this.moduleScopeNamesCache.get(ir);
|
|
170391
|
+
if (cached)
|
|
170392
|
+
return cached;
|
|
170393
|
+
const componentScope = new Set;
|
|
170394
|
+
for (const sig of ir.metadata.signals) {
|
|
170395
|
+
if (sig.isModule)
|
|
170396
|
+
continue;
|
|
170397
|
+
componentScope.add(sig.getter);
|
|
170398
|
+
if (sig.setter)
|
|
170399
|
+
componentScope.add(sig.setter);
|
|
170400
|
+
}
|
|
170401
|
+
for (const memo of ir.metadata.memos) {
|
|
170402
|
+
if (!memo.isModule)
|
|
170403
|
+
componentScope.add(memo.name);
|
|
170404
|
+
}
|
|
170405
|
+
for (const p of ir.metadata.propsParams)
|
|
170406
|
+
componentScope.add(p.name);
|
|
170407
|
+
if (ir.metadata.propsObjectName)
|
|
170408
|
+
componentScope.add(ir.metadata.propsObjectName);
|
|
170409
|
+
if (ir.metadata.restPropsName)
|
|
170410
|
+
componentScope.add(ir.metadata.restPropsName);
|
|
170411
|
+
for (const c of ir.metadata.localConstants) {
|
|
170412
|
+
if (!c.isModule)
|
|
170413
|
+
componentScope.add(c.name);
|
|
170414
|
+
}
|
|
170415
|
+
for (const f of ir.metadata.localFunctions) {
|
|
170416
|
+
if (!f.isModule)
|
|
170417
|
+
componentScope.add(f.name);
|
|
170418
|
+
}
|
|
170419
|
+
const exported = new Set;
|
|
170420
|
+
const candidates = new Map;
|
|
170421
|
+
for (const c of ir.metadata.localConstants) {
|
|
170422
|
+
if (!c.isModule)
|
|
170423
|
+
continue;
|
|
170424
|
+
if (c.isJsx || c.isJsxFunction)
|
|
170425
|
+
continue;
|
|
170426
|
+
if (c.isExported) {
|
|
170427
|
+
exported.add(c.name);
|
|
170428
|
+
continue;
|
|
170429
|
+
}
|
|
170430
|
+
candidates.set(c.name, c.freeIdentifiers ?? extractFreeIdentifiersFromText(c.value ?? ""));
|
|
170431
|
+
}
|
|
170432
|
+
for (const f of ir.metadata.localFunctions) {
|
|
170433
|
+
if (!f.isModule)
|
|
170434
|
+
continue;
|
|
170435
|
+
if (f.isJsxFunction || f.isMultiReturnJsxHelper)
|
|
170436
|
+
continue;
|
|
170437
|
+
if (f.isExported) {
|
|
170438
|
+
exported.add(f.name);
|
|
170439
|
+
continue;
|
|
170440
|
+
}
|
|
170441
|
+
const params = f.typedParams !== undefined ? f.typedParams : f.params.map(formatParamWithType).join(", ");
|
|
170442
|
+
candidates.set(f.name, extractFreeIdentifiersFromText(`(${params}) => ${f.body}`));
|
|
170443
|
+
}
|
|
170444
|
+
const referencesAny = (refs, names) => {
|
|
170445
|
+
for (const ref of refs) {
|
|
170446
|
+
if (names.has(ref))
|
|
170447
|
+
return true;
|
|
170448
|
+
}
|
|
170449
|
+
return false;
|
|
170450
|
+
};
|
|
170451
|
+
let changed = true;
|
|
170452
|
+
while (changed) {
|
|
170453
|
+
changed = false;
|
|
170454
|
+
for (const [name, refs] of candidates) {
|
|
170455
|
+
if (referencesAny(refs, componentScope)) {
|
|
170456
|
+
candidates.delete(name);
|
|
170457
|
+
componentScope.add(name);
|
|
170458
|
+
changed = true;
|
|
170459
|
+
}
|
|
170460
|
+
}
|
|
170461
|
+
}
|
|
170462
|
+
const result = new Set([...exported, ...candidates.keys()]);
|
|
170463
|
+
this.moduleScopeNamesCache.set(ir, result);
|
|
170464
|
+
return result;
|
|
170465
|
+
}
|
|
170466
|
+
generateModuleScopeDeclarations(ir) {
|
|
170467
|
+
const { preserveTypes } = this.jsxConfig;
|
|
170468
|
+
const moduleNames = this.moduleScopeDeclarationNames(ir);
|
|
170469
|
+
const entries = [];
|
|
170470
|
+
for (const t of ir.metadata.typeDefinitions) {
|
|
170471
|
+
entries.push({ line: t.loc.start.line, text: t.definition });
|
|
170472
|
+
}
|
|
170473
|
+
for (const c of ir.metadata.localConstants) {
|
|
170474
|
+
if (!c.isModule || !moduleNames.has(c.name))
|
|
170475
|
+
continue;
|
|
170476
|
+
const keyword = c.declarationKind ?? "const";
|
|
170477
|
+
const exportKw = c.isExported ? "export " : "";
|
|
170478
|
+
if (!c.value) {
|
|
170479
|
+
const typeAnnotation = preserveTypes && (c.typeAnnotation ?? c.type) ? `: ${c.typeAnnotation ?? c.type?.raw}` : "";
|
|
170480
|
+
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${typeAnnotation}` });
|
|
170481
|
+
continue;
|
|
170482
|
+
}
|
|
170483
|
+
const trimmed = c.value.trim();
|
|
170484
|
+
if (/^new WeakMap\b/.test(trimmed))
|
|
170485
|
+
continue;
|
|
170486
|
+
if (c.isExported && /^createContext\b/.test(trimmed))
|
|
170487
|
+
continue;
|
|
170488
|
+
const value = preserveTypes ? c.typedValue ?? c.value : c.value;
|
|
170489
|
+
const letTypeAnnotation = preserveTypes && keyword === "let" && c.typeAnnotation ? `: ${c.typeAnnotation}` : "";
|
|
170490
|
+
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${letTypeAnnotation} = ${value}` });
|
|
170491
|
+
}
|
|
170492
|
+
for (const f of ir.metadata.localFunctions) {
|
|
170493
|
+
if (!f.isModule || !moduleNames.has(f.name))
|
|
170494
|
+
continue;
|
|
170495
|
+
const params = preserveTypes && f.typedParams !== undefined ? f.typedParams : f.params.map(formatParamWithType).join(", ");
|
|
170496
|
+
const returnAnnotation = preserveTypes && f.typedReturnType ? `: ${f.typedReturnType}` : "";
|
|
170497
|
+
const body = preserveTypes ? f.typedBody ?? f.body : f.body;
|
|
170498
|
+
const asyncKw = f.isAsync ? "async " : "";
|
|
170499
|
+
const exportKw = f.isExported ? "export " : "";
|
|
170500
|
+
entries.push({
|
|
170501
|
+
line: f.loc.start.line,
|
|
170502
|
+
text: `${exportKw}${asyncKw}function ${f.name}(${params})${returnAnnotation} ${body}`
|
|
170503
|
+
});
|
|
170504
|
+
}
|
|
170505
|
+
entries.sort((a, b) => a.line - b.line);
|
|
170506
|
+
return entries.map((e) => e.text).join(`
|
|
170195
170507
|
`);
|
|
170196
170508
|
}
|
|
170197
170509
|
renderNodeRaw(node) {
|
|
@@ -170203,6 +170515,15 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170203
170515
|
}
|
|
170204
170516
|
return this.renderNode(node);
|
|
170205
170517
|
}
|
|
170518
|
+
renderTemplatePartsAsJs(parts) {
|
|
170519
|
+
return templatePartsToJsExpr(parts, { typed: this.jsxConfig.preserveTypes });
|
|
170520
|
+
}
|
|
170521
|
+
expressionValueToJs(value) {
|
|
170522
|
+
if (this.jsxConfig.preserveTypes && value.parts && value.expr === templatePartsToJsExpr(value.parts)) {
|
|
170523
|
+
return this.renderTemplatePartsAsJs(value.parts);
|
|
170524
|
+
}
|
|
170525
|
+
return value.expr;
|
|
170526
|
+
}
|
|
170206
170527
|
renderScopeMarker(instanceIdExpr) {
|
|
170207
170528
|
return `${BF_SCOPE}={${instanceIdExpr}}`;
|
|
170208
170529
|
}
|
|
@@ -170270,6 +170591,7 @@ class TestAdapter extends JsxAdapter {
|
|
|
170270
170591
|
generate(ir) {
|
|
170271
170592
|
this.componentName = ir.metadata.componentName;
|
|
170272
170593
|
const imports = this.generateImports(ir);
|
|
170594
|
+
const moduleConstants = this.generateModuleScopeDeclarations(ir);
|
|
170273
170595
|
const types = this.generateTypes(ir);
|
|
170274
170596
|
const component = this.generateComponent(ir);
|
|
170275
170597
|
const defaultExport = ir.metadata.hasDefaultExport ? `
|
|
@@ -170278,9 +170600,11 @@ export default ${this.componentName}` : "";
|
|
|
170278
170600
|
imports,
|
|
170279
170601
|
types: types || "",
|
|
170280
170602
|
component,
|
|
170281
|
-
defaultExport
|
|
170603
|
+
defaultExport,
|
|
170604
|
+
moduleConstants,
|
|
170605
|
+
moduleConstantsIncludeExports: true
|
|
170282
170606
|
};
|
|
170283
|
-
const template = [imports, types, component].filter(Boolean).join(`
|
|
170607
|
+
const template = [imports, moduleConstants, types, component].filter(Boolean).join(`
|
|
170284
170608
|
|
|
170285
170609
|
`) + defaultExport;
|
|
170286
170610
|
return {
|
|
@@ -170311,9 +170635,6 @@ export default ${this.componentName}` : "";
|
|
|
170311
170635
|
}
|
|
170312
170636
|
generateTypes(ir) {
|
|
170313
170637
|
const lines = [];
|
|
170314
|
-
for (const typeDef of ir.metadata.typeDefinitions) {
|
|
170315
|
-
lines.push(typeDef.definition);
|
|
170316
|
-
}
|
|
170317
170638
|
const propsTypeName = ir.metadata.propsType?.raw;
|
|
170318
170639
|
if (propsTypeName && !ir.metadata.propsObjectName) {
|
|
170319
170640
|
lines.push("");
|
|
@@ -170336,7 +170657,7 @@ export default ${this.componentName}` : "";
|
|
|
170336
170657
|
const bodyRefText = [jsxBody, signalInits, scopeIdLine].join(`
|
|
170337
170658
|
`);
|
|
170338
170659
|
const bfScopeAlias = /\b__bfScope\b/.test(bodyRefText) ? "__bfScope" : "__bfScope: _bfScope";
|
|
170339
|
-
const propsParams = ir.metadata.propsParams.map((p) => p
|
|
170660
|
+
const propsParams = ir.metadata.propsParams.map((p) => propsDestructureBinding(p)).join(", ");
|
|
170340
170661
|
const restPropsName = ir.metadata.restPropsName;
|
|
170341
170662
|
const hydrationProps = `__instanceId, ${bfScopeAlias}`;
|
|
170342
170663
|
const parts = [];
|
|
@@ -170483,13 +170804,7 @@ export default ${this.componentName}` : "";
|
|
|
170483
170804
|
}
|
|
170484
170805
|
flattenTemplate(value) {
|
|
170485
170806
|
const v = value;
|
|
170486
|
-
return
|
|
170487
|
-
if (p.type === "string")
|
|
170488
|
-
return p.value;
|
|
170489
|
-
if (p.type === "ternary")
|
|
170490
|
-
return `\${${p.condition} ? '${p.whenTrue}' : '${p.whenFalse}'}`;
|
|
170491
|
-
return `\${(${JSON.stringify(p.cases)})[${p.key}]}`;
|
|
170492
|
-
}).join("") + "`";
|
|
170807
|
+
return this.renderTemplatePartsAsJs(v.parts);
|
|
170493
170808
|
}
|
|
170494
170809
|
renderComponentProps(comp) {
|
|
170495
170810
|
const parts = [];
|
|
@@ -170610,11 +170925,11 @@ function registerBuiltinLoweringPlugins() {
|
|
|
170610
170925
|
registerLoweringPlugin(plugin);
|
|
170611
170926
|
}
|
|
170612
170927
|
// ../jsx/src/combine-client-js.ts
|
|
170613
|
-
var
|
|
170928
|
+
var import_typescript25 = __toESM(require_typescript(), 1);
|
|
170614
170929
|
// ../jsx/src/debug.ts
|
|
170615
|
-
var
|
|
170930
|
+
var import_typescript26 = __toESM(require_typescript(), 1);
|
|
170616
170931
|
// ../jsx/src/profiler.ts
|
|
170617
|
-
var
|
|
170932
|
+
var import_typescript27 = __toESM(require_typescript(), 1);
|
|
170618
170933
|
|
|
170619
170934
|
// ../jsx/src/index.ts
|
|
170620
170935
|
registerBuiltinLoweringPlugins();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/client",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.3",
|
|
4
4
|
"description": "BarefootJS client package: reactive primitives (SSR-safe) plus browser runtime under the `/runtime` subpath (compiler target)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"directory": "packages/client"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@barefootjs/shared": "0.31.
|
|
58
|
+
"@barefootjs/shared": "0.31.3"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@barefootjs/jsx": ">=0.2.0"
|