@kernlang/core 3.4.0 → 3.4.2-canary.3.1.6b4cbb13

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 (59) hide show
  1. package/dist/codegen/body-ts.d.ts +68 -0
  2. package/dist/codegen/body-ts.js +233 -0
  3. package/dist/codegen/body-ts.js.map +1 -0
  4. package/dist/codegen/functions.js +19 -2
  5. package/dist/codegen/functions.js.map +1 -1
  6. package/dist/codegen/kern-stdlib.d.ts +63 -0
  7. package/dist/codegen/kern-stdlib.js +160 -0
  8. package/dist/codegen/kern-stdlib.js.map +1 -0
  9. package/dist/codegen/stdlib-preamble.d.ts +19 -0
  10. package/dist/codegen/stdlib-preamble.js +62 -4
  11. package/dist/codegen/stdlib-preamble.js.map +1 -1
  12. package/dist/codegen/type-system.js +15 -1
  13. package/dist/codegen/type-system.js.map +1 -1
  14. package/dist/codegen-core.js +7 -0
  15. package/dist/codegen-core.js.map +1 -1
  16. package/dist/codegen-expression.d.ts +8 -0
  17. package/dist/codegen-expression.js +111 -5
  18. package/dist/codegen-expression.js.map +1 -1
  19. package/dist/decompiler.js +219 -0
  20. package/dist/decompiler.js.map +1 -1
  21. package/dist/index.d.ts +14 -1
  22. package/dist/index.js +16 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/native-eligibility.d.ts +69 -0
  25. package/dist/native-eligibility.js +155 -0
  26. package/dist/native-eligibility.js.map +1 -0
  27. package/dist/node-props.d.ts +4 -0
  28. package/dist/node-props.js.map +1 -1
  29. package/dist/parser-core.d.ts +7 -1
  30. package/dist/parser-core.js +5 -2
  31. package/dist/parser-core.js.map +1 -1
  32. package/dist/parser-diagnostics.js +6 -2
  33. package/dist/parser-diagnostics.js.map +1 -1
  34. package/dist/parser-expression.d.ts +8 -3
  35. package/dist/parser-expression.js +293 -5
  36. package/dist/parser-expression.js.map +1 -1
  37. package/dist/parser-keywords.js +16 -0
  38. package/dist/parser-keywords.js.map +1 -1
  39. package/dist/parser-validate-native-eligible.d.ts +21 -0
  40. package/dist/parser-validate-native-eligible.js +46 -0
  41. package/dist/parser-validate-native-eligible.js.map +1 -0
  42. package/dist/parser-validate-propagation.d.ts +105 -0
  43. package/dist/parser-validate-propagation.js +684 -0
  44. package/dist/parser-validate-propagation.js.map +1 -0
  45. package/dist/parser.d.ts +10 -3
  46. package/dist/parser.js +11 -5
  47. package/dist/parser.js.map +1 -1
  48. package/dist/schema.js +199 -13
  49. package/dist/schema.js.map +1 -1
  50. package/dist/semantic-validator.js +9 -5
  51. package/dist/semantic-validator.js.map +1 -1
  52. package/dist/spec.d.ts +2 -2
  53. package/dist/spec.js +13 -1
  54. package/dist/spec.js.map +1 -1
  55. package/dist/types.d.ts +1 -1
  56. package/dist/value-ir.d.ts +27 -0
  57. package/dist/value-ir.js +6 -1
  58. package/dist/value-ir.js.map +1 -1
  59. package/package.json +1 -1
