@barefootjs/erb 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
@@ -1948,6 +1948,20 @@ function templatePartsToJsExpr(parts, opts) {
1948
1948
  return result;
1949
1949
  }
1950
1950
 
1951
+ // ../jsx/src/identifier-pattern.ts
1952
+ function withUnicodeFlag(flags) {
1953
+ return flags.includes("u") ? flags : `${flags}u`;
1954
+ }
1955
+ function escapeIdentifierForRegex(name) {
1956
+ return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1957
+ }
1958
+ var ID_BOUNDARY_BEFORE = "(?<![\\p{ID_Continue}$])";
1959
+ var ID_BOUNDARY_AFTER = "(?![\\p{ID_Continue}$])";
1960
+ function identifierPattern(name, flags = "") {
1961
+ const esc = escapeIdentifierForRegex(name);
1962
+ return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}${ID_BOUNDARY_AFTER}`, withUnicodeFlag(flags));
1963
+ }
1964
+
1951
1965
  // ../jsx/src/scanner/js-scanner.ts
1952
1966
  import ts2 from "typescript";
1953
1967
 
@@ -2065,6 +2079,83 @@ function derivesScopeFromSlot(comp) {
2065
2079
  return comp.slotId != null && comp.loopItemRoot !== true;
2066
2080
  }
2067
2081
 
2082
+ // ../jsx/src/scope/binding-scope.ts
2083
+ class BindingScope {
2084
+ frames;
2085
+ static EMPTY = new BindingScope([]);
2086
+ constructor(frames) {
2087
+ this.frames = frames;
2088
+ }
2089
+ enterLoopRow(loop) {
2090
+ const bindings = new Map;
2091
+ if (loop.paramBindings && loop.paramBindings.length > 0) {
2092
+ for (const b of loop.paramBindings)
2093
+ bindings.set(b.name, { source: "destructure" });
2094
+ } else {
2095
+ bindings.set(loop.param, { source: "item" });
2096
+ }
2097
+ if (loop.index != null)
2098
+ bindings.set(loop.index, { source: "index" });
2099
+ for (const name of loop.preamble?.declaredNames ?? [])
2100
+ bindings.set(name, { source: "preamble" });
2101
+ const frame = { kind: "loop-row", bindings };
2102
+ return new BindingScope([frame, ...this.frames]);
2103
+ }
2104
+ enterCallback(params) {
2105
+ const bindings = new Map;
2106
+ for (const name of params)
2107
+ bindings.set(name, { source: "param" });
2108
+ const frame = { kind: "callback", bindings };
2109
+ return new BindingScope([frame, ...this.frames]);
2110
+ }
2111
+ isBound(name) {
2112
+ for (const frame of this.frames) {
2113
+ if (frame.bindings.has(name))
2114
+ return true;
2115
+ }
2116
+ return false;
2117
+ }
2118
+ lookup(name) {
2119
+ for (let depth = 0;depth < this.frames.length; depth++) {
2120
+ const frame = this.frames[depth];
2121
+ const binding = frame.bindings.get(name);
2122
+ if (binding)
2123
+ return { depth, frame, binding };
2124
+ }
2125
+ return null;
2126
+ }
2127
+ boundNames() {
2128
+ if (this.boundNamesCache)
2129
+ return this.boundNamesCache;
2130
+ const names = new Set;
2131
+ for (const frame of this.frames) {
2132
+ for (const name of frame.bindings.keys())
2133
+ names.add(name);
2134
+ }
2135
+ this.boundNamesCache = names;
2136
+ return names;
2137
+ }
2138
+ boundNamesCache;
2139
+ valueBoundNamesCache;
2140
+ valueBoundNames() {
2141
+ if (this.valueBoundNamesCache)
2142
+ return this.valueBoundNamesCache;
2143
+ const names = new Set;
2144
+ for (const frame of this.frames) {
2145
+ for (const [name, binding] of frame.bindings) {
2146
+ if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
2147
+ names.add(name);
2148
+ }
2149
+ }
2150
+ }
2151
+ this.valueBoundNamesCache = names;
2152
+ return names;
2153
+ }
2154
+ asShadowPredicate() {
2155
+ return (name) => this.isBound(name);
2156
+ }
2157
+ }
2158
+
2068
2159
  // ../jsx/src/ir-to-client-js/html-template.ts
2069
2160
  var VOID_ELEMENTS = new Set([
2070
2161
  "area",
@@ -2499,7 +2590,7 @@ function findReachableNames(primaryRefs, declarations) {
2499
2590
  const reachable = new Set;
2500
2591
  const queue = [];
2501
2592
  for (const name of allNames) {
2502
- if (new RegExp(`\\b${name}\\b`).test(primaryRefs)) {
2593
+ if (identifierPattern(name).test(primaryRefs)) {
2503
2594
  reachable.add(name);
2504
2595
  queue.push(name);
2505
2596
  }
@@ -2508,7 +2599,7 @@ function findReachableNames(primaryRefs, declarations) {
2508
2599
  const current = queue.shift();
2509
2600
  const body = bodyMap.get(current) || "";
2510
2601
  for (const name of allNames) {
2511
- if (!reachable.has(name) && new RegExp(`\\b${name}\\b`).test(body)) {
2602
+ if (!reachable.has(name) && identifierPattern(name).test(body)) {
2512
2603
  reachable.add(name);
2513
2604
  queue.push(name);
2514
2605
  }
@@ -3864,7 +3955,7 @@ class JsxAdapter extends BaseAdapter {
3864
3955
  lines.push(` const ${signal.getter} = () => ${initialValue}`);
3865
3956
  }
3866
3957
  if (signal.setter) {
3867
- const setterUsed = new RegExp(`\\b${signal.setter}\\b`).test(setterRefText);
3958
+ const setterUsed = identifierPattern(signal.setter).test(setterRefText);
3868
3959
  if (setterUsed) {
3869
3960
  lines.push(` const ${signal.setter} = (..._args: any[]) => {}`);
3870
3961
  }
@@ -3884,7 +3975,7 @@ class JsxAdapter extends BaseAdapter {
3884
3975
  continue;
3885
3976
  const keyword = constant.declarationKind ?? "const";
3886
3977
  if (!constant.value) {
3887
- const typeAnnotation = preserveTypes && constant.type ? `: ${constant.type.raw}` : "";
3978
+ const typeAnnotation = preserveTypes && (constant.typeAnnotation ?? constant.type) ? `: ${constant.typeAnnotation ?? constant.type?.raw}` : "";
3888
3979
  lines.push(` ${keyword} ${constant.name}${typeAnnotation}`);
3889
3980
  continue;
3890
3981
  }
@@ -3894,7 +3985,8 @@ class JsxAdapter extends BaseAdapter {
3894
3985
  if (!reachable.has(constant.name))
3895
3986
  continue;
3896
3987
  const constValue = preserveTypes ? constant.typedValue ?? constant.value : constant.value;
3897
- lines.push(` ${keyword} ${constant.name} = ${constValue}`);
3988
+ const letTypeAnnotation = preserveTypes && keyword === "let" && constant.typeAnnotation ? `: ${constant.typeAnnotation}` : "";
3989
+ lines.push(` ${keyword} ${constant.name}${letTypeAnnotation} = ${constValue}`);
3898
3990
  }
3899
3991
  for (const func of localFunctions) {
3900
3992
  if (moduleScopeNames.has(func.name))
@@ -4001,7 +4093,8 @@ class JsxAdapter extends BaseAdapter {
4001
4093
  const keyword = c.declarationKind ?? "const";
4002
4094
  const exportKw = c.isExported ? "export " : "";
4003
4095
  if (!c.value) {
4004
- entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}` });
4096
+ const typeAnnotation = preserveTypes && (c.typeAnnotation ?? c.type) ? `: ${c.typeAnnotation ?? c.type?.raw}` : "";
4097
+ entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${typeAnnotation}` });
4005
4098
  continue;
4006
4099
  }
4007
4100
  const trimmed = c.value.trim();
@@ -4010,7 +4103,8 @@ class JsxAdapter extends BaseAdapter {
4010
4103
  if (c.isExported && /^createContext\b/.test(trimmed))
4011
4104
  continue;
4012
4105
  const value = preserveTypes ? c.typedValue ?? c.value : c.value;
4013
- entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name} = ${value}` });
4106
+ const letTypeAnnotation = preserveTypes && keyword === "let" && c.typeAnnotation ? `: ${c.typeAnnotation}` : "";
4107
+ entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${letTypeAnnotation} = ${value}` });
4014
4108
  }
4015
4109
  for (const f of ir.metadata.localFunctions) {
4016
4110
  if (!f.isModule || !moduleNames.has(f.name))
@@ -4059,6 +4153,7 @@ class JsxAdapter extends BaseAdapter {
4059
4153
  }
4060
4154
 
4061
4155
  // ../jsx/src/adapters/template-imports.ts
4156
+ import ts25 from "typescript";
4062
4157
  var CLIENT_PACKAGE_SOURCES = new Set([
4063
4158
  "@barefootjs/client",
4064
4159
  "@barefootjs/client/runtime"
@@ -4732,7 +4827,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
4732
4827
  };
4733
4828
  }
4734
4829
  // ../jsx/src/combine-client-js.ts
4735
- import ts25 from "typescript";
4830
+ import ts26 from "typescript";
4736
4831
  // ../jsx/src/loop-destructure.ts
4737
4832
  function isLowerableLoopDestructure(loop) {
4738
4833
  const bindings = loop.paramBindings;
@@ -4872,9 +4967,9 @@ function escapeRe(s) {
4872
4967
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4873
4968
  }
4874
4969
  // ../jsx/src/debug.ts
4875
- import ts26 from "typescript";
4876
- // ../jsx/src/profiler.ts
4877
4970
  import ts27 from "typescript";
4971
+ // ../jsx/src/profiler.ts
4972
+ import ts28 from "typescript";
4878
4973
 
4879
4974
  // ../jsx/src/index.ts
4880
4975
  registerBuiltinLoweringPlugins();
@@ -5745,7 +5840,7 @@ function collectImportedLoopChildComponentErrors(ir, componentName) {
5745
5840
  }
5746
5841
 
5747
5842
  // src/adapter/spread/spread-codegen.ts
5748
- import ts28 from "typescript";
5843
+ import ts29 from "typescript";
5749
5844
  function conditionalSpreadToRuby(ctx, expr) {
5750
5845
  if (!expr || expr.kind !== "conditional")
5751
5846
  return null;
@@ -5800,7 +5895,7 @@ function recordIndexAccessToRuby(ctx, val) {
5800
5895
  if (val.kind !== "index-access" || val.object.kind !== "identifier" || val.index.kind !== "identifier") {
5801
5896
  return null;
5802
5897
  }
5803
- const tsVal = ts28.factory.createElementAccessExpression(ts28.factory.createIdentifier(val.object.name), ts28.factory.createIdentifier(val.index.name));
5898
+ const tsVal = ts29.factory.createElementAccessExpression(ts29.factory.createIdentifier(val.object.name), ts29.factory.createIdentifier(val.index.name));
5804
5899
  const parsed = parseRecordIndexAccess(tsVal, ctx.localConstants, ctx.propsParams);
5805
5900
  if (!parsed)
5806
5901
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/erb",
3
- "version": "0.31.2",
3
+ "version": "0.31.4",
4
4
  "description": "ERB (Embedded Ruby) adapter for BarefootJS — compiles IR to .erb templates and ships the Ruby rendering backend; runs under any Rack app (Sinatra, Rails)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -54,7 +54,7 @@
54
54
  "directory": "packages/adapter-erb"
55
55
  },
56
56
  "dependencies": {
57
- "@barefootjs/shared": "0.31.2"
57
+ "@barefootjs/shared": "0.31.4"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@barefootjs/jsx": ">=0.2.0",
@@ -71,9 +71,9 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@barefootjs/adapter-tests": "0.1.0",
74
- "@barefootjs/jsx": "0.31.2",
75
- "@barefootjs/vite": "0.31.2",
76
- "@barefootjs/client": "0.31.2",
74
+ "@barefootjs/jsx": "0.31.4",
75
+ "@barefootjs/vite": "0.31.4",
76
+ "@barefootjs/client": "0.31.4",
77
77
  "typescript": "^5.0.0",
78
78
  "vite": "^6.0.0"
79
79
  }