@barefootjs/test 0.10.1 → 0.12.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/index.js +480 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -187396,6 +187396,11 @@ function applyReplacement(slice, re, replacement) {
|
|
|
187396
187396
|
re.lastIndex = 0;
|
|
187397
187397
|
return typeof replacement === "string" ? slice.replace(re, replacement) : slice.replace(re, replacement);
|
|
187398
187398
|
}
|
|
187399
|
+
|
|
187400
|
+
// ../shared/src/markers.ts
|
|
187401
|
+
var BF_SCOPE = "bf-s";
|
|
187402
|
+
var BF_SLOT = "bf";
|
|
187403
|
+
var BF_COND = "bf-c";
|
|
187399
187404
|
// ../shared/src/dom-prop.ts
|
|
187400
187405
|
var BOOLEAN_ATTRS = new Set([
|
|
187401
187406
|
"checked",
|
|
@@ -190479,6 +190484,9 @@ var LOWERED_ARRAY_METHODS = new Set([
|
|
|
190479
190484
|
"lastIndexOf",
|
|
190480
190485
|
"concat"
|
|
190481
190486
|
]);
|
|
190487
|
+
function cssKebabCase(name) {
|
|
190488
|
+
return name.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase()).replace(/^ms-/, "-ms-");
|
|
190489
|
+
}
|
|
190482
190490
|
function parseExpression(expr) {
|
|
190483
190491
|
const trimmed = expr.trim();
|
|
190484
190492
|
if (!trimmed) {
|
|
@@ -194205,7 +194213,7 @@ function tryStaticStyleObjectToCss(expr) {
|
|
|
194205
194213
|
return null;
|
|
194206
194214
|
if (!import_typescript11.default.isStringLiteral(prop.initializer))
|
|
194207
194215
|
return null;
|
|
194208
|
-
const key = prop.name.text
|
|
194216
|
+
const key = cssKebabCase(prop.name.text);
|
|
194209
194217
|
parts.push(`${key}:${prop.initializer.text}`);
|
|
194210
194218
|
}
|
|
194211
194219
|
return parts.join(";");
|
|
@@ -195131,6 +195139,38 @@ class SourceMapGenerator {
|
|
|
195131
195139
|
}
|
|
195132
195140
|
}
|
|
195133
195141
|
|
|
195142
|
+
// ../jsx/src/module-exports.ts
|
|
195143
|
+
function formatParamWithType(p) {
|
|
195144
|
+
const rest = p.isRest ? "..." : "";
|
|
195145
|
+
const optional = p.optional ? "?" : "";
|
|
195146
|
+
const typeAnnotation = p.type?.raw && p.type.raw !== "unknown" ? `: ${p.type.raw}` : "";
|
|
195147
|
+
const defaultPart = p.defaultValue !== undefined ? ` = ${p.defaultValue}` : "";
|
|
195148
|
+
return `${rest}${p.name}${optional}${typeAnnotation}${defaultPart}`;
|
|
195149
|
+
}
|
|
195150
|
+
function findReachableNames(primaryRefs, declarations) {
|
|
195151
|
+
const allNames = new Set(declarations.map((d) => d.name));
|
|
195152
|
+
const bodyMap = new Map(declarations.map((d) => [d.name, d.body]));
|
|
195153
|
+
const reachable = new Set;
|
|
195154
|
+
const queue = [];
|
|
195155
|
+
for (const name of allNames) {
|
|
195156
|
+
if (new RegExp(`\\b${name}\\b`).test(primaryRefs)) {
|
|
195157
|
+
reachable.add(name);
|
|
195158
|
+
queue.push(name);
|
|
195159
|
+
}
|
|
195160
|
+
}
|
|
195161
|
+
while (queue.length > 0) {
|
|
195162
|
+
const current = queue.shift();
|
|
195163
|
+
const body = bodyMap.get(current) || "";
|
|
195164
|
+
for (const name of allNames) {
|
|
195165
|
+
if (!reachable.has(name) && new RegExp(`\\b${name}\\b`).test(body)) {
|
|
195166
|
+
reachable.add(name);
|
|
195167
|
+
queue.push(name);
|
|
195168
|
+
}
|
|
195169
|
+
}
|
|
195170
|
+
}
|
|
195171
|
+
return reachable;
|
|
195172
|
+
}
|
|
195173
|
+
|
|
195134
195174
|
// ../jsx/src/preprocess-inline-jsx-callbacks.ts
|
|
195135
195175
|
var import_typescript15 = __toESM(require_typescript(), 1);
|
|
195136
195176
|
|
|
@@ -195140,14 +195180,450 @@ var UNRESOLVED = Symbol("unresolved");
|
|
|
195140
195180
|
// ../jsx/src/shared-program.ts
|
|
195141
195181
|
init_path();
|
|
195142
195182
|
var import_typescript17 = __toESM(require_typescript(), 1);
|
|
195183
|
+
// ../jsx/src/adapters/interface.ts
|
|
195184
|
+
class BaseAdapter {
|
|
195185
|
+
renderChildren(children) {
|
|
195186
|
+
return children.map((child) => this.renderNode(child)).join("");
|
|
195187
|
+
}
|
|
195188
|
+
renderAsync(node) {
|
|
195189
|
+
return this.renderNode(node.fallback) + this.renderChildren(node.children);
|
|
195190
|
+
}
|
|
195191
|
+
}
|
|
195192
|
+
// ../jsx/src/adapters/jsx-adapter.ts
|
|
195193
|
+
class JsxAdapter extends BaseAdapter {
|
|
195194
|
+
componentName = "";
|
|
195195
|
+
formatImportSpecifiers(specifiers) {
|
|
195196
|
+
const defaultSpec = specifiers.find((s) => s.isDefault);
|
|
195197
|
+
const namespaceSpec = specifiers.find((s) => s.isNamespace);
|
|
195198
|
+
const namedSpecs = specifiers.filter((s) => !s.isDefault && !s.isNamespace);
|
|
195199
|
+
const parts = [];
|
|
195200
|
+
if (defaultSpec) {
|
|
195201
|
+
parts.push(defaultSpec.alias || defaultSpec.name);
|
|
195202
|
+
}
|
|
195203
|
+
if (namespaceSpec) {
|
|
195204
|
+
parts.push(`* as ${namespaceSpec.name}`);
|
|
195205
|
+
}
|
|
195206
|
+
if (namedSpecs.length > 0) {
|
|
195207
|
+
const named = namedSpecs.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ");
|
|
195208
|
+
parts.push(`{ ${named} }`);
|
|
195209
|
+
}
|
|
195210
|
+
return parts.join(", ");
|
|
195211
|
+
}
|
|
195212
|
+
generateSignalInitializers(ir, jsxBody) {
|
|
195213
|
+
const lines = [];
|
|
195214
|
+
const { preserveTypes } = this.jsxConfig;
|
|
195215
|
+
const primaryRefs = [jsxBody];
|
|
195216
|
+
for (const signal of ir.metadata.signals) {
|
|
195217
|
+
if (signal.isModule)
|
|
195218
|
+
continue;
|
|
195219
|
+
primaryRefs.push(signal.initialValue);
|
|
195220
|
+
}
|
|
195221
|
+
for (const memo of ir.metadata.memos) {
|
|
195222
|
+
if (memo.isModule)
|
|
195223
|
+
continue;
|
|
195224
|
+
primaryRefs.push(memo.computation);
|
|
195225
|
+
}
|
|
195226
|
+
const primaryRefText = primaryRefs.join(`
|
|
195227
|
+
`);
|
|
195228
|
+
const localFunctions = ir.metadata.localFunctions.filter((f) => !f.isExported);
|
|
195229
|
+
const localConstants = ir.metadata.localConstants.filter((c) => !c.isExported && c.value);
|
|
195230
|
+
const declarations = [
|
|
195231
|
+
...localFunctions.map((f) => ({ name: f.name, body: f.body })),
|
|
195232
|
+
...localConstants.map((c) => ({ name: c.name, body: c.value }))
|
|
195233
|
+
];
|
|
195234
|
+
const reachable = findReachableNames(primaryRefText, declarations);
|
|
195235
|
+
const reachableBodies = [...reachable].map((name) => {
|
|
195236
|
+
const func = localFunctions.find((f) => f.name === name);
|
|
195237
|
+
if (func)
|
|
195238
|
+
return func.body;
|
|
195239
|
+
const constant = localConstants.find((c) => c.name === name);
|
|
195240
|
+
return constant?.value ?? "";
|
|
195241
|
+
}).join(`
|
|
195242
|
+
`);
|
|
195243
|
+
const setterRefText = primaryRefText + `
|
|
195244
|
+
` + reachableBodies;
|
|
195245
|
+
for (const signal of ir.metadata.signals) {
|
|
195246
|
+
if (signal.isModule)
|
|
195247
|
+
continue;
|
|
195248
|
+
const rawInitialValue = preserveTypes ? signal.typedInitialValue ?? signal.initialValue : signal.initialValue;
|
|
195249
|
+
const initialValue = rawInitialValue.trim().startsWith("{") ? `(${rawInitialValue})` : rawInitialValue;
|
|
195250
|
+
const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive";
|
|
195251
|
+
if (needsTypeAssertion) {
|
|
195252
|
+
lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`);
|
|
195253
|
+
} else {
|
|
195254
|
+
lines.push(` const ${signal.getter} = () => ${initialValue}`);
|
|
195255
|
+
}
|
|
195256
|
+
if (signal.setter) {
|
|
195257
|
+
const setterUsed = new RegExp(`\\b${signal.setter}\\b`).test(setterRefText);
|
|
195258
|
+
if (setterUsed) {
|
|
195259
|
+
lines.push(` const ${signal.setter} = (..._args: any[]) => {}`);
|
|
195260
|
+
}
|
|
195261
|
+
}
|
|
195262
|
+
}
|
|
195263
|
+
for (const memo of ir.metadata.memos) {
|
|
195264
|
+
if (memo.isModule)
|
|
195265
|
+
continue;
|
|
195266
|
+
const computation = preserveTypes ? memo.typedComputation ?? memo.computation : memo.computation;
|
|
195267
|
+
lines.push(` const ${memo.name} = ${computation}`);
|
|
195268
|
+
}
|
|
195269
|
+
for (const constant of ir.metadata.localConstants) {
|
|
195270
|
+
if (constant.isExported)
|
|
195271
|
+
continue;
|
|
195272
|
+
const keyword = constant.declarationKind ?? "const";
|
|
195273
|
+
if (!constant.value) {
|
|
195274
|
+
lines.push(` ${keyword} ${constant.name}`);
|
|
195275
|
+
continue;
|
|
195276
|
+
}
|
|
195277
|
+
const value = constant.value.trim();
|
|
195278
|
+
if (/^createContext\b/.test(value) || /^new WeakMap\b/.test(value))
|
|
195279
|
+
continue;
|
|
195280
|
+
if (!reachable.has(constant.name))
|
|
195281
|
+
continue;
|
|
195282
|
+
const constValue = preserveTypes ? constant.typedValue ?? constant.value : constant.value;
|
|
195283
|
+
lines.push(` ${keyword} ${constant.name} = ${constValue}`);
|
|
195284
|
+
}
|
|
195285
|
+
for (const func of localFunctions) {
|
|
195286
|
+
if (!reachable.has(func.name))
|
|
195287
|
+
continue;
|
|
195288
|
+
const params = preserveTypes && func.typedParams !== undefined ? func.typedParams : func.params.map(formatParamWithType).join(", ");
|
|
195289
|
+
const returnAnnotation = preserveTypes && func.typedReturnType ? `: ${func.typedReturnType}` : "";
|
|
195290
|
+
const body = preserveTypes ? func.typedBody ?? func.body : func.body;
|
|
195291
|
+
const asyncKw = func.isAsync ? "async " : "";
|
|
195292
|
+
lines.push(` ${asyncKw}function ${func.name}(${params})${returnAnnotation} ${body}`);
|
|
195293
|
+
}
|
|
195294
|
+
return lines.join(`
|
|
195295
|
+
`);
|
|
195296
|
+
}
|
|
195297
|
+
renderNodeRaw(node) {
|
|
195298
|
+
if (node.type === "expression") {
|
|
195299
|
+
if (node.expr === "null" || node.expr === "undefined") {
|
|
195300
|
+
return "null";
|
|
195301
|
+
}
|
|
195302
|
+
return node.expr;
|
|
195303
|
+
}
|
|
195304
|
+
return this.renderNode(node);
|
|
195305
|
+
}
|
|
195306
|
+
renderScopeMarker(instanceIdExpr) {
|
|
195307
|
+
return `${BF_SCOPE}={${instanceIdExpr}}`;
|
|
195308
|
+
}
|
|
195309
|
+
renderSlotMarker(slotId) {
|
|
195310
|
+
return `${BF_SLOT}="${slotId}"`;
|
|
195311
|
+
}
|
|
195312
|
+
renderCondMarker(condId) {
|
|
195313
|
+
return `${BF_COND}="${condId}"`;
|
|
195314
|
+
}
|
|
195315
|
+
}
|
|
195316
|
+
|
|
195143
195317
|
// ../jsx/src/adapters/template-imports.ts
|
|
195144
195318
|
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
195145
195319
|
"@barefootjs/client",
|
|
195146
195320
|
"@barefootjs/client/runtime"
|
|
195147
195321
|
]);
|
|
195322
|
+
function rewriteImportsForTemplate(imports, shimSource, rewriteRelative) {
|
|
195323
|
+
const remap = (imp) => {
|
|
195324
|
+
if (!rewriteRelative || !imp.source.startsWith("."))
|
|
195325
|
+
return imp;
|
|
195326
|
+
const next = rewriteRelative(imp.source);
|
|
195327
|
+
return next === imp.source ? imp : { ...imp, source: next };
|
|
195328
|
+
};
|
|
195329
|
+
if (!shimSource) {
|
|
195330
|
+
return imports.filter((imp) => !CLIENT_PACKAGE_SOURCES.has(imp.source)).map(remap);
|
|
195331
|
+
}
|
|
195332
|
+
const merged = new Map;
|
|
195333
|
+
const result = [];
|
|
195334
|
+
for (const imp of imports) {
|
|
195335
|
+
if (!CLIENT_PACKAGE_SOURCES.has(imp.source)) {
|
|
195336
|
+
result.push(remap(imp));
|
|
195337
|
+
continue;
|
|
195338
|
+
}
|
|
195339
|
+
const existing = merged.get(shimSource);
|
|
195340
|
+
if (existing) {
|
|
195341
|
+
const seen = new Set(existing.specifiers.map(specKey));
|
|
195342
|
+
for (const spec of imp.specifiers) {
|
|
195343
|
+
if (!seen.has(specKey(spec))) {
|
|
195344
|
+
existing.specifiers.push(spec);
|
|
195345
|
+
seen.add(specKey(spec));
|
|
195346
|
+
}
|
|
195347
|
+
}
|
|
195348
|
+
existing.isTypeOnly = existing.isTypeOnly && imp.isTypeOnly;
|
|
195349
|
+
} else {
|
|
195350
|
+
const rewritten = {
|
|
195351
|
+
...imp,
|
|
195352
|
+
source: shimSource,
|
|
195353
|
+
specifiers: imp.specifiers.map((s) => ({ ...s }))
|
|
195354
|
+
};
|
|
195355
|
+
merged.set(shimSource, rewritten);
|
|
195356
|
+
result.push(rewritten);
|
|
195357
|
+
}
|
|
195358
|
+
}
|
|
195359
|
+
return result;
|
|
195360
|
+
}
|
|
195361
|
+
function specKey(s) {
|
|
195362
|
+
return `${s.isDefault ? "d" : ""}${s.isNamespace ? "n" : ""}:${s.name}:${s.alias ?? ""}`;
|
|
195363
|
+
}
|
|
195364
|
+
|
|
195365
|
+
// ../jsx/src/adapters/test-adapter.ts
|
|
195366
|
+
class TestAdapter extends JsxAdapter {
|
|
195367
|
+
name = "test";
|
|
195368
|
+
extension = ".test.tsx";
|
|
195369
|
+
jsxConfig = { preserveTypes: false };
|
|
195370
|
+
generate(ir) {
|
|
195371
|
+
this.componentName = ir.metadata.componentName;
|
|
195372
|
+
const imports = this.generateImports(ir);
|
|
195373
|
+
const types2 = this.generateTypes(ir);
|
|
195374
|
+
const component = this.generateComponent(ir);
|
|
195375
|
+
const defaultExport = ir.metadata.hasDefaultExport ? `
|
|
195376
|
+
export default ${this.componentName}` : "";
|
|
195377
|
+
const sections = {
|
|
195378
|
+
imports,
|
|
195379
|
+
types: types2 || "",
|
|
195380
|
+
component,
|
|
195381
|
+
defaultExport
|
|
195382
|
+
};
|
|
195383
|
+
const template = [imports, types2, component].filter(Boolean).join(`
|
|
195384
|
+
|
|
195385
|
+
`) + defaultExport;
|
|
195386
|
+
return {
|
|
195387
|
+
template,
|
|
195388
|
+
sections,
|
|
195389
|
+
types: types2 || undefined,
|
|
195390
|
+
extension: this.extension
|
|
195391
|
+
};
|
|
195392
|
+
}
|
|
195393
|
+
generateImports(ir) {
|
|
195394
|
+
const lines = [];
|
|
195395
|
+
const templateImports = rewriteImportsForTemplate(ir.metadata.templateImports, undefined);
|
|
195396
|
+
for (const imp of templateImports) {
|
|
195397
|
+
if (imp.specifiers.length === 0) {
|
|
195398
|
+
if (!imp.isTypeOnly) {
|
|
195399
|
+
lines.push(`import '${imp.source}'`);
|
|
195400
|
+
}
|
|
195401
|
+
continue;
|
|
195402
|
+
}
|
|
195403
|
+
if (imp.isTypeOnly) {
|
|
195404
|
+
lines.push(`import type ${this.formatImportSpecifiers(imp.specifiers)} from '${imp.source}'`);
|
|
195405
|
+
} else {
|
|
195406
|
+
lines.push(`import ${this.formatImportSpecifiers(imp.specifiers)} from '${imp.source}'`);
|
|
195407
|
+
}
|
|
195408
|
+
}
|
|
195409
|
+
return lines.join(`
|
|
195410
|
+
`);
|
|
195411
|
+
}
|
|
195412
|
+
generateTypes(ir) {
|
|
195413
|
+
const lines = [];
|
|
195414
|
+
for (const typeDef of ir.metadata.typeDefinitions) {
|
|
195415
|
+
lines.push(typeDef.definition);
|
|
195416
|
+
}
|
|
195417
|
+
const propsTypeName = ir.metadata.propsType?.raw;
|
|
195418
|
+
if (propsTypeName && !ir.metadata.propsObjectName) {
|
|
195419
|
+
lines.push("");
|
|
195420
|
+
lines.push(`type ${this.componentName}PropsWithHydration = ${propsTypeName} & {`);
|
|
195421
|
+
lines.push(" __instanceId?: string");
|
|
195422
|
+
lines.push(" __bfScope?: string");
|
|
195423
|
+
lines.push("}");
|
|
195424
|
+
}
|
|
195425
|
+
return lines.length > 0 ? lines.join(`
|
|
195426
|
+
`) : null;
|
|
195427
|
+
}
|
|
195428
|
+
generateComponent(ir) {
|
|
195429
|
+
const name = ir.metadata.componentName;
|
|
195430
|
+
const propsTypeName = ir.metadata.propsType?.raw;
|
|
195431
|
+
const hasClientInteractivity = ir.metadata.signals.length > 0 || ir.metadata.memos.length > 0;
|
|
195432
|
+
const typeAnnotation = propsTypeName ? `: ${name}PropsWithHydration` : ": { __instanceId?: string; __bfScope?: string }";
|
|
195433
|
+
const jsxBody = this.renderNode(ir.root);
|
|
195434
|
+
const signalInits = this.generateSignalInitializers(ir, jsxBody);
|
|
195435
|
+
const scopeIdLine = hasClientInteractivity ? `(/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId` : `__bfScope || __instanceId`;
|
|
195436
|
+
const bodyRefText = [jsxBody, signalInits, scopeIdLine].join(`
|
|
195437
|
+
`);
|
|
195438
|
+
const bfScopeAlias = /\b__bfScope\b/.test(bodyRefText) ? "__bfScope" : "__bfScope: _bfScope";
|
|
195439
|
+
const propsParams = ir.metadata.propsParams.map((p) => p.defaultValue ? `${p.name} = ${p.defaultValue}` : p.name).join(", ");
|
|
195440
|
+
const restPropsName = ir.metadata.restPropsName;
|
|
195441
|
+
const hydrationProps = `__instanceId, ${bfScopeAlias}`;
|
|
195442
|
+
const parts = [];
|
|
195443
|
+
if (propsParams) {
|
|
195444
|
+
parts.push(propsParams);
|
|
195445
|
+
}
|
|
195446
|
+
parts.push(hydrationProps);
|
|
195447
|
+
if (restPropsName) {
|
|
195448
|
+
parts.push(`...${restPropsName}`);
|
|
195449
|
+
}
|
|
195450
|
+
const fullPropsDestructure = `{ ${parts.join(", ")} }`;
|
|
195451
|
+
const hasRequiredProps = ir.metadata.propsParams.some((p) => !p.optional && p.defaultValue === undefined && !p.isRest);
|
|
195452
|
+
const propsTypeExpr = typeAnnotation.replace(/^:\s*/, "");
|
|
195453
|
+
const noArgDefault = hasRequiredProps ? "" : ` = {} as ${propsTypeExpr}`;
|
|
195454
|
+
const lines = [];
|
|
195455
|
+
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
195456
|
+
lines.push(`${exportPrefix}function ${name}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
195457
|
+
if (hasClientInteractivity) {
|
|
195458
|
+
lines.push(` const __scopeId = (/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
195459
|
+
} else {
|
|
195460
|
+
lines.push(` const __scopeId = __bfScope || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
195461
|
+
}
|
|
195462
|
+
if (signalInits) {
|
|
195463
|
+
lines.push(signalInits);
|
|
195464
|
+
}
|
|
195465
|
+
lines.push("");
|
|
195466
|
+
lines.push(` return (`);
|
|
195467
|
+
lines.push(` ${jsxBody}`);
|
|
195468
|
+
lines.push(` )`);
|
|
195469
|
+
lines.push(`}`);
|
|
195470
|
+
return lines.join(`
|
|
195471
|
+
`);
|
|
195472
|
+
}
|
|
195473
|
+
renderNode(node) {
|
|
195474
|
+
switch (node.type) {
|
|
195475
|
+
case "element":
|
|
195476
|
+
return this.renderElement(node);
|
|
195477
|
+
case "text":
|
|
195478
|
+
return node.value;
|
|
195479
|
+
case "expression":
|
|
195480
|
+
return this.renderExpression(node);
|
|
195481
|
+
case "conditional":
|
|
195482
|
+
return this.renderConditional(node);
|
|
195483
|
+
case "loop":
|
|
195484
|
+
return this.renderLoop(node);
|
|
195485
|
+
case "component":
|
|
195486
|
+
return this.renderComponent(node);
|
|
195487
|
+
case "fragment":
|
|
195488
|
+
return this.renderFragment(node);
|
|
195489
|
+
case "slot":
|
|
195490
|
+
return "{children}";
|
|
195491
|
+
default:
|
|
195492
|
+
return "";
|
|
195493
|
+
}
|
|
195494
|
+
}
|
|
195495
|
+
renderElement(element) {
|
|
195496
|
+
const tag = element.tag;
|
|
195497
|
+
const attrs = this.renderAttributes(element);
|
|
195498
|
+
const children = this.renderChildren(element.children);
|
|
195499
|
+
let hydrationAttrs = "";
|
|
195500
|
+
if (element.needsScope) {
|
|
195501
|
+
hydrationAttrs += " bf-s={__scopeId}";
|
|
195502
|
+
}
|
|
195503
|
+
if (element.slotId) {
|
|
195504
|
+
hydrationAttrs += ` bf="${element.slotId}"`;
|
|
195505
|
+
}
|
|
195506
|
+
if (children) {
|
|
195507
|
+
return `<${tag}${attrs}${hydrationAttrs}>${children}</${tag}>`;
|
|
195508
|
+
} else {
|
|
195509
|
+
return `<${tag}${attrs}${hydrationAttrs} />`;
|
|
195510
|
+
}
|
|
195511
|
+
}
|
|
195512
|
+
renderExpression(expr) {
|
|
195513
|
+
if (expr.expr === "null" || expr.expr === "undefined") {
|
|
195514
|
+
return "null";
|
|
195515
|
+
}
|
|
195516
|
+
if (expr.reactive && expr.slotId) {
|
|
195517
|
+
return `{bfText("${expr.slotId}")}{${expr.expr}}{bfTextEnd()}`;
|
|
195518
|
+
}
|
|
195519
|
+
return `{${expr.expr}}`;
|
|
195520
|
+
}
|
|
195521
|
+
renderConditional(cond) {
|
|
195522
|
+
const whenTrue = this.renderNodeRaw(cond.whenTrue);
|
|
195523
|
+
let whenFalse = this.renderNodeRaw(cond.whenFalse);
|
|
195524
|
+
if (!whenFalse || whenFalse === "" || whenFalse === "null") {
|
|
195525
|
+
whenFalse = "null";
|
|
195526
|
+
}
|
|
195527
|
+
return `{${cond.condition} ? ${whenTrue} : ${whenFalse}}`;
|
|
195528
|
+
}
|
|
195529
|
+
renderLoop(loop) {
|
|
195530
|
+
const indexParam = loop.index ? `, ${loop.index}` : "";
|
|
195531
|
+
const children = this.renderChildren(loop.children);
|
|
195532
|
+
const safeChildren = children.startsWith("{") ? `<>${children}</>` : children;
|
|
195533
|
+
return `{${loop.array}.map((${loop.param}${indexParam}) => ${safeChildren})}`;
|
|
195534
|
+
}
|
|
195535
|
+
renderComponent(comp) {
|
|
195536
|
+
const props = this.renderComponentProps(comp);
|
|
195537
|
+
const children = this.renderChildren(comp.children);
|
|
195538
|
+
const scopeAttr = " __bfScope={__scopeId}";
|
|
195539
|
+
if (children) {
|
|
195540
|
+
return `<${comp.name}${props}${scopeAttr}>${children}</${comp.name}>`;
|
|
195541
|
+
} else {
|
|
195542
|
+
return `<${comp.name}${props}${scopeAttr} />`;
|
|
195543
|
+
}
|
|
195544
|
+
}
|
|
195545
|
+
renderFragment(fragment) {
|
|
195546
|
+
const children = this.renderChildren(fragment.children);
|
|
195547
|
+
return `<>${children}</>`;
|
|
195548
|
+
}
|
|
195549
|
+
renderAttributes(element) {
|
|
195550
|
+
const parts = [];
|
|
195551
|
+
for (const attr of element.attrs) {
|
|
195552
|
+
const attrName = attr.name === "class" ? "className" : attr.name;
|
|
195553
|
+
switch (attr.value.kind) {
|
|
195554
|
+
case "spread":
|
|
195555
|
+
parts.push(`{...${attr.value.expr}}`);
|
|
195556
|
+
break;
|
|
195557
|
+
case "boolean-attr":
|
|
195558
|
+
parts.push(attrName);
|
|
195559
|
+
break;
|
|
195560
|
+
case "expression":
|
|
195561
|
+
parts.push(`${attrName}={${attr.value.expr}}`);
|
|
195562
|
+
break;
|
|
195563
|
+
case "template":
|
|
195564
|
+
parts.push(`${attrName}={${this.flattenTemplate(attr.value)}}`);
|
|
195565
|
+
break;
|
|
195566
|
+
case "literal":
|
|
195567
|
+
parts.push(`${attrName}="${attr.value.value}"`);
|
|
195568
|
+
break;
|
|
195569
|
+
case "boolean-shorthand":
|
|
195570
|
+
case "jsx-children":
|
|
195571
|
+
break;
|
|
195572
|
+
}
|
|
195573
|
+
}
|
|
195574
|
+
for (const event of element.events) {
|
|
195575
|
+
const handlerName = event.originalAttr ?? `on${event.name.charAt(0).toUpperCase()}${event.name.slice(1)}`;
|
|
195576
|
+
parts.push(`${handlerName}={() => {}}`);
|
|
195577
|
+
}
|
|
195578
|
+
return parts.length > 0 ? " " + parts.join(" ") : "";
|
|
195579
|
+
}
|
|
195580
|
+
flattenTemplate(value) {
|
|
195581
|
+
const v = value;
|
|
195582
|
+
return "`" + v.parts.map((p) => {
|
|
195583
|
+
if (p.type === "string")
|
|
195584
|
+
return p.value;
|
|
195585
|
+
if (p.type === "ternary")
|
|
195586
|
+
return `\${${p.condition} ? '${p.whenTrue}' : '${p.whenFalse}'}`;
|
|
195587
|
+
return `\${(${JSON.stringify(p.cases)})[${p.key}]}`;
|
|
195588
|
+
}).join("") + "`";
|
|
195589
|
+
}
|
|
195590
|
+
renderComponentProps(comp) {
|
|
195591
|
+
const parts = [];
|
|
195592
|
+
for (const prop of comp.props) {
|
|
195593
|
+
switch (prop.value.kind) {
|
|
195594
|
+
case "jsx-children": {
|
|
195595
|
+
const rendered = prop.value.children.map((c) => this.renderNode(c)).join("");
|
|
195596
|
+
parts.push(`${prop.name}={<>${rendered}</>}`);
|
|
195597
|
+
break;
|
|
195598
|
+
}
|
|
195599
|
+
case "spread":
|
|
195600
|
+
parts.push(`{...${prop.value.expr}}`);
|
|
195601
|
+
break;
|
|
195602
|
+
case "expression":
|
|
195603
|
+
parts.push(`${prop.name}={${prop.value.expr}}`);
|
|
195604
|
+
break;
|
|
195605
|
+
case "template":
|
|
195606
|
+
parts.push(`${prop.name}={${this.flattenTemplate(prop.value)}}`);
|
|
195607
|
+
break;
|
|
195608
|
+
case "boolean-shorthand":
|
|
195609
|
+
parts.push(prop.name);
|
|
195610
|
+
break;
|
|
195611
|
+
case "literal":
|
|
195612
|
+
parts.push(`${prop.name}="${prop.value.value}"`);
|
|
195613
|
+
break;
|
|
195614
|
+
case "boolean-attr":
|
|
195615
|
+
parts.push(prop.name);
|
|
195616
|
+
break;
|
|
195617
|
+
}
|
|
195618
|
+
}
|
|
195619
|
+
return parts.length > 0 ? " " + parts.join(" ") : "";
|
|
195620
|
+
}
|
|
195621
|
+
}
|
|
195622
|
+
var testAdapter = new TestAdapter;
|
|
195148
195623
|
// ../jsx/src/combine-client-js.ts
|
|
195149
195624
|
var import_typescript18 = __toESM(require_typescript(), 1);
|
|
195150
195625
|
// ../jsx/src/debug.ts
|
|
195626
|
+
var import_typescript19 = __toESM(require_typescript(), 1);
|
|
195151
195627
|
function escapeForIdBoundary(name) {
|
|
195152
195628
|
return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
195153
195629
|
}
|
|
@@ -195238,8 +195714,10 @@ function resolveSetters(handler, setterToSignal, fnSetters) {
|
|
|
195238
195714
|
}
|
|
195239
195715
|
return refs;
|
|
195240
195716
|
}
|
|
195717
|
+
// ../jsx/src/profiler.ts
|
|
195718
|
+
var import_typescript20 = __toESM(require_typescript(), 1);
|
|
195241
195719
|
// ../jsx/src/augment-inherited-props.ts
|
|
195242
|
-
var
|
|
195720
|
+
var import_typescript21 = __toESM(require_typescript(), 1);
|
|
195243
195721
|
// src/test-node.ts
|
|
195244
195722
|
class TestNode {
|
|
195245
195723
|
tag;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Test utilities for BarefootJS - IR-based component testing without a browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"directory": "packages/test"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@barefootjs/jsx": "0.
|
|
42
|
+
"@barefootjs/jsx": "0.12.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.0.0"
|