kopscript 0.7.2 → 0.9.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/LLM.md CHANGED
@@ -11,8 +11,8 @@ Compiles to plain ES modules.
11
11
  ## CLI
12
12
 
13
13
  ```
14
- ks build <file.ks> # type-check + emit <file>.js next to the source
15
- ks run <file.ks> # build, then execute with node
14
+ ks build <file.ks> # type-check + emit <file>.js and <file>.js.map next to the source
15
+ ks run <file.ks> # build, then execute with node --enable-source-maps
16
16
  ks watch <file.ks> # build, then rebuild on every change to any file in the graph
17
17
  ks check <file.ks> # type-check only, no output files
18
18
  ks build|check <file.ks> --json # single JSON object on stdout instead of human text
@@ -21,13 +21,18 @@ ks build|check <file.ks> --json # single JSON object on stdout instead of huma
21
21
  `--json` output shape (also what a tool/agent should parse instead of scraping text):
22
22
 
23
23
  ```json
24
- { "success": false, "diagnostics": [{ "severity": "error", "message": "...", "line": 2, "col": 14, "file": "/abs/path.ks" }], "written": [] }
24
+ { "success": false, "diagnostics": [{ "code": "KS4065", "severity": "error", "message": "...", "line": 2, "col": 14, "file": "/abs/path.ks" }], "written": [] }
25
25
  ```
26
26
 
27
27
  `written` is the absolute paths actually written (`build` only, and only on success — a
28
- failed `build` writes nothing). Exit code is `0` iff `success` is `true`. A missing entry
28
+ failed `build` writes nothing; `.js.map` paths aren't listed separately, one is written next
29
+ to each `.js` path in `written`). Exit code is `0` iff `success` is `true`. A missing entry
29
30
  file yields `{ success: false, diagnostics: [], written: [], error: "cannot find file '...'" }`.
30
31
 
32
+ Source maps are statement-level, not column-level (see `src/sourcemap.ts`, hand-rolled VLQ,
33
+ zero added dependencies) — a thrown/uncaught error resolves to the right `.ks` line, but a
34
+ specific sub-expression within one line isn't separately mapped.
35
+
31
36
  ## File shape
32
37
 
33
38
  ```ks
@@ -541,7 +546,11 @@ Real, observed cases where a plausible-looking guess was wrong — not hypotheti
541
546
 
542
547
  ## Diagnostics
543
548
 
544
- Every compiler error/warning is `{ severity, message, line, col }` (1-based). CLI output
545
- format: `` file:line:col - severity: message `` plus a source line and a `^` pointer.
546
- `DiagnosticBag.hasErrors` gates whether codegen runs at all a program with any error
547
- produces no output.
549
+ Every compiler error/warning is `{ code, severity, message, line, col }` (1-based).
550
+ `code` is `KS` + a number, stable across compiler versions even when `message`'s wording
551
+ changes — match on `code` in tooling, not on `message` text. Ranges by pipeline stage,
552
+ never reused once assigned: `KS1xxx` lexer, `KS2xxx` parser, `KS3xxx` module/`using`
553
+ resolution, `KS4xxx` checker (the large majority of real errors), `KS5xxx` templates.
554
+ CLI output format: `` file:line:col - severity code: message `` plus a source line and a
555
+ `^` pointer. `DiagnosticBag.hasErrors` gates whether codegen runs at all — a program with
556
+ any error produces no output.
package/README.md CHANGED
@@ -54,6 +54,10 @@ LLM's context, as opposed to this README's narrative explanation.
54
54
  file — interpolation, event/property bindings, `*if`/`*for` — down to the exact same
55
55
  AST a hand-written `Render()` would produce, with auto-`Subscribe` wiring for state
