gofront 0.0.9 → 1.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.
Files changed (53) hide show
  1. package/README.md +5 -5
  2. package/package.json +7 -4
  3. package/src/cli-core.js +65 -0
  4. package/src/codegen/expressions.js +523 -1717
  5. package/src/codegen/index.js +576 -0
  6. package/src/codegen/runtime.js +151 -0
  7. package/src/codegen/statements.js +308 -296
  8. package/src/codegen/stdlib/builder.js +39 -0
  9. package/src/codegen/stdlib/bytes.js +65 -0
  10. package/src/codegen/stdlib/errors.js +20 -0
  11. package/src/codegen/stdlib/fmt.js +104 -0
  12. package/src/codegen/stdlib/gom.js +155 -0
  13. package/src/codegen/stdlib/html.js +20 -0
  14. package/src/codegen/stdlib/index.js +98 -0
  15. package/src/codegen/stdlib/io.js +36 -0
  16. package/src/codegen/stdlib/maps.js +45 -0
  17. package/src/codegen/stdlib/math.js +56 -0
  18. package/src/codegen/stdlib/os.js +13 -0
  19. package/src/codegen/stdlib/path.js +34 -0
  20. package/src/codegen/stdlib/rand.js +27 -0
  21. package/src/codegen/stdlib/regexp.js +54 -0
  22. package/src/codegen/stdlib/slices.js +51 -0
  23. package/src/codegen/stdlib/sort.js +31 -0
  24. package/src/codegen/stdlib/strconv.js +33 -0
  25. package/src/codegen/stdlib/strings.js +86 -0
  26. package/src/codegen/stdlib/time.js +57 -0
  27. package/src/codegen/stdlib/unicode.js +25 -0
  28. package/src/codegen/stdlib/utf8.js +26 -0
  29. package/src/codegen/templ.js +284 -0
  30. package/src/compiler.js +142 -77
  31. package/src/dts-parser.js +355 -371
  32. package/src/index.js +32 -162
  33. package/src/lexer.js +186 -272
  34. package/src/minifier.js +305 -318
  35. package/src/{parser.js → parser/declarations.js} +18 -175
  36. package/src/parser/expressions.js +51 -34
  37. package/src/parser/index.js +161 -0
  38. package/src/parser/statements.js +24 -34
  39. package/src/parser/types.js +31 -29
  40. package/src/templ-parser.js +2 -2
  41. package/src/tokens.js +109 -0
  42. package/src/typechecker/assignability.js +261 -0
  43. package/src/typechecker/expressions.js +568 -549
  44. package/src/typechecker/index.js +556 -0
  45. package/src/typechecker/resolve.js +428 -0
  46. package/src/typechecker/statements.js +270 -280
  47. package/src/typechecker/stdlib/core.js +592 -0
  48. package/src/typechecker/stdlib/extended.js +332 -0
  49. package/src/typechecker/stdlib.js +9 -1060
  50. package/src/typechecker/termination.js +86 -0
  51. package/src/typechecker/types.js +1 -0
  52. package/src/codegen.js +0 -882
  53. package/src/typechecker.js +0 -1299
package/README.md CHANGED
@@ -108,9 +108,9 @@ operation on it is silently permitted, preventing cascading errors.
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.
110
110
 
111
- Runtime helpers (`__len`, `__append`, `__s`, `__sprintf`, `__cmul`, `__cdiv`, `__error`,
112
- `__errorIs`, `__timeFmt`, `__timeParse`, `__pathClean`) are tree-shaken: only emitted
113
- when actually used. Optional inline source maps are supported via VLQ-encoded mappings.
111
+ Runtime helpers (`__len`, `__append`, `__s`, `__sprintf`, `__equal`, `__cmul`, `__cdiv`,
112
+ `__error`, `__errorIs`, `__timeFmt`, `__timeParse`, `__pathClean`) are tree-shaken: only
113
+ emitted when actually used. Optional inline source maps are supported via VLQ-encoded mappings.
114
114
 
115
115
  ---
116
116
 
@@ -636,10 +636,10 @@ Design documents for planned features are organised by release under `docs/v*/`
636
636
  ```sh
637
637
  npm run test:unit # unit tests only (~1100 tests, no browser required)
638
638
  npm run test:e2e # E2E tests (Playwright, headless Chromium)
639
- npm test # both
639
+ npm run test:all # both
640
640
  ```
641
641
 
642
- **Unit tests** (~1100) cover language features, type errors, edge cases, DOM (jsdom),
642
+ **Unit tests** (~1118) cover language features, type errors, edge cases, DOM (jsdom),
643
643
  external `.d.ts`, npm resolver, multi-file compilation, embedded structs, string
