@junoscript/juno 0.0.0-stage → 0.1.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.
Files changed (57) hide show
  1. package/Modules/async.ts +81 -0
  2. package/Modules/juno-node-fs.ts +105 -0
  3. package/Modules/juno-test.jn +156 -0
  4. package/dist/CLI/build-juno.d.ts +5 -0
  5. package/dist/CLI/build-juno.js +58 -0
  6. package/dist/CLI/generate-juno-types.d.ts +1 -0
  7. package/dist/CLI/generate-juno-types.js +51 -0
  8. package/dist/CLI/junode.d.ts +2 -0
  9. package/dist/CLI/junode.js +32 -0
  10. package/dist/Lexer/lexer.d.ts +42 -0
  11. package/dist/Lexer/lexer.js +300 -0
  12. package/dist/Lexer/parser.d.ts +395 -0
  13. package/dist/Lexer/parser.js +1881 -0
  14. package/dist/Modules/async.d.ts +33 -0
  15. package/dist/Modules/async.js +76 -0
  16. package/dist/Modules/index.d.ts +195 -0
  17. package/dist/Modules/index.js +31 -0
  18. package/dist/Modules/juno-node-fs.d.ts +52 -0
  19. package/dist/Modules/juno-node-fs.js +129 -0
  20. package/dist/Modules/juno-node.d.ts +74 -0
  21. package/dist/Modules/juno-node.js +56 -0
  22. package/dist/Modules/juno-test.d.ts +141 -0
  23. package/dist/Modules/juno-test.js +134 -0
  24. package/dist/Modules/juno-types.d.ts +35 -0
  25. package/dist/Modules/juno-types.js +2 -0
  26. package/dist/Modules/juno.d.ts +21 -0
  27. package/dist/Modules/juno.js +76 -0
  28. package/dist/Modules/types.d.ts +56 -0
  29. package/dist/Modules/types.js +87 -0
  30. package/dist/Runtime/interpreter.d.ts +64 -0
  31. package/dist/Runtime/interpreter.js +2533 -0
  32. package/dist/Runtime/resolve-import.d.ts +2 -0
  33. package/dist/Runtime/resolve-import.js +30 -0
  34. package/dist/vscode-junoscript/src/language.d.ts +86 -0
  35. package/dist/vscode-junoscript/src/language.js +4206 -0
  36. package/package.json +19 -4
  37. package/types/array.jn +158 -0
  38. package/types/boolean.jn +18 -0
  39. package/types/error.jn +28 -0
  40. package/types/error.ts +9 -0
  41. package/types/index.jn +11 -0
  42. package/types/iterable.jn +211 -0
  43. package/types/map.jn +44 -0
  44. package/types/map.ts +132 -0
  45. package/types/number.ts +52 -0
  46. package/types/object.jn +94 -0
  47. package/types/object.ts +49 -0
  48. package/types/queue.jn +46 -0
  49. package/types/random.jn +25 -0
  50. package/types/random.ts +1 -0
  51. package/types/range.jn +27 -0
  52. package/types/set.jn +139 -0
  53. package/types/set.ts +209 -0
  54. package/types/string.jn +33 -0
  55. package/types/string.ts +1 -0
  56. package/types/tuple.jn +11 -0
  57. package/README.md +0 -3
