@barefootjs/test 0.29.0 → 0.30.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 +242 -29
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -189720,6 +189720,30 @@ function typeNodeToTypeInfo(typeNode, sourceFile, rawOf) {
|
|
|
189720
189720
|
if (import_typescript7.default.isArrayTypeNode(typeNode)) {
|
|
189721
189721
|
return { kind: "array", raw, elementType: recurse(typeNode.elementType) };
|
|
189722
189722
|
}
|
|
189723
|
+
if (import_typescript7.default.isLiteralTypeNode(typeNode)) {
|
|
189724
|
+
const lit = typeNode.literal;
|
|
189725
|
+
if (import_typescript7.default.isStringLiteral(lit) || import_typescript7.default.isNoSubstitutionTemplateLiteral(lit)) {
|
|
189726
|
+
return { kind: "primitive", raw, primitive: "string", literalValue: lit.text };
|
|
189727
|
+
}
|
|
189728
|
+
if (import_typescript7.default.isNumericLiteral(lit)) {
|
|
189729
|
+
return { kind: "primitive", raw, primitive: "number", literalValue: lit.text };
|
|
189730
|
+
}
|
|
189731
|
+
if (import_typescript7.default.isPrefixUnaryExpression(lit) && lit.operator === import_typescript7.default.SyntaxKind.MinusToken && import_typescript7.default.isNumericLiteral(lit.operand)) {
|
|
189732
|
+
return { kind: "primitive", raw, primitive: "number", literalValue: `-${lit.operand.text}` };
|
|
189733
|
+
}
|
|
189734
|
+
if (lit.kind === import_typescript7.default.SyntaxKind.TrueKeyword || lit.kind === import_typescript7.default.SyntaxKind.FalseKeyword) {
|
|
189735
|
+
return {
|
|
189736
|
+
kind: "primitive",
|
|
189737
|
+
raw,
|
|
189738
|
+
primitive: "boolean",
|
|
189739
|
+
literalValue: lit.kind === import_typescript7.default.SyntaxKind.TrueKeyword ? "true" : "false"
|
|
189740
|
+
};
|
|
189741
|
+
}
|
|
189742
|
+
if (lit.kind === import_typescript7.default.SyntaxKind.NullKeyword) {
|
|
189743
|
+
return { kind: "primitive", raw, primitive: "null" };
|
|
189744
|
+
}
|
|
189745
|
+
return { kind: "unknown", raw };
|
|
189746
|
+
}
|
|
189723
189747
|
if (import_typescript7.default.isUnionTypeNode(typeNode)) {
|
|
189724
189748
|
return { kind: "union", raw, unionTypes: typeNode.types.map(recurse) };
|
|
189725
189749
|
}
|
|
@@ -189909,9 +189933,7 @@ function baseTypeName(raw) {
|
|
|
189909
189933
|
return (idx === -1 ? raw : raw.slice(0, idx)).trim();
|
|
189910
189934
|
}
|
|
189911
189935
|
function isNullishArm(t) {
|
|
189912
|
-
|
|
189913
|
-
return true;
|
|
189914
|
-
return t.kind === "unknown" && (t.raw === "null" || t.raw === "undefined");
|
|
189936
|
+
return t.kind === "primitive" && (t.primitive === "null" || t.primitive === "undefined");
|
|
189915
189937
|
}
|
|
189916
189938
|
function stripUnion(type2) {
|
|
189917
189939
|
if (!type2 || type2.kind !== "union" || !type2.unionTypes)
|
|
@@ -190631,14 +190653,17 @@ function collectSignal(node, ctx) {
|
|
|
190631
190653
|
const pattern = node.name;
|
|
190632
190654
|
const callExpr = node.initializer;
|
|
190633
190655
|
const elements = pattern.elements;
|
|
190634
|
-
|
|
190656
|
+
const getterElided = elements.length === 2 && import_typescript8.default.isOmittedExpression(elements[0]);
|
|
190657
|
+
if (elements.length < 1 || elements.length > 2 || !getterElided && (!import_typescript8.default.isBindingElement(elements[0]) || !import_typescript8.default.isIdentifier(elements[0].name))) {
|
|
190635
190658
|
return;
|
|
190636
190659
|
}
|
|
190637
190660
|
if (elements.length === 2 && (!import_typescript8.default.isBindingElement(elements[1]) || !import_typescript8.default.isIdentifier(elements[1].name))) {
|
|
190638
190661
|
return;
|
|
190639
190662
|
}
|
|
190640
|
-
const getter = elements[0].name.text;
|
|
190641
190663
|
const setter = elements.length === 2 && import_typescript8.default.isBindingElement(elements[1]) && import_typescript8.default.isIdentifier(elements[1].name) ? elements[1].name.text : null;
|
|
190664
|
+
if (getterElided && !setter)
|
|
190665
|
+
return;
|
|
190666
|
+
const getter = getterElided ? `__bfGet_${setter}` : elements[0].name.text;
|
|
190642
190667
|
const initialValue = callExpr.arguments[0] ? ctx.getJS(callExpr.arguments[0]) : "";
|
|
190643
190668
|
const typedInitialValue = callExpr.arguments[0] ? callExpr.arguments[0].getText(ctx.sourceFile) : undefined;
|
|
190644
190669
|
let type2 = { kind: "unknown", raw: "unknown" };
|
|
@@ -190659,6 +190684,7 @@ function collectSignal(node, ctx) {
|
|
|
190659
190684
|
ctx.signals.push({
|
|
190660
190685
|
getter,
|
|
190661
190686
|
setter,
|
|
190687
|
+
getterElided: getterElided || undefined,
|
|
190662
190688
|
initialValue,
|
|
190663
190689
|
typedInitialValue: typedInitialValue !== initialValue ? typedInitialValue : undefined,
|
|
190664
190690
|
templateInitialValue,
|
|
@@ -190849,9 +190875,17 @@ function collectMemo(node, ctx) {
|
|
|
190849
190875
|
const blockBody = arrowNode && import_typescript8.default.isArrowFunction(arrowNode) && import_typescript8.default.isBlock(arrowNode.body) ? arrowNode.body : undefined;
|
|
190850
190876
|
const parsedBlock = blockBody ? parseBlockBodyTolerant(blockBody, ctx.sourceFile, (node2) => ctx.getJS(node2)) : undefined;
|
|
190851
190877
|
const parsedBlockComplete = parsedBlock && blockBody ? parsedBlock.length === blockBody.statements.length : undefined;
|
|
190878
|
+
let templateComputation;
|
|
190879
|
+
if (!ctx.propsObjectName && callExpr.arguments[0]) {
|
|
190880
|
+
const propNames = new Set(ctx.propsParams.map((p) => p.name));
|
|
190881
|
+
if (propNames.size > 0) {
|
|
190882
|
+
templateComputation = rewriteBarePropRefs(computation, callExpr.arguments[0], propNames);
|
|
190883
|
+
}
|
|
190884
|
+
}
|
|
190852
190885
|
ctx.memos.push({
|
|
190853
190886
|
name,
|
|
190854
190887
|
computation,
|
|
190888
|
+
templateComputation,
|
|
190855
190889
|
parsedBlock,
|
|
190856
190890
|
parsedBlockComplete,
|
|
190857
190891
|
typedComputation: typedComputation !== computation ? typedComputation : undefined,
|
|
@@ -193925,8 +193959,10 @@ function deriveFormat(locale, probeOptions) {
|
|
|
193925
193959
|
return { pattern, names };
|
|
193926
193960
|
}
|
|
193927
193961
|
function unionMemberLiteral(member) {
|
|
193928
|
-
|
|
193929
|
-
|
|
193962
|
+
if (member.kind === "primitive" && member.primitive === "string" && member.literalValue !== undefined) {
|
|
193963
|
+
return member.literalValue;
|
|
193964
|
+
}
|
|
193965
|
+
return null;
|
|
193930
193966
|
}
|
|
193931
193967
|
function resolveLocaleUnionMembers(locale, metadata) {
|
|
193932
193968
|
let sourcePropName = null;
|
|
@@ -194531,6 +194567,13 @@ function jsxToIR(analyzer) {
|
|
|
194531
194567
|
function buildIRRoot(analyzer) {
|
|
194532
194568
|
if (analyzer.conditionalReturns.length > 0) {
|
|
194533
194569
|
const ctx2 = createTransformContext(analyzer);
|
|
194570
|
+
const allReactiveNoLocals = analyzer.jsxReturn != null && analyzer.conditionalReturns.every((cr) => cr.scopeVariables.length === 0 && exprCallsReactiveGetters(cr.condition, ctx2));
|
|
194571
|
+
if (allReactiveNoLocals) {
|
|
194572
|
+
const chain = buildIfStatementChain(analyzer, ctx2, { asConditional: true });
|
|
194573
|
+
if (!chain)
|
|
194574
|
+
return null;
|
|
194575
|
+
return chain.type === "conditional" ? wrapInScopeElement(chain) : chain;
|
|
194576
|
+
}
|
|
194534
194577
|
return buildIfStatementChain(analyzer, ctx2);
|
|
194535
194578
|
}
|
|
194536
194579
|
if (!analyzer.jsxReturn)
|
|
@@ -194686,11 +194729,52 @@ function transformJsxElement(node, ctx) {
|
|
|
194686
194729
|
}
|
|
194687
194730
|
return transformHtmlElement(node, ctx, tagName);
|
|
194688
194731
|
}
|
|
194732
|
+
function lowerFormControlValueSsr(tagName, attrs, children) {
|
|
194733
|
+
if (tagName !== "textarea" && tagName !== "select")
|
|
194734
|
+
return;
|
|
194735
|
+
const valueAttr = attrs.find((a) => a.name === "value");
|
|
194736
|
+
if (!valueAttr || valueAttr.clientOnly || valueAttr.value.kind !== "expression")
|
|
194737
|
+
return;
|
|
194738
|
+
const { expr, templateExpr } = valueAttr.value;
|
|
194739
|
+
valueAttr.clientOnly = true;
|
|
194740
|
+
if (tagName === "textarea") {
|
|
194741
|
+
if (children.length > 0)
|
|
194742
|
+
return;
|
|
194743
|
+
children.push({
|
|
194744
|
+
type: "expression",
|
|
194745
|
+
expr,
|
|
194746
|
+
templateExpr: `escapeText(${templateExpr ?? expr})`,
|
|
194747
|
+
typeInfo: null,
|
|
194748
|
+
reactive: false,
|
|
194749
|
+
slotId: null,
|
|
194750
|
+
loc: valueAttr.loc,
|
|
194751
|
+
origin: { phase: "ssr", scope: "template", effect: "pure" }
|
|
194752
|
+
});
|
|
194753
|
+
return;
|
|
194754
|
+
}
|
|
194755
|
+
const selectedFor = (optValue) => AttrValueOf.expression(`(${expr}) === ${JSON.stringify(optValue)}`, templateExpr !== undefined ? { templateExpr: `(${templateExpr}) === ${JSON.stringify(optValue)}` } : undefined);
|
|
194756
|
+
const distribute = (nodes) => {
|
|
194757
|
+
for (const n of nodes) {
|
|
194758
|
+
if (n.type === "element" && n.tag === "option") {
|
|
194759
|
+
if (n.attrs.some((a) => a.name === "selected"))
|
|
194760
|
+
continue;
|
|
194761
|
+
const optValue = n.attrs.find((a) => a.name === "value");
|
|
194762
|
+
if (!optValue || optValue.value.kind !== "literal")
|
|
194763
|
+
continue;
|
|
194764
|
+
n.attrs.push({ name: "selected", value: selectedFor(optValue.value.value), loc: n.loc });
|
|
194765
|
+
} else if (n.type === "fragment" || n.type === "element" && n.tag === "optgroup") {
|
|
194766
|
+
distribute(n.children);
|
|
194767
|
+
}
|
|
194768
|
+
}
|
|
194769
|
+
};
|
|
194770
|
+
distribute(children);
|
|
194771
|
+
}
|
|
194689
194772
|
function transformHtmlElement(node, ctx, tagName) {
|
|
194690
194773
|
const { attrs, events, ref } = processAttributes(node.openingElement.attributes, ctx);
|
|
194691
194774
|
const needsScope = ctx.isRoot;
|
|
194692
194775
|
ctx.isRoot = false;
|
|
194693
194776
|
const children = transformChildren(node.children, ctx);
|
|
194777
|
+
lowerFormControlValueSsr(tagName, attrs, children);
|
|
194694
194778
|
const needsSlot = events.length > 0 || hasDynamicContent(children) || hasReactiveAttributes(attrs, ctx) || ref !== null;
|
|
194695
194779
|
const slotId = needsSlot ? generateSlotId(ctx) : null;
|
|
194696
194780
|
if (slotId) {
|
|
@@ -194722,6 +194806,8 @@ function transformSelfClosingElement(node, ctx) {
|
|
|
194722
194806
|
return transformSelfClosingComponent(node, ctx, resolved ?? tagName);
|
|
194723
194807
|
}
|
|
194724
194808
|
const { attrs, events, ref } = processAttributes(node.attributes, ctx);
|
|
194809
|
+
const selfClosingChildren = [];
|
|
194810
|
+
lowerFormControlValueSsr(tagName, attrs, selfClosingChildren);
|
|
194725
194811
|
const needsSlot = events.length > 0 || hasReactiveAttributes(attrs, ctx) || ref !== null;
|
|
194726
194812
|
const slotId = needsSlot ? generateSlotId(ctx) : null;
|
|
194727
194813
|
const needsScope = ctx.isRoot;
|
|
@@ -194732,7 +194818,7 @@ function transformSelfClosingElement(node, ctx) {
|
|
|
194732
194818
|
attrs,
|
|
194733
194819
|
events,
|
|
194734
194820
|
ref,
|
|
194735
|
-
children:
|
|
194821
|
+
children: selfClosingChildren,
|
|
194736
194822
|
slotId,
|
|
194737
194823
|
needsScope,
|
|
194738
194824
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath)
|
|
@@ -196115,6 +196201,15 @@ function branchHasNoElement(node) {
|
|
|
196115
196201
|
}
|
|
196116
196202
|
return true;
|
|
196117
196203
|
}
|
|
196204
|
+
function tagLoopItemRootComponents(nodes) {
|
|
196205
|
+
for (const node of nodes) {
|
|
196206
|
+
if (node.type === "component") {
|
|
196207
|
+
node.loopItemRoot = true;
|
|
196208
|
+
} else if (node.type === "conditional") {
|
|
196209
|
+
tagLoopItemRootComponents([node.whenTrue, node.whenFalse]);
|
|
196210
|
+
}
|
|
196211
|
+
}
|
|
196212
|
+
}
|
|
196118
196213
|
function loopBodyItemConditional(children) {
|
|
196119
196214
|
const real = children.filter((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
196120
196215
|
if (real.length !== 1)
|
|
@@ -196352,9 +196447,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
196352
196447
|
const pre = multiReturn.preamble ?? [];
|
|
196353
196448
|
if (pre.length > 0) {
|
|
196354
196449
|
preamble = preambleFromValueStatements(pre, ctx);
|
|
196355
|
-
if (!isClientOnly && !(ctx.analyzer.acceptsCallbackBody?.("map") ?? false)) {
|
|
196450
|
+
if (!preamble.declarations && !isClientOnly && !(ctx.analyzer.acceptsCallbackBody?.("map") ?? false)) {
|
|
196356
196451
|
ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, loc, {
|
|
196357
|
-
message: "A .map() callback body with a
|
|
196452
|
+
message: "A .map() callback body with a preamble before its branches cannot be " + "lowered to a template: the preamble is not a sequence of value " + "declarations, so this backend has no per-row local to carry into the " + "branches.",
|
|
196358
196453
|
suggestion: {
|
|
196359
196454
|
message: "Add /* @client */ to evaluate this expression on the client only"
|
|
196360
196455
|
}
|
|
@@ -196421,6 +196516,14 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
196421
196516
|
}
|
|
196422
196517
|
if (valueStmts.length > 0) {
|
|
196423
196518
|
preamble = preambleFromValueStatements(valueStmts, ctx);
|
|
196519
|
+
if (!preamble.declarations && !isClientOnly && !(ctx.analyzer.acceptsCallbackBody?.("map") ?? false)) {
|
|
196520
|
+
ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, getSourceLocation(body, ctx.sourceFile, ctx.filePath), {
|
|
196521
|
+
message: "A .map() callback preamble that is not a sequence of value " + "declarations cannot be lowered to a template: this backend can " + "declare a per-row local, but cannot run arbitrary statements per row.",
|
|
196522
|
+
suggestion: {
|
|
196523
|
+
message: "Add /* @client */ to evaluate this expression on the client only"
|
|
196524
|
+
}
|
|
196525
|
+
}));
|
|
196526
|
+
}
|
|
196424
196527
|
}
|
|
196425
196528
|
}
|
|
196426
196529
|
}
|
|
@@ -196506,6 +196609,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
196506
196609
|
}));
|
|
196507
196610
|
preamble = undefined;
|
|
196508
196611
|
}
|
|
196612
|
+
tagLoopItemRootComponents(children);
|
|
196509
196613
|
let childComponent;
|
|
196510
196614
|
if (children.length === 1 && children[0].type === "component") {
|
|
196511
196615
|
const comp = children[0];
|
|
@@ -196526,6 +196630,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
196526
196630
|
const isDirectPropArray = method !== "flatMap" && isArrayExprDirectPropRef(arrayExpr, ctx);
|
|
196527
196631
|
const isStaticArray = !isSignalOrMemoArray(array, ctx) && !isDirectPropArray && !hasCalls && !objectIteration;
|
|
196528
196632
|
const preambleRegions = preamble && !isStaticArray ? collectPreambleRegions(children, new Set(preamble.declaredNames), ctx) : undefined;
|
|
196633
|
+
if (preamble && !isStaticArray) {
|
|
196634
|
+
markPreambleAttrSlots(children, new Set(preamble.declaredNames), ctx);
|
|
196635
|
+
}
|
|
196529
196636
|
const nestedComponents = collectNestedComponents(children).filter((c) => c.name !== childComponent?.name);
|
|
196530
196637
|
return {
|
|
196531
196638
|
type: "loop",
|
|
@@ -196750,6 +196857,52 @@ function collectPreambleRegions(nodes, declared, ctx) {
|
|
|
196750
196857
|
visit2(nodes);
|
|
196751
196858
|
return regions;
|
|
196752
196859
|
}
|
|
196860
|
+
function markPreambleAttrSlots(nodes, declared, ctx) {
|
|
196861
|
+
const readsDeclared = (attr) => {
|
|
196862
|
+
if (attr.name === "key")
|
|
196863
|
+
return false;
|
|
196864
|
+
const value = attr.value;
|
|
196865
|
+
if (value.kind !== "expression" && value.kind !== "template")
|
|
196866
|
+
return false;
|
|
196867
|
+
const refs = attr.freeIdentifiers ?? extractFreeIdentifiersFromText(attrValueText(value));
|
|
196868
|
+
for (const r of refs)
|
|
196869
|
+
if (declared.has(r))
|
|
196870
|
+
return true;
|
|
196871
|
+
return false;
|
|
196872
|
+
};
|
|
196873
|
+
const visit2 = (list) => {
|
|
196874
|
+
for (const node of list) {
|
|
196875
|
+
switch (node.type) {
|
|
196876
|
+
case "element":
|
|
196877
|
+
if (!node.slotId && node.attrs.some(readsDeclared))
|
|
196878
|
+
node.slotId = generateSlotId(ctx);
|
|
196879
|
+
visit2(node.children);
|
|
196880
|
+
break;
|
|
196881
|
+
case "fragment":
|
|
196882
|
+
visit2(node.children);
|
|
196883
|
+
break;
|
|
196884
|
+
case "conditional":
|
|
196885
|
+
visit2([node.whenTrue, ...node.whenFalse ? [node.whenFalse] : []]);
|
|
196886
|
+
break;
|
|
196887
|
+
}
|
|
196888
|
+
}
|
|
196889
|
+
};
|
|
196890
|
+
visit2(nodes);
|
|
196891
|
+
}
|
|
196892
|
+
function attrValueText(value) {
|
|
196893
|
+
if (value.kind === "expression")
|
|
196894
|
+
return value.expr;
|
|
196895
|
+
if (value.kind !== "template")
|
|
196896
|
+
return "";
|
|
196897
|
+
const out = [];
|
|
196898
|
+
for (const p of value.parts) {
|
|
196899
|
+
if (p.type === "ternary")
|
|
196900
|
+
out.push(p.condition, p.whenTrue, p.whenFalse);
|
|
196901
|
+
else if (p.type === "lookup")
|
|
196902
|
+
out.push(p.key);
|
|
196903
|
+
}
|
|
196904
|
+
return out.join(" ");
|
|
196905
|
+
}
|
|
196753
196906
|
function collectBindingNames(name, out) {
|
|
196754
196907
|
if (import_typescript11.default.isIdentifier(name)) {
|
|
196755
196908
|
out.add(name.text);
|
|
@@ -196787,9 +196940,32 @@ function preambleFromValueStatements(statements, ctx) {
|
|
|
196787
196940
|
segments: trimPreambleSegments(segments),
|
|
196788
196941
|
ssrText: tsxSourceText(typedParts.join(" ")),
|
|
196789
196942
|
declaredNames: [...declared],
|
|
196790
|
-
builderNames: []
|
|
196943
|
+
builderNames: [],
|
|
196944
|
+
declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined
|
|
196791
196945
|
};
|
|
196792
196946
|
}
|
|
196947
|
+
function neutralPreambleDeclarations(statements, ctx) {
|
|
196948
|
+
const out = [];
|
|
196949
|
+
for (const stmt of statements) {
|
|
196950
|
+
if (!import_typescript11.default.isVariableStatement(stmt))
|
|
196951
|
+
return null;
|
|
196952
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
196953
|
+
if (!import_typescript11.default.isIdentifier(decl.name))
|
|
196954
|
+
return null;
|
|
196955
|
+
if (!decl.initializer)
|
|
196956
|
+
return null;
|
|
196957
|
+
const valueParsed = tsNodeToParsedExpr(decl.initializer);
|
|
196958
|
+
if (!isSupported(valueParsed).supported)
|
|
196959
|
+
return null;
|
|
196960
|
+
out.push({
|
|
196961
|
+
name: decl.name.text,
|
|
196962
|
+
valueParsed,
|
|
196963
|
+
raw: decl.initializer.getText(ctx.sourceFile)
|
|
196964
|
+
});
|
|
196965
|
+
}
|
|
196966
|
+
}
|
|
196967
|
+
return out.length > 0 ? out : null;
|
|
196968
|
+
}
|
|
196793
196969
|
function trimPreambleSegments(segments) {
|
|
196794
196970
|
const last = segments[segments.length - 1];
|
|
196795
196971
|
if (last?.kind === "js") {
|
|
@@ -197235,6 +197411,9 @@ function tryResolveIdentifierAsTemplateLiteral(ident, ctx) {
|
|
|
197235
197411
|
if (import_typescript11.default.isNoSubstitutionTemplateLiteral(ast) || import_typescript11.default.isStringLiteral(ast)) {
|
|
197236
197412
|
return [{ type: "string", value: ast.text }];
|
|
197237
197413
|
}
|
|
197414
|
+
if (import_typescript11.default.isElementAccessExpression(ast) && !import_typescript11.default.isStringLiteralLike(ast.argumentExpression) && !import_typescript11.default.isNumericLiteral(ast.argumentExpression)) {
|
|
197415
|
+
return tryResolveTemplateSpanFromConst(ast, ctx);
|
|
197416
|
+
}
|
|
197238
197417
|
if (!import_typescript11.default.isTemplateExpression(ast))
|
|
197239
197418
|
return null;
|
|
197240
197419
|
let resolvedAny = false;
|
|
@@ -197482,8 +197661,11 @@ function processComponentProps(attributes, ctx) {
|
|
|
197482
197661
|
}
|
|
197483
197662
|
let value = getAttributeValue(attr, ctx);
|
|
197484
197663
|
if (value.kind === "template") {
|
|
197485
|
-
|
|
197486
|
-
|
|
197664
|
+
const collapsed = templatePartsToJsString(value.parts);
|
|
197665
|
+
const collapsedTemplate = templatePartsToJsString(value.parts, { useTemplate: true });
|
|
197666
|
+
value = AttrValueOf.expression(collapsed, {
|
|
197667
|
+
parts: value.parts,
|
|
197668
|
+
...collapsedTemplate !== collapsed && { templateExpr: collapsedTemplate }
|
|
197487
197669
|
});
|
|
197488
197670
|
} else if (value.kind === "boolean-attr") {
|
|
197489
197671
|
value = AttrValueOf.booleanShorthand();
|
|
@@ -197512,16 +197694,18 @@ function processComponentProps(attributes, ctx) {
|
|
|
197512
197694
|
}
|
|
197513
197695
|
return props;
|
|
197514
197696
|
}
|
|
197515
|
-
function templatePartsToJsString(parts) {
|
|
197697
|
+
function templatePartsToJsString(parts, opts) {
|
|
197516
197698
|
let result = "`";
|
|
197517
197699
|
for (const part of parts) {
|
|
197518
197700
|
if (part.type === "string") {
|
|
197519
|
-
result += part.value;
|
|
197701
|
+
result += opts?.useTemplate && part.templateValue ? part.templateValue : part.value;
|
|
197520
197702
|
} else if (part.type === "ternary") {
|
|
197521
|
-
|
|
197703
|
+
const cond = opts?.useTemplate && part.templateCondition ? part.templateCondition : part.condition;
|
|
197704
|
+
result += `\${${cond} ? '${part.whenTrue}' : '${part.whenFalse}'}`;
|
|
197522
197705
|
} else if (part.type === "lookup") {
|
|
197706
|
+
const key = opts?.useTemplate && part.templateKey ? part.templateKey : part.key;
|
|
197523
197707
|
const obj = "{" + Object.entries(part.cases).map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`).join(", ") + "}";
|
|
197524
|
-
result += `\${(${obj})[${
|
|
197708
|
+
result += `\${(${obj})[${key}]}`;
|
|
197525
197709
|
}
|
|
197526
197710
|
}
|
|
197527
197711
|
result += "`";
|
|
@@ -197732,11 +197916,12 @@ function replaceBranchLocalRefs(text, branchNames, resolve2) {
|
|
|
197732
197916
|
const pattern = new RegExp(`(?<![\\w$])(${branchNames.join("|")})(?![\\w$])`, "g");
|
|
197733
197917
|
return replaceInExprContexts(text, pattern, (_match, name) => resolve2(name));
|
|
197734
197918
|
}
|
|
197735
|
-
function buildIfStatementChain(analyzer, ctx) {
|
|
197919
|
+
function buildIfStatementChain(analyzer, ctx, opts) {
|
|
197736
197920
|
const conditionalReturns = analyzer.conditionalReturns;
|
|
197921
|
+
const asConditional = opts?.asConditional === true;
|
|
197737
197922
|
let alternate = null;
|
|
197738
197923
|
if (analyzer.jsxReturn) {
|
|
197739
|
-
ctx.isRoot =
|
|
197924
|
+
ctx.isRoot = !asConditional;
|
|
197740
197925
|
alternate = transformNode(analyzer.jsxReturn, ctx);
|
|
197741
197926
|
}
|
|
197742
197927
|
for (let i2 = conditionalReturns.length - 1;i2 >= 0; i2--) {
|
|
@@ -197805,7 +197990,7 @@ function buildIfStatementChain(analyzer, ctx) {
|
|
|
197805
197990
|
ctx.getJS = substitutedGetJS;
|
|
197806
197991
|
ctx.analyzer.getJS = substitutedGetJS;
|
|
197807
197992
|
}
|
|
197808
|
-
ctx.isRoot =
|
|
197993
|
+
ctx.isRoot = !asConditional;
|
|
197809
197994
|
let consequent;
|
|
197810
197995
|
try {
|
|
197811
197996
|
consequent = transformNode(condReturn.jsxReturn, ctx);
|
|
@@ -197835,6 +198020,27 @@ function buildIfStatementChain(analyzer, ctx) {
|
|
|
197835
198020
|
}
|
|
197836
198021
|
}
|
|
197837
198022
|
const loc = getSourceLocation(condReturn.ifStatement, analyzer.sourceFile, analyzer.filePath);
|
|
198023
|
+
if (asConditional && alternate) {
|
|
198024
|
+
const conditional = {
|
|
198025
|
+
type: "conditional",
|
|
198026
|
+
condition,
|
|
198027
|
+
templateCondition,
|
|
198028
|
+
conditionType: null,
|
|
198029
|
+
reactive: true,
|
|
198030
|
+
whenTrue: consequent,
|
|
198031
|
+
whenFalse: alternate,
|
|
198032
|
+
slotId: generateSlotId(ctx),
|
|
198033
|
+
loc,
|
|
198034
|
+
origin: {
|
|
198035
|
+
phase: "tick",
|
|
198036
|
+
scope: "template",
|
|
198037
|
+
effect: "pure",
|
|
198038
|
+
freeRefs: resolveFreeRefs(condReturn.condition, makeBindingEnv(ctx))
|
|
198039
|
+
}
|
|
198040
|
+
};
|
|
198041
|
+
alternate = conditional;
|
|
198042
|
+
continue;
|
|
198043
|
+
}
|
|
197838
198044
|
const ifStmt = {
|
|
197839
198045
|
type: "if-statement",
|
|
197840
198046
|
condition,
|
|
@@ -198124,6 +198330,13 @@ function formatDateLocalNames(metadata) {
|
|
|
198124
198330
|
return names;
|
|
198125
198331
|
}
|
|
198126
198332
|
|
|
198333
|
+
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
198334
|
+
var import_typescript15 = __toESM(require_typescript(), 1);
|
|
198335
|
+
var NO_PREAMBLE = {
|
|
198336
|
+
lazySafe: true,
|
|
198337
|
+
facts: { declaredNames: new Set, freeNames: new Set }
|
|
198338
|
+
};
|
|
198339
|
+
|
|
198127
198340
|
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts
|
|
198128
198341
|
var PURE_SOURCE_GLOBALS = new Set([
|
|
198129
198342
|
"Object",
|
|
@@ -198168,7 +198381,7 @@ var INERT_BINDING_GLOBALS = new Set([
|
|
|
198168
198381
|
]);
|
|
198169
198382
|
|
|
198170
198383
|
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
198171
|
-
var
|
|
198384
|
+
var import_typescript16 = __toESM(require_typescript(), 1);
|
|
198172
198385
|
|
|
198173
198386
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/event-delegation.ts
|
|
198174
198387
|
var NON_BUBBLING_EVENTS = new Set([
|
|
@@ -198183,7 +198396,7 @@ var NON_BUBBLING_EVENTS = new Set([
|
|
|
198183
198396
|
]);
|
|
198184
198397
|
|
|
198185
198398
|
// ../jsx/src/ir-to-client-js/rewrite-props-object.ts
|
|
198186
|
-
var
|
|
198399
|
+
var import_typescript17 = __toESM(require_typescript(), 1);
|
|
198187
198400
|
|
|
198188
198401
|
// ../jsx/src/ir-to-client-js/source-map.ts
|
|
198189
198402
|
var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -198274,21 +198487,21 @@ class SourceMapGenerator {
|
|
|
198274
198487
|
}
|
|
198275
198488
|
|
|
198276
198489
|
// ../jsx/src/preprocess-inline-jsx-callbacks.ts
|
|
198277
|
-
var
|
|
198490
|
+
var import_typescript18 = __toESM(require_typescript(), 1);
|
|
198278
198491
|
|
|
198279
198492
|
// ../jsx/src/ssr-defaults.ts
|
|
198280
|
-
var
|
|
198493
|
+
var import_typescript19 = __toESM(require_typescript(), 1);
|
|
198281
198494
|
var UNRESOLVED = Symbol("unresolved");
|
|
198282
198495
|
var NO_RETURN = Symbol("no-return");
|
|
198283
198496
|
|
|
198284
198497
|
// ../jsx/src/augment-inherited-props.ts
|
|
198285
|
-
var
|
|
198498
|
+
var import_typescript20 = __toESM(require_typescript(), 1);
|
|
198286
198499
|
|
|
198287
198500
|
// ../jsx/src/rich-type-refusal.ts
|
|
198288
198501
|
var EMPTY_BINDINGS2 = new Map;
|
|
198289
198502
|
// ../jsx/src/shared-program.ts
|
|
198290
198503
|
init_path();
|
|
198291
|
-
var
|
|
198504
|
+
var import_typescript21 = __toESM(require_typescript(), 1);
|
|
198292
198505
|
// ../jsx/src/adapters/interface.ts
|
|
198293
198506
|
class BaseAdapter {
|
|
198294
198507
|
renderChildren(children) {
|
|
@@ -198827,9 +199040,9 @@ function registerBuiltinLoweringPlugins() {
|
|
|
198827
199040
|
registerLoweringPlugin(plugin);
|
|
198828
199041
|
}
|
|
198829
199042
|
// ../jsx/src/combine-client-js.ts
|
|
198830
|
-
var import_typescript21 = __toESM(require_typescript(), 1);
|
|
198831
|
-
// ../jsx/src/debug.ts
|
|
198832
199043
|
var import_typescript22 = __toESM(require_typescript(), 1);
|
|
199044
|
+
// ../jsx/src/debug.ts
|
|
199045
|
+
var import_typescript23 = __toESM(require_typescript(), 1);
|
|
198833
199046
|
function escapeForIdBoundary(name) {
|
|
198834
199047
|
return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
198835
199048
|
}
|
|
@@ -198921,7 +199134,7 @@ function resolveSetters(handler, setterToSignal, fnSetters) {
|
|
|
198921
199134
|
return refs;
|
|
198922
199135
|
}
|
|
198923
199136
|
// ../jsx/src/profiler.ts
|
|
198924
|
-
var
|
|
199137
|
+
var import_typescript24 = __toESM(require_typescript(), 1);
|
|
198925
199138
|
|
|
198926
199139
|
// ../jsx/src/index.ts
|
|
198927
199140
|
registerBuiltinLoweringPlugins();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.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.30.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.0.0"
|