@barefootjs/go-template 0.35.0 → 0.35.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/vite.js CHANGED
@@ -8,7 +8,7 @@ import { devModuleUrl, loadManifest, resolveDevOrigin, resolveScriptAssets, toPo
8
8
  import ts25 from "typescript";
9
9
 
10
10
  // ../jsx/src/analyzer.ts
11
- import ts10 from "typescript";
11
+ import ts11 from "typescript";
12
12
 
13
13
  // ../jsx/src/expression-parser.ts
14
14
  import ts from "typescript";
@@ -2462,14 +2462,17 @@ function freshCounters() {
2462
2462
  }
2463
2463
 
2464
2464
  // ../jsx/src/analyzer-context.ts
2465
- import ts9 from "typescript";
2465
+ import ts10 from "typescript";
2466
2466
 
2467
2467
  // ../jsx/src/strip-types.ts
2468
2468
  import ts8 from "typescript";
2469
2469
 
2470
+ // ../jsx/src/reactivity-checker.ts
2471
+ import ts9 from "typescript";
2472
+
2470
2473
  // ../jsx/src/analyzer-context.ts
2471
- var _typePrinter = ts9.createPrinter({ removeComments: true, omitTrailingSemicolon: true });
2472
- var _blankTypeSourceFile = ts9.createSourceFile("__bf_types__.ts", "", ts9.ScriptTarget.Latest);
2474
+ var _typePrinter = ts10.createPrinter({ removeComments: true, omitTrailingSemicolon: true });
2475
+ var _blankTypeSourceFile = ts10.createSourceFile("__bf_types__.ts", "", ts10.ScriptTarget.Latest);
2473
2476
 
2474
2477
  // ../jsx/src/errors.ts
2475
2478
  var ErrorCodes = {
@@ -2702,46 +2705,46 @@ function extractFreeIdentifiersFromNode(node) {
2702
2705
  const ids = new Set;
2703
2706
  const boundNames = new Set;
2704
2707
  function addBindingNames(name, out) {
2705
- if (ts10.isIdentifier(name))
2708
+ if (ts11.isIdentifier(name))
2706
2709
  out.push(name.text);
2707
- else if (ts10.isObjectBindingPattern(name))
2710
+ else if (ts11.isObjectBindingPattern(name))
2708
2711
  name.elements.forEach((e) => addBindingNames(e.name, out));
2709
- else if (ts10.isArrayBindingPattern(name))
2712
+ else if (ts11.isArrayBindingPattern(name))
2710
2713
  name.elements.forEach((e) => {
2711
- if (!ts10.isOmittedExpression(e))
2714
+ if (!ts11.isOmittedExpression(e))
2712
2715
  addBindingNames(e.name, out);
2713
2716
  });
2714
2717
  }
2715
2718
  function visit(n) {
2716
- if (ts10.isTypeNode(n))
2719
+ if (ts11.isTypeNode(n))
2717
2720
  return;
2718
- if (ts10.isIdentifier(n)) {
2721
+ if (ts11.isIdentifier(n)) {
2719
2722
  const parent = n.parent;
2720
- if (parent && ts10.isPropertyAccessExpression(parent) && parent.name === n)
2723
+ if (parent && ts11.isPropertyAccessExpression(parent) && parent.name === n)
2721
2724
  return;
2722
- if (parent && ts10.isPropertyAssignment(parent) && parent.name === n)
2725
+ if (parent && ts11.isPropertyAssignment(parent) && parent.name === n)
2723
2726
  return;
2724
- if (parent && ts10.isParameter(parent) && parent.name === n)
2727
+ if (parent && ts11.isParameter(parent) && parent.name === n)
2725
2728
  return;
2726
- if (parent && ts10.isVariableDeclaration(parent) && parent.name === n)
2729
+ if (parent && ts11.isVariableDeclaration(parent) && parent.name === n)
2727
2730
  return;
2728
2731
  if (boundNames.has(n.text))
2729
2732
  return;
2730
2733
  ids.add(n.text);
2731
2734
  return;
2732
2735
  }
2733
- if (ts10.isArrowFunction(n)) {
2736
+ if (ts11.isArrowFunction(n)) {
2734
2737
  const params = [];
2735
2738
  for (const p of n.parameters)
2736
2739
  addBindingNames(p.name, params);
2737
2740
  for (const name of params)
2738
2741
  boundNames.add(name);
2739
- ts10.forEachChild(n, visit);
2742
+ ts11.forEachChild(n, visit);
2740
2743
  for (const name of params)
2741
2744
  boundNames.delete(name);
2742
2745
  return;
2743
2746
  }
2744
- ts10.forEachChild(n, visit);
2747
+ ts11.forEachChild(n, visit);
2745
2748
  }
2746
2749
  visit(node);
2747
2750
  return ids;
@@ -2815,7 +2818,7 @@ function preambleAnalysisTemplateText(p) {
2815
2818
  }
2816
2819
 
2817
2820
  // ../jsx/src/module-exports.ts
2818
- import ts11 from "typescript";
2821
+ import ts12 from "typescript";
2819
2822
  function formatParamWithType(p) {
2820
2823
  const rest = p.isRest ? "..." : "";
2821
2824
  const optional = p.optional ? "?" : "";
@@ -2850,21 +2853,21 @@ function findAssignedNames(bodyText, candidates) {
2850
2853
  const assigned = new Set;
2851
2854
  if (candidates.size === 0)
2852
2855
  return assigned;
2853
- const sf = ts11.createSourceFile("bf-assignment-scan.tsx", bodyText, ts11.ScriptTarget.Latest, false, ts11.ScriptKind.TSX);
2856
+ const sf = ts12.createSourceFile("bf-assignment-scan.tsx", bodyText, ts12.ScriptTarget.Latest, false, ts12.ScriptKind.TSX);
2854
2857
  const record = (target) => {
2855
- if (ts11.isIdentifier(target) && candidates.has(target.text)) {
2858
+ if (ts12.isIdentifier(target) && candidates.has(target.text)) {
2856
2859
  assigned.add(target.text);
2857
2860
  }
2858
2861
  };
2859
2862
  const visit = (node) => {
2860
- if (ts11.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
2863
+ if (ts12.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
2861
2864
  record(node.left);
2862
- } else if ((ts11.isPrefixUnaryExpression(node) || ts11.isPostfixUnaryExpression(node)) && (node.operator === ts11.SyntaxKind.PlusPlusToken || node.operator === ts11.SyntaxKind.MinusMinusToken)) {
2865
+ } else if ((ts12.isPrefixUnaryExpression(node) || ts12.isPostfixUnaryExpression(node)) && (node.operator === ts12.SyntaxKind.PlusPlusToken || node.operator === ts12.SyntaxKind.MinusMinusToken)) {
2863
2866
  record(node.operand);
2864
2867
  }
2865
- ts11.forEachChild(node, visit);
2868
+ ts12.forEachChild(node, visit);
2866
2869
  };
2867
- ts11.forEachChild(sf, visit);
2870
+ ts12.forEachChild(sf, visit);
2868
2871
  return assigned;
2869
2872
  }
2870
2873
  function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNames) {
@@ -2887,12 +2890,9 @@ function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNam
2887
2890
  return reachable;
2888
2891
  }
2889
2892
  function isAssignmentOperator(kind) {
2890
- return kind >= ts11.SyntaxKind.FirstAssignment && kind <= ts11.SyntaxKind.LastAssignment;
2893
+ return kind >= ts12.SyntaxKind.FirstAssignment && kind <= ts12.SyntaxKind.LastAssignment;
2891
2894
  }
2892
2895
 
2893
- // ../jsx/src/reactivity-checker.ts
2894
- import ts12 from "typescript";
2895
-
2896
2896
  // ../jsx/src/free-refs.ts
2897
2897
  import ts13 from "typescript";
2898
2898
  var _bindingMapCache = new WeakMap;
@@ -6183,21 +6183,38 @@ function lowerUrlGuard(ctx, g) {
6183
6183
  if (isBoolShape) {
6184
6184
  return ctx.convertConditionToGo(stringifyParsedExpr(g), g).condition;
6185
6185
  }
6186
- const valueGo = wrapIfMultiToken(ctx.convertExpressionToGo(stringifyParsedExpr(g), undefined, g));
6186
+ const valueGo = lowerValueOperand(ctx, g);
6187
6187
  return `ne ${valueGo} ""`;
6188
6188
  }
6189
6189
  function lowerTernary(ctx, test, consequent, alternate) {
6190
6190
  const t = lowerTernaryTest(ctx, test);
6191
- return `(bf_ternary ${t} ${lowerTernaryOperand(ctx, consequent)} ${lowerTernaryOperand(ctx, alternate)})`;
6191
+ return `(bf_ternary ${t} ${lowerValueOperand(ctx, consequent)} ${lowerValueOperand(ctx, alternate)})`;
6192
+ }
6193
+ function lowerTemplateLiteralValue(ctx, parts) {
6194
+ const terms = [];
6195
+ for (const part of parts) {
6196
+ if (part.type === "string") {
6197
+ if (part.value !== "")
6198
+ terms.push(`"${escapeGoString(part.value)}"`);
6199
+ } else {
6200
+ terms.push(lowerValueOperand(ctx, part.expr));
6201
+ }
6202
+ }
6203
+ if (terms.length === 0)
6204
+ return '""';
6205
+ return terms.slice(1).reduce((acc, t) => `(bf_concat_str ${acc} ${t})`, terms[0]);
6192
6206
  }
6193
- function lowerTernaryOperand(ctx, n) {
6207
+ function lowerValueOperand(ctx, n) {
6194
6208
  if (n.kind === "conditional") {
6195
6209
  return lowerTernary(ctx, n.test, n.consequent, n.alternate);
6196
6210
  }
6211
+ if (n.kind === "template-literal") {
6212
+ return wrapIfMultiToken(lowerTemplateLiteralValue(ctx, n.parts));
6213
+ }
6197
6214
  return wrapIfMultiToken(ctx.convertExpressionToGo(stringifyParsedExpr(n), undefined, n));
6198
6215
  }
6199
6216
  function lowerTernaryTest(ctx, test) {
6200
- const go = wrapIfMultiToken(ctx.convertExpressionToGo(stringifyParsedExpr(test), undefined, test));
6217
+ const go = lowerValueOperand(ctx, test);
6201
6218
  const isBoolShape = test.kind === "binary" && BOOL_COMPARISON_OPS.has(test.op) || test.kind === "unary" && test.op === "!" || test.kind === "literal" && test.literalType === "boolean";
6202
6219
  return isBoolShape ? go : `(bf_truthy ${go})`;
6203
6220
  }
@@ -6258,18 +6275,16 @@ function renderLoweringNode(ctx, node) {
6258
6275
  const helper = goHelperName(node.helper);
6259
6276
  if (!helper)
6260
6277
  return null;
6261
- const lowerExpr = (n) => ctx.convertExpressionToGo(stringifyParsedExpr(n), undefined, n);
6262
- const lowerArg = (n) => n.kind === "conditional" ? lowerTernary(ctx, n.test, n.consequent, n.alternate) : wrapIfMultiToken(lowerExpr(n));
6263
6278
  if (node.kind === "helper-call") {
6264
- const args = node.args.map((a) => lowerArg(a));
6279
+ const args = node.args.map((a) => lowerValueOperand(ctx, a));
6265
6280
  return [helper, ...args].join(" ");
6266
6281
  }
6267
- const parts = [wrapIfMultiToken(lowerExpr(node.base))];
6282
+ const parts = [lowerValueOperand(ctx, node.base)];
6268
6283
  for (const t of node.triples) {
6269
6284
  const includeGo = t.guard === null ? "true" : lowerUrlGuard(ctx, t.guard);
6270
6285
  parts.push(`(${includeGo})`);
6271
6286
  parts.push(JSON.stringify(t.key));
6272
- parts.push(wrapIfMultiToken(lowerExpr(t.value)));
6287
+ parts.push(lowerValueOperand(ctx, t.value));
6273
6288
  }
6274
6289
  return `${helper} ${parts.join(" ")}`;
6275
6290
  }
@@ -6509,12 +6524,9 @@ function convertInitialValue(ctx, value, _typeInfo, propsParams, preParsed) {
6509
6524
  const inlinedStr = ctx.resolveModuleStringConst(value);
6510
6525
  if (inlinedStr !== null)
6511
6526
  return inlinedStr;
6512
- const inlinedNum = ctx.resolveModuleNumericConst(value);
6513
- if (inlinedNum !== null)
6514
- return inlinedNum;
6515
- const inlinedBool = ctx.resolveModuleBooleanConst(value);
6516
- if (inlinedBool !== null)
6517
- return inlinedBool;
6527
+ const inlinedConst = ctx.resolveModuleConstAsGo(value, { kind: "go-source", bakeType: typeInfo });
6528
+ if (inlinedConst !== null)
6529
+ return inlinedConst;
6518
6530
  }
6519
6531
  const propName = ctx.extractPropNameFromInitialValue(value, preParsed);
6520
6532
  const param = propName ? propsParams?.find((p) => p.name === propName) : undefined;
@@ -8223,8 +8235,7 @@ class GoTemplateAdapter extends BaseAdapter {
8223
8235
  extractPropFallback: (initialValue, preParsed) => this.extractPropFallback(initialValue, preParsed),
8224
8236
  extractCollisionDerivation: (parsed) => this.extractCollisionDerivation(parsed),
8225
8237
  resolveModuleStringConst: (name) => this.resolveModuleStringConst(name),
8226
- resolveModuleNumericConst: (name) => this.resolveModuleNumericConst(name),
8227
- resolveModuleBooleanConst: (name) => this.resolveModuleBooleanConst(name)
8238
+ resolveModuleConstAsGo: (name, target) => this.resolveModuleConstAsGo(name, target)
8228
8239
  };
8229
8240
  get errors() {
8230
8241
  return this.state.errors;
@@ -10422,9 +10433,9 @@ ${goFields.join(`
10422
10433
  const inlined = this.resolveModuleStringConst(name);
10423
10434
  if (inlined !== null)
10424
10435
  return inlined;
10425
- const inlinedNum = this.resolveModuleNumericConst(name);
10426
- if (inlinedNum !== null)
10427
- return inlinedNum;
10436
+ const inlinedScalar = this.resolveModuleConstAsGo(name, { kind: "template-action" });
10437
+ if (inlinedScalar !== null)
10438
+ return inlinedScalar;
10428
10439
  if (this.isCurrentLoopItem(name))
10429
10440
  return ".";
10430
10441
  if (this.isOuterLoopParam(name))
@@ -10501,11 +10512,18 @@ ${goFields.join(`
10501
10512
  return hit !== null && hit.depth > 0 && hit.binding.source === "item";
10502
10513
  }
10503
10514
  rootFieldRef(name) {
10504
- const resolved = this.state.getterAliases.get(name) ?? this.state.propDestructureAliases.get(name) ?? name;
10515
+ const resolved = this.resolveRootFieldAlias(name);
10505
10516
  this.state.templateReadRootFields.add(resolved);
10506
10517
  const prefix = this.inLoop ? "$." : ".";
10507
10518
  return `${prefix}${capitalizeFieldName(resolved)}`;
10508
10519
  }
10520
+ resolveRootFieldAlias(name) {
10521
+ return this.state.getterAliases.get(name) ?? this.state.propDestructureAliases.get(name) ?? name;
10522
+ }
10523
+ filterRootFieldRef(name) {
10524
+ this.rootFieldRef(name);
10525
+ return `$.${capitalizeFieldName(this.resolveRootFieldAlias(name))}`;
10526
+ }
10509
10527
  searchParamsFieldRef(name) {
10510
10528
  return this.state.searchParamsLocals.has(name) ? this.rootFieldRef("searchParams") : null;
10511
10529
  }
@@ -10527,7 +10545,7 @@ ${goFields.join(`
10527
10545
  findModuleConst(name) {
10528
10546
  return this.state.localConstants.find((k) => k.name === name && k.isModule && !k.containsArrow);
10529
10547
  }
10530
- resolveModuleNumericConst(name) {
10548
+ resolveModuleConstAsGo(name, target) {
10531
10549
  if (this.isCurrentLoopItem(name))
10532
10550
  return null;
10533
10551
  if (this.loopVarRefCount.has(name))
@@ -10535,23 +10553,13 @@ ${goFields.join(`
10535
10553
  if (this.isOuterLoopParam(name))
10536
10554
  return null;
10537
10555
  const c = this.findModuleConst(name);
10538
- if (!c || c.value === undefined)
10539
- return null;
10540
- const v = c.value.trim().replace(/(?<=\d)_(?=\d)/g, "");
10541
- return /^-?\d+(\.\d+)?$/.test(v) ? v : null;
10542
- }
10543
- resolveModuleBooleanConst(name) {
10544
- if (this.isCurrentLoopItem(name))
10556
+ if (!c?.parsed)
10545
10557
  return null;
10546
- if (this.loopVarRefCount.has(name))
10547
- return null;
10548
- if (this.isOuterLoopParam(name))
10549
- return null;
10550
- const c = this.findModuleConst(name);
10551
- if (!c || c.value === undefined)
10552
- return null;
10553
- const v = c.value.trim();
10554
- return v === "true" || v === "false" ? v : null;
10558
+ if (target.kind === "template-action") {
10559
+ return c.parsed.kind === "literal" || c.parsed.kind === "unary" ? parsedLiteralToGo(this.emitCtx, c.parsed) : null;
10560
+ }
10561
+ const bakeType = target.bakeType.kind !== "unknown" ? target.bakeType : c.type ?? undefined;
10562
+ return parsedLiteralToGo(this.emitCtx, c.parsed, bakeType);
10555
10563
  }
10556
10564
  literal(value, literalType) {
10557
10565
  if (literalType === "string")
@@ -10640,11 +10648,17 @@ ${goFields.join(`
10640
10648
  return `${obj}.${goFieldNameForKey(property)}`;
10641
10649
  }
10642
10650
  indexAccess(object, index, emit) {
10643
- return `bf_get ${wrapIfMultiToken(emit(object))} ${wrapIfMultiToken(emit(index))}`;
10651
+ return `bf_get ${wrapIfMultiToken(this.emitOperand(object, emit))} ${wrapIfMultiToken(this.emitOperand(index, emit))}`;
10652
+ }
10653
+ emitOperand(n, emit) {
10654
+ if (n.kind === "template-literal") {
10655
+ return wrapIfMultiToken(lowerTemplateLiteralValue(this.emitCtx, n.parts));
10656
+ }
10657
+ return emit(n);
10644
10658
  }
10645
10659
  binary(op, left, right, emit) {
10646
- const l = emit(left);
10647
- const r = emit(right);
10660
+ const l = this.emitOperand(left, emit);
10661
+ const r = this.emitOperand(right, emit);
10648
10662
  const wl = wrapIfMultiToken(l);
10649
10663
  const wr = wrapIfMultiToken(r);
10650
10664
  switch (op) {
@@ -10690,7 +10704,7 @@ ${goFields.join(`
10690
10704
  return this.state.stringValueNames.has(name);
10691
10705
  }
10692
10706
  unary(op, argument, emit) {
10693
- const arg = emit(argument);
10707
+ const arg = this.emitOperand(argument, emit);
10694
10708
  if (op === "!")
10695
10709
  return `not ${wrapIfMultiToken(arg)}`;
10696
10710
  if (op === "-")
@@ -10698,8 +10712,8 @@ ${goFields.join(`
10698
10712
  return arg;
10699
10713
  }
10700
10714
  logical(op, left, right, emit) {
10701
- const wrapLeft = wrapIfMultiToken(emit(left));
10702
- const wrapRight = wrapIfMultiToken(emit(right));
10715
+ const wrapLeft = wrapIfMultiToken(this.emitOperand(left, emit));
10716
+ const wrapRight = wrapIfMultiToken(this.emitOperand(right, emit));
10703
10717
  if (op === "&&")
10704
10718
  return `and ${wrapLeft} ${wrapRight}`;
10705
10719
  if (op === "??" && this.nillablePropNameOf(left) !== null) {
@@ -10864,7 +10878,8 @@ ${goFields.join(`
10864
10878
  }
10865
10879
  return this.pushCallbackBF101(method, true);
10866
10880
  }
10867
- arrayMethod(method, object, args, emit) {
10881
+ arrayMethod(method, object, args, rawEmit) {
10882
+ const emit = (e) => this.emitOperand(e, rawEmit);
10868
10883
  switch (method) {
10869
10884
  case "join": {
10870
10885
  const obj = emit(object);
@@ -11193,11 +11208,9 @@ ${goFields.join(`
11193
11208
  }
11194
11209
  const signal = localVarMap.get(expr.name);
11195
11210
  if (signal) {
11196
- this.rootFieldRef(signal);
11197
- return `$.${capitalizeFieldName(signal)}`;
11211
+ return this.filterRootFieldRef(signal);
11198
11212
  }
11199
- this.rootFieldRef(expr.name);
11200
- return `.${capitalizeFieldName(expr.name)}`;
11213
+ return this.filterRootFieldRef(expr.name);
11201
11214
  }
11202
11215
  case "literal":
11203
11216
  if (expr.literalType === "string") {
@@ -11211,6 +11224,9 @@ ${goFields.join(`
11211
11224
  if (expr.object.kind === "identifier" && expr.object.name === param) {
11212
11225
  return `${paramPrefix}.${capitalizeFieldName(expr.property)}`;
11213
11226
  }
11227
+ if (expr.object.kind === "identifier" && this.state.propsObjectName && expr.object.name === this.state.propsObjectName) {
11228
+ return this.filterRootFieldRef(expr.property);
11229
+ }
11214
11230
  if (expr.property === "length") {
11215
11231
  const innerHO = this.higherOrderShapeOf(expr.object);
11216
11232
  if (innerHO && innerHO.method === "filter") {
@@ -11229,8 +11245,7 @@ ${goFields.join(`
11229
11245
  return `${paramPrefix}.${capitalizeFieldName(expr.callee.property)}`;
11230
11246
  }
11231
11247
  if (expr.callee.kind === "identifier" && expr.args.length === 0) {
11232
- this.rootFieldRef(expr.callee.name);
11233
- return `$.${capitalizeFieldName(expr.callee.name)}`;
11248
+ return this.filterRootFieldRef(expr.callee.name);
11234
11249
  }
11235
11250
  if (asCallbackMethodCall(expr) !== null) {
11236
11251
  return this.refuseFilterExprNode(expr);
@@ -11260,29 +11275,33 @@ ${goFields.join(`
11260
11275
  const right = this.renderFilterExpr(expr.right, param, localVarMap, datumField);
11261
11276
  if (this.filterExprUnsupported)
11262
11277
  return "false";
11278
+ const wl = wrapIfMultiToken(left);
11279
+ const wr = wrapIfMultiToken(right);
11263
11280
  switch (expr.op) {
11264
11281
  case "===":
11265
11282
  case "==":
11266
- return `eq ${left} ${right}`;
11283
+ return `eq ${wl} ${wr}`;
11267
11284
  case "!==":
11268
11285
  case "!=":
11269
- return `ne ${left} ${right}`;
11286
+ return `ne ${wl} ${wr}`;
11270
11287
  case ">":
11271
- return `gt ${left} ${right}`;
11288
+ return `gt ${wl} ${wr}`;
11272
11289
  case "<":
11273
- return `lt ${left} ${right}`;
11290
+ return `lt ${wl} ${wr}`;
11274
11291
  case ">=":
11275
- return `ge ${left} ${right}`;
11292
+ return `ge ${wl} ${wr}`;
11276
11293
  case "<=":
11277
- return `le ${left} ${right}`;
11294
+ return `le ${wl} ${wr}`;
11278
11295
  case "+":
11279
- return this._emitPlus(expr.left, expr.right, left, right);
11296
+ return this._emitPlus(expr.left, expr.right, wl, wr);
11280
11297
  case "-":
11281
- return `bf_sub ${left} ${right}`;
11298
+ return `bf_sub ${wl} ${wr}`;
11282
11299
  case "*":
11283
- return `bf_mul ${left} ${right}`;
11300
+ return `bf_mul ${wl} ${wr}`;
11284
11301
  case "/":
11285
- return `bf_div ${left} ${right}`;
11302
+ return `bf_div ${wl} ${wr}`;
11303
+ case "%":
11304
+ return `bf_mod ${wl} ${wr}`;
11286
11305
  default:
11287
11306
  return `${left} ${expr.op} ${right}`;
11288
11307
  }
@@ -11454,11 +11473,9 @@ ${goFields.join(`
11454
11473
  }
11455
11474
  continue;
11456
11475
  }
11457
- const singlePartTemplateLiteral = exprOut.parsed?.kind === "template-literal" && exprOut.parsed.parts.length === 1 && exprOut.parsed.parts[0].type !== "string" && go.startsWith("{{") && go.endsWith("}}");
11458
- if (singlePartTemplateLiteral) {
11459
- go = go.slice(2, -2);
11460
- }
11461
- if (!singlePartTemplateLiteral && this.isTemplateFragment(go, exprOut.parsed?.kind)) {
11476
+ if (exprOut.parsed?.kind === "template-literal" || exprOut.parsed?.kind === "conditional") {
11477
+ go = lowerValueOperand(this.emitCtx, exprOut.parsed);
11478
+ } else if (this.isTemplateFragment(go, exprOut.parsed?.kind)) {
11462
11479
  this.state.errors.push({
11463
11480
  code: "BF101",
11464
11481
  severity: "error",
@@ -11735,6 +11752,9 @@ ${goFields.join(`
11735
11752
  case "/":
11736
11753
  result = `bf_div ${left} ${right}`;
11737
11754
  break;
11755
+ case "%":
11756
+ result = `bf_mod ${left} ${right}`;
11757
+ break;
11738
11758
  default:
11739
11759
  result = `${left} ${expr.op} ${right}`;
11740
11760
  }
@@ -11761,7 +11781,7 @@ ${goFields.join(`
11761
11781
  return plain(lowerTernary(this.emitCtx, expr.test, expr.consequent, expr.alternate));
11762
11782
  }
11763
11783
  case "template-literal":
11764
- return plain(this.renderParsedExpr(expr));
11784
+ return plain(lowerTemplateLiteralValue(this.emitCtx, expr.parts));
11765
11785
  case "arrow":
11766
11786
  return plain("[ARROW-FN]");
11767
11787
  case "regex":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/go-template",
3
- "version": "0.35.0",
3
+ "version": "0.35.2",
4
4
  "description": "Go html/template adapter for BarefootJS - generates Go template files from IR",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -49,7 +49,7 @@
49
49
  "directory": "packages/adapter-go-template"
50
50
  },
51
51
  "dependencies": {
52
- "@barefootjs/shared": "0.35.0"
52
+ "@barefootjs/shared": "0.35.2"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@barefootjs/jsx": ">=0.2.0",
@@ -67,9 +67,9 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@barefootjs/adapter-tests": "0.1.0",
70
- "@barefootjs/client": "0.35.0",
71
- "@barefootjs/jsx": "0.35.0",
72
- "@barefootjs/vite": "0.35.0",
70
+ "@barefootjs/client": "0.35.2",
71
+ "@barefootjs/jsx": "0.35.2",
72
+ "@barefootjs/vite": "0.35.2",
73
73
  "vite": "^6.0.0"
74
74
  }
75
75
  }