gofront 1.6.1 → 1.7.0
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/README.md +35 -39
- package/package.json +37 -4
- package/src/backend/js/expressions.js +323 -37
- package/src/backend/js/index.js +137 -49
- package/src/backend/js/runtime.js +570 -6
- package/src/backend/js/statements.js +36 -6
- package/src/backend/js/stdlib/errors.js +5 -0
- package/src/backend/js/stdlib/index.js +12 -0
- package/src/backend/js/stdlib/json.js +972 -0
- package/src/backend/js/stdlib/simd.js +24 -0
- package/src/backend/wasm/boundary.js +18 -0
- package/src/backend/wasm/emit-builtins.js +17 -0
- package/src/backend/wasm/emit-exprs.js +11 -0
- package/src/backend/wasm/emit.js +9 -0
- package/src/backend/wasm/encode.js +85 -0
- package/src/backend/wasm/optimize.js +4 -2
- package/src/backend/wasm/stdlib/index.js +3 -0
- package/src/backend/wasm/stdlib/simd.js +234 -0
- package/src/backend/wasm/types.js +21 -0
- package/src/backend/wasm/wat.js +37 -0
- package/src/dts-parser.js +71 -14
- package/src/lower/boxing.js +1 -6
- package/src/lower/embedding.js +2 -1
- package/src/parser/struct-tag.js +144 -0
- package/src/parser/types.js +63 -6
- package/src/typechecker/assignability.js +45 -0
- package/src/typechecker/expressions.js +66 -14
- package/src/typechecker/index.js +35 -8
- package/src/typechecker/resolve.js +151 -2
- package/src/typechecker/statements.js +68 -9
- package/src/typechecker/stdlib/extended.js +37 -0
- package/src/typechecker/stdlib/simd.js +73 -0
- package/src/typechecker/stdlib.js +2 -0
- package/src/typechecker/types.js +18 -3
- package/src/vendor.js +86 -11
package/README.md
CHANGED
|
@@ -136,45 +136,41 @@ example/simple/
|
|
|
136
136
|
app.js ← generated output
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
###
|
|
139
|
+
### Preact (components, hooks + d.ts tuples)
|
|
140
140
|
|
|
141
|
-
Same app rebuilt with [
|
|
142
|
-
signals-based reactive framework. Demonstrates how GoFront integrates with external JS
|
|
143
|
-
libraries via `.d.ts` type declarations — the entire reactive API surface is typed via a
|
|
144
|
-
hand-written `browser.d.ts` shim and exercised from GoFront source.
|
|
141
|
+
Same app rebuilt with [Preact](https://preactjs.com), using function components and hooks (`useState`, `useEffect`). Demonstrates how GoFront integrates with external JS libraries via `.d.ts` type declarations — TypeScript tuple return signatures (`[T, (v: T) => void]`) map directly to Go multi-value returns, allowing idiomatic Go hook destructuring:
|
|
145
142
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
```go
|
|
144
|
+
func TodoItem(p TodoItemProps) VNode {
|
|
145
|
+
editing, setEditing := useState(false)
|
|
146
|
+
return h("li", map[string]any{"class": itemClass(p.Todo, editing)}, ...)
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
149
|
|
|
150
150
|
```
|
|
151
|
-
example/
|
|
151
|
+
example/preact/
|
|
152
152
|
src/
|
|
153
|
-
types.go ← Todo, Stats,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
styles.go ← per-section cssClass() scoped styles
|
|
157
|
-
main.go ← async boot, Reactive.mount loading placeholder, signal.subscribe/once
|
|
153
|
+
types.go ← Todo, Stats, and props structs
|
|
154
|
+
components.go ← TodoItem, Header, InputRow, Footer, StatsBar Preact components
|
|
155
|
+
main.go ← App root component, async storage load, save, drag-and-drop
|
|
158
156
|
utils/
|
|
159
157
|
utils.go ← Plural() · generic Filter
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
index.html ← loads
|
|
158
|
+
preact.d.ts ← VNode · h · render · useState · useEffect · useRef · sleep
|
|
159
|
+
vendor.js ← bundled Preact & Preact hooks
|
|
160
|
+
index.html ← loads vendor.js, imports app.js
|
|
163
161
|
app.js ← generated output
|
|
164
162
|
```
|
|
165
163
|
|
|
166
|
-
The
|
|
164
|
+
The preact example covers:
|
|
167
165
|
|
|
168
166
|
| Category | Features used |
|
|
169
167
|
|---|---|
|
|
170
|
-
|
|
|
171
|
-
|
|
|
172
|
-
|
|
|
173
|
-
|
|
|
174
|
-
|
|
|
175
|
-
|
|
|
176
|
-
| Component instance | `signal`, `effect`, `on` (auto-cleanup event listeners) |
|
|
177
|
-
| Scan attributes | `data-model`, `data-text`, `data-html`, `data-if`, `data-visible`, `data-class-*`, `data-attr-*`, `data-bool-*`, `data-on-*`, `data-ref` |
|
|
168
|
+
| Hyperscript | `h(type, props, ...children)` with variadic and array children |
|
|
169
|
+
| Function components | Pure function components with Go struct props |
|
|
170
|
+
| Hooks | `useState` with tuple destructuring (`state, setState := useState(init)`), `useEffect` |
|
|
171
|
+
| Tuples | Multi-value returns from TypeScript `.d.ts` tuple types |
|
|
172
|
+
| Vendoring | Bundled subpath packages (`preact/hooks`) with named global exports |
|
|
173
|
+
| Typed persistence | `encoding/json` `Marshal`/`Unmarshal` of `[]Todo` to `localStorage`, driven by struct tags |
|
|
178
174
|
|
|
179
175
|
### templ (template files + direct DOM codegen)
|
|
180
176
|
|
|
@@ -276,17 +272,15 @@ Key types and functions (all accessed as `gom.*`, no import needed):
|
|
|
276
272
|
|
|
277
273
|
### Features demonstrated
|
|
278
274
|
|
|
279
|
-
The simple and
|
|
275
|
+
The simple and preact examples cover: structs & methods, iota constants, named return
|
|
280
276
|
values, closures, slices, `for range`, `switch`, cross-package imports, multi-file
|
|
281
277
|
same-package compilation, `async`/`await`, `defer`/`recover`, localStorage persistence,
|
|
282
|
-
DOM APIs, and generic utility functions (`Filter[T]
|
|
278
|
+
DOM APIs, and generic utility functions (`Filter[T]`).
|
|
283
279
|
|
|
284
|
-
The
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
as the primary composition unit (state, template, styles, mount lifecycle, `data-ref`
|
|
289
|
-
element refs, auto-cleanup event listeners).
|
|
280
|
+
The preact example additionally demonstrates: external `.d.ts` type imports,
|
|
281
|
+
TypeScript tuple return mapping to Go multi-value returns (`state, setState := useState(...)`),
|
|
282
|
+
Preact function components with field-only struct props, hooks-driven reactive rendering,
|
|
283
|
+
and npm dependency vendoring (`preact`, `preact/hooks`).
|
|
290
284
|
|
|
291
285
|
The gom example additionally demonstrates: **the `gom` built-in stdlib package**,
|
|
292
286
|
styles as nodes (`gom.Style` + `gom.MountTo`), `gom.Map` for list rendering, the
|
|
@@ -404,6 +398,7 @@ The compiler analyzes both sides of the boundary and synthesizes a facade into `
|
|
|
404
398
|
- **Slices & Arrays:** Slices and arrays copy element-wise in both directions; TypedArrays (`Float32Array`, `Int32Array`, etc.) are natively accepted.
|
|
405
399
|
- **Closures & Interfaces:** Function values, callbacks, and named non-empty interfaces cross the boundary transparently.
|
|
406
400
|
- **Shared Linear-Memory Buffers:** `gofront/shared` (`shared.NewFloat32`, etc.) exposes zero-copy TypedArray views over linear memory for bulk per-frame data.
|
|
401
|
+
- **WASM SIMD (`gofront/simd`):** Experimental 4-wide float vector type (`simd.F32x4`) compiling directly to native `v128` instructions with zero GC overhead, including `simd.LoadF32x4`/`StoreF32x4` for direct linear-memory access.
|
|
407
402
|
- **WASM Loader:** The generated JS bundle automatically fetches `app.wasm` relative to `app.js` (`import.meta.url`, customizable via `globalThis.__GOFRONT_WASM_URL` or `globalThis.__GOFRONT_WASM_BYTES`).
|
|
408
403
|
- **WAT Inspection:** Passing `--emit-wat` writes human-readable `app.wat` alongside the binary module.
|
|
409
404
|
- **Binaryen Optimization:** Passing `--release` or `--wasm-opt` optimizes `app.wasm` via Binaryen (`-O3` + GUFA), achieving ~23% smaller binaries and generating `app.wasm.map` source maps.
|
|
@@ -466,17 +461,18 @@ Design documents for planned features are organised by release under `docs/v*/`
|
|
|
466
461
|
## Tests
|
|
467
462
|
|
|
468
463
|
```sh
|
|
469
|
-
npm test # unit, zero-alloc perf, and example tests (~1,
|
|
464
|
+
npm test # unit, zero-alloc perf, and example tests (~1,920+ tests, no browser required)
|
|
470
465
|
npm run test:e2e # E2E browser tests (Playwright, headless Chromium)
|
|
471
466
|
npm run bench # Möller–Trumbore raycast benchmark comparing pure JS vs hybrid WASM
|
|
472
467
|
```
|
|
473
468
|
|
|
474
|
-
**Unit tests** (~1,
|
|
475
|
-
external `.d.ts`, npm resolver, multi-file compilation,
|
|
476
|
-
|
|
469
|
+
**Unit tests** (~1,920+) cover language features, type errors, edge cases, DOM (jsdom),
|
|
470
|
+
external `.d.ts`, npm resolver, TypeScript tuple return signatures, multi-file compilation,
|
|
471
|
+
embedded structs, string formatting, compile-time `encoding/json` serialization with struct tags,
|
|
472
|
+
map iteration order, integer overflow semantics, unused variable detection,
|
|
477
473
|
unused import detection, semantic difference verification, stdlib shim packages, generics,
|
|
478
474
|
the `testing` framework itself, the WasmGC backend and JS↔WASM boundary, `gofront/shared`
|
|
479
|
-
linear-memory buffers, Binaryen optimization, and `.templ` file compilation (element rendering,
|
|
475
|
+
linear-memory buffers, `gofront/simd` vector arithmetic, Binaryen optimization, and `.templ` file compilation (element rendering,
|
|
480
476
|
interpolation, boolean attrs, component calls, scoped `css` declarations with class hashing,
|
|
481
477
|
`if/else/else-if` chains, `for range`, `switch/case/default`, `@templ.Raw()` raw HTML injection,
|
|
482
478
|
SVG namespace handling, mixed `.go`+`.templ` packages).
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gofront",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"author": "Luuk van Venrooij",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/seriva/gofront.git"
|
|
8
|
+
"url": "git+https://github.com/seriva/gofront.git"
|
|
9
9
|
},
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/seriva/gofront/issues"
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"src/"
|
|
32
32
|
],
|
|
33
33
|
"bin": {
|
|
34
|
-
"gofront": "
|
|
34
|
+
"gofront": "src/index.js"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "node src/index.js example/simple/src -o example/simple/app.js && node src/index.js example/
|
|
37
|
+
"build": "node src/index.js example/simple/src -o example/simple/app.js && node src/index.js example/preact/src -o example/preact/app.js && node src/index.js example/gom/src -o example/gom/app.js && node src/index.js example/templ/src -o example/templ/app.js && node src/index.js example/webgl/src -o example/webgl/app.js && node src/index.js example/hybrid/src -o example/hybrid/app.js",
|
|
38
38
|
"test": "node test/unit/run.js && node test/e2e/perf/zero-alloc.js && node src/index.js test --dom example/...",
|
|
39
39
|
"test:e2e": "playwright test",
|
|
40
40
|
"test:coverage": "c8 --include='src/**' --reporter=text --reporter=lcov node test/unit/run.js",
|
|
@@ -47,11 +47,44 @@
|
|
|
47
47
|
"@biomejs/biome": "^2.5.15",
|
|
48
48
|
"@playwright/test": "^1.63.0",
|
|
49
49
|
"c8": "^12.0.0",
|
|
50
|
+
"esbuild": "^0.28.2",
|
|
50
51
|
"jsdom": "^30.1.2",
|
|
51
52
|
"lefthook": "^2.1.17",
|
|
53
|
+
"preact": "^11.0.1",
|
|
52
54
|
"serve": "^14.2.6"
|
|
53
55
|
},
|
|
54
56
|
"optionalDependencies": {
|
|
55
57
|
"binaryen": "^132.0.0"
|
|
58
|
+
},
|
|
59
|
+
"gofront": {
|
|
60
|
+
"vendor": {
|
|
61
|
+
"dest": "example/preact/vendor.js",
|
|
62
|
+
"packages": [
|
|
63
|
+
"preact",
|
|
64
|
+
"preact/hooks"
|
|
65
|
+
],
|
|
66
|
+
"globals": {
|
|
67
|
+
"preact": "preact",
|
|
68
|
+
"preact/hooks": [
|
|
69
|
+
"preact/hooks",
|
|
70
|
+
"preact_hooks"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
"namedExports": {
|
|
74
|
+
"preact": [
|
|
75
|
+
"h",
|
|
76
|
+
"render",
|
|
77
|
+
"Component"
|
|
78
|
+
],
|
|
79
|
+
"preact/hooks": [
|
|
80
|
+
"useState",
|
|
81
|
+
"useEffect",
|
|
82
|
+
"useRef",
|
|
83
|
+
"useMemo",
|
|
84
|
+
"useCallback",
|
|
85
|
+
"useReducer"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
56
89
|
}
|
|
57
90
|
}
|