@nola-lang/compiler 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/ambient-stub.d.ts +8 -0
- package/dist/ambient-stub.d.ts.map +1 -0
- package/dist/ambient-stub.js +71 -0
- package/dist/ambient-stub.js.map +1 -0
- package/dist/companion-name.d.ts +22 -0
- package/dist/companion-name.d.ts.map +1 -0
- package/dist/companion-name.js +48 -0
- package/dist/companion-name.js.map +1 -0
- package/dist/companion.d.ts +22 -0
- package/dist/companion.d.ts.map +1 -0
- package/dist/companion.js +90 -0
- package/dist/companion.js.map +1 -0
- package/dist/compile.d.ts +3 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +33 -0
- package/dist/compile.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/lower/Lowerer.d.ts +56 -0
- package/dist/lower/Lowerer.d.ts.map +1 -0
- package/dist/lower/Lowerer.js +353 -0
- package/dist/lower/Lowerer.js.map +1 -0
- package/dist/lower/index.d.ts +8 -0
- package/dist/lower/index.d.ts.map +1 -0
- package/dist/lower/index.js +5 -0
- package/dist/lower/index.js.map +1 -0
- package/dist/lower/lower.d.ts +2 -0
- package/dist/lower/lower.d.ts.map +1 -0
- package/dist/lower/lower.js +319 -0
- package/dist/lower/lower.js.map +1 -0
- package/dist/lower/templates.d.ts +61 -0
- package/dist/lower/templates.d.ts.map +1 -0
- package/dist/lower/templates.js +70 -0
- package/dist/lower/templates.js.map +1 -0
- package/dist/lower.d.ts +4 -0
- package/dist/lower.d.ts.map +1 -0
- package/dist/lower.js +322 -0
- package/dist/lower.js.map +1 -0
- package/dist/path.d.ts +16 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +28 -0
- package/dist/path.js.map +1 -0
- package/dist/schema-expr.d.ts +61 -0
- package/dist/schema-expr.d.ts.map +1 -0
- package/dist/schema-expr.js +211 -0
- package/dist/schema-expr.js.map +1 -0
- package/dist/schema.d.ts +16 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +152 -0
- package/dist/schema.js.map +1 -0
- package/dist/spans.d.ts +73 -0
- package/dist/spans.d.ts.map +1 -0
- package/dist/spans.js +169 -0
- package/dist/spans.js.map +1 -0
- package/dist/static-config.d.ts +15 -0
- package/dist/static-config.d.ts.map +1 -0
- package/dist/static-config.js +93 -0
- package/dist/static-config.js.map +1 -0
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Evgen Mykhailenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Part of [Nola](https://github.com/nola-lang/nola), a TypeScript superset (`.tsi`) where `infer` functions and `ask` extractors turn prompts into typed values.
|
|
2
|
+
|
|
3
|
+
**Internal package** — you probably want [`nola-lang`](https://www.npmjs.com/package/nola-lang) (the dev tool) or [`@nola-lang/runtime`](https://www.npmjs.com/package/@nola-lang/runtime) (the app dependency).
|
|
4
|
+
|
|
5
|
+
This package lowers Nola constructs to plain TypeScript (the JSX model): byte-identical outside replaced spans, source maps, schema derivation, and companion modules for cross-file types.
|
|
6
|
+
|
|
7
|
+
Versioned in lockstep with the whole toolchain; internal APIs may change in any release.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient declarations of the emit surface — what lowered code references when
|
|
3
|
+
* the real `@nola-lang/runtime` package is not resolvable (bare test projects).
|
|
4
|
+
* Single-sourced here since Track 2; tshost (nola check) and the tsc-clean test
|
|
5
|
+
* helper both import it. Keep in lockstep with __nola.ts + emit-surface.test.ts.
|
|
6
|
+
*/
|
|
7
|
+
export declare const RUNTIME_AMBIENT_STUB = "\nexport type JsonSchema = { type: string } & Record<string, unknown>;\nexport interface Askable<T = unknown> {\n withRetry(retries: number): Askable<T>;\n withProvider(provider: string): Askable<T>;\n withParams(params: Record<string, unknown>): Askable<T>;\n}\nexport interface Intent<T = unknown> extends Askable<T>, PromiseLike<T> {\n withRetry(retries: number): Intent<T>;\n withProvider(provider: string): Intent<T>;\n withParams(params: Record<string, unknown>): Intent<T>;\n withTimeout(timeout: number): Intent<T>;\n detached(): Intent<T>;\n}\nexport interface InferContext {\n scope(data: Record<string, unknown>): InferContext;\n}\nexport interface InferType<T = unknown> {\n describe(text: string): InferType<T>;\n toJsonSchema(): JsonSchema;\n}\nexport interface FunctionInferContext extends InferContext {\n readonly __nolaFunctionScope: true;\n}\nexport interface FileInferContext extends InferContext {\n func(init: {\n fn: string; instruction?: string;\n args?: Array<{ name: string; type?: InferType<unknown>; contextual?: boolean; value?: unknown }>;\n }): FunctionInferContext;\n}\nexport interface Frame {\n readonly infer: InferContext;\n}\nexport interface UnsupportedType<Reason extends string = string> {\n readonly __nolaTypeUnsupported: Reason;\n}\nexport declare const __nola: {\n intents: {\n Intent<T>(executor: (ctx: Frame) => Promise<T>, scope: FunctionInferContext): Intent<T>;\n ExtractIntent<T = unknown>(init: { instruction: string; type: unknown; loc: string }): Askable<T>;\n FunctionCallingIntent<T = unknown>(init: {\n fn: unknown; name: string; instruction: string; loc: string; args: unknown[];\n }): Askable<T>;\n };\n types: {\n string(): InferType<string>;\n number(): InferType<number>;\n boolean(): InferType<boolean>;\n date(): InferType<Date>;\n enum(labels: readonly string[]): InferType<string>;\n array<T>(item: InferType<T>): InferType<T[]>;\n object(props: Record<string, InferType<unknown>>): InferType<Record<string, unknown>>;\n optional<T>(t: InferType<T>): InferType<T | undefined>;\n ref<T = unknown>(name: string, resolve: () => InferType<T>): InferType<T>;\n unsupported<R extends string>(reason: R): UnsupportedType<R>;\n };\n context: {\n file(file: string): FileInferContext;\n };\n ask<T>(value: Askable<T>, ctx: Frame, provider?: string): Promise<T>;\n fmt(value: unknown): string;\n useRuntime(v: number): void;\n};\n";
|
|
8
|
+
//# sourceMappingURL=ambient-stub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ambient-stub.d.ts","sourceRoot":"","sources":["../src/ambient-stub.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,u6EA+DhC,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient declarations of the emit surface — what lowered code references when
|
|
3
|
+
* the real `@nola-lang/runtime` package is not resolvable (bare test projects).
|
|
4
|
+
* Single-sourced here since Track 2; tshost (nola check) and the tsc-clean test
|
|
5
|
+
* helper both import it. Keep in lockstep with __nola.ts + emit-surface.test.ts.
|
|
6
|
+
*/
|
|
7
|
+
export const RUNTIME_AMBIENT_STUB = `
|
|
8
|
+
export type JsonSchema = { type: string } & Record<string, unknown>;
|
|
9
|
+
export interface Askable<T = unknown> {
|
|
10
|
+
withRetry(retries: number): Askable<T>;
|
|
11
|
+
withProvider(provider: string): Askable<T>;
|
|
12
|
+
withParams(params: Record<string, unknown>): Askable<T>;
|
|
13
|
+
}
|
|
14
|
+
export interface Intent<T = unknown> extends Askable<T>, PromiseLike<T> {
|
|
15
|
+
withRetry(retries: number): Intent<T>;
|
|
16
|
+
withProvider(provider: string): Intent<T>;
|
|
17
|
+
withParams(params: Record<string, unknown>): Intent<T>;
|
|
18
|
+
withTimeout(timeout: number): Intent<T>;
|
|
19
|
+
detached(): Intent<T>;
|
|
20
|
+
}
|
|
21
|
+
export interface InferContext {
|
|
22
|
+
scope(data: Record<string, unknown>): InferContext;
|
|
23
|
+
}
|
|
24
|
+
export interface InferType<T = unknown> {
|
|
25
|
+
describe(text: string): InferType<T>;
|
|
26
|
+
toJsonSchema(): JsonSchema;
|
|
27
|
+
}
|
|
28
|
+
export interface FunctionInferContext extends InferContext {
|
|
29
|
+
readonly __nolaFunctionScope: true;
|
|
30
|
+
}
|
|
31
|
+
export interface FileInferContext extends InferContext {
|
|
32
|
+
func(init: {
|
|
33
|
+
fn: string; instruction?: string;
|
|
34
|
+
args?: Array<{ name: string; type?: InferType<unknown>; contextual?: boolean; value?: unknown }>;
|
|
35
|
+
}): FunctionInferContext;
|
|
36
|
+
}
|
|
37
|
+
export interface Frame {
|
|
38
|
+
readonly infer: InferContext;
|
|
39
|
+
}
|
|
40
|
+
export interface UnsupportedType<Reason extends string = string> {
|
|
41
|
+
readonly __nolaTypeUnsupported: Reason;
|
|
42
|
+
}
|
|
43
|
+
export declare const __nola: {
|
|
44
|
+
intents: {
|
|
45
|
+
Intent<T>(executor: (ctx: Frame) => Promise<T>, scope: FunctionInferContext): Intent<T>;
|
|
46
|
+
ExtractIntent<T = unknown>(init: { instruction: string; type: unknown; loc: string }): Askable<T>;
|
|
47
|
+
FunctionCallingIntent<T = unknown>(init: {
|
|
48
|
+
fn: unknown; name: string; instruction: string; loc: string; args: unknown[];
|
|
49
|
+
}): Askable<T>;
|
|
50
|
+
};
|
|
51
|
+
types: {
|
|
52
|
+
string(): InferType<string>;
|
|
53
|
+
number(): InferType<number>;
|
|
54
|
+
boolean(): InferType<boolean>;
|
|
55
|
+
date(): InferType<Date>;
|
|
56
|
+
enum(labels: readonly string[]): InferType<string>;
|
|
57
|
+
array<T>(item: InferType<T>): InferType<T[]>;
|
|
58
|
+
object(props: Record<string, InferType<unknown>>): InferType<Record<string, unknown>>;
|
|
59
|
+
optional<T>(t: InferType<T>): InferType<T | undefined>;
|
|
60
|
+
ref<T = unknown>(name: string, resolve: () => InferType<T>): InferType<T>;
|
|
61
|
+
unsupported<R extends string>(reason: R): UnsupportedType<R>;
|
|
62
|
+
};
|
|
63
|
+
context: {
|
|
64
|
+
file(file: string): FileInferContext;
|
|
65
|
+
};
|
|
66
|
+
ask<T>(value: Askable<T>, ctx: Frame, provider?: string): Promise<T>;
|
|
67
|
+
fmt(value: unknown): string;
|
|
68
|
+
useRuntime(v: number): void;
|
|
69
|
+
};
|
|
70
|
+
`;
|
|
71
|
+
//# sourceMappingURL=ambient-stub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ambient-stub.js","sourceRoot":"","sources":["../src/ambient-stub.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+DnC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Pure string transforms for the reserved `*.nola.js` companion namespace. */
|
|
2
|
+
export declare function isCompanionSpecifier(s: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Forward transform: the specifier the lowerer emits for a type import.
|
|
5
|
+
* `.js`/`.ts` are interchangeable origins (NodeNext vs type-stripping worlds),
|
|
6
|
+
* so both collapse to the extensionless base; `.tsi` and `.d.ts` stay whole so
|
|
7
|
+
* the reverse is exact.
|
|
8
|
+
*/
|
|
9
|
+
export declare function companionSpecifierFor(sourceSpecifier: string): string;
|
|
10
|
+
/** Reverse transform: candidate source specifiers, in probe order. */
|
|
11
|
+
export declare function companionSourceCandidates(companionSpecifier: string): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Stable identity of the module a specifier points at, relative to the project
|
|
14
|
+
* root — used to qualify ref names so same-named types from different files
|
|
15
|
+
* stay distinct inside one $defs. Pure path arithmetic, no resolution.
|
|
16
|
+
*/
|
|
17
|
+
export declare function moduleIdFor(importerDisplayFile: string, specifier: string): string;
|
|
18
|
+
/** The whole `*.nola.*` filename namespace is reserved (spec invariant 3). */
|
|
19
|
+
export declare function isReservedNolaName(fileName: string): boolean;
|
|
20
|
+
/** The virtual TS document name for a lowered .tsi file (tshost + editor share it). */
|
|
21
|
+
export declare function loweredVirtualNameFor(file: string): string;
|
|
22
|
+
//# sourceMappingURL=companion-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"companion-name.d.ts","sourceRoot":"","sources":["../src/companion-name.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAE/E,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAGrE;AAED,sEAAsE;AACtE,wBAAgB,yBAAyB,CAAC,kBAAkB,EAAE,MAAM,GAAG,MAAM,EAAE,CAI9E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,mBAAmB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAQlF;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAG5D;AAED,uFAAuF;AACvF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Pure string transforms for the reserved `*.nola.js` companion namespace. */
|
|
2
|
+
export function isCompanionSpecifier(s) {
|
|
3
|
+
return s.endsWith(".nola.js");
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Forward transform: the specifier the lowerer emits for a type import.
|
|
7
|
+
* `.js`/`.ts` are interchangeable origins (NodeNext vs type-stripping worlds),
|
|
8
|
+
* so both collapse to the extensionless base; `.tsi` and `.d.ts` stay whole so
|
|
9
|
+
* the reverse is exact.
|
|
10
|
+
*/
|
|
11
|
+
export function companionSpecifierFor(sourceSpecifier) {
|
|
12
|
+
const base = /\.d\.ts$/.test(sourceSpecifier) ? sourceSpecifier : sourceSpecifier.replace(/\.(?:js|ts)$/, "");
|
|
13
|
+
return `${base}.nola.js`;
|
|
14
|
+
}
|
|
15
|
+
/** Reverse transform: candidate source specifiers, in probe order. */
|
|
16
|
+
export function companionSourceCandidates(companionSpecifier) {
|
|
17
|
+
const base = companionSpecifier.slice(0, -".nola.js".length);
|
|
18
|
+
if (/\.(?:tsi|d\.ts)$/.test(base))
|
|
19
|
+
return [base];
|
|
20
|
+
return [`${base}.ts`, `${base}.tsi`, `${base}.js`];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Stable identity of the module a specifier points at, relative to the project
|
|
24
|
+
* root — used to qualify ref names so same-named types from different files
|
|
25
|
+
* stay distinct inside one $defs. Pure path arithmetic, no resolution.
|
|
26
|
+
*/
|
|
27
|
+
export function moduleIdFor(importerDisplayFile, specifier) {
|
|
28
|
+
const stack = importerDisplayFile.replace(/\\/g, "/").split("/").slice(0, -1);
|
|
29
|
+
for (const part of specifier.replace(/\\/g, "/").split("/")) {
|
|
30
|
+
if (part === "" || part === ".")
|
|
31
|
+
continue;
|
|
32
|
+
if (part === "..")
|
|
33
|
+
stack.pop();
|
|
34
|
+
else
|
|
35
|
+
stack.push(part);
|
|
36
|
+
}
|
|
37
|
+
return stack.join("/").replace(/\.(?:tsi|ts|js)$/, "");
|
|
38
|
+
}
|
|
39
|
+
/** The whole `*.nola.*` filename namespace is reserved (spec invariant 3). */
|
|
40
|
+
export function isReservedNolaName(fileName) {
|
|
41
|
+
const base = fileName.replace(/\\/g, "/").split("/").pop() ?? "";
|
|
42
|
+
return /\.nola\./.test(base);
|
|
43
|
+
}
|
|
44
|
+
/** The virtual TS document name for a lowered .tsi file (tshost + editor share it). */
|
|
45
|
+
export function loweredVirtualNameFor(file) {
|
|
46
|
+
return `${file.replace(/\\/g, "/")}.ts`;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=companion-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"companion-name.js","sourceRoot":"","sources":["../src/companion-name.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAE/E,MAAM,UAAU,oBAAoB,CAAC,CAAS;IAC5C,OAAO,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,eAAuB;IAC3D,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IAC9G,OAAO,GAAG,IAAI,UAAU,CAAC;AAC3B,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,yBAAyB,CAAC,kBAA0B;IAClE,MAAM,IAAI,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CA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AAC,KAAK,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Diagnostic } from "@nola-lang/ast";
|
|
2
|
+
import type { CompileOptions } from "./types.js";
|
|
3
|
+
export interface CompanionResult {
|
|
4
|
+
/** a TS module; "" when the source could not be parsed at all */
|
|
5
|
+
code: string;
|
|
6
|
+
/** companion specifiers THIS module imports (transitive worklist fuel) */
|
|
7
|
+
companions: string[];
|
|
8
|
+
diagnostics: Diagnostic[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Derive the companion module of one source file: an accessor per exported
|
|
12
|
+
* type (plus reachable private helpers), re-exported under the type's own
|
|
13
|
+
* name (`<Name>` — companions are INTERNAL, only generated code imports
|
|
14
|
+
* them, so the export name needs no user-facing disambiguation). Every
|
|
15
|
+
* accessor is a hoisted `function` declaration and exports are aliases — ESM
|
|
16
|
+
* initializes function bindings during instantiation, which is what makes
|
|
17
|
+
* CIRCULAR companion imports work. All refs are `<moduleId>#`-qualified so
|
|
18
|
+
* same-named types from different files stay distinct in one $defs. Pure —
|
|
19
|
+
* same inputs as compileNola; hosts do all I/O and probing.
|
|
20
|
+
*/
|
|
21
|
+
export declare function compileCompanion(source: string, file: string, options?: CompileOptions): CompanionResult;
|
|
22
|
+
//# sourceMappingURL=companion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"companion.d.ts","sourceRoot":"","sources":["../src/companion.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAMhB,MAAM,gBAAgB,CAAC;AAcxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,eAAe;IAC9B,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAqBD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,eAAe,CAwD5G"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { programBody, } from "@nola-lang/ast";
|
|
2
|
+
import { NOLA_EMIT } from "@nola-lang/core";
|
|
3
|
+
import { parseNola } from "@nola-lang/parser";
|
|
4
|
+
import { companionSpecifierFor } from "./companion-name.js";
|
|
5
|
+
import { displayPathFor } from "./path.js";
|
|
6
|
+
import { collectTypeRegistry } from "./schema.js";
|
|
7
|
+
import { accessorNameFor, buildAccessorPlan, collectTypeImports, deriveTypeExpr, } from "./schema-expr.js";
|
|
8
|
+
/** Exported type/interface/enum names, in declaration order. */
|
|
9
|
+
function collectExportedTypeNames(ast) {
|
|
10
|
+
const out = [];
|
|
11
|
+
for (const stmt of programBody(ast)) {
|
|
12
|
+
if (stmt.type !== "ExportNamedDeclaration")
|
|
13
|
+
continue;
|
|
14
|
+
const decl = stmt.declaration;
|
|
15
|
+
if (!decl)
|
|
16
|
+
continue;
|
|
17
|
+
if (decl.type === "TSTypeAliasDeclaration" ||
|
|
18
|
+
decl.type === "TSInterfaceDeclaration" ||
|
|
19
|
+
decl.type === "TSEnumDeclaration") {
|
|
20
|
+
const name = decl.id?.name;
|
|
21
|
+
if (name)
|
|
22
|
+
out.push(name);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Derive the companion module of one source file: an accessor per exported
|
|
29
|
+
* type (plus reachable private helpers), re-exported under the type's own
|
|
30
|
+
* name (`<Name>` — companions are INTERNAL, only generated code imports
|
|
31
|
+
* them, so the export name needs no user-facing disambiguation). Every
|
|
32
|
+
* accessor is a hoisted `function` declaration and exports are aliases — ESM
|
|
33
|
+
* initializes function bindings during instantiation, which is what makes
|
|
34
|
+
* CIRCULAR companion imports work. All refs are `<moduleId>#`-qualified so
|
|
35
|
+
* same-named types from different files stay distinct in one $defs. Pure —
|
|
36
|
+
* same inputs as compileNola; hosts do all I/O and probing.
|
|
37
|
+
*/
|
|
38
|
+
export function compileCompanion(source, file, options = {}) {
|
|
39
|
+
const { ast, diagnostics } = parseNola(source, file, { tolerant: true });
|
|
40
|
+
if (!ast)
|
|
41
|
+
return { code: "", companions: [], diagnostics };
|
|
42
|
+
const displayFile = displayPathFor(file, options.sourceRoot);
|
|
43
|
+
const moduleId = displayFile.replace(/\\/g, "/").replace(/\.(?:tsi|ts|js)$/, "");
|
|
44
|
+
const registry = collectTypeRegistry(ast);
|
|
45
|
+
const ctx = {
|
|
46
|
+
source,
|
|
47
|
+
registry,
|
|
48
|
+
imports: collectTypeImports(ast),
|
|
49
|
+
importerDisplayFile: displayFile,
|
|
50
|
+
refQualifier: `${moduleId}#`,
|
|
51
|
+
};
|
|
52
|
+
const exported = collectExportedTypeNames(ast).filter((n) => registry.has(n));
|
|
53
|
+
const accessors = new Map(); // name -> full statement text
|
|
54
|
+
const companionImports = new Map();
|
|
55
|
+
const plan = buildAccessorPlan(new Set(exported), ctx);
|
|
56
|
+
for (const [local, imp] of plan.companions)
|
|
57
|
+
companionImports.set(local, imp);
|
|
58
|
+
for (const [name, expr] of plan.accessors) {
|
|
59
|
+
accessors.set(name, `function ${accessorNameFor(name)}(): InferType<unknown> { return ${expr}; }`);
|
|
60
|
+
}
|
|
61
|
+
// Exported types the plan could not derive become unsupported accessors: the
|
|
62
|
+
// module still compiles, and the failure surfaces at the USE site as a TS
|
|
63
|
+
// error carrying the reason (UnsupportedType<Reason>) or NOLA3009 at run
|
|
64
|
+
// time if it executes anyway.
|
|
65
|
+
for (const name of exported) {
|
|
66
|
+
if (accessors.has(name))
|
|
67
|
+
continue;
|
|
68
|
+
const decl = registry.get(name);
|
|
69
|
+
const derived = deriveTypeExpr(decl, ctx);
|
|
70
|
+
const reason = derived.ok ? "internal: derivation succeeded on retry" : derived.message;
|
|
71
|
+
const literal = JSON.stringify(reason);
|
|
72
|
+
accessors.set(name, `function ${accessorNameFor(name)}(): UnsupportedType<${literal}> { return __nola.types.unsupported(${literal}) as UnsupportedType<${literal}>; }`);
|
|
73
|
+
}
|
|
74
|
+
const lines = [
|
|
75
|
+
`import { __nola } from "@nola-lang/runtime";`,
|
|
76
|
+
`__nola.useRuntime(${NOLA_EMIT});`,
|
|
77
|
+
`import type { InferType, UnsupportedType } from "@nola-lang/runtime";`,
|
|
78
|
+
];
|
|
79
|
+
for (const [local, imp] of companionImports) {
|
|
80
|
+
lines.push(`import { ${imp.importedName} as ${accessorNameFor(local)} } from ${JSON.stringify(companionSpecifierFor(imp.specifier))};`);
|
|
81
|
+
}
|
|
82
|
+
for (const body of accessors.values())
|
|
83
|
+
lines.push(body);
|
|
84
|
+
if (exported.length > 0) {
|
|
85
|
+
lines.push(`export { ${exported.map((n) => `${accessorNameFor(n)} as ${n}`).join(", ")} };`);
|
|
86
|
+
}
|
|
87
|
+
const companions = [...new Set([...companionImports.values()].map((i) => companionSpecifierFor(i.specifier)))].sort();
|
|
88
|
+
return { code: `${lines.join("\n")}\n`, companions, diagnostics };
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=companion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"companion.js","sourceRoot":"","sources":["../src/companion.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,GAIZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,eAAe,EACf,iBAAiB,EAEjB,kBAAkB,EAElB,cAAc,GACf,MAAM,kBAA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,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhE,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,aAAa,CA4BrG"}
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { parseNola } from "@nola-lang/parser";
|
|
2
|
+
import { lower } from "./lower/index.js";
|
|
3
|
+
import { displayPathFor } from "./path.js";
|
|
4
|
+
export function compileNola(source, file, options = {}) {
|
|
5
|
+
const { ast, diagnostics } = parseNola(source, file, { tolerant: options.tolerant });
|
|
6
|
+
if (!ast) {
|
|
7
|
+
return {
|
|
8
|
+
code: source,
|
|
9
|
+
map: { mappings: "", sources: [file] },
|
|
10
|
+
meta: {
|
|
11
|
+
nolaFunctions: [],
|
|
12
|
+
spans: [
|
|
13
|
+
{
|
|
14
|
+
sourceStart: 0,
|
|
15
|
+
sourceEnd: source.length,
|
|
16
|
+
generatedStart: 0,
|
|
17
|
+
generatedEnd: source.length,
|
|
18
|
+
kind: "verbatim",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
anchors: [],
|
|
22
|
+
companions: [],
|
|
23
|
+
mode: "bailed",
|
|
24
|
+
},
|
|
25
|
+
diagnostics,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const result = lower(source, file, ast, displayPathFor(file, options.sourceRoot), {
|
|
29
|
+
underivableContextType: options.underivableContextType,
|
|
30
|
+
});
|
|
31
|
+
return { ...result, diagnostics: [...diagnostics, ...result.diagnostics] };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMapping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AM,CAAC,WAAW,CAAC,EAAE,CAAC;AAC7E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { SourceMap } from "magic-string";
|
|
2
|
+
export { RUNTIME_AMBIENT_STUB } from "./ambient-stub.js";
|
|
3
|
+
export { type CompanionResult, compileCompanion } from "./companion.js";
|
|
4
|
+
export { companionSourceCandidates, companionSpecifierFor, isCompanionSpecifier, isReservedNolaName, loweredVirtualNameFor, moduleIdFor, } from "./companion-name.js";
|
|
5
|
+
export { compileNola } from "./compile.js";
|
|
6
|
+
export { displayPathFor } from "./path.js";
|
|
7
|
+
export { collectTypeRegistry, deriveSchema, type SchemaResult } from "./schema.js";
|
|
8
|
+
export { type AccessorPlan, accessorNameFor, buildAccessorPlan, type CompanionImport, collectTypeImports, type DeriveContext, deriveTypeExpr, type TypeExprResult, } from "./schema-expr.js";
|
|
9
|
+
export { type Anchor, type EditAnchor, type Span, type SpanKind, SpanRecorder } from "./spans.js";
|
|
10
|
+
export { type StaticContextTypeMode, staticUnderivableContextType } from "./static-config.js";
|
|
11
|
+
export type { CompileOptions, CompileResult } from "./types.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,KAAK,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EACL,KAAK,YAAY,EACjB,eAAe,EACf,iBAAiB,EACjB,KAAK,eAAe,EACpB,kBAAkB,EAClB,KAAK,aAAa,EAClB,cAAc,EACd,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAClG,OAAO,EAAE,KAAK,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAC9F,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { RUNTIME_AMBIENT_STUB } from "./ambient-stub.js";
|
|
2
|
+
export { compileCompanion } from "./companion.js";
|
|
3
|
+
export { companionSourceCandidates, companionSpecifierFor, isCompanionSpecifier, isReservedNolaName, loweredVirtualNameFor, moduleIdFor, } from "./companion-name.js";
|
|
4
|
+
export { compileNola } from "./compile.js";
|
|
5
|
+
export { displayPathFor } from "./path.js";
|
|
6
|
+
export { collectTypeRegistry, deriveSchema } from "./schema.js";
|
|
7
|
+
export { accessorNameFor, buildAccessorPlan, collectTypeImports, deriveTypeExpr, } from "./schema-expr.js";
|
|
8
|
+
export { SpanRecorder } from "./spans.js";
|
|
9
|
+
export { staticUnderivableContextType } from "./static-config.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAwB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAqB,MAAM,aAAa,CAAC;AACnF,OAAO,EAEL,eAAe,EACf,iBAAiB,EAEjB,kBAAkB,EAElB,cAAc,GAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA0D,YAAY,EAAE,MAAM,YAAY,CAAC;AAClG,OAAO,EAA8B,4BAA4B,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type BaseNode } from "@nola-lang/ast";
|
|
2
|
+
import type { CompileResult } from "../types.js";
|
|
3
|
+
export declare class Lowerer {
|
|
4
|
+
private readonly s;
|
|
5
|
+
private readonly source;
|
|
6
|
+
/** Absolute on-disk path. Diagnostics and source maps use this. */
|
|
7
|
+
private readonly file;
|
|
8
|
+
/** Project-root-relative path. Only this reaches the emitted code. */
|
|
9
|
+
private readonly displayFile;
|
|
10
|
+
private readonly ast;
|
|
11
|
+
private readonly diagnostics;
|
|
12
|
+
private readonly meta;
|
|
13
|
+
private usedRuntime;
|
|
14
|
+
/** named types needing a __nola_type_<Name> accessor in the appendix, in first-use order */
|
|
15
|
+
private readonly typeAccessors;
|
|
16
|
+
/** local binding name -> companion import emitted in the appendix */
|
|
17
|
+
private readonly companionImports;
|
|
18
|
+
/** shared derivation context (registry, imports, display file, bare ref names) */
|
|
19
|
+
private readonly deriveCtx;
|
|
20
|
+
/** policy for underivable `..`-contextual param types (compiler.underivableContextType) */
|
|
21
|
+
private readonly underivableContextType;
|
|
22
|
+
constructor(source: string, file: string, ast: BaseNode, displayFile: string, options?: {
|
|
23
|
+
underivableContextType?: "error" | "prune" | "omit";
|
|
24
|
+
});
|
|
25
|
+
run(): CompileResult;
|
|
26
|
+
private diag;
|
|
27
|
+
/** Fold a derivation's transitive needs (accessors, companion imports) into the state. */
|
|
28
|
+
private absorbPlan;
|
|
29
|
+
private absorbTypeNeeds;
|
|
30
|
+
/**
|
|
31
|
+
* A `..`-contextual param's type failed to derive (shallowly or in its
|
|
32
|
+
* accessor plan). Resolve it per the configured policy; the returned expr
|
|
33
|
+
* (if any) replaces the failed one.
|
|
34
|
+
*/
|
|
35
|
+
private applyContextTypePolicy;
|
|
36
|
+
/**
|
|
37
|
+
* Lossy derivation for the prune policy: underivable object members drop out
|
|
38
|
+
* instead of failing the type. Named refs derive lazily, so "underivable" is
|
|
39
|
+
* discovered through the accessor plan — every plan failure marks its type
|
|
40
|
+
* dead and the derivation reruns with refs to dead names failing (and thus
|
|
41
|
+
* pruning) at their use sites. deadRefs grows monotonically and is bounded
|
|
42
|
+
* by the registry, so the loop terminates. Returns undefined (-> omit) when
|
|
43
|
+
* the top-level type itself prunes away.
|
|
44
|
+
*/
|
|
45
|
+
private pruneDerive;
|
|
46
|
+
private visit;
|
|
47
|
+
private lowerInferFunction;
|
|
48
|
+
private lowerCallIntent;
|
|
49
|
+
/**
|
|
50
|
+
* NOLA2004 for untyped extractors in slot positions: direct args and anywhere
|
|
51
|
+
* inside plain object/array literal nesting (mirrors the runtime slot walk).
|
|
52
|
+
*/
|
|
53
|
+
private checkCallIntentArg;
|
|
54
|
+
private lowerExtract;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=lowerer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lowerer.d.ts","sourceRoot":"","sources":["../../src/lower/lowerer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EAYd,MAAM,gBAAgB,CAAC;AAYxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAuBjD,qBAAa,OAAO;IAClB,OA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