@@ -0,0 +1,141 @@
1
+ import { ModuleMocker } from 'jest-mock';
2
+ type AnyFunction = (...args: any[]) => any;
3
+ type TestCallback = () => unknown | Promise<unknown>;
4
+ export type JunoExpectMatchers = {
5
+ that(actual: unknown): any;
6
+ toBe<T>(actual: T, expected: T): void;
7
+ toBeEqual<T>(actual: T, expected: T): void;
8
+ toEqual<T>(actual: T, expected: T): void;
9
+ toStrictEqual<T>(actual: T, expected: T): void;
10
+ toBeTrue(actual: boolean): void;
11
+ toBeTruthy(actual: unknown): void;
12
+ toBeFalse(actual: boolean): void;
13
+ toBeFalsy(actual: unknown): void;
14
+ toBeDefined<T>(actual: T): void;
15
+ toBeUndefined(actual: unknown): void;
16
+ toBeNull<T>(actual: T): void;
17
+ toBeNaN(actual: number): void;
18
+ toBeCloseTo(actual: number, expected: number, precision?: number): void;
19
+ toBeGreaterThan(actual: number, expected: number): void;
20
+ toBeGreaterThanOrEqual(actual: number, expected: number): void;
21
+ toBeLessThan(actual: number, expected: number): void;
22
+ toBeLessThanOrEqual(actual: number, expected: number): void;
23
+ toContain(actual: unknown, expected: unknown): void;
24
+ toContainEqual(actual: unknown, expected: unknown): void;
25
+ toHaveLength(actual: unknown, expected: number): void;
26
+ toHaveProperty(actual: object, path: string, expected?: unknown): void;
27
+ toMatch(actual: string, expected: string | RegExp): void;
28
+ toMatchObject(actual: object, expected: object): void;
29
+ toThrow(actual: AnyFunction, expected?: unknown): void;
30
+ toBeInstanceOf(actual: unknown, expected: unknown): void;
31
+ toHaveBeenCalled(actual: AnyFunction): void;
32
+ toHaveBeenCalledTimes(actual: AnyFunction, count: number): void;
33
+ toHaveBeenCalledWith(actual: AnyFunction, ...args: unknown[]): void;
34
+ toHaveBeenLastCalledWith(actual: AnyFunction, ...args: unknown[]): void;
35
+ toHaveBeenNthCalledWith(actual: AnyFunction, nth: number, ...args: unknown[]): void;
36
+ toHaveReturned(actual: AnyFunction): void;
37
+ toHaveReturnedTimes(actual: AnyFunction, count: number): void;
38
+ toHaveReturnedWith(actual: AnyFunction, value: unknown): void;
39
+ toHaveLastReturnedWith(actual: AnyFunction, value: unknown): void;
40
+ toHaveNthReturnedWith(actual: AnyFunction, nth: number, value: unknown): void;
41
+ any(type: unknown): unknown;
42
+ anything(): unknown;
43
+ arrayContaining(value: unknown[]): unknown;
44
+ arrayOf(value: unknown): unknown;
45
+ closeTo(value: number, precision?: number): unknown;
46
+ objectContaining(value: object): unknown;
47
+ stringContaining(value: string): unknown;
48
+ stringMatching(value: string | RegExp): unknown;
49
+ assertions(count: number): void;
50
+ hasAssertions(): void;
51
+ extend(matchers: object): void;
52
+ addEqualityTesters(testers: AnyFunction[]): void;
53
+ };
54
+ export type JunoExpect = JunoExpectMatchers & {
55
+ not: JunoExpectMatchers;
56
+ };
57
+ /** Juno-friendly two-argument matchers. `expect.not` contains their inverse. */
58
+ export declare const expect: JunoExpect;
59
+ /** Creates a real Jest mock function, including `.mock`, `mockReturnValue`, etc. */
60
+ export declare function Mock(implementation?: AnyFunction): ReturnType<ModuleMocker['fn']>;
61
+ export declare const spyOn: ModuleMocker["spyOn"];
62
+ export declare const replaceProperty: ModuleMocker["replaceProperty"];
63
+ export declare const isMockFunction: {
64
+ <T extends import("jest-mock").FunctionLike = import("jest-mock").UnknownFunction>(fn: import("jest-mock").MockInstance<T>): fn is import("jest-mock").MockInstance<T>;
65
+ <P extends Array<unknown>, R>(fn: (...args: P) => R): fn is import("jest-mock").Mock<(...args: P) => R>;
66
+ (fn: unknown): fn is import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
67
+ };
68
+ export declare const clearAllMocks: () => void;
69
+ export declare const resetAllMocks: () => void;
70
+ export declare const restoreAllMocks: () => void;
71
+ export declare const useFakeTimers: (fakeTimersConfig?: {
72
+ advanceTimers?: boolean | number;
73
+ doNotFake?: Array<"Date" | "hrtime" | "nextTick" | "performance" | "queueMicrotask" | "requestAnimationFrame" | "cancelAnimationFrame" | "requestIdleCallback" | "cancelIdleCallback" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "setTimeout" | "clearTimeout" | "Temporal">;
74
+ now?: number | Date | {
75
+ epochMilliseconds: number;
76
+ };
77
+ timerLimit?: number;
78
+ legacyFakeTimers?: false;
79
+ }) => void;
80
+ export declare const useRealTimers: () => void;
81
+ export declare const clearAllTimers: () => void;
82
+ export declare const runAllTimers: () => void;
83
+ export declare const runAllTimersAsync: () => Promise<void>;
84
+ export declare const runOnlyPendingTimers: () => void;
85
+ export declare const advanceTimersByTime: (msToRun: number | import("@sinonjs/fake-timers").TemporalDuration) => void;
86
+ export declare const advanceTimersByTimeAsync: (msToRun: number | import("@sinonjs/fake-timers").TemporalDuration) => Promise<void>;
87
+ export declare const advanceTimersToNextTimer: (steps?: number) => void;
88
+ export declare const setSystemTime: (now?: number | Date | import("@sinonjs/fake-timers").TemporalTimelike) => void;
89
+ export declare const getTimerCount: () => number;
90
+ /** A lightweight in-process Jest-style suite for executable `.jn` files. */
91
+ export declare function describe(name: string, body: TestCallback): unknown;
92
+ export declare function beforeEach(callback: TestCallback): void;
93
+ export declare function afterEach(callback: TestCallback): void;
94
+ export declare function test(name: string, body: TestCallback): unknown;
95
+ export declare namespace test {
96
+ var only: typeof test;
97
+ var skip: (_name: string, _body: TestCallback) => void;
98
+ }
99
+ export declare const it: typeof test;
100
+ declare const _default: {
101
+ expect: JunoExpect;
102
+ Mock: typeof Mock;
103
+ spyOn: {
104
+ <T extends object, K extends import("jest-mock").PropertyLikeKeys<T>, V extends Required<T>[K], A extends "get" | "set">(object: T, methodKey: K, accessType: A): A extends "get" ? import("jest-mock").SpiedGetter<V> : A extends "set" ? import("jest-mock").SpiedSetter<V> : never;
105
+ <T extends object, K extends import("jest-mock").ConstructorLikeKeys<T> | import("jest-mock").MethodLikeKeys<T>, V extends Required<T>[K]>(object: T, methodKey: K): V extends import("jest-mock").ClassLike | import("jest-mock").FunctionLike ? import("jest-mock").Spied<V> : never;
106
+ };
107
+ replaceProperty: <T extends object, K extends keyof T>(object: T, propertyKey: K, value: T[K]) => import("jest-mock").Replaced<T[K]>;
108
+ isMockFunction: {
109
+ <T extends import("jest-mock").FunctionLike = import("jest-mock").UnknownFunction>(fn: import("jest-mock").MockInstance<T>): fn is import("jest-mock").MockInstance<T>;
110
+ <P extends Array<unknown>, R>(fn: (...args: P) => R): fn is import("jest-mock").Mock<(...args: P) => R>;
111
+ (fn: unknown): fn is import("jest-mock").Mock<import("jest-mock").UnknownFunction>;
112
+ };
113
+ clearAllMocks: () => void;
114
+ resetAllMocks: () => void;
115
+ restoreAllMocks: () => void;
116
+ describe: typeof describe;
117
+ test: typeof test;
118
+ it: typeof test;
119
+ beforeEach: typeof beforeEach;
120
+ afterEach: typeof afterEach;
121
+ useFakeTimers: (fakeTimersConfig?: {
122
+ advanceTimers?: boolean | number;
123
+ doNotFake?: Array<"Date" | "hrtime" | "nextTick" | "performance" | "queueMicrotask" | "requestAnimationFrame" | "cancelAnimationFrame" | "requestIdleCallback" | "cancelIdleCallback" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "setTimeout" | "clearTimeout" | "Temporal">;
124
+ now?: number | Date | {
125
+ epochMilliseconds: number;
126
+ };
127
+ timerLimit?: number;
128
+ legacyFakeTimers?: false;
129
+ }) => void;
130
+ useRealTimers: () => void;
131
+ clearAllTimers: () => void;
132
+ runAllTimers: () => void;
133
+ runAllTimersAsync: () => Promise<void>;
134
+ runOnlyPendingTimers: () => void;
135
+ advanceTimersByTime: (msToRun: number | import("@sinonjs/fake-timers").TemporalDuration) => void;
136
+ advanceTimersByTimeAsync: (msToRun: number | import("@sinonjs/fake-timers").TemporalDuration) => Promise<void>;
137
+ advanceTimersToNextTimer: (steps?: number) => void;
138
+ setSystemTime: (now?: number | Date | import("@sinonjs/fake-timers").TemporalTimelike) => void;
139
+ getTimerCount: () => number;
140
+ };
141
+ export default _default;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.it = exports.getTimerCount = exports.setSystemTime = exports.advanceTimersToNextTimer = exports.advanceTimersByTimeAsync = exports.advanceTimersByTime = exports.runOnlyPendingTimers = exports.runAllTimersAsync = exports.runAllTimers = exports.clearAllTimers = exports.useRealTimers = exports.useFakeTimers = exports.restoreAllMocks = exports.resetAllMocks = exports.clearAllMocks = exports.isMockFunction = exports.replaceProperty = exports.spyOn = exports.expect = void 0;
7
+ exports.Mock = Mock;
8
+ exports.describe = describe;
9
+ exports.beforeEach = beforeEach;
10
+ exports.afterEach = afterEach;
11
+ exports.test = test;
12
+ const expect_1 = __importDefault(require("expect"));
13
+ const fake_timers_1 = require("@jest/fake-timers");
14
+ const jest_mock_1 = require("jest-mock");
15
+ const moduleMocker = new jest_mock_1.ModuleMocker(globalThis);
16
+ const timers = new fake_timers_1.ModernFakeTimers({
17
+ global: globalThis,
18
+ config: { fakeTimers: { enableGlobally: false } }
19
+ });
20
+ /** Jest's regular `expect(value)` entry point. */
21
+ const that = expect_1.default;
22
+ function assertion(jestName, actual, expected, inverse) {
23
+ const matchers = inverse ? (0, expect_1.default)(actual).not : (0, expect_1.default)(actual);
24
+ const candidate = matchers[jestName];
25
+ if (typeof candidate !== 'function')
26
+ throw new TypeError(`Unknown Jest matcher '${jestName}'`);
27
+ candidate.apply(matchers, expected);
28
+ }
29
+ const matcherNames = {
30
+ toBe: 'toBe', toBeEqual: 'toEqual', toEqual: 'toEqual', toStrictEqual: 'toStrictEqual',
31
+ toBeTrue: 'toBeTruthy', toBeTruthy: 'toBeTruthy', toBeFalse: 'toBeFalsy', toBeFalsy: 'toBeFalsy',
32
+ toBeDefined: 'toBeDefined', toBeUndefined: 'toBeUndefined', toBeNull: 'toBeNull', toBeNaN: 'toBeNaN',
33
+ toBeCloseTo: 'toBeCloseTo', toBeGreaterThan: 'toBeGreaterThan', toBeGreaterThanOrEqual: 'toBeGreaterThanOrEqual',
34
+ toBeLessThan: 'toBeLessThan', toBeLessThanOrEqual: 'toBeLessThanOrEqual', toContain: 'toContain',
35
+ toContainEqual: 'toContainEqual', toHaveLength: 'toHaveLength', toHaveProperty: 'toHaveProperty',
36
+ toMatch: 'toMatch', toMatchObject: 'toMatchObject', toThrow: 'toThrow', toBeInstanceOf: 'toBeInstanceOf',
37
+ toHaveBeenCalled: 'toHaveBeenCalled', toHaveBeenCalledTimes: 'toHaveBeenCalledTimes',
38
+ toHaveBeenCalledWith: 'toHaveBeenCalledWith', toHaveBeenLastCalledWith: 'toHaveBeenLastCalledWith',
39
+ toHaveBeenNthCalledWith: 'toHaveBeenNthCalledWith', toHaveReturned: 'toHaveReturned',
40
+ toHaveReturnedTimes: 'toHaveReturnedTimes', toHaveReturnedWith: 'toHaveReturnedWith',
41
+ toHaveLastReturnedWith: 'toHaveLastReturnedWith', toHaveNthReturnedWith: 'toHaveNthReturnedWith'
42
+ };
43
+ function createExpect(inverse) {
44
+ const api = {
45
+ that, any: expect_1.default.any, anything: expect_1.default.anything,
46
+ arrayContaining: expect_1.default.arrayContaining, arrayOf: expect_1.default.arrayOf,
47
+ closeTo: expect_1.default.closeTo, objectContaining: expect_1.default.objectContaining,
48
+ stringContaining: expect_1.default.stringContaining, stringMatching: expect_1.default.stringMatching,
49
+ assertions: expect_1.default.assertions, hasAssertions: expect_1.default.hasAssertions,
50
+ extend: expect_1.default.extend, addEqualityTesters: expect_1.default.addEqualityTesters
51
+ };
52
+ for (const [name, jestName] of Object.entries(matcherNames)) {
53
+ api[name] = (actual, ...expected) => {
54
+ if (name === 'toBeDefined')
55
+ return assertion('toBeNull', actual, [], !inverse);
56
+ if (name === 'toBeTrue')
57
+ return assertion('toBe', actual, [true], inverse);
58
+ if (name === 'toBeFalse')
59
+ return assertion('toBe', actual, [false], inverse);
60
+ return assertion(jestName, actual, expected, inverse);
61
+ };
62
+ }
63
+ return api;
64
+ }
65
+ /** Juno-friendly two-argument matchers. `expect.not` contains their inverse. */
66
+ exports.expect = createExpect(false);
67
+ exports.expect.not = createExpect(true);
68
+ /** Creates a real Jest mock function, including `.mock`, `mockReturnValue`, etc. */
69
+ function Mock(implementation) {
70
+ return moduleMocker.fn(implementation);
71
+ }
72
+ exports.spyOn = moduleMocker.spyOn.bind(moduleMocker);
73
+ exports.replaceProperty = moduleMocker.replaceProperty.bind(moduleMocker);
74
+ exports.isMockFunction = moduleMocker.isMockFunction.bind(moduleMocker);
75
+ exports.clearAllMocks = moduleMocker.clearAllMocks.bind(moduleMocker);
76
+ exports.resetAllMocks = moduleMocker.resetAllMocks.bind(moduleMocker);
77
+ exports.restoreAllMocks = moduleMocker.restoreAllMocks.bind(moduleMocker);
78
+ exports.useFakeTimers = timers.useFakeTimers.bind(timers);
79
+ exports.useRealTimers = timers.useRealTimers.bind(timers);
80
+ exports.clearAllTimers = timers.clearAllTimers.bind(timers);
81
+ exports.runAllTimers = timers.runAllTimers.bind(timers);
82
+ exports.runAllTimersAsync = timers.runAllTimersAsync.bind(timers);
83
+ exports.runOnlyPendingTimers = timers.runOnlyPendingTimers.bind(timers);
84
+ exports.advanceTimersByTime = timers.advanceTimersByTime.bind(timers);
85
+ exports.advanceTimersByTimeAsync = timers.advanceTimersByTimeAsync.bind(timers);
86
+ exports.advanceTimersToNextTimer = timers.advanceTimersToNextTimer.bind(timers);
87
+ exports.setSystemTime = timers.setSystemTime.bind(timers);
88
+ exports.getTimerCount = timers.getTimerCount.bind(timers);
89
+ let suiteNames = [];
90
+ let beforeEachCallbacks = [];
91
+ let afterEachCallbacks = [];
92
+ /** A lightweight in-process Jest-style suite for executable `.jn` files. */
93
+ function describe(name, body) {
94
+ suiteNames.push(name);
95
+ try {
96
+ return body();
97
+ }
98
+ finally {
99
+ suiteNames.pop();
100
+ }
101
+ }
102
+ function beforeEach(callback) { beforeEachCallbacks.push(callback); }
103
+ function afterEach(callback) { afterEachCallbacks.push(callback); }
104
+ function test(name, body) {
105
+ const fullName = [...suiteNames, name].join(' > ');
106
+ const execute = async () => {
107
+ try {
108
+ for (const callback of beforeEachCallbacks)
109
+ await callback();
110
+ await body();
111
+ console.log(`\u2713 ${fullName}`);
112
+ }
113
+ catch (error) {
114
+ console.error(`\u2717 ${fullName}`);
115
+ throw error;
116
+ }
117
+ finally {
118
+ for (const callback of afterEachCallbacks)
119
+ await callback();
120
+ }
121
+ };
122
+ return execute();
123
+ }
124
+ test.only = test;
125
+ test.skip = (_name, _body) => undefined;
126
+ exports.it = test;
127
+ exports.default = {
128
+ expect: exports.expect, Mock, spyOn: exports.spyOn, replaceProperty: exports.replaceProperty, isMockFunction: exports.isMockFunction,
129
+ clearAllMocks: exports.clearAllMocks, resetAllMocks: exports.resetAllMocks, restoreAllMocks: exports.restoreAllMocks,
130
+ describe, test, it: exports.it, beforeEach, afterEach,
131
+ useFakeTimers: exports.useFakeTimers, useRealTimers: exports.useRealTimers, clearAllTimers: exports.clearAllTimers, runAllTimers: exports.runAllTimers, runAllTimersAsync: exports.runAllTimersAsync,
132
+ runOnlyPendingTimers: exports.runOnlyPendingTimers, advanceTimersByTime: exports.advanceTimersByTime, advanceTimersByTimeAsync: exports.advanceTimersByTimeAsync,
133
+ advanceTimersToNextTimer: exports.advanceTimersToNextTimer, setSystemTime: exports.setSystemTime, getTimerCount: exports.getTimerCount
134
+ };
@@ -0,0 +1,35 @@
1
+ /** Generated from types/iterable.jn. Edit the JunoScript source instead. */
2
+ export type Iterable<T> = (({
3
+ iterator(): () => ({
4
+ value: T;
5
+ } | null);
6
+ } | {
7
+ toArray(): Array<T>;
8
+ }) & {
9
+ toArray(): Array<T>;
10
+ get length(): number;
11
+ at(index: number): (T | null);
12
+ concat(other: Array<T>): Array<T>;
13
+ every(callback: (arg0: T) => boolean): boolean;
14
+ filter(callback: (arg0: T) => boolean): Array<T>;
15
+ flat(): Array<unknown>;
16
+ find(callback: (arg0: T) => boolean): (T | null);
17
+ findLast(callback: (arg0: T) => boolean): (T | null);
18
+ flatMap(callback: (arg0: T) => Array<T>): Array<T>;
19
+ forEach(callback: (arg0: T) => unknown): void;
20
+ includes(value: T): boolean;
21
+ indexOf(value: T): number;
22
+ lastIndexOf(value: T): number;
23
+ join(separator?: string): string;
24
+ map(callback: (arg0: T) => unknown): Array<unknown>;
25
+ reduce(callback: (arg0: T, arg1: T) => T, initial: T): T;
26
+ reduceRight(callback: (arg0: T, arg1: T) => T, initial: T): T;
27
+ slice(start?: number, end?: number): Array<T>;
28
+ toReversed(): Array<T>;
29
+ toSorted(): Array<T>;
30
+ toLocaleString(): string;
31
+ toString(): string;
32
+ toSpliced(start: number, deleteCount: number, items?: Array<T>): Array<T>;
33
+ with(index: number, value: T): Array<T>;
34
+ some(callback: (arg0: T) => boolean): boolean;
35
+ });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ /** Standard JunoScript console module; mirrors the JavaScript/TypeScript console. */
2
+ import { types } from './types';
3
+ import type { Iterable } from './juno-types';
4
+ export declare const console: Console;
5
+ export { types };
6
+ export type { Iterable } from './juno-types';
7
+ export type Range = Iterable<number> & {
8
+ readonly start: number;
9
+ readonly end: number;
10
+ readonly step: number;
11
+ };
12
+ /** TypeScript entry point matching the JunoScript Range constructor. */
13
+ export declare function Range(start: number, end?: number, step?: number): Range;
14
+ /** TypeScript-compatible error shape for values thrown or returned by Juno code. */
15
+ export type Error = {
16
+ name: string;
17
+ message: string;
18
+ stack?: string;
19
+ };
20
+ declare const juno: Record<string, any>;
21
+ export default juno;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.types = exports.console = void 0;
4
+ exports.Range = Range;
5
+ /** Standard JunoScript console module; mirrors the JavaScript/TypeScript console. */
6
+ const types_1 = require("./types");
7
+ Object.defineProperty(exports, "types", { enumerable: true, get: function () { return types_1.types; } });
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = require("node:path");
10
+ const lexer_1 = require("../Lexer/lexer");
11
+ const parser_1 = require("../Lexer/parser");
12
+ exports.console = globalThis.console;
13
+ /** TypeScript entry point matching the JunoScript Range constructor. */
14
+ function Range(start, end, step = 1) {
15
+ if (end === undefined)
16
+ [start, end] = [0, start];
17
+ const first = start;
18
+ const last = end;
19
+ const values = () => {
20
+ const result = [];
21
+ if (step > 0)
22
+ for (let value = first; value < last; value += step)
23
+ result.push(value);
24
+ else if (step < 0)
25
+ for (let value = first; value > last; value += step)
26
+ result.push(value);
27
+ return result;
28
+ };
29
+ return {
30
+ start: first,
31
+ end: last,
32
+ step,
33
+ iterator: () => {
34
+ const items = values();
35
+ let index = 0;
36
+ return () => index < items.length ? { value: items[index++] } : null;
37
+ },
38
+ toArray: values
39
+ };
40
+ }
41
+ const JunoMath = Object.create(Math);
42
+ Object.defineProperties(JunoMath, {
43
+ NaN: { value: Number.NaN, enumerable: true },
44
+ Infinity: { value: Number.POSITIVE_INFINITY, enumerable: true }
45
+ });
46
+ const juno = {
47
+ console: exports.console,
48
+ Math: JunoMath,
49
+ types: types_1.types,
50
+ Error,
51
+ Range
52
+ };
53
+ // Parse the JunoScript declaration so runtime JN imports use the same type AST.
54
+ const iterableSource = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(__dirname, '../../types/iterable.jn'), 'utf8');
55
+ const iterableDeclaration = new parser_1.Parser((0, lexer_1.Lexer)(iterableSource).tokenize()).parse().find(statement => statement.kind === 'Export' && statement.declaration.kind === 'TypeDeclaration' && statement.declaration.name === 'Iterable');
56
+ if (!iterableDeclaration || iterableDeclaration.kind !== 'Export' || iterableDeclaration.declaration.kind !== 'TypeDeclaration') {
57
+ throw new Error("types/iterable.jn must export type 'Iterable'");
58
+ }
59
+ const iterableType = iterableDeclaration.declaration.value;
60
+ const junoTypes = {
61
+ Error: { value: { kind: 'ObjectType', members: [
62
+ { name: 'name', type: { kind: 'NamedType', name: 'string' }, optional: false, readonly: false, constant: false },
63
+ { name: 'message', type: { kind: 'NamedType', name: 'string' }, optional: false, readonly: false, constant: false },
64
+ { name: 'stack', type: { kind: 'NamedType', name: 'string' }, optional: true, readonly: false, constant: false }
65
+ ] }, generics: [] },
66
+ Iterable: { value: iterableType, generics: iterableDeclaration.declaration.generics }
67
+ };
68
+ for (const [name, alias] of Object.entries(junoTypes))
69
+ juno[name] = {
70
+ __junoTypeConstructor: true,
71
+ typeName: name,
72
+ typeNode: alias.value,
73
+ generics: alias.generics
74
+ };
75
+ Object.defineProperty(juno, '__junoTypes', { value: junoTypes, enumerable: false });
76
+ exports.default = juno;
@@ -0,0 +1,56 @@
1
+ /** TypeScript utility types re-exported as a module for project consumers. */
2
+ import type { TypeNode } from '../Lexer/parser';
3
+ export type Partial<T> = {
4
+ [P in keyof T]?: T[P];
5
+ };
6
+ export type Required<T> = {
7
+ [P in keyof T]-?: T[P];
8
+ };
9
+ export type Readonly<T> = {
10
+ readonly [P in keyof T]: T[P];
11
+ };
12
+ export type KeyOf<T extends object> = keyof T;
13
+ export type Pick<T, K extends keyof T> = {
14
+ [P in K]: T[P];
15
+ };
16
+ export type Record<K extends keyof any, T> = {
17
+ [P in K]: T;
18
+ };
19
+ export type Exclude<T, U> = T extends U ? never : T;
20
+ export type Extract<T, U> = T extends U ? T : never;
21
+ export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
22
+ export type NonNullable<T> = Exclude<T, null | undefined>;
23
+ export type Parameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
24
+ export type ConstructorParameters<T extends abstract new (...args: any[]) => any> = T extends abstract new (...args: infer P) => any ? P : never;
25
+ export type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : any;
26
+ export type InstanceType<T extends abstract new (...args: any[]) => any> = T extends abstract new (...args: any[]) => infer R ? R : any;
27
+ export type ThisParameterType<T> = T extends (this: infer U, ...args: any[]) => any ? U : unknown;
28
+ export type OmitThisParameter<T> = unknown extends ThisParameterType<T> ? T : T extends (this: any, ...args: infer A) => infer R ? (...args: A) => R : T;
29
+ export type ThisType<T> = {};
30
+ export type Awaited<T> = T extends null | undefined ? T : T extends object & {
31
+ then(onfulfilled: infer F, ...args: any[]): any;
32
+ } ? F extends (value: infer V, ...args: any[]) => any ? Awaited<V> : never : T;
33
+ type RuntimeTypeInput = {
34
+ __junoTypeConstructor?: true;
35
+ __junoTypeDescriptor?: true;
36
+ typeNode?: TypeNode;
37
+ };
38
+ export declare const Partial: (input: unknown) => RuntimeTypeInput;
39
+ export declare const Required: (input: unknown) => RuntimeTypeInput;
40
+ export declare const Readonly: (input: unknown) => RuntimeTypeInput;
41
+ export declare const KeyOf: (input: unknown) => RuntimeTypeInput;
42
+ export declare const Exclude: (input: unknown, excluded: unknown) => RuntimeTypeInput;
43
+ export declare const Pick: (input: unknown, keys: unknown) => RuntimeTypeInput;
44
+ export declare const Omit: (input: unknown, keys: unknown) => RuntimeTypeInput;
45
+ export declare const Items: () => (string | number)[];
46
+ export declare const types: {
47
+ Partial: (input: unknown) => RuntimeTypeInput;
48
+ Required: (input: unknown) => RuntimeTypeInput;
49
+ Readonly: (input: unknown) => RuntimeTypeInput;
50
+ Pick: (input: unknown, keys: unknown) => RuntimeTypeInput;
51
+ Omit: (input: unknown, keys: unknown) => RuntimeTypeInput;
52
+ KeyOf: (input: unknown) => RuntimeTypeInput;
53
+ Exclude: (input: unknown, excluded: unknown) => RuntimeTypeInput;
54
+ Items: () => (string | number)[];
55
+ };
56
+ export default types;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.types = exports.Items = exports.Omit = exports.Pick = exports.Exclude = exports.KeyOf = exports.Readonly = exports.Required = exports.Partial = void 0;
4
+ function typeNodeOf(input) {
5
+ const node = input?.typeNode;
6
+ if (node && typeof node === 'object' && 'kind' in node)
7
+ return node;
8
+ throw new TypeError('Expected a Juno type declaration or a runtime type descriptor');
9
+ }
10
+ function descriptor(typeNode) {
11
+ return { __junoTypeDescriptor: true, typeNode };
12
+ }
13
+ function transformMembers(typeNode, transform) {
14
+ if (typeNode.kind === 'ObjectType')
15
+ return { ...typeNode, members: transform(typeNode.members) };
16
+ if (typeNode.kind === 'UnionType' || typeNode.kind === 'IntersectionType') {
17
+ return { ...typeNode, types: typeNode.types.map(part => transformMembers(part, transform)) };
18
+ }
19
+ throw new TypeError(`Utility type requires an object type; received ${typeNode.kind}`);
20
+ }
21
+ function keyLiteral(name) {
22
+ const numeric = Number(name);
23
+ return { kind: 'LiteralType', value: name !== '' && Number.isFinite(numeric) && String(numeric) === name ? numeric : name };
24
+ }
25
+ function keyType(typeNode) {
26
+ if (typeNode.kind === 'ArrayType' || typeNode.kind === 'GenericType' && (typeNode.name === 'Array' || typeNode.name === 'ReadonlyArray')) {
27
+ const names = ['length', 'indices', 'has', 'pick', 'omit', 'deepClone', 'deepFreeze', 'toDeepFreezed', 'at', 'concat', 'copy', 'copyWithin', 'entries', 'enumerate', 'every', 'fill', 'filter', 'find', 'findIndex', 'findLast', 'findLastIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'iterator', 'join', 'lastIndexOf', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toArray', 'toReversed', 'toSorted', 'toSpliced', 'toString', 'unshift', 'with'];
28
+ return { kind: 'UnionType', types: [{ kind: 'NamedType', name: 'number' }, ...names.map(name => ({ kind: 'LiteralType', value: name }))] };
29
+ }
30
+ if (typeNode.kind === 'ObjectType') {
31
+ const keys = typeNode.members.flatMap(member => member.indexType ? [member.indexType] : [keyLiteral(member.name)]);
32
+ return keys.length === 1 ? keys[0] : { kind: 'UnionType', types: keys };
33
+ }
34
+ if (typeNode.kind === 'UnionType' || typeNode.kind === 'IntersectionType') {
35
+ const keys = typeNode.types.map(keyType);
36
+ return keys.length === 1 ? keys[0] : { kind: 'UnionType', types: keys };
37
+ }
38
+ throw new TypeError(`KeyOf requires an object or array type; received ${typeNode.kind}`);
39
+ }
40
+ function excludeType(source, excluded) {
41
+ const excludedParts = excluded.kind === 'UnionType' ? excluded.types : [excluded];
42
+ const parts = source.kind === 'UnionType' ? source.types : [source];
43
+ const remaining = parts.filter(part => !excludedParts.some(item => JSON.stringify(item) === JSON.stringify(part)));
44
+ return remaining.length === 1 ? remaining[0] : remaining.length ? { kind: 'UnionType', types: remaining } : { kind: 'NamedType', name: 'never' };
45
+ }
46
+ function keysFrom(value) {
47
+ if (Array.isArray(value) && value.every(key => typeof key === 'string'))
48
+ return new Set(value);
49
+ const node = value?.typeNode;
50
+ if (node?.kind === 'LiteralType' && typeof node.value === 'string')
51
+ return new Set([node.value]);
52
+ if (node?.kind === 'UnionType') {
53
+ const keys = new Set();
54
+ for (const part of node.types) {
55
+ if (part.kind !== 'LiteralType' || typeof part.value !== 'string')
56
+ throw new TypeError('Utility type keys must be string literal types');
57
+ keys.add(part.value);
58
+ }
59
+ return keys;
60
+ }
61
+ throw new TypeError('Utility type keys must be string literals or an array of strings');
62
+ }
63
+ const Partial = (input) => descriptor(transformMembers(typeNodeOf(input), members => members.map(member => ({ ...member, optional: true }))));
64
+ exports.Partial = Partial;
65
+ const Required = (input) => descriptor(transformMembers(typeNodeOf(input), members => members.map(member => ({ ...member, optional: false }))));
66
+ exports.Required = Required;
67
+ const Readonly = (input) => descriptor(transformMembers(typeNodeOf(input), members => members.map(member => ({ ...member, readonly: true }))));
68
+ exports.Readonly = Readonly;
69
+ const KeyOf = (input) => descriptor(keyType(typeNodeOf(input)));
70
+ exports.KeyOf = KeyOf;
71
+ const Exclude = (input, excluded) => descriptor(excludeType(typeNodeOf(input), typeNodeOf(excluded)));
72
+ exports.Exclude = Exclude;
73
+ const Pick = (input, keys) => {
74
+ const selected = keysFrom(keys);
75
+ return descriptor(transformMembers(typeNodeOf(input), members => members.filter(member => selected.has(member.name))));
76
+ };
77
+ exports.Pick = Pick;
78
+ const Omit = (input, keys) => {
79
+ const removed = keysFrom(keys);
80
+ return descriptor(transformMembers(typeNodeOf(input), members => members.filter(member => !removed.has(member.name))));
81
+ };
82
+ exports.Omit = Omit;
83
+ // The interpreter materializes Items<T>() from its compile-time literal type argument.
84
+ const Items = () => [];
85
+ exports.Items = Items;
86
+ exports.types = { Partial: exports.Partial, Required: exports.Required, Readonly: exports.Readonly, Pick: exports.Pick, Omit: exports.Omit, KeyOf: exports.KeyOf, Exclude: exports.Exclude, Items: exports.Items };
87
+ exports.default = exports.types;
@@ -0,0 +1,64 @@
1
+ export declare class Interpreter {
2
+ private readonly globals;
3
+ private currentDirectory;
4
+ private currentFile?;
5
+ private readonly sourceFiles;
6
+ private readonly errorTraces;
7
+ private readonly callStack;
8
+ constructor();
9
+ run(source: string, filePath?: string): void;
10
+ runModule(source: string, filePath: string): Record<string, unknown>;
11
+ private executeStatements;
12
+ private execute;
13
+ private registerTypeDeclarations;
14
+ private loadLocalModule;
15
+ private evaluateSpread;
16
+ private addExpressionFrame;
17
+ private evaluate;
18
+ private evaluateExpression;
19
+ private callFunction;
20
+ private callFunctionAsync;
21
+ private executeStatementsAsync;
22
+ private executeAsync;
23
+ private evaluateAsync;
24
+ private evaluateExpressionAsync;
25
+ private resolveAwaitList;
26
+ private resolveAwaitExpressions;
27
+ private patternBindings;
28
+ private patternTypeNode;
29
+ private matchesPattern;
30
+ private captureStackTrace;
31
+ private toNativeValue;
32
+ private callRuntimeConstructor;
33
+ private toNativeExport;
34
+ private adaptNativeValue;
35
+ private declare;
36
+ private childEnvironment;
37
+ private adaptModule;
38
+ private adaptConsole;
39
+ private toJunoString;
40
+ private defaultToString;
41
+ private installDefaultHas;
42
+ private installCallableMethods;
43
+ private writeTarget;
44
+ private applyCompoundOperator;
45
+ private requireCondition;
46
+ private toBoolean;
47
+ private lookup;
48
+ private typeOf;
49
+ private indexedType;
50
+ private nonNullableType;
51
+ private inferValueType;
52
+ private inferRuntimeValueType;
53
+ private resolveAliasType;
54
+ private instantiateAlias;
55
+ private isCallableType;
56
+ private instantiateUtilityType;
57
+ private literalKeys;
58
+ private matchesTypeNode;
59
+ private applyTypeDefaults;
60
+ private findTypeMember;
61
+ private readMember;
62
+ }
63
+ export declare function runFile(file: string): void;
64
+ export declare function runBuiltModule(source: string, file: string): Record<string, unknown>;