@barefootjs/jinja 0.31.2 → 0.31.4

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.
Files changed (2) hide show
  1. package/dist/vite.js +107 -12
  2. package/package.json +5 -5
package/dist/vite.js CHANGED
@@ -2000,6 +2000,20 @@ function templatePartsToJsExpr(parts, opts) {
2000
2000
  return result;
2001
2001
  }
2002
2002
 
2003
+ // ../jsx/src/identifier-pattern.ts
2004
+ function withUnicodeFlag(flags) {
2005
+ return flags.includes("u") ? flags : `${flags}u`;
2006
+ }
2007
+ function escapeIdentifierForRegex(name) {
2008
+ return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2009
+ }
2010
+ var ID_BOUNDARY_BEFORE = "(?<![\\p{ID_Continue}$])";
2011
+ var ID_BOUNDARY_AFTER = "(?![\\p{ID_Continue}$])";
2012
+ function identifierPattern(name, flags = "") {
2013
+ const esc = escapeIdentifierForRegex(name);
2014
+ return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}${ID_BOUNDARY_AFTER}`, withUnicodeFlag(flags));
2015
+ }
2016
+
2003
2017
  // ../jsx/src/scanner/js-scanner.ts
2004
2018
  import ts2 from "typescript";
2005
2019
 
@@ -2117,6 +2131,83 @@ function derivesScopeFromSlot(comp) {
2117
2131
  return comp.slotId != null && comp.loopItemRoot !== true;
2118
2132
  }
2119
2133
 
2134
+ // ../jsx/src/scope/binding-scope.ts
2135
+ class BindingScope {
2136
+ frames;
2137
+ static EMPTY = new BindingScope([]);
2138
+ constructor(frames) {
2139
+ this.frames = frames;
2140
+ }
2141
+ enterLoopRow(loop) {
2142
+ const bindings = new Map;
2143
+ if (loop.paramBindings && loop.paramBindings.length > 0) {
2144
+ for (const b of loop.paramBindings)
2145
+ bindings.set(b.name, { source: "destructure" });
2146
+ } else {
2147
+ bindings.set(loop.param, { source: "item" });
2148
+ }
2149
+ if (loop.index != null)
2150
+ bindings.set(loop.index, { source: "index" });
2151
+ for (const name of loop.preamble?.declaredNames ?? [])
2152
+ bindings.set(name, { source: "preamble" });
2153
+ const frame = { kind: "loop-row", bindings };
2154
+ return new BindingScope([frame, ...this.frames]);
2155
+ }
2156
+ enterCallback(params) {
2157
+ const bindings = new Map;
2158
+ for (const name of params)
2159
+ bindings.set(name, { source: "param" });
2160
+ const frame = { kind: "callback", bindings };
2161
+ return new BindingScope([frame, ...this.frames]);
2162
+ }
2163
+ isBound(name) {
2164
+ for (const frame of this.frames) {
2165
+ if (frame.bindings.has(name))
2166
+ return true;
2167
+ }
2168
+ return false;
2169
+ }
2170
+ lookup(name) {
2171
+ for (let depth = 0;depth < this.frames.length; depth++) {
2172
+ const frame = this.frames[depth];
2173
+ const binding = frame.bindings.get(name);
2174
+ if (binding)
2175
+ return { depth, frame, binding };
2176
+ }
2177
+ return null;
2178
+ }
2179
+ boundNames() {
2180
+ if (this.boundNamesCache)
2181
+ return this.boundNamesCache;
2182
+ const names = new Set;
2183
+ for (const frame of this.frames) {
2184
+ for (const name of frame.bindings.keys())
2185
+ names.add(name);
2186
+ }
2187
+ this.boundNamesCache = names;
2188
+ return names;
2189
+ }
2190
+ boundNamesCache;
2191
+ valueBoundNamesCache;
2192
+ valueBoundNames() {
2193
+ if (this.valueBoundNamesCache)
2194
+ return this.valueBoundNamesCache;
2195
+ const names = new Set;
2196
+ for (const frame of this.frames) {
2197
+ for (const [name, binding] of frame.bindings) {
2198
+ if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
2199
+ names.add(name);
2200
+ }
2201
+ }
2202
+ }
2203
+ this.valueBoundNamesCache = names;
2204
+ return names;
2205
+ }
2206
+ asShadowPredicate() {
2207
+ return (name) => this.isBound(name);
2208
+ }
2209
+ }
2210
+
2120
2211
  // ../jsx/src/ir-to-client-js/html-template.ts
2121
2212
  var VOID_ELEMENTS = new Set([
2122
2213
  "area",
@@ -2551,7 +2642,7 @@ function findReachableNames(primaryRefs, declarations) {
2551
2642
  const reachable = new Set;
2552
2643
  const queue = [];
2553
2644
  for (const name of allNames) {
2554
- if (new RegExp(`\\b${name}\\b`).test(primaryRefs)) {
2645
+ if (identifierPattern(name).test(primaryRefs)) {
2555
2646
  reachable.add(name);
2556
2647
  queue.push(name);
2557
2648
  }
@@ -2560,7 +2651,7 @@ function findReachableNames(primaryRefs, declarations) {
2560
2651
  const current = queue.shift();
2561
2652
  const body = bodyMap.get(current) || "";
2562
2653
  for (const name of allNames) {
2563
- if (!reachable.has(name) && new RegExp(`\\b${name}\\b`).test(body)) {
2654
+ if (!reachable.has(name) && identifierPattern(name).test(body)) {
2564
2655
  reachable.add(name);
2565
2656
  queue.push(name);
2566
2657
  }
@@ -3916,7 +4007,7 @@ class JsxAdapter extends BaseAdapter {
3916
4007
  lines.push(` const ${signal.getter} = () => ${initialValue}`);
3917
4008
  }
3918
4009
  if (signal.setter) {
3919
- const setterUsed = new RegExp(`\\b${signal.setter}\\b`).test(setterRefText);
4010
+ const setterUsed = identifierPattern(signal.setter).test(setterRefText);
3920
4011
  if (setterUsed) {
3921
4012
  lines.push(` const ${signal.setter} = (..._args: any[]) => {}`);
3922
4013
  }
@@ -3936,7 +4027,7 @@ class JsxAdapter extends BaseAdapter {
3936
4027
  continue;
3937
4028
  const keyword = constant.declarationKind ?? "const";
3938
4029
  if (!constant.value) {
3939
- const typeAnnotation = preserveTypes && constant.type ? `: ${constant.type.raw}` : "";
4030
+ const typeAnnotation = preserveTypes && (constant.typeAnnotation ?? constant.type) ? `: ${constant.typeAnnotation ?? constant.type?.raw}` : "";
3940
4031
  lines.push(` ${keyword} ${constant.name}${typeAnnotation}`);
3941
4032
  continue;
3942
4033
  }
@@ -3946,7 +4037,8 @@ class JsxAdapter extends BaseAdapter {
3946
4037
  if (!reachable.has(constant.name))
3947
4038
  continue;
3948
4039
  const constValue = preserveTypes ? constant.typedValue ?? constant.value : constant.value;
3949
- lines.push(` ${keyword} ${constant.name} = ${constValue}`);
4040
+ const letTypeAnnotation = preserveTypes && keyword === "let" && constant.typeAnnotation ? `: ${constant.typeAnnotation}` : "";
4041
+ lines.push(` ${keyword} ${constant.name}${letTypeAnnotation} = ${constValue}`);
3950
4042
  }
3951
4043
  for (const func of localFunctions) {
3952
4044
  if (moduleScopeNames.has(func.name))
@@ -4053,7 +4145,8 @@ class JsxAdapter extends BaseAdapter {
4053
4145
  const keyword = c.declarationKind ?? "const";
4054
4146
  const exportKw = c.isExported ? "export " : "";
4055
4147
  if (!c.value) {
4056
- entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}` });
4148
+ const typeAnnotation = preserveTypes && (c.typeAnnotation ?? c.type) ? `: ${c.typeAnnotation ?? c.type?.raw}` : "";
4149
+ entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${typeAnnotation}` });
4057
4150
  continue;
4058
4151
  }
4059
4152
  const trimmed = c.value.trim();
@@ -4062,7 +4155,8 @@ class JsxAdapter extends BaseAdapter {
4062
4155
  if (c.isExported && /^createContext\b/.test(trimmed))
4063
4156
  continue;
4064
4157
  const value = preserveTypes ? c.typedValue ?? c.value : c.value;
4065
- entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name} = ${value}` });
4158
+ const letTypeAnnotation = preserveTypes && keyword === "let" && c.typeAnnotation ? `: ${c.typeAnnotation}` : "";
4159
+ entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${letTypeAnnotation} = ${value}` });
4066
4160
  }
4067
4161
  for (const f of ir.metadata.localFunctions) {
4068
4162
  if (!f.isModule || !moduleNames.has(f.name))
@@ -4111,6 +4205,7 @@ class JsxAdapter extends BaseAdapter {
4111
4205
  }
4112
4206
 
4113
4207
  // ../jsx/src/adapters/template-imports.ts
4208
+ import ts25 from "typescript";
4114
4209
  var CLIENT_PACKAGE_SOURCES = new Set([
4115
4210
  "@barefootjs/client",
4116
4211
  "@barefootjs/client/runtime"
@@ -4853,7 +4948,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
4853
4948
  };
4854
4949
  }
4855
4950
  // ../jsx/src/combine-client-js.ts
4856
- import ts25 from "typescript";
4951
+ import ts26 from "typescript";
4857
4952
  // ../jsx/src/loop-destructure.ts
4858
4953
  function isLowerableLoopDestructure(loop) {
4859
4954
  const bindings = loop.paramBindings;
@@ -4993,9 +5088,9 @@ function escapeRe(s) {
4993
5088
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4994
5089
  }
4995
5090
  // ../jsx/src/debug.ts
4996
- import ts26 from "typescript";
4997
- // ../jsx/src/profiler.ts
4998
5091
  import ts27 from "typescript";
5092
+ // ../jsx/src/profiler.ts
5093
+ import ts28 from "typescript";
4999
5094
 
5000
5095
  // ../jsx/src/index.ts
5001
5096
  registerBuiltinLoweringPlugins();
@@ -5821,7 +5916,7 @@ function collectImportedLoopChildComponentErrors(ir, componentName) {
5821
5916
  }
5822
5917
 
5823
5918
  // src/adapter/spread/spread-codegen.ts
5824
- import ts28 from "typescript";
5919
+ import ts29 from "typescript";
5825
5920
  function conditionalSpreadToJinja(ctx, expr) {
5826
5921
  if (!expr || expr.kind !== "conditional")
5827
5922
  return null;
@@ -5876,7 +5971,7 @@ function recordIndexAccessToJinja(ctx, val) {
5876
5971
  if (val.kind !== "index-access" || val.object.kind !== "identifier" || val.index.kind !== "identifier") {
5877
5972
  return null;
5878
5973
  }
5879
- const tsVal = ts28.factory.createElementAccessExpression(ts28.factory.createIdentifier(val.object.name), ts28.factory.createIdentifier(val.index.name));
5974
+ const tsVal = ts29.factory.createElementAccessExpression(ts29.factory.createIdentifier(val.object.name), ts29.factory.createIdentifier(val.index.name));
5880
5975
  const parsed = parseRecordIndexAccess(tsVal, ctx.localConstants ?? [], ctx.propsParams);
5881
5976
  if (!parsed)
5882
5977
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/jinja",
3
- "version": "0.31.2",
3
+ "version": "0.31.4",
4
4
  "description": "Jinja2 adapter for BarefootJS — compiles IR to .jinja templates and ships the Python BarefootJS rendering runtime; runs under any Python web framework (Flask, etc.)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -53,7 +53,7 @@
53
53
  "directory": "packages/adapter-jinja"
54
54
  },
55
55
  "dependencies": {
56
- "@barefootjs/shared": "0.31.2"
56
+ "@barefootjs/shared": "0.31.4"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@barefootjs/jsx": ">=0.2.0",
@@ -70,9 +70,9 @@
70
70
  },
71
71
  "devDependencies": {
72
72
  "@barefootjs/adapter-tests": "0.1.0",
73
- "@barefootjs/jsx": "0.31.2",
74
- "@barefootjs/vite": "0.31.2",
75
- "@barefootjs/client": "0.31.2",
73
+ "@barefootjs/jsx": "0.31.4",
74
+ "@barefootjs/vite": "0.31.4",
75
+ "@barefootjs/client": "0.31.4",
76
76
  "typescript": "^5.0.0",
77
77
  "vite": "^6.0.0"
78
78
  }