tjs-lang 0.5.2 → 0.5.4
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/CLAUDE.md +1 -1
- package/demo/docs.json +9 -9
- package/demo/src/demo-nav.ts +51 -136
- package/demo/src/index.ts +35 -68
- package/demo/src/ts-playground.ts +18 -8
- package/dist/index.js +126 -112
- package/dist/index.js.map +11 -11
- package/dist/src/lang/emitters/js.d.ts +2 -2
- package/dist/src/lang/inference.d.ts +2 -2
- package/dist/src/test-examples.d.ts +41 -0
- package/dist/tjs-full.js +126 -112
- package/dist/tjs-full.js.map +11 -11
- package/dist/tjs-transpiler.js +102 -88
- package/dist/tjs-transpiler.js.map +8 -8
- package/dist/tjs-vm.js +18 -18
- package/dist/tjs-vm.js.map +5 -5
- package/package.json +1 -1
- package/src/lang/codegen.test.ts +76 -16
- package/src/lang/emitters/from-ts.ts +8 -28
- package/src/lang/emitters/js.ts +97 -7
- package/src/lang/eval.ts +41 -2
- package/src/lang/from-ts.test.ts +3 -3
- package/src/lang/inference.ts +34 -20
- package/src/lang/parser.test.ts +4 -4
- package/src/lang/transpiler.test.ts +5 -3
- package/src/lang/typescript-syntax.test.ts +20 -17
- package/src/runtime.test.ts +144 -13
- package/src/test-examples.test.ts +4 -12
- package/src/test-examples.ts +3 -1
- package/src/vm/runtime.ts +19 -0
|
@@ -150,7 +150,7 @@ interface SafetyOptions {
|
|
|
150
150
|
* if (typeof input !== 'object' || input === null ||
|
|
151
151
|
* typeof input.x !== 'number' ||
|
|
152
152
|
* typeof input.y !== 'number') {
|
|
153
|
-
* return
|
|
153
|
+
* return __tjs.typeError('funcName.input', 'object', input)
|
|
154
154
|
* }
|
|
155
155
|
*/
|
|
156
156
|
export declare function generateInlineValidation(funcName: string, paramName: string, shape: Record<string, TypeDescriptor>, requiredFields: Set<string>): string;
|
|
@@ -162,7 +162,7 @@ export declare function generateInlineValidation(funcName: string, paramName: st
|
|
|
162
162
|
* const _original_funcName = funcName
|
|
163
163
|
* funcName = function(__input) {
|
|
164
164
|
* if (typeof __input !== 'object' || __input === null || ...) {
|
|
165
|
-
* return
|
|
165
|
+
* return __tjs.typeError('funcName.input', 'object', __input)
|
|
166
166
|
* }
|
|
167
167
|
* return _original_funcName.call(this, __input)
|
|
168
168
|
* }
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* 10 -> { kind: 'number' }
|
|
7
7
|
* ['string'] -> { kind: 'array', items: { kind: 'string' } }
|
|
8
8
|
* { name: 'string' } -> { kind: 'object', shape: { name: { kind: 'string' } } }
|
|
9
|
-
* 'string'
|
|
10
|
-
* 'string'
|
|
9
|
+
* 'string' | null -> { kind: 'string', nullable: true }
|
|
10
|
+
* 'string' | 0 -> { kind: 'union', members: [{ kind: 'string' }, { kind: 'number' }] }
|
|
11
11
|
*/
|
|
12
12
|
import type { Expression, Pattern } from 'acorn';
|
|
13
13
|
import type { TypeDescriptor, ParameterDescriptor } from './types';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for loading and testing playground example markdown files.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { loadExample, loadExamples } from './test-examples'
|
|
6
|
+
*
|
|
7
|
+
* const ex = loadExample('guides/examples/tjs/wasm-starfield.md')
|
|
8
|
+
* // ex.code — the source code from the first code block
|
|
9
|
+
* // ex.language — 'tjs', 'ajs', 'javascript', etc.
|
|
10
|
+
* // ex.title — from the markdown # heading
|
|
11
|
+
* // ex.metadata — parsed JSON from <!--{...}--> comment
|
|
12
|
+
*
|
|
13
|
+
* const all = loadExamples('guides/examples/tjs')
|
|
14
|
+
* // array of all examples in that directory
|
|
15
|
+
*/
|
|
16
|
+
export interface ExampleFile {
|
|
17
|
+
/** Absolute or relative path to the source .md file */
|
|
18
|
+
path: string;
|
|
19
|
+
/** Title from the first # heading */
|
|
20
|
+
title: string;
|
|
21
|
+
/** Description — first paragraph between title and code block */
|
|
22
|
+
description: string;
|
|
23
|
+
/** Source code from the first fenced code block */
|
|
24
|
+
code: string;
|
|
25
|
+
/** Language tag from the code fence (e.g. 'tjs', 'ajs', 'javascript') */
|
|
26
|
+
language: string;
|
|
27
|
+
/** Parsed metadata from the <!--{...}--> comment, if present */
|
|
28
|
+
metadata: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Load a single example from a markdown file.
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadExample(filePath: string): ExampleFile;
|
|
34
|
+
/**
|
|
35
|
+
* Load all .md examples from a directory.
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadExamples(dirPath: string): ExampleFile[];
|
|
38
|
+
/**
|
|
39
|
+
* Parse example content from markdown source.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseExample(content: string, filePath?: string): ExampleFile;
|