@barefootjs/go-template 0.5.3 → 0.6.1
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/adapter/go-template-adapter.d.ts +5 -2
- package/dist/adapter/go-template-adapter.d.ts.map +1 -1
- package/dist/adapter/index.js +104 -23
- package/dist/build.js +104 -23
- package/dist/index.js +104 -23
- package/package.json +2 -2
- package/src/__tests__/go-template-adapter.test.ts +199 -18
- package/src/adapter/go-template-adapter.ts +213 -22
- package/src/test-render.ts +8 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Generates Go html/template files from BarefootJS IR.
|
|
5
5
|
*/
|
|
6
|
-
import type { ComponentIR, IRNode, IRElement, IRText, IRExpression, IRConditional, IRLoop, IRComponent, IRFragment, IRSlot, ParsedExpr, SortComparator, TemplatePart, IRIfStatement, IRProvider, IRAsync, TemplatePrimitiveRegistry } from '@barefootjs/jsx';
|
|
6
|
+
import type { ComponentIR, IRNode, IRElement, IRText, IRExpression, IRConditional, IRLoop, IRComponent, IRFragment, IRSlot, ParsedExpr, SortComparator, ReduceOp, FlatDepth, FlatMapOp, TemplatePart, IRIfStatement, IRProvider, IRAsync, TemplatePrimitiveRegistry } from '@barefootjs/jsx';
|
|
7
7
|
import { BaseAdapter, type AdapterOutput, type AdapterGenerateOptions, type ParsedExprEmitter, type HigherOrderMethod, type ArrayMethod, type LiteralType, type IRNodeEmitter, type EmitIRNode } from '@barefootjs/jsx';
|
|
8
8
|
/**
|
|
9
9
|
* Go-template adapter's IRNode render context. Only `isRootOfClientComponent`
|
|
@@ -469,7 +469,7 @@ export declare class GoTemplateAdapter extends BaseAdapter implements ParsedExpr
|
|
|
469
469
|
*/
|
|
470
470
|
private static GO_IDENTIFIER;
|
|
471
471
|
/** Go common initialisms that should be fully uppercased (https://go.dev/wiki/CodeReviewComments#initialisms) */
|
|
472
|
-
|
|
472
|
+
static GO_INITIALISMS: Set<string>;
|
|
473
473
|
/**
|
|
474
474
|
* (#1423) Go reserved keywords. When we hoist a local var named after
|
|
475
475
|
* a JSX prop, the prop name could collide with one of these — append
|
|
@@ -567,6 +567,9 @@ export declare class GoTemplateAdapter extends BaseAdapter implements ParsedExpr
|
|
|
567
567
|
higherOrder(method: HigherOrderMethod, object: ParsedExpr, param: string, predicate: ParsedExpr, emit: (e: ParsedExpr) => string): string;
|
|
568
568
|
arrayMethod(method: ArrayMethod, object: ParsedExpr, args: ParsedExpr[], emit: (e: ParsedExpr) => string): string;
|
|
569
569
|
sortMethod(method: 'sort' | 'toSorted', object: ParsedExpr, comparator: SortComparator, emit: (e: ParsedExpr) => string): string;
|
|
570
|
+
reduceMethod(method: 'reduce' | 'reduceRight', object: ParsedExpr, reduceOp: ReduceOp, emit: (e: ParsedExpr) => string): string;
|
|
571
|
+
flatMethod(object: ParsedExpr, depth: FlatDepth, emit: (e: ParsedExpr) => string): string;
|
|
572
|
+
flatMapMethod(object: ParsedExpr, op: FlatMapOp, emit: (e: ParsedExpr) => string): string;
|
|
570
573
|
unsupported(raw: string, _reason: string): string;
|
|
571
574
|
/**
|
|
572
575
|
* Extract field name and negation from a simple predicate.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"go-template-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/go-template-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,YAAY,EACZ,aAAa,EACb,MAAM,EAEN,WAAW,EACX,UAAU,EACV,MAAM,EAON,UAAU,EAEV,cAAc,EACd,YAAY,EACZ,aAAa,EACb,UAAU,EACV,OAAO,EACP,yBAAyB,EAC1B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAE3B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"go-template-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/go-template-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,YAAY,EACZ,aAAa,EACb,MAAM,EAEN,WAAW,EACX,UAAU,EACV,MAAM,EAON,UAAU,EAEV,cAAc,EACd,QAAQ,EACR,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,UAAU,EACV,OAAO,EACP,yBAAyB,EAC1B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAE3B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,UAAU,EAWhB,MAAM,iBAAiB,CAAA;AAGxB;;;;;GAKG;AACH,KAAK,WAAW,GAAG;IACjB,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAClC,CAAA;AA2ED,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEzB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AA+JD,qBAAa,iBAAkB,SAAQ,WAAY,YAAW,iBAAiB,EAAE,aAAa,CAAC,WAAW,CAAC;IACzG,IAAI,SAAgB;IACpB,SAAS,SAAU;IAGnB,kBAAkB,EAAG,cAAc,CAAS;IAQ5C,OAAO,CAAC,eAAe,CAAI;IAC3B,OAAO,CAAC,qBAAqB,CAAQ;IAErC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,kBAAkB,EAAE,yBAAyB,CAG1C;IAEH;;;;;;;;;OASG;IACH,OAAO,CAAC,QA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OAWG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAyElC;IAED,OAAO,CAAC,gBAAgB;IAsBxB;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,0BAA0B;IA4BlC;;;;;;;;OAQG;IACH,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,0BAA0B;IAiClC,iBAAiB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAKjD;IAED,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvC;IAED,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvC;IAED,OAAO,CAAC,kBAAkB;CAmB3B;AAED,eAAO,MAAM,iBAAiB,mBAA0B,CAAA"}
|
package/dist/adapter/index.js
CHANGED
|
@@ -51,8 +51,20 @@ function emitBfSort(recv, c) {
|
|
|
51
51
|
});
|
|
52
52
|
return `bf_sort ${wrapIfMultiToken(recv)} ${groups.join(" ")}`;
|
|
53
53
|
}
|
|
54
|
+
function emitBfReduce(recv, op, direction) {
|
|
55
|
+
const keyName = op.key.kind === "field" ? capitalize(op.key.field) : "";
|
|
56
|
+
return `bf_reduce ${wrapIfMultiToken(recv)} "${op.op}" "${op.key.kind}" "${keyName}" "${op.type}" "${escapeGoString(op.init)}" "${direction}"`;
|
|
57
|
+
}
|
|
58
|
+
function escapeGoString(s) {
|
|
59
|
+
return s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
60
|
+
}
|
|
54
61
|
function capitalize(s) {
|
|
55
|
-
|
|
62
|
+
if (s.length === 0)
|
|
63
|
+
return s;
|
|
64
|
+
if (GoTemplateAdapter.GO_INITIALISMS.has(s.toLowerCase())) {
|
|
65
|
+
return s.toUpperCase();
|
|
66
|
+
}
|
|
67
|
+
return s[0].toUpperCase() + s.slice(1);
|
|
56
68
|
}
|
|
57
69
|
function slotIdToFieldSuffix(slotId) {
|
|
58
70
|
const cleanId = slotId.startsWith("^") ? slotId.slice(1) : slotId;
|
|
@@ -62,6 +74,18 @@ function slotIdToFieldSuffix(slotId) {
|
|
|
62
74
|
}
|
|
63
75
|
return cleanId.replace("slot_", "Slot");
|
|
64
76
|
}
|
|
77
|
+
var GO_REMEDIATION_OPTIONS = `Options:
|
|
78
|
+
1. Use @client directive for client-side evaluation
|
|
79
|
+
2. Pre-compute the value in Go code`;
|
|
80
|
+
function buildUnsupportedSuggestion(support) {
|
|
81
|
+
if (!support.reason)
|
|
82
|
+
return GO_REMEDIATION_OPTIONS;
|
|
83
|
+
if (support.selfContained)
|
|
84
|
+
return support.reason;
|
|
85
|
+
return `${support.reason}
|
|
86
|
+
|
|
87
|
+
${GO_REMEDIATION_OPTIONS}`;
|
|
88
|
+
}
|
|
65
89
|
var GO_TEMPLATE_PRIMITIVES = {
|
|
66
90
|
"JSON.stringify": { arity: 1, emit: (args) => `bf_json ${args[0]}` },
|
|
67
91
|
String: { arity: 1, emit: (args) => `bf_string ${args[0]}` },
|
|
@@ -1905,9 +1929,7 @@ ${goFields.join(`
|
|
|
1905
1929
|
message: `Higher-order method '.${method}' shape cannot be lowered to a Go template action`,
|
|
1906
1930
|
loc: this.makeLoc(),
|
|
1907
1931
|
suggestion: {
|
|
1908
|
-
message:
|
|
1909
|
-
1. Use @client directive for client-side evaluation
|
|
1910
|
-
2. Pre-compute the value in Go code`
|
|
1932
|
+
message: GO_REMEDIATION_OPTIONS
|
|
1911
1933
|
}
|
|
1912
1934
|
});
|
|
1913
1935
|
return `""`;
|
|
@@ -1916,7 +1938,7 @@ ${goFields.join(`
|
|
|
1916
1938
|
switch (method) {
|
|
1917
1939
|
case "join": {
|
|
1918
1940
|
const obj = emit(object);
|
|
1919
|
-
const sep = emit(args[0]);
|
|
1941
|
+
const sep = args.length >= 1 ? emit(args[0]) : '","';
|
|
1920
1942
|
return `bf_join (${obj}) ${wrapIfMultiToken(sep)}`;
|
|
1921
1943
|
}
|
|
1922
1944
|
case "includes": {
|
|
@@ -1933,18 +1955,21 @@ ${goFields.join(`
|
|
|
1933
1955
|
}
|
|
1934
1956
|
case "at": {
|
|
1935
1957
|
const obj = emit(object);
|
|
1936
|
-
const idx = emit(args[0]);
|
|
1958
|
+
const idx = args.length >= 1 ? emit(args[0]) : "0";
|
|
1937
1959
|
return `bf_at ${wrapIfMultiToken(obj)} ${wrapIfMultiToken(idx)}`;
|
|
1938
1960
|
}
|
|
1939
1961
|
case "concat": {
|
|
1962
|
+
if (args.length === 0) {
|
|
1963
|
+
return emit(object);
|
|
1964
|
+
}
|
|
1940
1965
|
const a = emit(object);
|
|
1941
1966
|
const b = emit(args[0]);
|
|
1942
1967
|
return `bf_concat ${wrapIfMultiToken(a)} ${wrapIfMultiToken(b)}`;
|
|
1943
1968
|
}
|
|
1944
1969
|
case "slice": {
|
|
1945
1970
|
const recv = emit(object);
|
|
1946
|
-
const start = emit(args[0]);
|
|
1947
|
-
if (args.length
|
|
1971
|
+
const start = args.length >= 1 ? emit(args[0]) : "0";
|
|
1972
|
+
if (args.length <= 1) {
|
|
1948
1973
|
return `bf_slice ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(start)}`;
|
|
1949
1974
|
}
|
|
1950
1975
|
const end = emit(args[1]);
|
|
@@ -1967,6 +1992,54 @@ ${goFields.join(`
|
|
|
1967
1992
|
const recv = emit(object);
|
|
1968
1993
|
return `bf_trim ${wrapIfMultiToken(recv)}`;
|
|
1969
1994
|
}
|
|
1995
|
+
case "split": {
|
|
1996
|
+
const recv = emit(object);
|
|
1997
|
+
if (args.length === 0) {
|
|
1998
|
+
return `bf_arr ${wrapIfMultiToken(recv)}`;
|
|
1999
|
+
}
|
|
2000
|
+
const sep = emit(args[0]);
|
|
2001
|
+
if (args.length === 1) {
|
|
2002
|
+
return `bf_split ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(sep)}`;
|
|
2003
|
+
}
|
|
2004
|
+
const limit = emit(args[1]);
|
|
2005
|
+
return `bf_split ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(sep)} ${wrapIfMultiToken(limit)}`;
|
|
2006
|
+
}
|
|
2007
|
+
case "startsWith":
|
|
2008
|
+
case "endsWith": {
|
|
2009
|
+
const fn = method === "startsWith" ? "bf_starts_with" : "bf_ends_with";
|
|
2010
|
+
const recv = emit(object);
|
|
2011
|
+
const arg = emit(args[0]);
|
|
2012
|
+
const base = `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(arg)}`;
|
|
2013
|
+
if (args.length >= 2) {
|
|
2014
|
+
return `${base} ${wrapIfMultiToken(emit(args[1]))}`;
|
|
2015
|
+
}
|
|
2016
|
+
return base;
|
|
2017
|
+
}
|
|
2018
|
+
case "replace": {
|
|
2019
|
+
const recv = emit(object);
|
|
2020
|
+
const oldS = emit(args[0]);
|
|
2021
|
+
const newS = emit(args[1]);
|
|
2022
|
+
return `bf_replace ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(oldS)} ${wrapIfMultiToken(newS)}`;
|
|
2023
|
+
}
|
|
2024
|
+
case "repeat": {
|
|
2025
|
+
const recv = emit(object);
|
|
2026
|
+
const count = args.length === 0 ? "0" : emit(args[0]);
|
|
2027
|
+
return `bf_repeat ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(count)}`;
|
|
2028
|
+
}
|
|
2029
|
+
case "padStart":
|
|
2030
|
+
case "padEnd": {
|
|
2031
|
+
const fn = method === "padStart" ? "bf_pad_start" : "bf_pad_end";
|
|
2032
|
+
const recv = emit(object);
|
|
2033
|
+
if (args.length === 0) {
|
|
2034
|
+
return `${fn} ${wrapIfMultiToken(recv)} 0`;
|
|
2035
|
+
}
|
|
2036
|
+
const target = emit(args[0]);
|
|
2037
|
+
if (args.length === 1) {
|
|
2038
|
+
return `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(target)}`;
|
|
2039
|
+
}
|
|
2040
|
+
const pad = emit(args[1]);
|
|
2041
|
+
return `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(target)} ${wrapIfMultiToken(pad)}`;
|
|
2042
|
+
}
|
|
1970
2043
|
default: {
|
|
1971
2044
|
const _exhaustive = method;
|
|
1972
2045
|
throw new Error(`Go arrayMethod: unhandled ArrayMethod '${_exhaustive}'`);
|
|
@@ -1976,6 +2049,26 @@ ${goFields.join(`
|
|
|
1976
2049
|
sortMethod(method, object, comparator, emit) {
|
|
1977
2050
|
return emitBfSort(emit(object), comparator);
|
|
1978
2051
|
}
|
|
2052
|
+
reduceMethod(method, object, reduceOp, emit) {
|
|
2053
|
+
const direction = method === "reduceRight" ? "right" : "left";
|
|
2054
|
+
return emitBfReduce(emit(object), reduceOp, direction);
|
|
2055
|
+
}
|
|
2056
|
+
flatMethod(object, depth, emit) {
|
|
2057
|
+
const d = depth === "infinity" ? -1 : depth;
|
|
2058
|
+
return `bf_flat ${wrapIfMultiToken(emit(object))} ${d}`;
|
|
2059
|
+
}
|
|
2060
|
+
flatMapMethod(object, op, emit) {
|
|
2061
|
+
const recv = wrapIfMultiToken(emit(object));
|
|
2062
|
+
const proj = op.projection;
|
|
2063
|
+
if (proj.kind === "tuple") {
|
|
2064
|
+
const pairs = proj.elements.map((l) => l.kind === "self" ? `"self" ""` : `"field" "${capitalize(l.field)}"`).join(" ");
|
|
2065
|
+
return `bf_flat_map_tuple ${recv} ${pairs}`;
|
|
2066
|
+
}
|
|
2067
|
+
if (proj.kind === "self") {
|
|
2068
|
+
return `bf_flat_map ${recv} "self" ""`;
|
|
2069
|
+
}
|
|
2070
|
+
return `bf_flat_map ${recv} "field" "${capitalize(proj.field)}"`;
|
|
2071
|
+
}
|
|
1979
2072
|
unsupported(raw, _reason) {
|
|
1980
2073
|
return `[UNSUPPORTED: ${raw}]`;
|
|
1981
2074
|
}
|
|
@@ -2398,13 +2491,7 @@ ${goFields.join(`
|
|
|
2398
2491
|
message: `Expression not supported: ${trimmed}`,
|
|
2399
2492
|
loc: this.makeLoc(),
|
|
2400
2493
|
suggestion: {
|
|
2401
|
-
message: support
|
|
2402
|
-
|
|
2403
|
-
Options:
|
|
2404
|
-
1. Use @client directive for client-side evaluation
|
|
2405
|
-
2. Pre-compute the value in Go code` : `Options:
|
|
2406
|
-
1. Use @client directive for client-side evaluation
|
|
2407
|
-
2. Pre-compute the value in Go code`
|
|
2494
|
+
message: buildUnsupportedSuggestion(support)
|
|
2408
2495
|
}
|
|
2409
2496
|
});
|
|
2410
2497
|
return `""`;
|
|
@@ -2433,9 +2520,7 @@ Options:
|
|
|
2433
2520
|
message: `Complex predicate in else-if is not supported: ${altIfStmt.condition}`,
|
|
2434
2521
|
loc: this.makeLoc(),
|
|
2435
2522
|
suggestion: {
|
|
2436
|
-
message:
|
|
2437
|
-
1. Use @client directive for client-side evaluation
|
|
2438
|
-
2. Pre-compute the value in Go code`
|
|
2523
|
+
message: GO_REMEDIATION_OPTIONS
|
|
2439
2524
|
}
|
|
2440
2525
|
});
|
|
2441
2526
|
}
|
|
@@ -2511,11 +2596,7 @@ Options:
|
|
|
2511
2596
|
message: `Condition not supported: ${trimmed}`,
|
|
2512
2597
|
loc: this.makeLoc(),
|
|
2513
2598
|
suggestion: {
|
|
2514
|
-
message: support
|
|
2515
|
-
|
|
2516
|
-
Options:
|
|
2517
|
-
1. Use @client directive for client-side evaluation
|
|
2518
|
-
2. Pre-compute the value in Go code` : "Expression contains unsupported syntax"
|
|
2599
|
+
message: buildUnsupportedSuggestion(support)
|
|
2519
2600
|
}
|
|
2520
2601
|
});
|
|
2521
2602
|
return { condition: `false`, preamble: "" };
|
package/dist/build.js
CHANGED
|
@@ -391,8 +391,20 @@ function emitBfSort(recv, c) {
|
|
|
391
391
|
});
|
|
392
392
|
return `bf_sort ${wrapIfMultiToken(recv)} ${groups.join(" ")}`;
|
|
393
393
|
}
|
|
394
|
+
function emitBfReduce(recv, op, direction) {
|
|
395
|
+
const keyName = op.key.kind === "field" ? capitalize(op.key.field) : "";
|
|
396
|
+
return `bf_reduce ${wrapIfMultiToken(recv)} "${op.op}" "${op.key.kind}" "${keyName}" "${op.type}" "${escapeGoString(op.init)}" "${direction}"`;
|
|
397
|
+
}
|
|
398
|
+
function escapeGoString(s) {
|
|
399
|
+
return s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
400
|
+
}
|
|
394
401
|
function capitalize(s) {
|
|
395
|
-
|
|
402
|
+
if (s.length === 0)
|
|
403
|
+
return s;
|
|
404
|
+
if (GoTemplateAdapter.GO_INITIALISMS.has(s.toLowerCase())) {
|
|
405
|
+
return s.toUpperCase();
|
|
406
|
+
}
|
|
407
|
+
return s[0].toUpperCase() + s.slice(1);
|
|
396
408
|
}
|
|
397
409
|
function slotIdToFieldSuffix(slotId) {
|
|
398
410
|
const cleanId = slotId.startsWith("^") ? slotId.slice(1) : slotId;
|
|
@@ -402,6 +414,18 @@ function slotIdToFieldSuffix(slotId) {
|
|
|
402
414
|
}
|
|
403
415
|
return cleanId.replace("slot_", "Slot");
|
|
404
416
|
}
|
|
417
|
+
var GO_REMEDIATION_OPTIONS = `Options:
|
|
418
|
+
1. Use @client directive for client-side evaluation
|
|
419
|
+
2. Pre-compute the value in Go code`;
|
|
420
|
+
function buildUnsupportedSuggestion(support) {
|
|
421
|
+
if (!support.reason)
|
|
422
|
+
return GO_REMEDIATION_OPTIONS;
|
|
423
|
+
if (support.selfContained)
|
|
424
|
+
return support.reason;
|
|
425
|
+
return `${support.reason}
|
|
426
|
+
|
|
427
|
+
${GO_REMEDIATION_OPTIONS}`;
|
|
428
|
+
}
|
|
405
429
|
var GO_TEMPLATE_PRIMITIVES = {
|
|
406
430
|
"JSON.stringify": { arity: 1, emit: (args) => `bf_json ${args[0]}` },
|
|
407
431
|
String: { arity: 1, emit: (args) => `bf_string ${args[0]}` },
|
|
@@ -2245,9 +2269,7 @@ ${goFields.join(`
|
|
|
2245
2269
|
message: `Higher-order method '.${method}' shape cannot be lowered to a Go template action`,
|
|
2246
2270
|
loc: this.makeLoc(),
|
|
2247
2271
|
suggestion: {
|
|
2248
|
-
message:
|
|
2249
|
-
1. Use @client directive for client-side evaluation
|
|
2250
|
-
2. Pre-compute the value in Go code`
|
|
2272
|
+
message: GO_REMEDIATION_OPTIONS
|
|
2251
2273
|
}
|
|
2252
2274
|
});
|
|
2253
2275
|
return `""`;
|
|
@@ -2256,7 +2278,7 @@ ${goFields.join(`
|
|
|
2256
2278
|
switch (method) {
|
|
2257
2279
|
case "join": {
|
|
2258
2280
|
const obj = emit(object);
|
|
2259
|
-
const sep = emit(args[0]);
|
|
2281
|
+
const sep = args.length >= 1 ? emit(args[0]) : '","';
|
|
2260
2282
|
return `bf_join (${obj}) ${wrapIfMultiToken(sep)}`;
|
|
2261
2283
|
}
|
|
2262
2284
|
case "includes": {
|
|
@@ -2273,18 +2295,21 @@ ${goFields.join(`
|
|
|
2273
2295
|
}
|
|
2274
2296
|
case "at": {
|
|
2275
2297
|
const obj = emit(object);
|
|
2276
|
-
const idx = emit(args[0]);
|
|
2298
|
+
const idx = args.length >= 1 ? emit(args[0]) : "0";
|
|
2277
2299
|
return `bf_at ${wrapIfMultiToken(obj)} ${wrapIfMultiToken(idx)}`;
|
|
2278
2300
|
}
|
|
2279
2301
|
case "concat": {
|
|
2302
|
+
if (args.length === 0) {
|
|
2303
|
+
return emit(object);
|
|
2304
|
+
}
|
|
2280
2305
|
const a = emit(object);
|
|
2281
2306
|
const b = emit(args[0]);
|
|
2282
2307
|
return `bf_concat ${wrapIfMultiToken(a)} ${wrapIfMultiToken(b)}`;
|
|
2283
2308
|
}
|
|
2284
2309
|
case "slice": {
|
|
2285
2310
|
const recv = emit(object);
|
|
2286
|
-
const start = emit(args[0]);
|
|
2287
|
-
if (args.length
|
|
2311
|
+
const start = args.length >= 1 ? emit(args[0]) : "0";
|
|
2312
|
+
if (args.length <= 1) {
|
|
2288
2313
|
return `bf_slice ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(start)}`;
|
|
2289
2314
|
}
|
|
2290
2315
|
const end = emit(args[1]);
|
|
@@ -2307,6 +2332,54 @@ ${goFields.join(`
|
|
|
2307
2332
|
const recv = emit(object);
|
|
2308
2333
|
return `bf_trim ${wrapIfMultiToken(recv)}`;
|
|
2309
2334
|
}
|
|
2335
|
+
case "split": {
|
|
2336
|
+
const recv = emit(object);
|
|
2337
|
+
if (args.length === 0) {
|
|
2338
|
+
return `bf_arr ${wrapIfMultiToken(recv)}`;
|
|
2339
|
+
}
|
|
2340
|
+
const sep = emit(args[0]);
|
|
2341
|
+
if (args.length === 1) {
|
|
2342
|
+
return `bf_split ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(sep)}`;
|
|
2343
|
+
}
|
|
2344
|
+
const limit = emit(args[1]);
|
|
2345
|
+
return `bf_split ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(sep)} ${wrapIfMultiToken(limit)}`;
|
|
2346
|
+
}
|
|
2347
|
+
case "startsWith":
|
|
2348
|
+
case "endsWith": {
|
|
2349
|
+
const fn = method === "startsWith" ? "bf_starts_with" : "bf_ends_with";
|
|
2350
|
+
const recv = emit(object);
|
|
2351
|
+
const arg = emit(args[0]);
|
|
2352
|
+
const base = `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(arg)}`;
|
|
2353
|
+
if (args.length >= 2) {
|
|
2354
|
+
return `${base} ${wrapIfMultiToken(emit(args[1]))}`;
|
|
2355
|
+
}
|
|
2356
|
+
return base;
|
|
2357
|
+
}
|
|
2358
|
+
case "replace": {
|
|
2359
|
+
const recv = emit(object);
|
|
2360
|
+
const oldS = emit(args[0]);
|
|
2361
|
+
const newS = emit(args[1]);
|
|
2362
|
+
return `bf_replace ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(oldS)} ${wrapIfMultiToken(newS)}`;
|
|
2363
|
+
}
|
|
2364
|
+
case "repeat": {
|
|
2365
|
+
const recv = emit(object);
|
|
2366
|
+
const count = args.length === 0 ? "0" : emit(args[0]);
|
|
2367
|
+
return `bf_repeat ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(count)}`;
|
|
2368
|
+
}
|
|
2369
|
+
case "padStart":
|
|
2370
|
+
case "padEnd": {
|
|
2371
|
+
const fn = method === "padStart" ? "bf_pad_start" : "bf_pad_end";
|
|
2372
|
+
const recv = emit(object);
|
|
2373
|
+
if (args.length === 0) {
|
|
2374
|
+
return `${fn} ${wrapIfMultiToken(recv)} 0`;
|
|
2375
|
+
}
|
|
2376
|
+
const target = emit(args[0]);
|
|
2377
|
+
if (args.length === 1) {
|
|
2378
|
+
return `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(target)}`;
|
|
2379
|
+
}
|
|
2380
|
+
const pad = emit(args[1]);
|
|
2381
|
+
return `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(target)} ${wrapIfMultiToken(pad)}`;
|
|
2382
|
+
}
|
|
2310
2383
|
default: {
|
|
2311
2384
|
const _exhaustive = method;
|
|
2312
2385
|
throw new Error(`Go arrayMethod: unhandled ArrayMethod '${_exhaustive}'`);
|
|
@@ -2316,6 +2389,26 @@ ${goFields.join(`
|
|
|
2316
2389
|
sortMethod(method, object, comparator, emit) {
|
|
2317
2390
|
return emitBfSort(emit(object), comparator);
|
|
2318
2391
|
}
|
|
2392
|
+
reduceMethod(method, object, reduceOp, emit) {
|
|
2393
|
+
const direction = method === "reduceRight" ? "right" : "left";
|
|
2394
|
+
return emitBfReduce(emit(object), reduceOp, direction);
|
|
2395
|
+
}
|
|
2396
|
+
flatMethod(object, depth, emit) {
|
|
2397
|
+
const d = depth === "infinity" ? -1 : depth;
|
|
2398
|
+
return `bf_flat ${wrapIfMultiToken(emit(object))} ${d}`;
|
|
2399
|
+
}
|
|
2400
|
+
flatMapMethod(object, op, emit) {
|
|
2401
|
+
const recv = wrapIfMultiToken(emit(object));
|
|
2402
|
+
const proj = op.projection;
|
|
2403
|
+
if (proj.kind === "tuple") {
|
|
2404
|
+
const pairs = proj.elements.map((l) => l.kind === "self" ? `"self" ""` : `"field" "${capitalize(l.field)}"`).join(" ");
|
|
2405
|
+
return `bf_flat_map_tuple ${recv} ${pairs}`;
|
|
2406
|
+
}
|
|
2407
|
+
if (proj.kind === "self") {
|
|
2408
|
+
return `bf_flat_map ${recv} "self" ""`;
|
|
2409
|
+
}
|
|
2410
|
+
return `bf_flat_map ${recv} "field" "${capitalize(proj.field)}"`;
|
|
2411
|
+
}
|
|
2319
2412
|
unsupported(raw, _reason) {
|
|
2320
2413
|
return `[UNSUPPORTED: ${raw}]`;
|
|
2321
2414
|
}
|
|
@@ -2738,13 +2831,7 @@ ${goFields.join(`
|
|
|
2738
2831
|
message: `Expression not supported: ${trimmed}`,
|
|
2739
2832
|
loc: this.makeLoc(),
|
|
2740
2833
|
suggestion: {
|
|
2741
|
-
message: support
|
|
2742
|
-
|
|
2743
|
-
Options:
|
|
2744
|
-
1. Use @client directive for client-side evaluation
|
|
2745
|
-
2. Pre-compute the value in Go code` : `Options:
|
|
2746
|
-
1. Use @client directive for client-side evaluation
|
|
2747
|
-
2. Pre-compute the value in Go code`
|
|
2834
|
+
message: buildUnsupportedSuggestion(support)
|
|
2748
2835
|
}
|
|
2749
2836
|
});
|
|
2750
2837
|
return `""`;
|
|
@@ -2773,9 +2860,7 @@ Options:
|
|
|
2773
2860
|
message: `Complex predicate in else-if is not supported: ${altIfStmt.condition}`,
|
|
2774
2861
|
loc: this.makeLoc(),
|
|
2775
2862
|
suggestion: {
|
|
2776
|
-
message:
|
|
2777
|
-
1. Use @client directive for client-side evaluation
|
|
2778
|
-
2. Pre-compute the value in Go code`
|
|
2863
|
+
message: GO_REMEDIATION_OPTIONS
|
|
2779
2864
|
}
|
|
2780
2865
|
});
|
|
2781
2866
|
}
|
|
@@ -2851,11 +2936,7 @@ Options:
|
|
|
2851
2936
|
message: `Condition not supported: ${trimmed}`,
|
|
2852
2937
|
loc: this.makeLoc(),
|
|
2853
2938
|
suggestion: {
|
|
2854
|
-
message: support
|
|
2855
|
-
|
|
2856
|
-
Options:
|
|
2857
|
-
1. Use @client directive for client-side evaluation
|
|
2858
|
-
2. Pre-compute the value in Go code` : "Expression contains unsupported syntax"
|
|
2939
|
+
message: buildUnsupportedSuggestion(support)
|
|
2859
2940
|
}
|
|
2860
2941
|
});
|
|
2861
2942
|
return { condition: `false`, preamble: "" };
|
package/dist/index.js
CHANGED
|
@@ -51,8 +51,20 @@ function emitBfSort(recv, c) {
|
|
|
51
51
|
});
|
|
52
52
|
return `bf_sort ${wrapIfMultiToken(recv)} ${groups.join(" ")}`;
|
|
53
53
|
}
|
|
54
|
+
function emitBfReduce(recv, op, direction) {
|
|
55
|
+
const keyName = op.key.kind === "field" ? capitalize(op.key.field) : "";
|
|
56
|
+
return `bf_reduce ${wrapIfMultiToken(recv)} "${op.op}" "${op.key.kind}" "${keyName}" "${op.type}" "${escapeGoString(op.init)}" "${direction}"`;
|
|
57
|
+
}
|
|
58
|
+
function escapeGoString(s) {
|
|
59
|
+
return s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
60
|
+
}
|
|
54
61
|
function capitalize(s) {
|
|
55
|
-
|
|
62
|
+
if (s.length === 0)
|
|
63
|
+
return s;
|
|
64
|
+
if (GoTemplateAdapter.GO_INITIALISMS.has(s.toLowerCase())) {
|
|
65
|
+
return s.toUpperCase();
|
|
66
|
+
}
|
|
67
|
+
return s[0].toUpperCase() + s.slice(1);
|
|
56
68
|
}
|
|
57
69
|
function slotIdToFieldSuffix(slotId) {
|
|
58
70
|
const cleanId = slotId.startsWith("^") ? slotId.slice(1) : slotId;
|
|
@@ -62,6 +74,18 @@ function slotIdToFieldSuffix(slotId) {
|
|
|
62
74
|
}
|
|
63
75
|
return cleanId.replace("slot_", "Slot");
|
|
64
76
|
}
|
|
77
|
+
var GO_REMEDIATION_OPTIONS = `Options:
|
|
78
|
+
1. Use @client directive for client-side evaluation
|
|
79
|
+
2. Pre-compute the value in Go code`;
|
|
80
|
+
function buildUnsupportedSuggestion(support) {
|
|
81
|
+
if (!support.reason)
|
|
82
|
+
return GO_REMEDIATION_OPTIONS;
|
|
83
|
+
if (support.selfContained)
|
|
84
|
+
return support.reason;
|
|
85
|
+
return `${support.reason}
|
|
86
|
+
|
|
87
|
+
${GO_REMEDIATION_OPTIONS}`;
|
|
88
|
+
}
|
|
65
89
|
var GO_TEMPLATE_PRIMITIVES = {
|
|
66
90
|
"JSON.stringify": { arity: 1, emit: (args) => `bf_json ${args[0]}` },
|
|
67
91
|
String: { arity: 1, emit: (args) => `bf_string ${args[0]}` },
|
|
@@ -1905,9 +1929,7 @@ ${goFields.join(`
|
|
|
1905
1929
|
message: `Higher-order method '.${method}' shape cannot be lowered to a Go template action`,
|
|
1906
1930
|
loc: this.makeLoc(),
|
|
1907
1931
|
suggestion: {
|
|
1908
|
-
message:
|
|
1909
|
-
1. Use @client directive for client-side evaluation
|
|
1910
|
-
2. Pre-compute the value in Go code`
|
|
1932
|
+
message: GO_REMEDIATION_OPTIONS
|
|
1911
1933
|
}
|
|
1912
1934
|
});
|
|
1913
1935
|
return `""`;
|
|
@@ -1916,7 +1938,7 @@ ${goFields.join(`
|
|
|
1916
1938
|
switch (method) {
|
|
1917
1939
|
case "join": {
|
|
1918
1940
|
const obj = emit(object);
|
|
1919
|
-
const sep = emit(args[0]);
|
|
1941
|
+
const sep = args.length >= 1 ? emit(args[0]) : '","';
|
|
1920
1942
|
return `bf_join (${obj}) ${wrapIfMultiToken(sep)}`;
|
|
1921
1943
|
}
|
|
1922
1944
|
case "includes": {
|
|
@@ -1933,18 +1955,21 @@ ${goFields.join(`
|
|
|
1933
1955
|
}
|
|
1934
1956
|
case "at": {
|
|
1935
1957
|
const obj = emit(object);
|
|
1936
|
-
const idx = emit(args[0]);
|
|
1958
|
+
const idx = args.length >= 1 ? emit(args[0]) : "0";
|
|
1937
1959
|
return `bf_at ${wrapIfMultiToken(obj)} ${wrapIfMultiToken(idx)}`;
|
|
1938
1960
|
}
|
|
1939
1961
|
case "concat": {
|
|
1962
|
+
if (args.length === 0) {
|
|
1963
|
+
return emit(object);
|
|
1964
|
+
}
|
|
1940
1965
|
const a = emit(object);
|
|
1941
1966
|
const b = emit(args[0]);
|
|
1942
1967
|
return `bf_concat ${wrapIfMultiToken(a)} ${wrapIfMultiToken(b)}`;
|
|
1943
1968
|
}
|
|
1944
1969
|
case "slice": {
|
|
1945
1970
|
const recv = emit(object);
|
|
1946
|
-
const start = emit(args[0]);
|
|
1947
|
-
if (args.length
|
|
1971
|
+
const start = args.length >= 1 ? emit(args[0]) : "0";
|
|
1972
|
+
if (args.length <= 1) {
|
|
1948
1973
|
return `bf_slice ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(start)}`;
|
|
1949
1974
|
}
|
|
1950
1975
|
const end = emit(args[1]);
|
|
@@ -1967,6 +1992,54 @@ ${goFields.join(`
|
|
|
1967
1992
|
const recv = emit(object);
|
|
1968
1993
|
return `bf_trim ${wrapIfMultiToken(recv)}`;
|
|
1969
1994
|
}
|
|
1995
|
+
case "split": {
|
|
1996
|
+
const recv = emit(object);
|
|
1997
|
+
if (args.length === 0) {
|
|
1998
|
+
return `bf_arr ${wrapIfMultiToken(recv)}`;
|
|
1999
|
+
}
|
|
2000
|
+
const sep = emit(args[0]);
|
|
2001
|
+
if (args.length === 1) {
|
|
2002
|
+
return `bf_split ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(sep)}`;
|
|
2003
|
+
}
|
|
2004
|
+
const limit = emit(args[1]);
|
|
2005
|
+
return `bf_split ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(sep)} ${wrapIfMultiToken(limit)}`;
|
|
2006
|
+
}
|
|
2007
|
+
case "startsWith":
|
|
2008
|
+
case "endsWith": {
|
|
2009
|
+
const fn = method === "startsWith" ? "bf_starts_with" : "bf_ends_with";
|
|
2010
|
+
const recv = emit(object);
|
|
2011
|
+
const arg = emit(args[0]);
|
|
2012
|
+
const base = `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(arg)}`;
|
|
2013
|
+
if (args.length >= 2) {
|
|
2014
|
+
return `${base} ${wrapIfMultiToken(emit(args[1]))}`;
|
|
2015
|
+
}
|
|
2016
|
+
return base;
|
|
2017
|
+
}
|
|
2018
|
+
case "replace": {
|
|
2019
|
+
const recv = emit(object);
|
|
2020
|
+
const oldS = emit(args[0]);
|
|
2021
|
+
const newS = emit(args[1]);
|
|
2022
|
+
return `bf_replace ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(oldS)} ${wrapIfMultiToken(newS)}`;
|
|
2023
|
+
}
|
|
2024
|
+
case "repeat": {
|
|
2025
|
+
const recv = emit(object);
|
|
2026
|
+
const count = args.length === 0 ? "0" : emit(args[0]);
|
|
2027
|
+
return `bf_repeat ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(count)}`;
|
|
2028
|
+
}
|
|
2029
|
+
case "padStart":
|
|
2030
|
+
case "padEnd": {
|
|
2031
|
+
const fn = method === "padStart" ? "bf_pad_start" : "bf_pad_end";
|
|
2032
|
+
const recv = emit(object);
|
|
2033
|
+
if (args.length === 0) {
|
|
2034
|
+
return `${fn} ${wrapIfMultiToken(recv)} 0`;
|
|
2035
|
+
}
|
|
2036
|
+
const target = emit(args[0]);
|
|
2037
|
+
if (args.length === 1) {
|
|
2038
|
+
return `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(target)}`;
|
|
2039
|
+
}
|
|
2040
|
+
const pad = emit(args[1]);
|
|
2041
|
+
return `${fn} ${wrapIfMultiToken(recv)} ${wrapIfMultiToken(target)} ${wrapIfMultiToken(pad)}`;
|
|
2042
|
+
}
|
|
1970
2043
|
default: {
|
|
1971
2044
|
const _exhaustive = method;
|
|
1972
2045
|
throw new Error(`Go arrayMethod: unhandled ArrayMethod '${_exhaustive}'`);
|
|
@@ -1976,6 +2049,26 @@ ${goFields.join(`
|
|
|
1976
2049
|
sortMethod(method, object, comparator, emit) {
|
|
1977
2050
|
return emitBfSort(emit(object), comparator);
|
|
1978
2051
|
}
|
|
2052
|
+
reduceMethod(method, object, reduceOp, emit) {
|
|
2053
|
+
const direction = method === "reduceRight" ? "right" : "left";
|
|
2054
|
+
return emitBfReduce(emit(object), reduceOp, direction);
|
|
2055
|
+
}
|
|
2056
|
+
flatMethod(object, depth, emit) {
|
|
2057
|
+
const d = depth === "infinity" ? -1 : depth;
|
|
2058
|
+
return `bf_flat ${wrapIfMultiToken(emit(object))} ${d}`;
|
|
2059
|
+
}
|
|
2060
|
+
flatMapMethod(object, op, emit) {
|
|
2061
|
+
const recv = wrapIfMultiToken(emit(object));
|
|
2062
|
+
const proj = op.projection;
|
|
2063
|
+
if (proj.kind === "tuple") {
|
|
2064
|
+
const pairs = proj.elements.map((l) => l.kind === "self" ? `"self" ""` : `"field" "${capitalize(l.field)}"`).join(" ");
|
|
2065
|
+
return `bf_flat_map_tuple ${recv} ${pairs}`;
|
|
2066
|
+
}
|
|
2067
|
+
if (proj.kind === "self") {
|
|
2068
|
+
return `bf_flat_map ${recv} "self" ""`;
|
|
2069
|
+
}
|
|
2070
|
+
return `bf_flat_map ${recv} "field" "${capitalize(proj.field)}"`;
|
|
2071
|
+
}
|
|
1979
2072
|
unsupported(raw, _reason) {
|
|
1980
2073
|
return `[UNSUPPORTED: ${raw}]`;
|
|
1981
2074
|
}
|
|
@@ -2398,13 +2491,7 @@ ${goFields.join(`
|
|
|
2398
2491
|
message: `Expression not supported: ${trimmed}`,
|
|
2399
2492
|
loc: this.makeLoc(),
|
|
2400
2493
|
suggestion: {
|
|
2401
|
-
message: support
|
|
2402
|
-
|
|
2403
|
-
Options:
|
|
2404
|
-
1. Use @client directive for client-side evaluation
|
|
2405
|
-
2. Pre-compute the value in Go code` : `Options:
|
|
2406
|
-
1. Use @client directive for client-side evaluation
|
|
2407
|
-
2. Pre-compute the value in Go code`
|
|
2494
|
+
message: buildUnsupportedSuggestion(support)
|
|
2408
2495
|
}
|
|
2409
2496
|
});
|
|
2410
2497
|
return `""`;
|
|
@@ -2433,9 +2520,7 @@ Options:
|
|
|
2433
2520
|
message: `Complex predicate in else-if is not supported: ${altIfStmt.condition}`,
|
|
2434
2521
|
loc: this.makeLoc(),
|
|
2435
2522
|
suggestion: {
|
|
2436
|
-
message:
|
|
2437
|
-
1. Use @client directive for client-side evaluation
|
|
2438
|
-
2. Pre-compute the value in Go code`
|
|
2523
|
+
message: GO_REMEDIATION_OPTIONS
|
|
2439
2524
|
}
|
|
2440
2525
|
});
|
|
2441
2526
|
}
|
|
@@ -2511,11 +2596,7 @@ Options:
|
|
|
2511
2596
|
message: `Condition not supported: ${trimmed}`,
|
|
2512
2597
|
loc: this.makeLoc(),
|
|
2513
2598
|
suggestion: {
|
|
2514
|
-
message: support
|
|
2515
|
-
|
|
2516
|
-
Options:
|
|
2517
|
-
1. Use @client directive for client-side evaluation
|
|
2518
|
-
2. Pre-compute the value in Go code` : "Expression contains unsupported syntax"
|
|
2599
|
+
message: buildUnsupportedSuggestion(support)
|
|
2519
2600
|
}
|
|
2520
2601
|
});
|
|
2521
2602
|
return { condition: `false`, preamble: "" };
|