gofront 0.0.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/LICENSE +9 -0
- package/README.md +202 -0
- package/package.json +41 -0
- package/src/codegen.js +1192 -0
- package/src/compiler.js +156 -0
- package/src/dts-parser.js +762 -0
- package/src/index.js +338 -0
- package/src/lexer.js +465 -0
- package/src/parser.js +1120 -0
- package/src/resolver.js +114 -0
- package/src/typechecker.js +1252 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luuk van Venrooij
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# GoFront
|
|
2
|
+
|
|
3
|
+
I love Go for the backend — simple, type-safe, no nonsense. I like JavaScript for the
|
|
4
|
+
frontend — runs everywhere, no setup. What I don't like is JavaScript's loose typing. And
|
|
5
|
+
I don't like TypeScript either. I know, controversial. It's fine, I just don't enjoy it.
|
|
6
|
+
|
|
7
|
+
So I built GoFront. Go syntax, type safety, compiles to plain ES modules. Same language
|
|
8
|
+
front and back, no runtime, no framework, no tsconfig.json.
|
|
9
|
+
|
|
10
|
+
Is this useful? Probably only for hobby projects. But it was fun to build and it works.
|
|
11
|
+
|
|
12
|
+
```go
|
|
13
|
+
package main
|
|
14
|
+
|
|
15
|
+
type Todo struct {
|
|
16
|
+
id int
|
|
17
|
+
text string
|
|
18
|
+
done bool
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var todos []Todo
|
|
22
|
+
|
|
23
|
+
func addTodo(text string) {
|
|
24
|
+
todos = append(todos, Todo{id: len(todos), text: text, done: false})
|
|
25
|
+
render()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func main() {
|
|
29
|
+
btn := document.getElementById("add-btn")
|
|
30
|
+
btn.addEventListener("click", func() {
|
|
31
|
+
addTodo(document.getElementById("input").value)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Compiles to clean, readable JavaScript — no runtime, no framework.
|
|
37
|
+
|
|
38
|
+
GoFront source files use the `.go` extension so editors automatically apply Go syntax
|
|
39
|
+
highlighting, bracket matching, and indentation rules without any extra configuration.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npm install -g gofront
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Requires Node.js 25+.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Example — Todo App
|
|
54
|
+
|
|
55
|
+
The only example is a full todo web app in `example/`, split across a
|
|
56
|
+
sub-package and four source files to showcase multi-file compilation.
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
example/
|
|
60
|
+
src/
|
|
61
|
+
utils/ ← sub-package: Plural(), Max(), Clamp() — pure utilities
|
|
62
|
+
utils.go
|
|
63
|
+
types.go ← Todo struct · FilterMode & Priority consts (iota) · filterLabel()
|
|
64
|
+
store.go ← state management: add/toggle/remove/clear · visibleTodos()
|
|
65
|
+
· stats() with named returns · statusLine() via utils.Plural
|
|
66
|
+
render.go ← renderTodo() · renderFilterBar() · renderFooter() · render()
|
|
67
|
+
main.go ← priority-toggle state · submitInput() · event wiring · seed data
|
|
68
|
+
index.html ← HTML + CSS, loads app.js as an ES module
|
|
69
|
+
app.js ← generated output (produced by build)
|
|
70
|
+
build.sh ← build script
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Features demonstrated:** structs & methods, iota constants, named return values,
|
|
74
|
+
closures, slices, maps, `for range`, `switch`, cross-package imports, multi-file
|
|
75
|
+
same-package compilation, DOM APIs.
|
|
76
|
+
|
|
77
|
+
**Build and run:**
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
sh example/build.sh
|
|
81
|
+
# → writes example/app.js
|
|
82
|
+
# open example/index.html in a browser
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## CLI
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
gofront <file.go> compile single file → stdout
|
|
91
|
+
gofront <dir> compile all *.go in directory → stdout
|
|
92
|
+
gofront <input> -o out.js write output to file (prints elapsed compile time e.g. "15ms")
|
|
93
|
+
gofront <input> --check type-check only
|
|
94
|
+
gofront <input> --watch watch for changes and recompile
|
|
95
|
+
gofront <input> --source-map append inline source map to output
|
|
96
|
+
gofront <input> --minify minify output with terser
|
|
97
|
+
gofront <file.go> --ast dump AST (debug)
|
|
98
|
+
gofront <file.go> --tokens dump tokens (debug)
|
|
99
|
+
gofront init [dir] scaffold a new project
|
|
100
|
+
gofront --version / -v print version
|
|
101
|
+
gofront --help / -h print this help
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Multi-file packages
|
|
107
|
+
|
|
108
|
+
All `.go` files in a directory share the same namespace and are compiled as one unit:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
myapp/
|
|
112
|
+
types.go ← type Point struct { X, Y int }
|
|
113
|
+
utils.go ← func distance(a, b Point) float64 { ... }
|
|
114
|
+
main.go ← func main() { ... }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
node src/index.js myapp -o myapp/bundle.js
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Cross-package imports are supported via relative paths:
|
|
122
|
+
|
|
123
|
+
```go
|
|
124
|
+
import "./mathpkg"
|
|
125
|
+
|
|
126
|
+
func main() {
|
|
127
|
+
x := math.Add(1, 2) // math package inlined into the bundle
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Type checking
|
|
134
|
+
|
|
135
|
+
GoFront performs static type checking before emitting any code, accurately tracking source locations in error messages across multiple files:
|
|
136
|
+
|
|
137
|
+
```go
|
|
138
|
+
func greet(name string) {
|
|
139
|
+
console.log("Hello, " + name)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
greet(42) // → Type error in src/main.go at line 5: cannot use int as string
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
External TypeScript type definitions are supported via `js:` imports:
|
|
146
|
+
|
|
147
|
+
```go
|
|
148
|
+
import "js:./dom.d.ts"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
npm package types are resolved automatically from `node_modules/` and `@types/`.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Language features
|
|
156
|
+
|
|
157
|
+
| Feature | Status |
|
|
158
|
+
|---|---|
|
|
159
|
+
| Variables (`var`, `:=` short re-declaration) | ✓ |
|
|
160
|
+
| Constants (`const`, `iota`) | ✓ |
|
|
161
|
+
| Functions, multiple returns | ✓ |
|
|
162
|
+
| Named return values | ✓ |
|
|
163
|
+
| Variadic parameters | ✓ |
|
|
164
|
+
| `init()` functions | ✓ |
|
|
165
|
+
| Structs + methods | ✓ |
|
|
166
|
+
| Embedded structs | ✓ |
|
|
167
|
+
| Pointer receivers | ✓ |
|
|
168
|
+
| Interfaces | ✓ |
|
|
169
|
+
| Closures | ✓ |
|
|
170
|
+
| Slices (`append`, `len`, `make`) | ✓ |
|
|
171
|
+
| Maps (`make`, `delete`, comma-ok) | ✓ — note: iteration order is insertion-order (JS), not randomised (Go) |
|
|
172
|
+
| `for`, `for range`, `for {}` | ✓ |
|
|
173
|
+
| `range` over string | ✓ |
|
|
174
|
+
| `switch` / `fallthrough` | ✓ |
|
|
175
|
+
| `new(T)` | ✓ |
|
|
176
|
+
| Type conversions | ✓ |
|
|
177
|
+
| Type assertions (`x.(T)`) | ✓ |
|
|
178
|
+
| Slice expressions (`s[lo:hi]`) | ✓ |
|
|
179
|
+
| `break` / `continue` | ✓ |
|
|
180
|
+
| `cap()`, `copy()`, `panic()` | ✓ |
|
|
181
|
+
| Bitwise operators (`&`, `\|`, `^`, `<<`, `>>`) | ✓ |
|
|
182
|
+
| Compound assignment (`+=`, `-=`, `*=`, `/=`, `%=`) | ✓ |
|
|
183
|
+
| Increment / decrement (`i++`, `i--`) | ✓ |
|
|
184
|
+
| Raw string literals (backticks) | ✓ |
|
|
185
|
+
| `defer` | ✓ |
|
|
186
|
+
| `error` type / `error("msg")` / `.Error()` | ✓ |
|
|
187
|
+
| `async func` / `await` expressions | ✓ |
|
|
188
|
+
| `fmt.Sprintf` / `fmt.Printf` / `fmt.Println` / `fmt.Errorf` | ✓ |
|
|
189
|
+
| External `.d.ts` types | ✓ |
|
|
190
|
+
| npm package types | ✓ |
|
|
191
|
+
| Multi-file packages | ✓ |
|
|
192
|
+
| Cross-package imports | ✓ |
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Tests
|
|
197
|
+
|
|
198
|
+
```sh
|
|
199
|
+
npm test
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
191 tests covering language features, type errors, edge cases, DOM (jsdom), external `.d.ts`, npm resolver, multi-file compilation, embedded structs, string formatting, and the example app.
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gofront",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "Luuk van Venrooij",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/seriva/gofront.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/seriva/gofront/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/seriva/gofront#readme",
|
|
14
|
+
"description": "A Go-inspired language that transpiles to JavaScript",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"go",
|
|
17
|
+
"compiler",
|
|
18
|
+
"transpiler",
|
|
19
|
+
"javascript",
|
|
20
|
+
"frontend",
|
|
21
|
+
"type-safe"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=25"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"bin": {
|
|
28
|
+
"gofront": "./src/index.js"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "node src/index.js",
|
|
32
|
+
"test": "node test/run.js",
|
|
33
|
+
"format": "biome format --write .",
|
|
34
|
+
"check": "biome check ."
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@biomejs/biome": "^2.4.11",
|
|
38
|
+
"jsdom": "^29.0.2",
|
|
39
|
+
"terser": "^5.46.1"
|
|
40
|
+
}
|
|
41
|
+
}
|