@barefootjs/mojolicious 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.
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"
@@ -4822,7 +4917,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
4822
4917
  };
4823
4918
  }
4824
4919
  // ../jsx/src/combine-client-js.ts
4825
- import ts25 from "typescript";
4920
+ import ts26 from "typescript";
4826
4921
  // ../jsx/src/loop-destructure.ts
4827
4922
  function isLowerableLoopDestructure(loop) {
4828
4923
  const bindings = loop.paramBindings;
@@ -4962,9 +5057,9 @@ function escapeRe(s) {
4962
5057
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4963
5058
  }
4964
5059
  // ../jsx/src/debug.ts
4965
- import ts26 from "typescript";
4966
- // ../jsx/src/profiler.ts
4967
5060
  import ts27 from "typescript";
5061
+ // ../jsx/src/profiler.ts
5062
+ import ts28 from "typescript";
4968
5063
 
4969
5064
  // ../jsx/src/index.ts
4970
5065
  registerBuiltinLoweringPlugins();
@@ -5790,7 +5885,7 @@ function collectImportedLoopChildComponentErrors(ir, componentName) {
5790
5885
  }
5791
5886
 
5792
5887
  // src/adapter/spread/spread-codegen.ts
5793
- import ts28 from "typescript";
5888
+ import ts29 from "typescript";
5794
5889
  function conditionalSpreadToPerl(ctx, expr) {
5795
5890
  if (!expr || expr.kind !== "conditional")
5796
5891
  return null;
@@ -5845,7 +5940,7 @@ function recordIndexAccessToPerl(ctx, val) {
5845
5940
  if (val.kind !== "index-access" || val.object.kind !== "identifier" || val.index.kind !== "identifier") {
5846
5941
  return null;
5847
5942
  }
5848
- const tsVal = ts28.factory.createElementAccessExpression(ts28.factory.createIdentifier(val.object.name), ts28.factory.createIdentifier(val.index.name));
5943
+ const tsVal = ts29.factory.createElementAccessExpression(ts29.factory.createIdentifier(val.object.name), ts29.factory.createIdentifier(val.index.name));
5849
5944
  const parsed = parseRecordIndexAccess(tsVal, ctx.localConstants, ctx.propsParams);
5850
5945
  if (!parsed)
5851
5946
  return null;
@@ -1,5 +1,5 @@
1
1
  package BarefootJS::Backend::Mojo;
2
- our $VERSION = "0.31.1";
2
+ our $VERSION = "0.31.3";
3
3
  use Mojo::Base -base, -signatures;
4
4
 
5
5
  use Mojo::ByteStream qw(b);
@@ -1,5 +1,5 @@
1
1
  package Mojolicious::Plugin::BarefootJS::DevReload;
2
- our $VERSION = "0.31.1";
2
+ our $VERSION = "0.31.3";
3
3
  use Mojo::Base 'Mojolicious::Plugin', -signatures;
4
4
 
5
5
  =head1 NAME
@@ -1,5 +1,5 @@
1
1
  package Mojolicious::Plugin::BarefootJS;
2
- our $VERSION = "0.31.1";
2
+ our $VERSION = "0.31.3";
3
3
  use Mojo::Base 'Mojolicious::Plugin', -signatures;
4
4
 
5
5
  use Mojo::File qw(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/mojolicious",
3
- "version": "0.31.2",
3
+ "version": "0.31.4",
4
4
  "description": "Mojolicious EP template adapter for BarefootJS - generates .html.ep files from IR",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -52,7 +52,7 @@
52
52
  "directory": "packages/adapter-mojolicious"
53
53
  },
54
54
  "dependencies": {
55
- "@barefootjs/shared": "0.31.2"
55
+ "@barefootjs/shared": "0.31.4"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@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
  "vite": "^6.0.0"
77
77
  }
78
78
  }