@barefootjs/go-template 0.18.7 → 0.19.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/emit-context.d.ts +11 -5
- package/dist/adapter/emit-context.d.ts.map +1 -1
- package/dist/adapter/go-template-adapter.d.ts +45 -6
- package/dist/adapter/go-template-adapter.d.ts.map +1 -1
- package/dist/adapter/index.js +326 -38
- package/dist/adapter/lib/compile-state.d.ts +32 -0
- package/dist/adapter/lib/compile-state.d.ts.map +1 -1
- package/dist/adapter/lib/types.d.ts +9 -0
- package/dist/adapter/lib/types.d.ts.map +1 -1
- package/dist/adapter/memo/memo-compute.d.ts +8 -0
- package/dist/adapter/memo/memo-compute.d.ts.map +1 -1
- package/dist/adapter/props/prop-types.d.ts +97 -0
- package/dist/adapter/props/prop-types.d.ts.map +1 -1
- package/dist/adapter/value/value-lowering.d.ts +9 -1
- package/dist/adapter/value/value-lowering.d.ts.map +1 -1
- package/dist/build.js +326 -38
- package/dist/index.js +326 -38
- package/package.json +3 -3
- package/src/__tests__/derived-state-memo.test.ts +10 -3
- package/src/__tests__/go-template-adapter.test.ts +282 -23
- package/src/adapter/emit-context.ts +14 -5
- package/src/adapter/go-template-adapter.ts +291 -50
- package/src/adapter/lib/compile-state.ts +36 -0
- package/src/adapter/lib/types.ts +9 -0
- package/src/adapter/memo/memo-compute.ts +123 -9
- package/src/adapter/props/prop-types.ts +310 -1
- package/src/adapter/value/value-lowering.ts +58 -5
- package/src/test-render.ts +18 -4
package/src/test-render.ts
CHANGED
|
@@ -699,7 +699,7 @@ function buildGoPropsInit(
|
|
|
699
699
|
// not the naive `Id`) — see `goMapLiteralFromObject`'s identical fix.
|
|
700
700
|
const goField = capitalizeFieldName(key)
|
|
701
701
|
if (typeof value === 'string') {
|
|
702
|
-
lines.push(`\t\t${goField}:
|
|
702
|
+
lines.push(`\t\t${goField}: ${goStringLit(value)},`)
|
|
703
703
|
} else if (typeof value === 'number') {
|
|
704
704
|
lines.push(`\t\t${goField}: ${value},`)
|
|
705
705
|
} else if (typeof value === 'boolean') {
|
|
@@ -828,6 +828,20 @@ function goTypedMapSliceLiteralFromArray(arr: unknown[], elemType: string): stri
|
|
|
828
828
|
* names. Only the keys the caller supplied are set, so an omitted optional prop
|
|
829
829
|
* (e.g. `defaultOn` on the third toggle item) takes the Go zero value. (#1297)
|
|
830
830
|
*/
|
|
831
|
+
/**
|
|
832
|
+
* Emit a JS string as a Go interpreted string literal. JSON string
|
|
833
|
+
* escaping is a subset of Go's (`\"`, `\\`, `\n`, `\uXXXX` are all valid
|
|
834
|
+
* Go escapes), so `JSON.stringify` is a correct emitter — unlike the
|
|
835
|
+
* previous quote-only `.replace(/"/g, '\\"')`, it also survives
|
|
836
|
+
* backslashes, newlines, and control characters (data-point conformance
|
|
837
|
+
* caught the quote case: a `"` in a string prop broke the generated
|
|
838
|
+
* `main.go` at compile time). Lone surrogates emit as `\uDXXX`, which Go
|
|
839
|
+
* rejects — acceptable until a fixture needs malformed-UTF-16 props.
|
|
840
|
+
*/
|
|
841
|
+
function goStringLit(v: string): string {
|
|
842
|
+
return JSON.stringify(v)
|
|
843
|
+
}
|
|
844
|
+
|
|
831
845
|
function goStructLiteral(obj: Record<string, unknown>, typeName: string): string {
|
|
832
846
|
const fields: string[] = []
|
|
833
847
|
for (const [k, v] of Object.entries(obj)) {
|
|
@@ -836,7 +850,7 @@ function goStructLiteral(obj: Record<string, unknown>, typeName: string): string
|
|
|
836
850
|
// adapter's own struct-literal baking (`parsed-literal-to-go.ts`)
|
|
837
851
|
// sanitizes those to `DataX`, not `Data-x` (Copilot review, #2202).
|
|
838
852
|
const goField = goFieldNameForKey(k)
|
|
839
|
-
if (typeof v === 'string') fields.push(`${goField}:
|
|
853
|
+
if (typeof v === 'string') fields.push(`${goField}: ${goStringLit(v)}`)
|
|
840
854
|
else if (typeof v === 'number' || typeof v === 'boolean') fields.push(`${goField}: ${v}`)
|
|
841
855
|
else if (v === null) fields.push(`${goField}: nil`)
|
|
842
856
|
else if (Array.isArray(v)) fields.push(`${goField}: ${goArrayLiteralFromArray(v)}`)
|
|
@@ -848,7 +862,7 @@ function goStructLiteral(obj: Record<string, unknown>, typeName: string): string
|
|
|
848
862
|
function goArrayLiteralFromArray(arr: unknown[]): string {
|
|
849
863
|
const entries: string[] = []
|
|
850
864
|
for (const v of arr) {
|
|
851
|
-
if (typeof v === 'string') entries.push(
|
|
865
|
+
if (typeof v === 'string') entries.push(goStringLit(v))
|
|
852
866
|
else if (typeof v === 'number') entries.push(String(v))
|
|
853
867
|
else if (typeof v === 'boolean') entries.push(String(v))
|
|
854
868
|
else if (v === null) entries.push('nil')
|
|
@@ -886,7 +900,7 @@ function goMapLiteralFromObject(
|
|
|
886
900
|
// uses for exactly this key-to-Go-field sanitization.
|
|
887
901
|
const emittedKey = capitalizeKeys ? goFieldNameForKey(k) : k
|
|
888
902
|
const key = JSON.stringify(emittedKey)
|
|
889
|
-
if (typeof v === 'string') entries.push(`${key}:
|
|
903
|
+
if (typeof v === 'string') entries.push(`${key}: ${goStringLit(v)}`)
|
|
890
904
|
else if (typeof v === 'number') entries.push(`${key}: ${v}`)
|
|
891
905
|
else if (typeof v === 'boolean') entries.push(`${key}: ${v}`)
|
|
892
906
|
else if (v === null) entries.push(`${key}: nil`)
|