@barefootjs/client 0.31.1 → 0.31.2
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 +272 -37
- 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
|
|
@@ -169714,13 +169821,13 @@ var KEYWORDS_AND_GLOBALS = new Set([
|
|
|
169714
169821
|
]);
|
|
169715
169822
|
|
|
169716
169823
|
// ../jsx/src/ir-to-client-js/walk-prop-accesses.ts
|
|
169717
|
-
var
|
|
169824
|
+
var import_typescript13 = __toESM(require_typescript(), 1);
|
|
169718
169825
|
|
|
169719
169826
|
// ../jsx/src/value-references.ts
|
|
169720
|
-
var
|
|
169827
|
+
var import_typescript14 = __toESM(require_typescript(), 1);
|
|
169721
169828
|
|
|
169722
169829
|
// ../jsx/src/relocate.ts
|
|
169723
|
-
var
|
|
169830
|
+
var import_typescript15 = __toESM(require_typescript(), 1);
|
|
169724
169831
|
|
|
169725
169832
|
// ../jsx/src/lowering-registry.ts
|
|
169726
169833
|
var plugins = [];
|
|
@@ -169899,10 +170006,10 @@ function formatDateLocalNames(metadata) {
|
|
|
169899
170006
|
}
|
|
169900
170007
|
|
|
169901
170008
|
// ../jsx/src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
169902
|
-
var
|
|
170009
|
+
var import_typescript16 = __toESM(require_typescript(), 1);
|
|
169903
170010
|
|
|
169904
170011
|
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
169905
|
-
var
|
|
170012
|
+
var import_typescript17 = __toESM(require_typescript(), 1);
|
|
169906
170013
|
var NO_PREAMBLE = {
|
|
169907
170014
|
lazySafe: true,
|
|
169908
170015
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -169952,7 +170059,7 @@ var INERT_BINDING_GLOBALS = new Set([
|
|
|
169952
170059
|
]);
|
|
169953
170060
|
|
|
169954
170061
|
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
169955
|
-
var
|
|
170062
|
+
var import_typescript18 = __toESM(require_typescript(), 1);
|
|
169956
170063
|
|
|
169957
170064
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/event-delegation.ts
|
|
169958
170065
|
var NON_BUBBLING_EVENTS = new Set([
|
|
@@ -169967,7 +170074,7 @@ var NON_BUBBLING_EVENTS = new Set([
|
|
|
169967
170074
|
]);
|
|
169968
170075
|
|
|
169969
170076
|
// ../jsx/src/ir-to-client-js/rewrite-props-object.ts
|
|
169970
|
-
var
|
|
170077
|
+
var import_typescript19 = __toESM(require_typescript(), 1);
|
|
169971
170078
|
|
|
169972
170079
|
// ../jsx/src/ir-to-client-js/source-map.ts
|
|
169973
170080
|
var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -170058,20 +170165,20 @@ class SourceMapGenerator {
|
|
|
170058
170165
|
}
|
|
170059
170166
|
|
|
170060
170167
|
// ../jsx/src/preprocess-inline-jsx-callbacks.ts
|
|
170061
|
-
var
|
|
170168
|
+
var import_typescript20 = __toESM(require_typescript(), 1);
|
|
170062
170169
|
|
|
170063
170170
|
// ../jsx/src/ssr-defaults.ts
|
|
170064
|
-
var
|
|
170171
|
+
var import_typescript21 = __toESM(require_typescript(), 1);
|
|
170065
170172
|
var UNRESOLVED = Symbol("unresolved");
|
|
170066
170173
|
var NO_RETURN = Symbol("no-return");
|
|
170067
170174
|
|
|
170068
170175
|
// ../jsx/src/augment-inherited-props.ts
|
|
170069
|
-
var
|
|
170176
|
+
var import_typescript22 = __toESM(require_typescript(), 1);
|
|
170070
170177
|
|
|
170071
170178
|
// ../jsx/src/rich-type-refusal.ts
|
|
170072
170179
|
var EMPTY_BINDINGS2 = new Map;
|
|
170073
170180
|
// ../jsx/src/shared-program.ts
|
|
170074
|
-
var
|
|
170181
|
+
var import_typescript24 = __toESM(require_typescript(), 1);
|
|
170075
170182
|
// ../jsx/src/adapters/interface.ts
|
|
170076
170183
|
class BaseAdapter {
|
|
170077
170184
|
renderChildren(children) {
|
|
@@ -170147,7 +170254,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170147
170254
|
}
|
|
170148
170255
|
const rawInitialValue = preserveTypes ? signal.typedInitialValue ?? signal.initialValue : signal.initialValue;
|
|
170149
170256
|
const initialValue = rawInitialValue.trim().startsWith("{") ? `(${rawInitialValue})` : rawInitialValue;
|
|
170150
|
-
const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive";
|
|
170257
|
+
const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive" && signal.type.raw !== "object";
|
|
170151
170258
|
if (needsTypeAssertion) {
|
|
170152
170259
|
lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`);
|
|
170153
170260
|
} else {
|
|
@@ -170166,12 +170273,16 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170166
170273
|
const computation = preserveTypes ? memo.typedComputation ?? memo.computation : memo.computation;
|
|
170167
170274
|
lines.push(` const ${memo.name} = ${computation}`);
|
|
170168
170275
|
}
|
|
170276
|
+
const moduleScopeNames = this.moduleScopeDeclarationNames(ir);
|
|
170169
170277
|
for (const constant of ir.metadata.localConstants) {
|
|
170170
170278
|
if (constant.isExported)
|
|
170171
170279
|
continue;
|
|
170280
|
+
if (moduleScopeNames.has(constant.name))
|
|
170281
|
+
continue;
|
|
170172
170282
|
const keyword = constant.declarationKind ?? "const";
|
|
170173
170283
|
if (!constant.value) {
|
|
170174
|
-
|
|
170284
|
+
const typeAnnotation = preserveTypes && constant.type ? `: ${constant.type.raw}` : "";
|
|
170285
|
+
lines.push(` ${keyword} ${constant.name}${typeAnnotation}`);
|
|
170175
170286
|
continue;
|
|
170176
170287
|
}
|
|
170177
170288
|
const value = constant.value.trim();
|
|
@@ -170183,6 +170294,8 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170183
170294
|
lines.push(` ${keyword} ${constant.name} = ${constValue}`);
|
|
170184
170295
|
}
|
|
170185
170296
|
for (const func of localFunctions) {
|
|
170297
|
+
if (moduleScopeNames.has(func.name))
|
|
170298
|
+
continue;
|
|
170186
170299
|
if (!reachable.has(func.name))
|
|
170187
170300
|
continue;
|
|
170188
170301
|
const params = preserveTypes && func.typedParams !== undefined ? func.typedParams : func.params.map(formatParamWithType).join(", ");
|
|
@@ -170192,6 +170305,125 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170192
170305
|
lines.push(` ${asyncKw}function ${func.name}(${params})${returnAnnotation} ${body}`);
|
|
170193
170306
|
}
|
|
170194
170307
|
return lines.join(`
|
|
170308
|
+
`);
|
|
170309
|
+
}
|
|
170310
|
+
moduleScopeNamesCache = new WeakMap;
|
|
170311
|
+
moduleScopeDeclarationNames(ir) {
|
|
170312
|
+
const cached = this.moduleScopeNamesCache.get(ir);
|
|
170313
|
+
if (cached)
|
|
170314
|
+
return cached;
|
|
170315
|
+
const componentScope = new Set;
|
|
170316
|
+
for (const sig of ir.metadata.signals) {
|
|
170317
|
+
if (sig.isModule)
|
|
170318
|
+
continue;
|
|
170319
|
+
componentScope.add(sig.getter);
|
|
170320
|
+
if (sig.setter)
|
|
170321
|
+
componentScope.add(sig.setter);
|
|
170322
|
+
}
|
|
170323
|
+
for (const memo of ir.metadata.memos) {
|
|
170324
|
+
if (!memo.isModule)
|
|
170325
|
+
componentScope.add(memo.name);
|
|
170326
|
+
}
|
|
170327
|
+
for (const p of ir.metadata.propsParams)
|
|
170328
|
+
componentScope.add(p.name);
|
|
170329
|
+
if (ir.metadata.propsObjectName)
|
|
170330
|
+
componentScope.add(ir.metadata.propsObjectName);
|
|
170331
|
+
if (ir.metadata.restPropsName)
|
|
170332
|
+
componentScope.add(ir.metadata.restPropsName);
|
|
170333
|
+
for (const c of ir.metadata.localConstants) {
|
|
170334
|
+
if (!c.isModule)
|
|
170335
|
+
componentScope.add(c.name);
|
|
170336
|
+
}
|
|
170337
|
+
for (const f of ir.metadata.localFunctions) {
|
|
170338
|
+
if (!f.isModule)
|
|
170339
|
+
componentScope.add(f.name);
|
|
170340
|
+
}
|
|
170341
|
+
const exported = new Set;
|
|
170342
|
+
const candidates = new Map;
|
|
170343
|
+
for (const c of ir.metadata.localConstants) {
|
|
170344
|
+
if (!c.isModule)
|
|
170345
|
+
continue;
|
|
170346
|
+
if (c.isJsx || c.isJsxFunction)
|
|
170347
|
+
continue;
|
|
170348
|
+
if (c.isExported) {
|
|
170349
|
+
exported.add(c.name);
|
|
170350
|
+
continue;
|
|
170351
|
+
}
|
|
170352
|
+
candidates.set(c.name, c.freeIdentifiers ?? extractFreeIdentifiersFromText(c.value ?? ""));
|
|
170353
|
+
}
|
|
170354
|
+
for (const f of ir.metadata.localFunctions) {
|
|
170355
|
+
if (!f.isModule)
|
|
170356
|
+
continue;
|
|
170357
|
+
if (f.isJsxFunction || f.isMultiReturnJsxHelper)
|
|
170358
|
+
continue;
|
|
170359
|
+
if (f.isExported) {
|
|
170360
|
+
exported.add(f.name);
|
|
170361
|
+
continue;
|
|
170362
|
+
}
|
|
170363
|
+
const params = f.typedParams !== undefined ? f.typedParams : f.params.map(formatParamWithType).join(", ");
|
|
170364
|
+
candidates.set(f.name, extractFreeIdentifiersFromText(`(${params}) => ${f.body}`));
|
|
170365
|
+
}
|
|
170366
|
+
const referencesAny = (refs, names) => {
|
|
170367
|
+
for (const ref of refs) {
|
|
170368
|
+
if (names.has(ref))
|
|
170369
|
+
return true;
|
|
170370
|
+
}
|
|
170371
|
+
return false;
|
|
170372
|
+
};
|
|
170373
|
+
let changed = true;
|
|
170374
|
+
while (changed) {
|
|
170375
|
+
changed = false;
|
|
170376
|
+
for (const [name, refs] of candidates) {
|
|
170377
|
+
if (referencesAny(refs, componentScope)) {
|
|
170378
|
+
candidates.delete(name);
|
|
170379
|
+
componentScope.add(name);
|
|
170380
|
+
changed = true;
|
|
170381
|
+
}
|
|
170382
|
+
}
|
|
170383
|
+
}
|
|
170384
|
+
const result = new Set([...exported, ...candidates.keys()]);
|
|
170385
|
+
this.moduleScopeNamesCache.set(ir, result);
|
|
170386
|
+
return result;
|
|
170387
|
+
}
|
|
170388
|
+
generateModuleScopeDeclarations(ir) {
|
|
170389
|
+
const { preserveTypes } = this.jsxConfig;
|
|
170390
|
+
const moduleNames = this.moduleScopeDeclarationNames(ir);
|
|
170391
|
+
const entries = [];
|
|
170392
|
+
for (const t of ir.metadata.typeDefinitions) {
|
|
170393
|
+
entries.push({ line: t.loc.start.line, text: t.definition });
|
|
170394
|
+
}
|
|
170395
|
+
for (const c of ir.metadata.localConstants) {
|
|
170396
|
+
if (!c.isModule || !moduleNames.has(c.name))
|
|
170397
|
+
continue;
|
|
170398
|
+
const keyword = c.declarationKind ?? "const";
|
|
170399
|
+
const exportKw = c.isExported ? "export " : "";
|
|
170400
|
+
if (!c.value) {
|
|
170401
|
+
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}` });
|
|
170402
|
+
continue;
|
|
170403
|
+
}
|
|
170404
|
+
const trimmed = c.value.trim();
|
|
170405
|
+
if (/^new WeakMap\b/.test(trimmed))
|
|
170406
|
+
continue;
|
|
170407
|
+
if (c.isExported && /^createContext\b/.test(trimmed))
|
|
170408
|
+
continue;
|
|
170409
|
+
const value = preserveTypes ? c.typedValue ?? c.value : c.value;
|
|
170410
|
+
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name} = ${value}` });
|
|
170411
|
+
}
|
|
170412
|
+
for (const f of ir.metadata.localFunctions) {
|
|
170413
|
+
if (!f.isModule || !moduleNames.has(f.name))
|
|
170414
|
+
continue;
|
|
170415
|
+
const params = preserveTypes && f.typedParams !== undefined ? f.typedParams : f.params.map(formatParamWithType).join(", ");
|
|
170416
|
+
const returnAnnotation = preserveTypes && f.typedReturnType ? `: ${f.typedReturnType}` : "";
|
|
170417
|
+
const body = preserveTypes ? f.typedBody ?? f.body : f.body;
|
|
170418
|
+
const asyncKw = f.isAsync ? "async " : "";
|
|
170419
|
+
const exportKw = f.isExported ? "export " : "";
|
|
170420
|
+
entries.push({
|
|
170421
|
+
line: f.loc.start.line,
|
|
170422
|
+
text: `${exportKw}${asyncKw}function ${f.name}(${params})${returnAnnotation} ${body}`
|
|
170423
|
+
});
|
|
170424
|
+
}
|
|
170425
|
+
entries.sort((a, b) => a.line - b.line);
|
|
170426
|
+
return entries.map((e) => e.text).join(`
|
|
170195
170427
|
`);
|
|
170196
170428
|
}
|
|
170197
170429
|
renderNodeRaw(node) {
|
|
@@ -170203,6 +170435,15 @@ class JsxAdapter extends BaseAdapter {
|
|
|
170203
170435
|
}
|
|
170204
170436
|
return this.renderNode(node);
|
|
170205
170437
|
}
|
|
170438
|
+
renderTemplatePartsAsJs(parts) {
|
|
170439
|
+
return templatePartsToJsExpr(parts, { typed: this.jsxConfig.preserveTypes });
|
|
170440
|
+
}
|
|
170441
|
+
expressionValueToJs(value) {
|
|
170442
|
+
if (this.jsxConfig.preserveTypes && value.parts && value.expr === templatePartsToJsExpr(value.parts)) {
|
|
170443
|
+
return this.renderTemplatePartsAsJs(value.parts);
|
|
170444
|
+
}
|
|
170445
|
+
return value.expr;
|
|
170446
|
+
}
|
|
170206
170447
|
renderScopeMarker(instanceIdExpr) {
|
|
170207
170448
|
return `${BF_SCOPE}={${instanceIdExpr}}`;
|
|
170208
170449
|
}
|
|
@@ -170270,6 +170511,7 @@ class TestAdapter extends JsxAdapter {
|
|
|
170270
170511
|
generate(ir) {
|
|
170271
170512
|
this.componentName = ir.metadata.componentName;
|
|
170272
170513
|
const imports = this.generateImports(ir);
|
|
170514
|
+
const moduleConstants = this.generateModuleScopeDeclarations(ir);
|
|
170273
170515
|
const types = this.generateTypes(ir);
|
|
170274
170516
|
const component = this.generateComponent(ir);
|
|
170275
170517
|
const defaultExport = ir.metadata.hasDefaultExport ? `
|
|
@@ -170278,9 +170520,11 @@ export default ${this.componentName}` : "";
|
|
|
170278
170520
|
imports,
|
|
170279
170521
|
types: types || "",
|
|
170280
170522
|
component,
|
|
170281
|
-
defaultExport
|
|
170523
|
+
defaultExport,
|
|
170524
|
+
moduleConstants,
|
|
170525
|
+
moduleConstantsIncludeExports: true
|
|
170282
170526
|
};
|
|
170283
|
-
const template = [imports, types, component].filter(Boolean).join(`
|
|
170527
|
+
const template = [imports, moduleConstants, types, component].filter(Boolean).join(`
|
|
170284
170528
|
|
|
170285
170529
|
`) + defaultExport;
|
|
170286
170530
|
return {
|
|
@@ -170311,9 +170555,6 @@ export default ${this.componentName}` : "";
|
|
|
170311
170555
|
}
|
|
170312
170556
|
generateTypes(ir) {
|
|
170313
170557
|
const lines = [];
|
|
170314
|
-
for (const typeDef of ir.metadata.typeDefinitions) {
|
|
170315
|
-
lines.push(typeDef.definition);
|
|
170316
|
-
}
|
|
170317
170558
|
const propsTypeName = ir.metadata.propsType?.raw;
|
|
170318
170559
|
if (propsTypeName && !ir.metadata.propsObjectName) {
|
|
170319
170560
|
lines.push("");
|
|
@@ -170336,7 +170577,7 @@ export default ${this.componentName}` : "";
|
|
|
170336
170577
|
const bodyRefText = [jsxBody, signalInits, scopeIdLine].join(`
|
|
170337
170578
|
`);
|
|
170338
170579
|
const bfScopeAlias = /\b__bfScope\b/.test(bodyRefText) ? "__bfScope" : "__bfScope: _bfScope";
|
|
170339
|
-
const propsParams = ir.metadata.propsParams.map((p) => p
|
|
170580
|
+
const propsParams = ir.metadata.propsParams.map((p) => propsDestructureBinding(p)).join(", ");
|
|
170340
170581
|
const restPropsName = ir.metadata.restPropsName;
|
|
170341
170582
|
const hydrationProps = `__instanceId, ${bfScopeAlias}`;
|
|
170342
170583
|
const parts = [];
|
|
@@ -170483,13 +170724,7 @@ export default ${this.componentName}` : "";
|
|
|
170483
170724
|
}
|
|
170484
170725
|
flattenTemplate(value) {
|
|
170485
170726
|
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("") + "`";
|
|
170727
|
+
return this.renderTemplatePartsAsJs(v.parts);
|
|
170493
170728
|
}
|
|
170494
170729
|
renderComponentProps(comp) {
|
|
170495
170730
|
const parts = [];
|
|
@@ -170610,11 +170845,11 @@ function registerBuiltinLoweringPlugins() {
|
|
|
170610
170845
|
registerLoweringPlugin(plugin);
|
|
170611
170846
|
}
|
|
170612
170847
|
// ../jsx/src/combine-client-js.ts
|
|
170613
|
-
var
|
|
170848
|
+
var import_typescript25 = __toESM(require_typescript(), 1);
|
|
170614
170849
|
// ../jsx/src/debug.ts
|
|
170615
|
-
var
|
|
170850
|
+
var import_typescript26 = __toESM(require_typescript(), 1);
|
|
170616
170851
|
// ../jsx/src/profiler.ts
|
|
170617
|
-
var
|
|
170852
|
+
var import_typescript27 = __toESM(require_typescript(), 1);
|
|
170618
170853
|
|
|
170619
170854
|
// ../jsx/src/index.ts
|
|
170620
170855
|
registerBuiltinLoweringPlugins();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/client",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.2",
|
|
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.2"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@barefootjs/jsx": ">=0.2.0"
|