@barefootjs/go-template 0.31.3 → 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 +104 -89
- package/package.json +5 -5
package/dist/vite.js
CHANGED
|
@@ -1946,6 +1946,20 @@ function templatePartsToJsExpr(parts, opts) {
|
|
|
1946
1946
|
return result;
|
|
1947
1947
|
}
|
|
1948
1948
|
|
|
1949
|
+
// ../jsx/src/identifier-pattern.ts
|
|
1950
|
+
function withUnicodeFlag(flags) {
|
|
1951
|
+
return flags.includes("u") ? flags : `${flags}u`;
|
|
1952
|
+
}
|
|
1953
|
+
function escapeIdentifierForRegex(name) {
|
|
1954
|
+
return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1955
|
+
}
|
|
1956
|
+
var ID_BOUNDARY_BEFORE = "(?<![\\p{ID_Continue}$])";
|
|
1957
|
+
var ID_BOUNDARY_AFTER = "(?![\\p{ID_Continue}$])";
|
|
1958
|
+
function identifierPattern(name, flags = "") {
|
|
1959
|
+
const esc = escapeIdentifierForRegex(name);
|
|
1960
|
+
return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}${ID_BOUNDARY_AFTER}`, withUnicodeFlag(flags));
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1949
1963
|
// ../jsx/src/scanner/js-scanner.ts
|
|
1950
1964
|
import ts2 from "typescript";
|
|
1951
1965
|
function* iterateJsTokens(text, start = 0, end = text.length) {
|
|
@@ -2135,6 +2149,83 @@ function extractFreeIdentifiersFromText(text) {
|
|
|
2135
2149
|
return extractFreeIdentifiersFromNode(expr);
|
|
2136
2150
|
}
|
|
2137
2151
|
|
|
2152
|
+
// ../jsx/src/scope/binding-scope.ts
|
|
2153
|
+
class BindingScope {
|
|
2154
|
+
frames;
|
|
2155
|
+
static EMPTY = new BindingScope([]);
|
|
2156
|
+
constructor(frames) {
|
|
2157
|
+
this.frames = frames;
|
|
2158
|
+
}
|
|
2159
|
+
enterLoopRow(loop) {
|
|
2160
|
+
const bindings = new Map;
|
|
2161
|
+
if (loop.paramBindings && loop.paramBindings.length > 0) {
|
|
2162
|
+
for (const b of loop.paramBindings)
|
|
2163
|
+
bindings.set(b.name, { source: "destructure" });
|
|
2164
|
+
} else {
|
|
2165
|
+
bindings.set(loop.param, { source: "item" });
|
|
2166
|
+
}
|
|
2167
|
+
if (loop.index != null)
|
|
2168
|
+
bindings.set(loop.index, { source: "index" });
|
|
2169
|
+
for (const name of loop.preamble?.declaredNames ?? [])
|
|
2170
|
+
bindings.set(name, { source: "preamble" });
|
|
2171
|
+
const frame = { kind: "loop-row", bindings };
|
|
2172
|
+
return new BindingScope([frame, ...this.frames]);
|
|
2173
|
+
}
|
|
2174
|
+
enterCallback(params) {
|
|
2175
|
+
const bindings = new Map;
|
|
2176
|
+
for (const name of params)
|
|
2177
|
+
bindings.set(name, { source: "param" });
|
|
2178
|
+
const frame = { kind: "callback", bindings };
|
|
2179
|
+
return new BindingScope([frame, ...this.frames]);
|
|
2180
|
+
}
|
|
2181
|
+
isBound(name) {
|
|
2182
|
+
for (const frame of this.frames) {
|
|
2183
|
+
if (frame.bindings.has(name))
|
|
2184
|
+
return true;
|
|
2185
|
+
}
|
|
2186
|
+
return false;
|
|
2187
|
+
}
|
|
2188
|
+
lookup(name) {
|
|
2189
|
+
for (let depth = 0;depth < this.frames.length; depth++) {
|
|
2190
|
+
const frame = this.frames[depth];
|
|
2191
|
+
const binding = frame.bindings.get(name);
|
|
2192
|
+
if (binding)
|
|
2193
|
+
return { depth, frame, binding };
|
|
2194
|
+
}
|
|
2195
|
+
return null;
|
|
2196
|
+
}
|
|
2197
|
+
boundNames() {
|
|
2198
|
+
if (this.boundNamesCache)
|
|
2199
|
+
return this.boundNamesCache;
|
|
2200
|
+
const names = new Set;
|
|
2201
|
+
for (const frame of this.frames) {
|
|
2202
|
+
for (const name of frame.bindings.keys())
|
|
2203
|
+
names.add(name);
|
|
2204
|
+
}
|
|
2205
|
+
this.boundNamesCache = names;
|
|
2206
|
+
return names;
|
|
2207
|
+
}
|
|
2208
|
+
boundNamesCache;
|
|
2209
|
+
valueBoundNamesCache;
|
|
2210
|
+
valueBoundNames() {
|
|
2211
|
+
if (this.valueBoundNamesCache)
|
|
2212
|
+
return this.valueBoundNamesCache;
|
|
2213
|
+
const names = new Set;
|
|
2214
|
+
for (const frame of this.frames) {
|
|
2215
|
+
for (const [name, binding] of frame.bindings) {
|
|
2216
|
+
if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
|
|
2217
|
+
names.add(name);
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
this.valueBoundNamesCache = names;
|
|
2222
|
+
return names;
|
|
2223
|
+
}
|
|
2224
|
+
asShadowPredicate() {
|
|
2225
|
+
return (name) => this.isBound(name);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2138
2229
|
// ../jsx/src/ir-to-client-js/html-template.ts
|
|
2139
2230
|
var VOID_ELEMENTS = new Set([
|
|
2140
2231
|
"area",
|
|
@@ -2569,7 +2660,7 @@ function findReachableNames(primaryRefs, declarations) {
|
|
|
2569
2660
|
const reachable = new Set;
|
|
2570
2661
|
const queue = [];
|
|
2571
2662
|
for (const name of allNames) {
|
|
2572
|
-
if (
|
|
2663
|
+
if (identifierPattern(name).test(primaryRefs)) {
|
|
2573
2664
|
reachable.add(name);
|
|
2574
2665
|
queue.push(name);
|
|
2575
2666
|
}
|
|
@@ -2578,7 +2669,7 @@ function findReachableNames(primaryRefs, declarations) {
|
|
|
2578
2669
|
const current = queue.shift();
|
|
2579
2670
|
const body = bodyMap.get(current) || "";
|
|
2580
2671
|
for (const name of allNames) {
|
|
2581
|
-
if (!reachable.has(name) &&
|
|
2672
|
+
if (!reachable.has(name) && identifierPattern(name).test(body)) {
|
|
2582
2673
|
reachable.add(name);
|
|
2583
2674
|
queue.push(name);
|
|
2584
2675
|
}
|
|
@@ -2909,83 +3000,6 @@ var toLocaleDatePlugin = {
|
|
|
2909
3000
|
}
|
|
2910
3001
|
};
|
|
2911
3002
|
|
|
2912
|
-
// ../jsx/src/scope/binding-scope.ts
|
|
2913
|
-
class BindingScope {
|
|
2914
|
-
frames;
|
|
2915
|
-
static EMPTY = new BindingScope([]);
|
|
2916
|
-
constructor(frames) {
|
|
2917
|
-
this.frames = frames;
|
|
2918
|
-
}
|
|
2919
|
-
enterLoopRow(loop) {
|
|
2920
|
-
const bindings = new Map;
|
|
2921
|
-
if (loop.paramBindings && loop.paramBindings.length > 0) {
|
|
2922
|
-
for (const b of loop.paramBindings)
|
|
2923
|
-
bindings.set(b.name, { source: "destructure" });
|
|
2924
|
-
} else {
|
|
2925
|
-
bindings.set(loop.param, { source: "item" });
|
|
2926
|
-
}
|
|
2927
|
-
if (loop.index != null)
|
|
2928
|
-
bindings.set(loop.index, { source: "index" });
|
|
2929
|
-
for (const name of loop.preamble?.declaredNames ?? [])
|
|
2930
|
-
bindings.set(name, { source: "preamble" });
|
|
2931
|
-
const frame = { kind: "loop-row", bindings };
|
|
2932
|
-
return new BindingScope([frame, ...this.frames]);
|
|
2933
|
-
}
|
|
2934
|
-
enterCallback(params) {
|
|
2935
|
-
const bindings = new Map;
|
|
2936
|
-
for (const name of params)
|
|
2937
|
-
bindings.set(name, { source: "param" });
|
|
2938
|
-
const frame = { kind: "callback", bindings };
|
|
2939
|
-
return new BindingScope([frame, ...this.frames]);
|
|
2940
|
-
}
|
|
2941
|
-
isBound(name) {
|
|
2942
|
-
for (const frame of this.frames) {
|
|
2943
|
-
if (frame.bindings.has(name))
|
|
2944
|
-
return true;
|
|
2945
|
-
}
|
|
2946
|
-
return false;
|
|
2947
|
-
}
|
|
2948
|
-
lookup(name) {
|
|
2949
|
-
for (let depth = 0;depth < this.frames.length; depth++) {
|
|
2950
|
-
const frame = this.frames[depth];
|
|
2951
|
-
const binding = frame.bindings.get(name);
|
|
2952
|
-
if (binding)
|
|
2953
|
-
return { depth, frame, binding };
|
|
2954
|
-
}
|
|
2955
|
-
return null;
|
|
2956
|
-
}
|
|
2957
|
-
boundNames() {
|
|
2958
|
-
if (this.boundNamesCache)
|
|
2959
|
-
return this.boundNamesCache;
|
|
2960
|
-
const names = new Set;
|
|
2961
|
-
for (const frame of this.frames) {
|
|
2962
|
-
for (const name of frame.bindings.keys())
|
|
2963
|
-
names.add(name);
|
|
2964
|
-
}
|
|
2965
|
-
this.boundNamesCache = names;
|
|
2966
|
-
return names;
|
|
2967
|
-
}
|
|
2968
|
-
boundNamesCache;
|
|
2969
|
-
valueBoundNamesCache;
|
|
2970
|
-
valueBoundNames() {
|
|
2971
|
-
if (this.valueBoundNamesCache)
|
|
2972
|
-
return this.valueBoundNamesCache;
|
|
2973
|
-
const names = new Set;
|
|
2974
|
-
for (const frame of this.frames) {
|
|
2975
|
-
for (const [name, binding] of frame.bindings) {
|
|
2976
|
-
if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
|
|
2977
|
-
names.add(name);
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2981
|
-
this.valueBoundNamesCache = names;
|
|
2982
|
-
return names;
|
|
2983
|
-
}
|
|
2984
|
-
asShadowPredicate() {
|
|
2985
|
-
return (name) => this.isBound(name);
|
|
2986
|
-
}
|
|
2987
|
-
}
|
|
2988
|
-
|
|
2989
3003
|
// ../jsx/src/jsx-to-ir.ts
|
|
2990
3004
|
var EMPTY_BOUND = new Set;
|
|
2991
3005
|
var constInitializerCache = new WeakMap;
|
|
@@ -3956,7 +3970,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
3956
3970
|
lines.push(` const ${signal.getter} = () => ${initialValue}`);
|
|
3957
3971
|
}
|
|
3958
3972
|
if (signal.setter) {
|
|
3959
|
-
const setterUsed =
|
|
3973
|
+
const setterUsed = identifierPattern(signal.setter).test(setterRefText);
|
|
3960
3974
|
if (setterUsed) {
|
|
3961
3975
|
lines.push(` const ${signal.setter} = (..._args: any[]) => {}`);
|
|
3962
3976
|
}
|
|
@@ -4154,6 +4168,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
4154
4168
|
}
|
|
4155
4169
|
|
|
4156
4170
|
// ../jsx/src/adapters/template-imports.ts
|
|
4171
|
+
import ts25 from "typescript";
|
|
4157
4172
|
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
4158
4173
|
"@barefootjs/client",
|
|
4159
4174
|
"@barefootjs/client/runtime"
|
|
@@ -4890,7 +4905,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
|
|
|
4890
4905
|
};
|
|
4891
4906
|
}
|
|
4892
4907
|
// ../jsx/src/combine-client-js.ts
|
|
4893
|
-
import
|
|
4908
|
+
import ts26 from "typescript";
|
|
4894
4909
|
// ../jsx/src/loop-destructure.ts
|
|
4895
4910
|
function isLowerableLoopDestructure(loop) {
|
|
4896
4911
|
const bindings = loop.paramBindings;
|
|
@@ -5030,9 +5045,9 @@ function escapeRe(s) {
|
|
|
5030
5045
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5031
5046
|
}
|
|
5032
5047
|
// ../jsx/src/debug.ts
|
|
5033
|
-
import ts26 from "typescript";
|
|
5034
|
-
// ../jsx/src/profiler.ts
|
|
5035
5048
|
import ts27 from "typescript";
|
|
5049
|
+
// ../jsx/src/profiler.ts
|
|
5050
|
+
import ts28 from "typescript";
|
|
5036
5051
|
|
|
5037
5052
|
// ../jsx/src/index.ts
|
|
5038
5053
|
registerBuiltinLoweringPlugins();
|
|
@@ -6663,7 +6678,7 @@ function computeObjectMemoInitialValue(ctx, memo) {
|
|
|
6663
6678
|
}
|
|
6664
6679
|
|
|
6665
6680
|
// src/adapter/memo/template-interp.ts
|
|
6666
|
-
import
|
|
6681
|
+
import ts29 from "typescript";
|
|
6667
6682
|
function computeTemplateLiteralMemoInitialValue(ctx, memo, propsParams) {
|
|
6668
6683
|
const localKeyBindings = new Map;
|
|
6669
6684
|
let templateValue;
|
|
@@ -7294,7 +7309,7 @@ function collectPropsReadByCtorInit(body, propsObjectName, propNames) {
|
|
|
7294
7309
|
}
|
|
7295
7310
|
|
|
7296
7311
|
// src/adapter/spread/spread-codegen.ts
|
|
7297
|
-
import
|
|
7312
|
+
import ts30 from "typescript";
|
|
7298
7313
|
function collectSpreadSlots(ctx, node) {
|
|
7299
7314
|
const result = [];
|
|
7300
7315
|
collectSpreadSlotsRecursive(ctx, node, result);
|
|
@@ -7529,7 +7544,7 @@ function recordIndexAccessToGoMap(ctx, val, ir) {
|
|
|
7529
7544
|
if (val.kind !== "index-access" || val.object.kind !== "identifier" || val.index.kind !== "identifier") {
|
|
7530
7545
|
return null;
|
|
7531
7546
|
}
|
|
7532
|
-
const tsVal =
|
|
7547
|
+
const tsVal = ts30.factory.createElementAccessExpression(ts30.factory.createIdentifier(val.object.name), ts30.factory.createIdentifier(val.index.name));
|
|
7533
7548
|
const parsed = parseRecordIndexAccess(tsVal, ir.metadata.localConstants ?? [], ir.metadata.propsParams);
|
|
7534
7549
|
if (!parsed)
|
|
7535
7550
|
return null;
|
|
@@ -9437,9 +9452,9 @@ ${goFields.join(`
|
|
|
9437
9452
|
}
|
|
9438
9453
|
}
|
|
9439
9454
|
const propsObjectName = this.state.propsObjectName;
|
|
9440
|
-
const
|
|
9441
|
-
const bareIdentifier =
|
|
9442
|
-
const barePropAccess = propsObjectName && expr.startsWith(`${propsObjectName}.`) &&
|
|
9455
|
+
const identifierPattern2 = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
9456
|
+
const bareIdentifier = identifierPattern2.test(expr) ? expr : null;
|
|
9457
|
+
const barePropAccess = propsObjectName && expr.startsWith(`${propsObjectName}.`) && identifierPattern2.test(expr.slice(propsObjectName.length + 1)) ? expr.slice(propsObjectName.length + 1) : null;
|
|
9443
9458
|
const passthroughName = bareIdentifier ?? barePropAccess;
|
|
9444
9459
|
const localConst = this.state.localConstants.find((c) => c.name === passthroughName);
|
|
9445
9460
|
const isPropsDestructureAlias = localConst !== undefined && propsObjectName !== null && localConst.value === `${propsObjectName}.${passthroughName}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/go-template",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.4",
|
|
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.31.
|
|
52
|
+
"@barefootjs/shared": "0.31.4"
|
|
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.31.
|
|
71
|
-
"@barefootjs/jsx": "0.31.
|
|
72
|
-
"@barefootjs/vite": "0.31.
|
|
70
|
+
"@barefootjs/client": "0.31.4",
|
|
71
|
+
"@barefootjs/jsx": "0.31.4",
|
|
72
|
+
"@barefootjs/vite": "0.31.4",
|
|
73
73
|
"vite": "^6.0.0"
|
|
74
74
|
}
|
|
75
75
|
}
|