gofront 1.3.6 → 1.3.7

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 CHANGED
@@ -79,7 +79,7 @@ identifier, literal, `)`, `]`, `}`, or certain keywords (`return`, `break`, `con
79
79
  `fallthrough`). This is why Go doesn't need explicit semicolons — and neither does
80
80
  GoFront.
81
81
 
82
- ### 2. Parser (`src/parser.js`)
82
+ ### 2. Parser (`src/parser/`)
83
83
 
84
84
  A hand-written recursive-descent parser. No parser generators, no grammar files — just
85
85
  straightforward top-down parsing. Produces an AST where every node is a plain JS object
@@ -88,7 +88,7 @@ with a `kind` field (`"FuncDecl"`, `"IfStmt"`, `"BinaryExpr"`, etc.).
88
88
  Operator precedence is handled via a Pratt-style expression parser with numeric
89
89
  precedence levels.
90
90
 
91
- ### 3. Type Checker (`src/typechecker.js`)
91
+ ### 3. Type Checker (`src/typechecker/`)
92
92
 
93
93
  Three-pass type checker operating on the AST:
94
94
 
@@ -103,7 +103,7 @@ Types are plain JS objects (`{ kind: "basic", name: "int" }`, `{ kind: "slice",
103
103
  elem: ... }`, etc.). The special `any` type acts as a recovery/escape hatch — any
104
104
  operation on it is silently permitted, preventing cascading errors.
105
105
 
106
- ### 4. Code Generator (`src/codegen.js`)
106
+ ### 4. Code Generator (`src/codegen/`)
107
107
 
108
108
  Walks the typed AST and emits clean, readable JavaScript. No intermediate representation
109
109
  — the codegen writes directly to an output buffer with indentation tracking.
@@ -123,10 +123,11 @@ readable and debuggable — no name mangling, no opaque wrappers.
123
123
 
124
124
  | Go | JavaScript | Notes |
125
125
  |---|---|---|
126
- | `struct` | ES6 `class` | Single destructured-object constructor: `new Point({ X: 1, Y: 2 })` |
127
- | Methods | Class instance methods | Receiver is `this` |
126
+ | `struct` | ES6 `class` | Positional constructor with zero-value defaults: `new Point(1, 2)`; a generated `__clone()` gives struct values Go copy semantics on assignment, call, return, `append`, and `range` |
127
+ | Methods | Class instance methods | Receiver is `this` (typed `*T` for pointer receivers) |
128
128
  | Embedded structs | Flattened fields + delegation stubs | `Greet(...a) { return Base.prototype.Greet.call(this, ...a); }` |
129
- | `[]T` (slice) | `Array` | `append` → spread, `len` → `.length` |
129
+ | `[]T` (slice) | `Array` | `append` → `__append`, `len` → `__len` |
130
+ | `[]float32`, `[]int8`…`[]int32`, `[]uint8`/`[]byte`…`[]uint32`, `[]rune` | TypedArray (`Float32Array`, `Int32Array`, `Uint8Array`, …) | `[]float64` and `[]int` stay plain `Array`; slicing → `.subarray` |
130
131
  | `map[K]V` | Plain object `{}` | Key access via `[]`, iteration via `Object.entries()` |
131
132
  | `nil` | `null` | |
132
133
  | `error` | `__error` object | `error("msg")` → `__error("msg")`, `.Error()` → real method call. `toString()` for string context compat |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gofront",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "author": "Luuk van Venrooij",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -319,6 +319,15 @@ export class CodeGen {
319
319
  if (d.kind === "TypeDecl" && d.type.kind === "StructType")
320
320
  this.structNames.add(d.name);
321
321
  }
322
+ // Structs from bundled GoFront packages are inlined under their bare name.
323
+ // Skip aliases (key differs from the type's own name) — no class is emitted for them.
324
+ if (this.checker) {
325
+ for (const [name, t] of this.checker.types) {
326
+ if (name.includes(".") || t?.name !== name) continue;
327
+ if (t.kind === "named" && t.underlying?.kind === "struct")
328
+ this.structNames.add(name);
329
+ }
330
+ }
322
331
  }
323
332
 
324
333
  _collectMethodMap(program) {
@@ -505,7 +505,10 @@ export class TypeChecker {
505
505
  const recvNamedType = this.types.get(recvTypeName);
506
506
  this._injectGenericReceiverTypeParams(inner, recvNamedType);
507
507
  const recvType = this.resolveTypeNodeName(decl.recvType, outer);
508
- inner.define(decl.recvName, recvType);
508
+ inner.define(
509
+ decl.recvName,
510
+ decl.recvPointer ? { kind: "pointer", base: recvType } : recvType,
511
+ );
509
512
  for (const p of decl.params) {
510
513
  inner.define(p.name, this.resolveTypeNode(p.type, inner));
511
514
  }