644
644
  formatting, map iteration order, integer overflow semantics, unused variable detection,
645
645
  unused import detection, semantic difference verification, stdlib shim packages, generics,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gofront",
3
- "version": "0.0.9",
3
+ "version": "1.0.1",
4
4
  "author": "Luuk van Venrooij",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,16 +35,19 @@
35
35
  "build:reactive": "node src/index.js example/reactive/src -o example/reactive/app.js",
36
36
  "build:gom": "node src/index.js example/gom/src -o example/gom/app.js",
37
37
  "build:templ": "node src/index.js example/templ/src -o example/templ/app.js",
38
- "test": "npm run test:unit && npm run test:e2e",
38
+ "build:all": "npm run build:simple && npm run build:reactive && npm run build:gom && npm run build:templ",
39
+ "test:all": "npm run test:unit && npm run test:e2e",
39
40
  "test:unit": "node test/unit/run.js",
40
- "test:e2e": "playwright test",
41
+ "test:coverage": "c8 --include='src/**' --reporter=text --reporter=lcov node test/unit/run.js",
42
+ "test:e2e": "npm run build:all && playwright test",
41
43
  "format": "biome format --write .",
42
- "check": "biome check . && node src/index.js example/simple/src --check && node src/index.js example/reactive/src --check && node src/index.js example/gom/src --check && node src/index.js example/templ/src --check",
44
+ "check": "biome check . && sentrux check && sentrux gate && node src/index.js example/simple/src --check && node src/index.js example/reactive/src --check && node src/index.js example/gom/src --check && node src/index.js example/templ/src --check",
43
45
  "prepare": "husky"
44
46
  },
45
47
  "devDependencies": {
46
48
  "@biomejs/biome": "^2.4.12",
47
49
  "@playwright/test": "^1.59.1",
50
+ "c8": "^11.0.0",
48
51
  "husky": "^9.1.7",
49
52
  "jsdom": "^29.0.2",
50
53
  "serve": "^14.2.6"
@@ -0,0 +1,65 @@
1
+ // CLI compilation core — extracted for direct import in tests.
2
+ // index.js retains only arg parsing, file I/O, watch mode, and process.exit.
3
+
4
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
5
+ import { basename, dirname, join, resolve } from "node:path";
6
+ import { compileDir, compileSingleFile } from "./compiler.js";
7
+ import { minify } from "./minifier.js";
8
+
9
+ export function runCompile(inputPath, isDir, options) {
10
+ const {
11
+ sourceMap = false,
12
+ outputFile = null,
13
+ dumpTokens = false,
14
+ dumpAst = false,
15
+ } = options ?? {};
16
+
17
+ if (isDir) {
18
+ const outputDir = outputFile ? dirname(resolve(outputFile)) : resolve(".");
19
+ return compileDir(inputPath, { sourceMap, outputDir });
20
+ }
21
+
22
+ return compileSingleFile(inputPath, {
23
+ sourceMap,
24
+ outputFile,
25
+ dumpTokens,
26
+ dumpAst,
27
+ });
28
+ }
29
+
30
+ export function maybeMinify(js, options) {
31
+ const {
32
+ minify: doMinify = false,
33
+ mangle = false,
34
+ sourceMap = false,
35
+ } = options ?? {};
36
+ if (!doMinify) return js;
37
+ if (sourceMap)
38
+ throw new Error("--source-map and --minify cannot be used together");
39
+ return minify(js, { mangle });
40
+ }
41
+
42
+ export function handleInit(targetDir) {
43
+ try {
44
+ mkdirSync(targetDir, { recursive: true });
45
+ } catch (e) {
46
+ throw new Error(`cannot create '${targetDir}': ${e.message}`);
47
+ }
48
+
49
+ const mainPath = join(targetDir, "main.go");
50
+ if (existsSync(mainPath)) {
51
+ throw new Error(`${mainPath} already exists — nothing written`);
52
+ }
53
+
54
+ const pkgName = basename(targetDir);
55
+ const safePkg = pkgName.replace(/[^a-zA-Z0-9_]/g, "_").replace(/^[0-9]/, "_");
56
+ const template = `package ${safePkg}\n\nfunc main() {\n\tconsole.log("Hello from GoFront!")\n}\n`;
57
+
58
+ try {
59
+ writeFileSync(mainPath, template);
60
+ } catch (e) {
61
+ throw new Error(`cannot write '${mainPath}': ${e.message}`);
62
+ }
63
+
64
+ return { mainPath };
65
+ }