56
56
  referenced directly in the markup. See [Templates](#templates).
57
+ - **Real debugging, not just readable output**: `ks build` emits a real source map next to
58
+ every `.js` file (original `.ks` embedded, no separate file to ship), and `ks run` enables
59
+ it automatically — an uncaught exception names the real `.ks` file and line, not the
60
+ generated JS. Hand-rolled VLQ encoder, zero added dependencies. See "Source maps" below.
57
61
  - **A companion framework, [Kopular](https://dev.azure.com/koppinator/Koppindependence/_git/Kopular)**:
58
62
  components, constructor-injected services via a composition root (no DI container), and
59
63
  real-URL routing (no config DSL) — built entirely on the features above, in a separate
@@ -741,8 +745,8 @@ runtime representation at all and are dropped from the emitted JS entirely.
741
745
  ## CLI
742
746
 
743
747
  ```
744
- ks build <file.ks> # type-check and emit <file>.js next to the source
745
- ks run <file.ks> # build, then execute the emitted JS with node
748
+ ks build <file.ks> # type-check and emit <file>.js (+ <file>.js.map) next to the source
749
+ ks run <file.ks> # build, then execute the emitted JS with node --enable-source-maps
746
750
  ks watch <file.ks> # build, then rebuild on every change to any file in the graph
747
751
  ks check <file.ks> # type-check only — no output files written
748
752
  ```
@@ -755,7 +759,7 @@ programmatically instead of scraping formatted text:
755
759
  {
756
760
  "success": false,
757
761
  "diagnostics": [
758
- { "severity": "error", "message": "Argument 2 has type 'string', expected 'number'", "line": 2, "col": 14, "file": "/abs/path/to/file.ks" }
762
+ { "code": "KS4065", "severity": "error", "message": "Argument 2 has type 'string', expected 'number'", "line": 2, "col": 14, "file": "/abs/path/to/file.ks" }
759
763
  ],
760
764
  "written": []
761
765
  }
@@ -767,6 +771,28 @@ error-free). A missing entry file reports `{ "success": false, "diagnostics": []
767
771
  "written": [], "error": "cannot find file '...'" }` instead of throwing. Exit code is 0
768
772
  exactly when `success` is `true`, both with and without `--json`.
769
773
 
774
+ Every diagnostic carries a stable `code` (`KS` + a number) alongside its human-readable
775
+ `message` — meant for a tool/agent to pattern-match reliably (`code === "KS4065"`) instead
776
+ of parsing prose that can be reworded between versions. Codes are grouped by pipeline stage
777
+ and never reused once assigned: `KS1xxx` lexer, `KS2xxx` parser, `KS3xxx` module/`using`
778
+ resolution, `KS4xxx` the checker (by far the largest category — most real type errors live
779
+ here), `KS5xxx` templates. There's no generated reference doc mapping every code to an
780
+ explanation yet — for now, `message` is still the primary explanation; `code` is for
781
+ matching, not (yet) for looking up docs.
782
+
783
+ **Source maps**: `build` writes a real source-map v3 `<file>.js.map` alongside every
784
+ `<file>.js`, with the original `.ks` source embedded (`sourcesContent`) so a deployed app
785
+ doesn't need to ship its `.ks` files for devtools/stack traces to show real source. `run`
786
+ passes Node's own `--enable-source-maps` flag automatically, so an uncaught exception
787
+ during `ks run` names the real `.ks` file and line, not the generated `.js`. Hand-rolled
788
+ (base64 VLQ), not the `source-map` npm package — kopscript has zero runtime dependencies
789
+ and this keeps it that way (see `src/sourcemap.ts`). **Scope**: statement-level, not full
790
+ expression/column-level — every statement (a class member, a block statement, a top-level
791
+ declaration) gets its own mapping, but a specific sub-expression *within* one line doesn't.
792
+ This is a deliberate v1 cut, the same spirit as generics/nullable types/templates: real,
793
+ useful debugging (correct stack-trace lines, working breakpoints) without a full rewrite of
794
+ codegen's string-concatenation architecture into a position-tracking writer.
795
+
770
796
  During development, use `npm run ks -- <build|run|watch|check> <file.ks>` (backed by
771
797
  `tsx`), or run `npm run build` to compile the TypeScript compiler itself to `dist/` and
772
798
  use `node dist/cli.js` directly.