@barefootjs/xslate 0.31.2 → 0.31.3

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
@@ -2839,6 +2839,83 @@ var toLocaleDatePlugin = {
2839
2839
  }
2840
2840
  };
2841
2841
 
2842
+ // ../jsx/src/scope/binding-scope.ts
2843
+ class BindingScope {
2844
+ frames;
2845
+ static EMPTY = new BindingScope([]);
2846
+ constructor(frames) {
2847
+ this.frames = frames;
2848
+ }
2849
+ enterLoopRow(loop) {
2850
+ const bindings = new Map;
2851
+ if (loop.paramBindings && loop.paramBindings.length > 0) {
2852
+ for (const b of loop.paramBindings)
2853
+ bindings.set(b.name, { source: "destructure" });
2854
+ } else {
2855
+ bindings.set(loop.param, { source: "item" });
2856
+ }
2857
+ if (loop.index != null)
2858
+ bindings.set(loop.index, { source: "index" });
2859
+ for (const name of loop.preamble?.declaredNames ?? [])
2860
+ bindings.set(name, { source: "preamble" });
2861
+ const frame = { kind: "loop-row", bindings };
2862
+ return new BindingScope([frame, ...this.frames]);
2863
+ }
2864
+ enterCallback(params) {
2865
+ const bindings = new Map;
2866
+ for (const name of params)
2867
+ bindings.set(name, { source: "param" });
2868
+ const frame = { kind: "callback", bindings };
2869
+ return new BindingScope([frame, ...this.frames]);
2870
+ }
2871
+ isBound(name) {
2872
+ for (const frame of this.frames) {
2873
+ if (frame.bindings.has(name))
2874
+ return true;
2875
+ }
2876
+ return false;
2877
+ }
2878
+ lookup(name) {
2879
+ for (let depth = 0;depth < this.frames.length; depth++) {
2880
+ const frame = this.frames[depth];
2881
+ const binding = frame.bindings.get(name);
2882
+ if (binding)
2883
+ return { depth, frame, binding };
2884
+ }
2885
+ return null;
2886
+ }
2887
+ boundNames() {
2888
+ if (this.boundNamesCache)
2889
+ return this.boundNamesCache;
2890
+ const names = new Set;
2891
+ for (const frame of this.frames) {
2892
+ for (const name of frame.bindings.keys())
2893
+ names.add(name);
2894
+ }
2895
+ this.boundNamesCache = names;
2896
+ return names;
2897
+ }
2898
+ boundNamesCache;
2899
+ valueBoundNamesCache;
2900
+ valueBoundNames() {
2901
+ if (this.valueBoundNamesCache)
2902
+ return this.valueBoundNamesCache;
2903
+ const names = new Set;
2904
+ for (const frame of this.frames) {
2905
+ for (const [name, binding] of frame.bindings) {
2906
+ if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
2907
+ names.add(name);
2908
+ }
2909
+ }
2910
+ }
2911
+ this.valueBoundNamesCache = names;
2912
+ return names;
2913
+ }
2914
+ asShadowPredicate() {
2915
+ return (name) => this.isBound(name);
2916
+ }
2917
+ }
2918
+
2842
2919
  // ../jsx/src/jsx-to-ir.ts
2843
2920
  var EMPTY_BOUND = new Set;
2844
2921
  var constInitializerCache = new WeakMap;
@@ -3884,7 +3961,7 @@ class JsxAdapter extends BaseAdapter {
3884
3961
  continue;
3885
3962
  const keyword = constant.declarationKind ?? "const";
3886
3963
  if (!constant.value) {
3887
- const typeAnnotation = preserveTypes && constant.type ? `: ${constant.type.raw}` : "";
3964
+ const typeAnnotation = preserveTypes && (constant.typeAnnotation ?? constant.type) ? `: ${constant.typeAnnotation ?? constant.type?.raw}` : "";
3888
3965
  lines.push(` ${keyword} ${constant.name}${typeAnnotation}`);
3889
3966
  continue;
3890
3967
  }
@@ -3894,7 +3971,8 @@ class JsxAdapter extends BaseAdapter {
3894
3971
  if (!reachable.has(constant.name))
3895
3972
  continue;
3896
3973
  const constValue = preserveTypes ? constant.typedValue ?? constant.value : constant.value;
3897
- lines.push(` ${keyword} ${constant.name} = ${constValue}`);
3974
+ const letTypeAnnotation = preserveTypes && keyword === "let" && constant.typeAnnotation ? `: ${constant.typeAnnotation}` : "";
3975
+ lines.push(` ${keyword} ${constant.name}${letTypeAnnotation} = ${constValue}`);
3898
3976
  }
3899
3977
  for (const func of localFunctions) {
3900
3978
  if (moduleScopeNames.has(func.name))
@@ -4001,7 +4079,8 @@ class JsxAdapter extends BaseAdapter {
4001
4079
  const keyword = c.declarationKind ?? "const";
4002
4080
  const exportKw = c.isExported ? "export " : "";
4003
4081
  if (!c.value) {
4004
- entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}` });
4082
+ const typeAnnotation = preserveTypes && (c.typeAnnotation ?? c.type) ? `: ${c.typeAnnotation ?? c.type?.raw}` : "";
4083
+ entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${typeAnnotation}` });
4005
4084
  continue;
4006
4085
  }
4007
4086
  const trimmed = c.value.trim();
@@ -4010,7 +4089,8 @@ class JsxAdapter extends BaseAdapter {
4010
4089
  if (c.isExported && /^createContext\b/.test(trimmed))
4011
4090
  continue;
4012
4091
  const value = preserveTypes ? c.typedValue ?? c.value : c.value;
4013
- entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name} = ${value}` });
4092
+ const letTypeAnnotation = preserveTypes && keyword === "let" && c.typeAnnotation ? `: ${c.typeAnnotation}` : "";
4093
+ entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${letTypeAnnotation} = ${value}` });
4014
4094
  }
4015
4095
  for (const f of ir.metadata.localFunctions) {
4016
4096
  if (!f.isModule || !moduleNames.has(f.name))
@@ -1,5 +1,5 @@
1
1
  package BarefootJS::Backend::Xslate;
2
- our $VERSION = "0.31.1";
2
+ our $VERSION = "0.31.2";
3
3
  use strict;
4
4
  use warnings;
5
5
  use utf8;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/xslate",
3
- "version": "0.31.2",
3
+ "version": "0.31.3",
4
4
  "description": "Text::Xslate (Kolon) adapter for BarefootJS — compiles IR to .tx templates and ships the Xslate rendering backend; runs under any PSGI/Plack app",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -55,7 +55,7 @@
55
55
  "directory": "packages/adapter-xslate"
56
56
  },
57
57
  "dependencies": {
58
- "@barefootjs/shared": "0.31.2"
58
+ "@barefootjs/shared": "0.31.3"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@barefootjs/jsx": ">=0.2.0",
@@ -72,9 +72,9 @@
72
72
  },
73
73
  "devDependencies": {
74
74
  "@barefootjs/adapter-tests": "0.1.0",
75
- "@barefootjs/jsx": "0.31.2",
76
- "@barefootjs/vite": "0.31.2",
77
- "@barefootjs/client": "0.31.2",
75
+ "@barefootjs/jsx": "0.31.3",
76
+ "@barefootjs/vite": "0.31.3",
77
+ "@barefootjs/client": "0.31.3",
78
78
  "typescript": "^5.0.0",
79
79
  "vite": "^6.0.0"
80
80
  }