@barefootjs/go-template 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 +111 -16
- 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
|
}
|
|
@@ -3879,7 +3970,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
3879
3970
|
lines.push(` const ${signal.getter} = () => ${initialValue}`);
|
|
3880
3971
|
}
|
|
3881
3972
|
if (signal.setter) {
|
|
3882
|
-
const setterUsed =
|
|
3973
|
+
const setterUsed = identifierPattern(signal.setter).test(setterRefText);
|
|
3883
3974
|
if (setterUsed) {
|
|
3884
3975
|
lines.push(` const ${signal.setter} = (..._args: any[]) => {}`);
|
|
3885
3976
|
}
|
|
@@ -3899,7 +3990,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
3899
3990
|
continue;
|
|
3900
3991
|
const keyword = constant.declarationKind ?? "const";
|
|
3901
3992
|
if (!constant.value) {
|
|
3902
|
-
const typeAnnotation = preserveTypes && constant.type ? `: ${constant.type
|
|
3993
|
+
const typeAnnotation = preserveTypes && (constant.typeAnnotation ?? constant.type) ? `: ${constant.typeAnnotation ?? constant.type?.raw}` : "";
|
|
3903
3994
|
lines.push(` ${keyword} ${constant.name}${typeAnnotation}`);
|
|
3904
3995
|
continue;
|
|
3905
3996
|
}
|
|
@@ -3909,7 +4000,8 @@ class JsxAdapter extends BaseAdapter {
|
|
|
3909
4000
|
if (!reachable.has(constant.name))
|
|
3910
4001
|
continue;
|
|
3911
4002
|
const constValue = preserveTypes ? constant.typedValue ?? constant.value : constant.value;
|
|
3912
|
-
|
|
4003
|
+
const letTypeAnnotation = preserveTypes && keyword === "let" && constant.typeAnnotation ? `: ${constant.typeAnnotation}` : "";
|
|
4004
|
+
lines.push(` ${keyword} ${constant.name}${letTypeAnnotation} = ${constValue}`);
|
|
3913
4005
|
}
|
|
3914
4006
|
for (const func of localFunctions) {
|
|
3915
4007
|
if (moduleScopeNames.has(func.name))
|
|
@@ -4016,7 +4108,8 @@ class JsxAdapter extends BaseAdapter {
|
|
|
4016
4108
|
const keyword = c.declarationKind ?? "const";
|
|
4017
4109
|
const exportKw = c.isExported ? "export " : "";
|
|
4018
4110
|
if (!c.value) {
|
|
4019
|
-
|
|
4111
|
+
const typeAnnotation = preserveTypes && (c.typeAnnotation ?? c.type) ? `: ${c.typeAnnotation ?? c.type?.raw}` : "";
|
|
4112
|
+
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${typeAnnotation}` });
|
|
4020
4113
|
continue;
|
|
4021
4114
|
}
|
|
4022
4115
|
const trimmed = c.value.trim();
|
|
@@ -4025,7 +4118,8 @@ class JsxAdapter extends BaseAdapter {
|
|
|
4025
4118
|
if (c.isExported && /^createContext\b/.test(trimmed))
|
|
4026
4119
|
continue;
|
|
4027
4120
|
const value = preserveTypes ? c.typedValue ?? c.value : c.value;
|
|
4028
|
-
|
|
4121
|
+
const letTypeAnnotation = preserveTypes && keyword === "let" && c.typeAnnotation ? `: ${c.typeAnnotation}` : "";
|
|
4122
|
+
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${letTypeAnnotation} = ${value}` });
|
|
4029
4123
|
}
|
|
4030
4124
|
for (const f of ir.metadata.localFunctions) {
|
|
4031
4125
|
if (!f.isModule || !moduleNames.has(f.name))
|
|
@@ -4074,6 +4168,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
4074
4168
|
}
|
|
4075
4169
|
|
|
4076
4170
|
// ../jsx/src/adapters/template-imports.ts
|
|
4171
|
+
import ts25 from "typescript";
|
|
4077
4172
|
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
4078
4173
|
"@barefootjs/client",
|
|
4079
4174
|
"@barefootjs/client/runtime"
|
|
@@ -4810,7 +4905,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
|
|
|
4810
4905
|
};
|
|
4811
4906
|
}
|
|
4812
4907
|
// ../jsx/src/combine-client-js.ts
|
|
4813
|
-
import
|
|
4908
|
+
import ts26 from "typescript";
|
|
4814
4909
|
// ../jsx/src/loop-destructure.ts
|
|
4815
4910
|
function isLowerableLoopDestructure(loop) {
|
|
4816
4911
|
const bindings = loop.paramBindings;
|
|
@@ -4950,9 +5045,9 @@ function escapeRe(s) {
|
|
|
4950
5045
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4951
5046
|
}
|
|
4952
5047
|
// ../jsx/src/debug.ts
|
|
4953
|
-
import ts26 from "typescript";
|
|
4954
|
-
// ../jsx/src/profiler.ts
|
|
4955
5048
|
import ts27 from "typescript";
|
|
5049
|
+
// ../jsx/src/profiler.ts
|
|
5050
|
+
import ts28 from "typescript";
|
|
4956
5051
|
|
|
4957
5052
|
// ../jsx/src/index.ts
|
|
4958
5053
|
registerBuiltinLoweringPlugins();
|
|
@@ -6583,7 +6678,7 @@ function computeObjectMemoInitialValue(ctx, memo) {
|
|
|
6583
6678
|
}
|
|
6584
6679
|
|
|
6585
6680
|
// src/adapter/memo/template-interp.ts
|
|
6586
|
-
import
|
|
6681
|
+
import ts29 from "typescript";
|
|
6587
6682
|
function computeTemplateLiteralMemoInitialValue(ctx, memo, propsParams) {
|
|
6588
6683
|
const localKeyBindings = new Map;
|
|
6589
6684
|
let templateValue;
|
|
@@ -7214,7 +7309,7 @@ function collectPropsReadByCtorInit(body, propsObjectName, propNames) {
|
|
|
7214
7309
|
}
|
|
7215
7310
|
|
|
7216
7311
|
// src/adapter/spread/spread-codegen.ts
|
|
7217
|
-
import
|
|
7312
|
+
import ts30 from "typescript";
|
|
7218
7313
|
function collectSpreadSlots(ctx, node) {
|
|
7219
7314
|
const result = [];
|
|
7220
7315
|
collectSpreadSlotsRecursive(ctx, node, result);
|
|
@@ -7449,7 +7544,7 @@ function recordIndexAccessToGoMap(ctx, val, ir) {
|
|
|
7449
7544
|
if (val.kind !== "index-access" || val.object.kind !== "identifier" || val.index.kind !== "identifier") {
|
|
7450
7545
|
return null;
|
|
7451
7546
|
}
|
|
7452
|
-
const tsVal =
|
|
7547
|
+
const tsVal = ts30.factory.createElementAccessExpression(ts30.factory.createIdentifier(val.object.name), ts30.factory.createIdentifier(val.index.name));
|
|
7453
7548
|
const parsed = parseRecordIndexAccess(tsVal, ir.metadata.localConstants ?? [], ir.metadata.propsParams);
|
|
7454
7549
|
if (!parsed)
|
|
7455
7550
|
return null;
|
|
@@ -9357,9 +9452,9 @@ ${goFields.join(`
|
|
|
9357
9452
|
}
|
|
9358
9453
|
}
|
|
9359
9454
|
const propsObjectName = this.state.propsObjectName;
|
|
9360
|
-
const
|
|
9361
|
-
const bareIdentifier =
|
|
9362
|
-
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;
|
|
9363
9458
|
const passthroughName = bareIdentifier ?? barePropAccess;
|
|
9364
9459
|
const localConst = this.state.localConstants.find((c) => c.name === passthroughName);
|
|
9365
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
|
}
|