@@ -0,0 +1,105 @@
1
+ /** Slice 7 — `?` and `!` propagation operators.
2
+ *
3
+ * Walks every `fn` / `method` node whose handler body uses a postfix `?`
4
+ * or `!` after a call to a Result/Option-producing function, and rewrites
5
+ * the body with statement-level hoisting:
6
+ *
7
+ * const u = parseUser(raw)?; → const __k_t1 = parseUser(raw);
8
+ * if (__k_t1.kind === 'err') return __k_t1;
9
+ * const u = __k_t1.value;
10
+ *
11
+ * const u = parseUser(raw)!; → const __k_t1 = parseUser(raw);
12
+ * if (__k_t1.kind === 'err') throw new KernUnwrapError(__k_t1);
13
+ * const u = __k_t1.value;
14
+ *
15
+ * IIFE wrappers were tried in v0 and rejected: their `return` exits the
16
+ * IIFE, not the enclosing handler, so propagation fell through silently.
17
+ *
18
+ * Recognition is **name-anchored** at call expressions and accepts a tiny
19
+ * statement grammar:
20
+ * 1. `(const|let|var) <name>(:<type>)? = <call><op>;`
21
+ * 2. `return <call><op>;`
22
+ * 3. `<call><op>;`
23
+ * Everything else (mid-expression, `await call()?`, ternary surroundings,
24
+ * for-headers, JSX attributes, template `${…}`) is rejected with a clear
25
+ * diagnostic. Bare `obj.prop!` (TypeScript non-null assertion) is preserved
26
+ * verbatim because pass B skips member-access call sites.
27
+ *
28
+ * The failure discriminator (`'err'` vs `'none'`) comes from the CALLEE's
29
+ * kind, not the enclosing function's return type — `Option.some(x)?` always
30
+ * branches on `'none'` regardless of whether the enclosing fn returns
31
+ * Result or Option. Mixed cases (`?` on Option callee inside a Result fn)
32
+ * are rejected.
33
+ *
34
+ * Diagnostics:
35
+ * - INVALID_PROPAGATION — `?` outside a Result/Option fn,
36
+ * mismatched callee/container kind,
37
+ * closure-nested, mid-expression, or
38
+ * `await` in front of the call
39
+ * - UNSAFE_UNWRAP_IN_RESULT_FN — soft warning when `!` lives inside
40
+ * a Result/Option-returning fn (`?`
41
+ * keeps the rich error shape)
42
+ * - NESTED_PROPAGATION — `expr??` chains rejected; bind to
43
+ * a let between steps */
44
+ import type { ParseState } from './parser-diagnostics.js';
45
+ import type { IRNode } from './types.js';
46
+ interface PropagationContext {
47
+ /** Identifiers known to return Result<…> in this module. */
48
+ resultFns: Set<string>;
49
+ /** Identifiers known to return Option<…> in this module. */
50
+ optionFns: Set<string>;
51
+ /** Slice 7 v2.1 — identifiers known to return Promise<Result<…>>. */
52
+ asyncResultFns?: Set<string>;
53
+ /** Slice 7 v2.1 — identifiers known to return Promise<Option<…>>. */
54
+ asyncOptionFns?: Set<string>;
55
+ }
56
+ /** Slice 7 v2 — exported fn signatures of a single KERN module, narrowed
57
+ * to the names whose `returns` is `Result<…>` / `Option<…>` (sync) or
58
+ * `Promise<Result<…>>` / `Promise<Option<…>>` (async). */
59
+ export interface ModuleExports {
60
+ /** Names of fns / methods exported by the module that return `Result<…>`. */
61
+ resultFns: Set<string>;
62
+ /** Names of fns / methods exported by the module that return `Option<…>`. */
63
+ optionFns: Set<string>;
64
+ /** Slice 7 v2.1 — async fns that return `Promise<Result<…>>` (or any
65
+ * fn marked `async=true` with a `Result<…>` return). Recognised at
66
+ * `await call()?` propagation sites. */
67
+ asyncResultFns?: Set<string>;
68
+ /** Slice 7 v2.1 — async fns that return `Promise<Option<…>>`. */
69
+ asyncOptionFns?: Set<string>;
70
+ }
71
+ /** Slice 7 v2 — caller-supplied resolver mapping a `use path="…"` value to
72
+ * the imported KERN module's exported fn signatures. Returning `null`
73
+ * means "this import does not resolve to a KERN module" (bare npm import,
74
+ * unresolved path, or non-KERN file) — those are skipped silently. The
75
+ * CLI builds and supplies the resolver after a project-wide pre-pass.
76
+ * Pure-parse callers (browser playground, tests) can omit it; cross-
77
+ * module recognition is then disabled. */
78
+ export type ImportResolver = (path: string) => ModuleExports | null;
79
+ /** Containing-fn return-type classification for the current handler.
80
+ * `result`/`option` cover the slice 7 v1 sync shapes; `asyncResult` /
81
+ * `asyncOption` cover slice 7 v2.1 — async fns whose declared return is
82
+ * `Promise<Result<…>>` / `Promise<Option<…>>` (or marked `async=true`
83
+ * with the inner Result/Option return). */
84
+ type FnReturn = 'result' | 'option' | 'asyncResult' | 'asyncOption' | 'other';
85
+ export interface PropagationRewriteResult {
86
+ code: string;
87
+ usedUnwrap: boolean;
88
+ }
89
+ type DiagCode = 'INVALID_PROPAGATION' | 'NESTED_PROPAGATION' | 'UNSAFE_UNWRAP_IN_RESULT_FN';
90
+ type Emit = (code: DiagCode, message: string) => void;
91
+ /** Rewrite a single handler body. Public entry exported for tests. */
92
+ export declare function rewritePropagationInBody(code: string, fnReturn: FnReturn, ctx: PropagationContext, emit: Emit): PropagationRewriteResult;
93
+ /** Walk the IR and rewrite every fn/method handler body in place. Returns
94
+ * the set of nodes whose handlers used `!` so the codegen can decide
95
+ * whether to add `KernUnwrapError` to the auto-emitted preamble.
96
+ *
97
+ * Slice 7 v2 — when `resolveImport` is supplied, fn names imported via
98
+ * `use path="…"` get merged into the recognised set so cross-module
99
+ * `parseUser(raw)?` calls propagate. The CLI builds the resolver from a
100
+ * project-wide pre-pass; pure-parse callers omit it and cross-module
101
+ * recognition is disabled. */
102
+ export declare function validateAndRewritePropagation(state: ParseState, root: IRNode, resolveImport?: ImportResolver): {
103
+ unwrapUsedAnywhere: boolean;
104
+ };
105
+ export {};