tjs-lang 0.6.26 → 0.6.27
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/demo/docs.json +1 -1
- package/dist/bin/benchmarks.d.ts +9 -0
- package/dist/bin/dev.d.ts +1 -0
- package/dist/bin/docs.d.ts +1 -0
- package/dist/bin/select-local-models.d.ts +1 -0
- package/dist/examples/modules/dist/main.d.ts +34 -0
- package/dist/examples/modules/dist/math.d.ts +120 -0
- package/dist/index.js +423 -0
- package/dist/index.js.map +45 -0
- package/dist/scripts/build-demo.d.ts +2 -0
- package/dist/scripts/build.d.ts +11 -0
- package/dist/scripts/seed-blog-rules.d.ts +2 -0
- package/dist/scripts/seed-stored-function.d.ts +2 -0
- package/dist/src/atoms/batteries.d.ts +4 -0
- package/dist/src/atoms/browser.d.ts +4 -0
- package/dist/src/atoms/index.d.ts +4 -0
- package/dist/src/batteries/audit.d.ts +9 -0
- package/dist/src/batteries/index.d.ts +28 -0
- package/dist/src/batteries/llm.d.ts +18 -0
- package/dist/src/batteries/models.d.ts +19 -0
- package/dist/src/batteries/store.d.ts +13 -0
- package/dist/src/builder.d.ts +127 -0
- package/dist/src/bun-plugin/tjs-plugin.d.ts +12 -0
- package/dist/src/cli/commands/check.d.ts +4 -0
- package/dist/src/cli/commands/convert.d.ts +20 -0
- package/dist/src/cli/commands/emit.d.ts +34 -0
- package/dist/src/cli/commands/run.d.ts +6 -0
- package/dist/src/cli/commands/test.d.ts +21 -0
- package/dist/src/cli/commands/types.d.ts +4 -0
- package/dist/src/cli/create-app.d.ts +9 -0
- package/dist/src/cli/playground.d.ts +9 -0
- package/dist/src/cli/tjs.d.ts +15 -0
- package/dist/src/cli/tjsx.d.ts +16 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/inference.types.d.ts +1 -0
- package/dist/src/lang/core.d.ts +56 -0
- package/dist/src/lang/docs.d.ts +69 -0
- package/dist/src/lang/emitters/ast.d.ts +24 -0
- package/dist/src/lang/emitters/dts.d.ts +48 -0
- package/dist/src/lang/emitters/from-ts.d.ts +94 -0
- package/dist/src/lang/emitters/js-tests.d.ts +70 -0
- package/dist/src/lang/emitters/js-wasm.d.ts +15 -0
- package/dist/src/lang/emitters/js.d.ts +175 -0
- package/dist/src/lang/eval.d.ts +63 -0
- package/dist/src/lang/index.d.ts +216 -0
- package/dist/src/lang/inference.d.ts +40 -0
- package/dist/src/lang/linter.d.ts +53 -0
- package/dist/src/lang/metadata-cache.d.ts +172 -0
- package/dist/src/lang/parser-params.d.ts +37 -0
- package/dist/src/lang/parser-transforms.d.ts +281 -0
- package/dist/src/lang/parser-types.d.ts +175 -0
- package/dist/src/lang/parser.d.ts +56 -0
- package/dist/src/lang/runtime.d.ts +488 -0
- package/dist/src/lang/schema.d.ts +35 -0
- package/dist/src/lang/tests.d.ts +94 -0
- package/dist/src/lang/transpiler.d.ts +25 -0
- package/dist/src/lang/types.d.ts +147 -0
- package/dist/src/lang/wasm.d.ts +83 -0
- package/dist/src/rbac/index.d.ts +85 -0
- package/dist/src/rbac/rules.d.ts +184 -0
- package/dist/src/runtime.d.ts +4 -0
- package/dist/src/store/index.d.ts +3 -0
- package/dist/src/store/indexeddb.d.ts +6 -0
- package/dist/src/store/interface.d.ts +90 -0
- package/dist/src/store/memory.d.ts +10 -0
- package/dist/src/test-examples.d.ts +41 -0
- package/dist/src/test-utils.d.ts +86 -0
- package/dist/src/transpiler/index.d.ts +6 -0
- package/dist/src/transpiler/parser.d.ts +4 -0
- package/dist/src/transpiler/transformer.d.ts +4 -0
- package/dist/src/transpiler/type-system/inference.d.ts +1 -0
- package/dist/src/transpiler/types.d.ts +4 -0
- package/dist/src/types/LegalDate.d.ts +241 -0
- package/dist/src/types/Timestamp.d.ts +233 -0
- package/dist/src/types/Type.d.ts +234 -0
- package/dist/src/types/index.d.ts +8 -0
- package/dist/src/vm/atoms/batteries.d.ts +6 -0
- package/dist/src/vm/atoms/browser.d.ts +18 -0
- package/dist/src/vm/atoms/index.d.ts +10 -0
- package/dist/src/vm/index.d.ts +12 -0
- package/dist/src/vm/runtime.d.ts +333 -0
- package/dist/src/vm/vm.d.ts +28 -0
- package/dist/src/vm.d.ts +4 -0
- package/dist/test-preprocess.d.ts +1 -0
- package/dist/tjs-batteries.js +4 -0
- package/dist/tjs-batteries.js.map +15 -0
- package/dist/tjs-full.js +423 -0
- package/dist/tjs-full.js.map +45 -0
- package/dist/tjs-src/runtime.d.ts +1 -0
- package/dist/tjs-transpiler.js +3 -0
- package/dist/tjs-transpiler.js.map +11 -0
- package/dist/tjs-vm.js +54 -0
- package/dist/tjs-vm.js.map +22 -0
- package/package.json +1 -1
- package/src/cli/tjs.ts +1 -1
- package/src/lang/emitters/js.ts +3 -0
- package/src/lang/parser-transforms.ts +6 -0
- package/src/lang/roundtrip.test.ts +1 -1
- package/src/lang/runtime.ts +18 -1
- package/src/lang/wasm.ts +1 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser types and interfaces
|
|
3
|
+
*
|
|
4
|
+
* Shared type definitions used across parser modules.
|
|
5
|
+
*/
|
|
6
|
+
/** Parser options */
|
|
7
|
+
export interface ParseOptions {
|
|
8
|
+
/** Filename for error messages */
|
|
9
|
+
filename?: string;
|
|
10
|
+
/** Enable colon shorthand syntax preprocessing */
|
|
11
|
+
colonShorthand?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Target is the VM (AJS code).
|
|
14
|
+
* When true, skips == to Is() transformation since the VM handles == correctly.
|
|
15
|
+
*/
|
|
16
|
+
vmTarget?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A WASM block extracted from source
|
|
20
|
+
*
|
|
21
|
+
* Simple form (body is both WASM source and JS fallback):
|
|
22
|
+
* wasm {
|
|
23
|
+
* for (let i = 0; i < arr.length; i++) { arr[i] *= 2 }
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* With explicit fallback (when WASM and JS need different code):
|
|
27
|
+
* wasm {
|
|
28
|
+
* // WASM-optimized path
|
|
29
|
+
* } fallback {
|
|
30
|
+
* // JS fallback using different approach
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* Variables are captured from scope automatically.
|
|
34
|
+
*/
|
|
35
|
+
export interface WasmBlock {
|
|
36
|
+
/** Unique ID for this block */
|
|
37
|
+
id: string;
|
|
38
|
+
/** The body (JS subset that compiles to WASM, also used as fallback) */
|
|
39
|
+
body: string;
|
|
40
|
+
/** Explicit fallback body (only if different from body) */
|
|
41
|
+
fallback?: string;
|
|
42
|
+
/** Variables captured from enclosing scope (auto-detected) */
|
|
43
|
+
captures: string[];
|
|
44
|
+
/** Start position in original source */
|
|
45
|
+
start: number;
|
|
46
|
+
/** End position in original source */
|
|
47
|
+
end: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A test block extracted from source
|
|
51
|
+
*
|
|
52
|
+
* Syntax:
|
|
53
|
+
* test { body }
|
|
54
|
+
* test 'description' { body }
|
|
55
|
+
*
|
|
56
|
+
* Tests run at transpile time and are stripped from output.
|
|
57
|
+
*/
|
|
58
|
+
export interface TestBlock {
|
|
59
|
+
/** Optional description */
|
|
60
|
+
description?: string;
|
|
61
|
+
/** The test body code */
|
|
62
|
+
body: string;
|
|
63
|
+
/** Start position in original source */
|
|
64
|
+
start: number;
|
|
65
|
+
/** End position in original source */
|
|
66
|
+
end: number;
|
|
67
|
+
/** Source line number (1-indexed) */
|
|
68
|
+
line?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Preprocess options
|
|
72
|
+
*/
|
|
73
|
+
export interface PreprocessOptions {
|
|
74
|
+
/** Skip test execution (tests still stripped from output) */
|
|
75
|
+
dangerouslySkipTests?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Skip == to Is() transformation.
|
|
78
|
+
* Set to true for AJS code that runs in the VM, which already handles == correctly.
|
|
79
|
+
* Default: false (transform == to Is() for TJS code running in regular JS)
|
|
80
|
+
*/
|
|
81
|
+
vmTarget?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Tokenizer state for tracking context during source transformation
|
|
85
|
+
*/
|
|
86
|
+
export type TokenizerState = 'normal' | 'single-string' | 'double-string' | 'template-string' | 'line-comment' | 'block-comment' | 'regex';
|
|
87
|
+
/**
|
|
88
|
+
* Structural context for tracking where we are in the code
|
|
89
|
+
* This enables proper handling of class methods vs function calls
|
|
90
|
+
*/
|
|
91
|
+
export type StructuralContext = 'top-level' | 'class-body' | 'function-body' | 'block';
|
|
92
|
+
export interface ContextFrame {
|
|
93
|
+
type: StructuralContext;
|
|
94
|
+
braceDepth: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Unified paren expression transformer using state machine tokenizer
|
|
98
|
+
*
|
|
99
|
+
* Model: opening paren can be ( or (? or (!, closing can be ) or )->type or )-?type or )-!type
|
|
100
|
+
*
|
|
101
|
+
* This unifies handling of:
|
|
102
|
+
* - Function declaration params: function foo(x: type) -> returnType { }
|
|
103
|
+
* - Arrow function params: (x: type) => expr
|
|
104
|
+
* - Safe/unsafe markers: function foo(?) or function foo(!)
|
|
105
|
+
* - Return type annotations: ) -> type or ) -? type or ) -! type
|
|
106
|
+
*
|
|
107
|
+
* @param source The source code to transform
|
|
108
|
+
* @param ctx Context for tracking required params, safe/unsafe functions, etc.
|
|
109
|
+
* @returns Transformed source and extracted metadata
|
|
110
|
+
*/
|
|
111
|
+
/** TJS mode flags for opt-in language improvements */
|
|
112
|
+
export interface TjsModes {
|
|
113
|
+
/** TjsEquals: == and != use structural equality */
|
|
114
|
+
tjsEquals: boolean;
|
|
115
|
+
/** TjsClass: classes callable without new, explicit new is banned */
|
|
116
|
+
tjsClass: boolean;
|
|
117
|
+
/** TjsDate: Date is banned, use Timestamp/LegalDate */
|
|
118
|
+
tjsDate: boolean;
|
|
119
|
+
/** TjsNoeval: eval() and new Function() are banned */
|
|
120
|
+
tjsNoeval: boolean;
|
|
121
|
+
/** TjsStandard: newlines as statement terminators (prevents ASI footguns) */
|
|
122
|
+
tjsStandard: boolean;
|
|
123
|
+
/** TjsSafeEval: include Eval/SafeFunction in runtime for dynamic code execution */
|
|
124
|
+
tjsSafeEval: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Extension info for a single extend block
|
|
128
|
+
*/
|
|
129
|
+
export interface ExtensionInfo {
|
|
130
|
+
/** The type name being extended (e.g., 'String', 'Array', 'MyClass') */
|
|
131
|
+
typeName: string;
|
|
132
|
+
/** Method names defined in this extend block */
|
|
133
|
+
methods: string[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Transform `extend TypeName { ... }` blocks into `const __ext_TypeName = { ... }` objects
|
|
137
|
+
* and runtime registration calls.
|
|
138
|
+
*
|
|
139
|
+
* extend String {
|
|
140
|
+
* capitalize() { return this[0].toUpperCase() + this.slice(1) }
|
|
141
|
+
* }
|
|
142
|
+
*
|
|
143
|
+
* becomes:
|
|
144
|
+
*
|
|
145
|
+
* const __ext_String = {
|
|
146
|
+
* capitalize: function() { return this[0].toUpperCase() + this.slice(1) }
|
|
147
|
+
* }
|
|
148
|
+
* if (__tjs?.registerExtension) {
|
|
149
|
+
* __tjs.registerExtension('String', 'capitalize', __ext_String.capitalize)
|
|
150
|
+
* }
|
|
151
|
+
*/
|
|
152
|
+
export interface PolyVariant {
|
|
153
|
+
/** Index (1-based) for renaming */
|
|
154
|
+
index: number;
|
|
155
|
+
/** Start position in source */
|
|
156
|
+
start: number;
|
|
157
|
+
/** End position in source (after closing brace) */
|
|
158
|
+
end: number;
|
|
159
|
+
/** The full function source text */
|
|
160
|
+
text: string;
|
|
161
|
+
/** Whether it was exported */
|
|
162
|
+
exported: boolean;
|
|
163
|
+
/** Whether it was async */
|
|
164
|
+
isAsync: boolean;
|
|
165
|
+
/** Parsed parameter info: [name, defaultValue][] */
|
|
166
|
+
params: {
|
|
167
|
+
name: string;
|
|
168
|
+
defaultValue: string;
|
|
169
|
+
required: boolean;
|
|
170
|
+
}[];
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Infer a type-check expression from a parameter's default value string.
|
|
174
|
+
* Returns a condition that checks if an argument matches this param's type.
|
|
175
|
+
*/
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TJS Parser — Orchestration Layer
|
|
3
|
+
*
|
|
4
|
+
* This module contains the main entry points: preprocess() and parse().
|
|
5
|
+
* Transform functions are in parser-transforms.ts, param processing in parser-params.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type { Program, FunctionDeclaration } from 'acorn';
|
|
8
|
+
export type { ParseOptions, WasmBlock, TestBlock, PreprocessOptions, TjsModes, } from './parser-types';
|
|
9
|
+
import type { ParseOptions, WasmBlock, TestBlock, PreprocessOptions, TjsModes } from './parser-types';
|
|
10
|
+
export { transformExtensionCalls } from './parser-transforms';
|
|
11
|
+
export declare function preprocess(source: string, options?: PreprocessOptions): {
|
|
12
|
+
source: string;
|
|
13
|
+
returnType?: string;
|
|
14
|
+
returnSafety?: 'safe' | 'unsafe';
|
|
15
|
+
moduleSafety?: 'none' | 'inputs' | 'all';
|
|
16
|
+
tjsModes: TjsModes;
|
|
17
|
+
originalSource: string;
|
|
18
|
+
requiredParams: Set<string>;
|
|
19
|
+
unsafeFunctions: Set<string>;
|
|
20
|
+
safeFunctions: Set<string>;
|
|
21
|
+
wasmBlocks: WasmBlock[];
|
|
22
|
+
tests: TestBlock[];
|
|
23
|
+
testErrors: string[];
|
|
24
|
+
polymorphicNames: Set<string>;
|
|
25
|
+
extensions: Map<string, Set<string>>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Parse source code into an Acorn AST
|
|
29
|
+
*/
|
|
30
|
+
export declare function parse(source: string, options?: ParseOptions): {
|
|
31
|
+
ast: Program;
|
|
32
|
+
returnType?: string;
|
|
33
|
+
returnSafety?: 'safe' | 'unsafe';
|
|
34
|
+
moduleSafety?: 'none' | 'inputs' | 'all';
|
|
35
|
+
originalSource: string;
|
|
36
|
+
requiredParams: Set<string>;
|
|
37
|
+
unsafeFunctions: Set<string>;
|
|
38
|
+
safeFunctions: Set<string>;
|
|
39
|
+
wasmBlocks: WasmBlock[];
|
|
40
|
+
tests: TestBlock[];
|
|
41
|
+
testErrors: string[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Validate that the source contains exactly one function declaration
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateSingleFunction(ast: Program, filename?: string): FunctionDeclaration;
|
|
47
|
+
/**
|
|
48
|
+
* Extract TDoc comment from before a function
|
|
49
|
+
*
|
|
50
|
+
* TJS doc comments use /\*# ... \*\/ syntax and preserve full markdown content.
|
|
51
|
+
* Legacy JSDoc (/\*\* ... \*\/) is supported as a fallback.
|
|
52
|
+
*/
|
|
53
|
+
export declare function extractTDoc(source: string, func: FunctionDeclaration): {
|
|
54
|
+
description?: string;
|
|
55
|
+
params: Record<string, string>;
|
|
56
|
+
};
|