tjs-lang 0.2.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/CONTEXT.md +594 -0
- package/LICENSE +190 -0
- package/README.md +220 -0
- package/bin/benchmarks.ts +351 -0
- package/bin/dev.ts +205 -0
- package/bin/docs.js +170 -0
- package/bin/install-cursor.sh +71 -0
- package/bin/install-vscode.sh +71 -0
- package/bin/select-local-models.d.ts +1 -0
- package/bin/select-local-models.js +28 -0
- package/bin/select-local-models.ts +31 -0
- package/demo/autocomplete.test.ts +232 -0
- package/demo/docs.json +186 -0
- package/demo/examples.test.ts +598 -0
- package/demo/index.html +91 -0
- package/demo/src/autocomplete.ts +482 -0
- package/demo/src/capabilities.ts +859 -0
- package/demo/src/demo-nav.ts +2097 -0
- package/demo/src/examples.test.ts +161 -0
- package/demo/src/examples.ts +476 -0
- package/demo/src/imports.test.ts +196 -0
- package/demo/src/imports.ts +421 -0
- package/demo/src/index.ts +639 -0
- package/demo/src/module-store.ts +635 -0
- package/demo/src/module-sw.ts +132 -0
- package/demo/src/playground.ts +949 -0
- package/demo/src/service-host.ts +389 -0
- package/demo/src/settings.ts +440 -0
- package/demo/src/style.ts +280 -0
- package/demo/src/tjs-playground.ts +1605 -0
- package/demo/src/ts-examples.ts +478 -0
- package/demo/src/ts-playground.ts +1092 -0
- package/demo/static/favicon.svg +30 -0
- package/demo/static/photo-1.jpg +0 -0
- package/demo/static/photo-2.jpg +0 -0
- package/demo/static/texts/ai-history.txt +9 -0
- package/demo/static/texts/coffee-origins.txt +9 -0
- package/demo/static/texts/renewable-energy.txt +9 -0
- package/dist/index.js +256 -0
- package/dist/index.js.map +37 -0
- package/dist/tjs-batteries.js +4 -0
- package/dist/tjs-batteries.js.map +15 -0
- package/dist/tjs-full.js +256 -0
- package/dist/tjs-full.js.map +37 -0
- package/dist/tjs-transpiler.js +220 -0
- package/dist/tjs-transpiler.js.map +21 -0
- package/dist/tjs-vm.js +4 -0
- package/dist/tjs-vm.js.map +14 -0
- package/docs/CNAME +1 -0
- package/docs/favicon.svg +30 -0
- package/docs/index.html +91 -0
- package/docs/index.js +10468 -0
- package/docs/index.js.map +92 -0
- package/docs/photo-1.jpg +0 -0
- package/docs/photo-1.webp +0 -0
- package/docs/photo-2.jpg +0 -0
- package/docs/photo-2.webp +0 -0
- package/docs/texts/ai-history.txt +9 -0
- package/docs/texts/coffee-origins.txt +9 -0
- package/docs/texts/renewable-energy.txt +9 -0
- package/docs/tjs-lang.svg +31 -0
- package/docs/tosijs-agent.svg +31 -0
- package/editors/README.md +325 -0
- package/editors/ace/ajs-mode.js +328 -0
- package/editors/ace/ajs-mode.ts +269 -0
- package/editors/ajs-syntax.ts +212 -0
- package/editors/build-grammars.ts +510 -0
- package/editors/codemirror/ajs-language.js +287 -0
- package/editors/codemirror/ajs-language.ts +1447 -0
- package/editors/codemirror/autocomplete.test.ts +531 -0
- package/editors/codemirror/component.ts +404 -0
- package/editors/monaco/ajs-monarch.js +243 -0
- package/editors/monaco/ajs-monarch.ts +225 -0
- package/editors/tjs-syntax.ts +115 -0
- package/editors/vscode/language-configuration.json +37 -0
- package/editors/vscode/package.json +65 -0
- package/editors/vscode/syntaxes/ajs-injection.tmLanguage.json +107 -0
- package/editors/vscode/syntaxes/ajs.tmLanguage.json +252 -0
- package/editors/vscode/syntaxes/tjs.tmLanguage.json +333 -0
- package/package.json +83 -0
- package/src/cli/commands/check.ts +41 -0
- package/src/cli/commands/convert.ts +133 -0
- package/src/cli/commands/emit.ts +260 -0
- package/src/cli/commands/run.ts +68 -0
- package/src/cli/commands/test.ts +194 -0
- package/src/cli/commands/types.ts +20 -0
- package/src/cli/create-app.ts +236 -0
- package/src/cli/playground.ts +250 -0
- package/src/cli/tjs.ts +166 -0
- package/src/cli/tjsx.ts +160 -0
- package/tjs-lang.svg +31 -0
package/src/cli/tjsx.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* tjsx - Execute TJS files instantly
|
|
4
|
+
*
|
|
5
|
+
* Like `bun run` but for TJS files. Transpiles and executes in one step.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* tjsx script.tjs [args...]
|
|
9
|
+
* tjsx --help
|
|
10
|
+
*
|
|
11
|
+
* Examples:
|
|
12
|
+
* tjsx hello.tjs
|
|
13
|
+
* tjsx server.tjs --port 3000
|
|
14
|
+
* echo '{"name": "World"}' | tjsx greet.tjs
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { readFileSync } from 'fs'
|
|
18
|
+
import { tjs } from '../lang'
|
|
19
|
+
import { installRuntime } from '../lang/runtime'
|
|
20
|
+
|
|
21
|
+
// Install TJS runtime globally before executing any transpiled code
|
|
22
|
+
installRuntime()
|
|
23
|
+
|
|
24
|
+
const HELP = `
|
|
25
|
+
tjsx - Execute TJS files instantly
|
|
26
|
+
|
|
27
|
+
Usage:
|
|
28
|
+
tjsx <file.tjs> [args...]
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
-h, --help Show this help message
|
|
32
|
+
-e, --eval Evaluate TJS code from string
|
|
33
|
+
--json Parse stdin as JSON and pass as first argument
|
|
34
|
+
|
|
35
|
+
Examples:
|
|
36
|
+
tjsx hello.tjs
|
|
37
|
+
tjsx greet.tjs --json < input.json
|
|
38
|
+
tjsx -e "function f() { return 42 }"
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
async function main() {
|
|
42
|
+
const args = process.argv.slice(2)
|
|
43
|
+
|
|
44
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
45
|
+
console.log(HELP)
|
|
46
|
+
process.exit(0)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let source: string
|
|
50
|
+
let fnArgs: Record<string, any> = {}
|
|
51
|
+
|
|
52
|
+
// Handle --eval flag
|
|
53
|
+
const evalIndex = args.findIndex((a) => a === '-e' || a === '--eval')
|
|
54
|
+
if (evalIndex !== -1) {
|
|
55
|
+
source = args[evalIndex + 1]
|
|
56
|
+
if (!source) {
|
|
57
|
+
console.error('Error: --eval requires a code string')
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
// Read from file
|
|
62
|
+
const file = args[0]
|
|
63
|
+
if (!file) {
|
|
64
|
+
console.error('Error: No file specified')
|
|
65
|
+
process.exit(1)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
source = readFileSync(file, 'utf-8')
|
|
70
|
+
} catch (err: any) {
|
|
71
|
+
console.error(`Error reading file: ${err.message}`)
|
|
72
|
+
process.exit(1)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Parse remaining args as key=value pairs or JSON
|
|
76
|
+
const restArgs = args.slice(1)
|
|
77
|
+
|
|
78
|
+
if (restArgs.includes('--json')) {
|
|
79
|
+
// Read JSON from stdin
|
|
80
|
+
try {
|
|
81
|
+
const stdin = readFileSync(0, 'utf-8')
|
|
82
|
+
fnArgs = JSON.parse(stdin)
|
|
83
|
+
} catch {
|
|
84
|
+
console.error('Error: Could not parse JSON from stdin')
|
|
85
|
+
process.exit(1)
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
// Parse key=value args
|
|
89
|
+
for (const arg of restArgs) {
|
|
90
|
+
if (arg.startsWith('--')) {
|
|
91
|
+
const [key, value] = arg.slice(2).split('=')
|
|
92
|
+
if (value !== undefined) {
|
|
93
|
+
// Try to parse as JSON, fall back to string
|
|
94
|
+
try {
|
|
95
|
+
fnArgs[key] = JSON.parse(value)
|
|
96
|
+
} catch {
|
|
97
|
+
fnArgs[key] = value
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
fnArgs[key] = true
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Transpile
|
|
108
|
+
let result
|
|
109
|
+
try {
|
|
110
|
+
result = tjs(source)
|
|
111
|
+
} catch (err: any) {
|
|
112
|
+
console.error(`Transpile error: ${err.message}`)
|
|
113
|
+
process.exit(1)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Get the first function name from the types dictionary
|
|
117
|
+
const fnNames = Object.keys(result.types ?? {})
|
|
118
|
+
const fnName = fnNames[0]
|
|
119
|
+
if (!fnName) {
|
|
120
|
+
console.error('Error: No function found in source')
|
|
121
|
+
process.exit(1)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Execute
|
|
125
|
+
try {
|
|
126
|
+
const moduleCode = `
|
|
127
|
+
${result.code}
|
|
128
|
+
return ${fnName};
|
|
129
|
+
`
|
|
130
|
+
const fn = new Function(moduleCode)()
|
|
131
|
+
|
|
132
|
+
// Use __tjs metadata to determine how to pass args
|
|
133
|
+
const hasArgs = Object.keys(fnArgs).length > 0
|
|
134
|
+
let output
|
|
135
|
+
|
|
136
|
+
if (hasArgs && fn.__tjs?.params) {
|
|
137
|
+
// Get param names in order from metadata
|
|
138
|
+
const paramNames = Object.keys(fn.__tjs.params)
|
|
139
|
+
|
|
140
|
+
// Build positional args array from named args
|
|
141
|
+
const positionalArgs = paramNames.map((name) => fnArgs[name])
|
|
142
|
+
output = await Promise.resolve(fn(...positionalArgs))
|
|
143
|
+
} else {
|
|
144
|
+
output = await Promise.resolve(fn())
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (output !== undefined) {
|
|
148
|
+
if (typeof output === 'object') {
|
|
149
|
+
console.log(JSON.stringify(output, null, 2))
|
|
150
|
+
} else {
|
|
151
|
+
console.log(output)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} catch (err: any) {
|
|
155
|
+
console.error(`Runtime error: ${err.message}`)
|
|
156
|
+
process.exit(1)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
main()
|
package/tjs-lang.svg
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<svg x="0pt" y="0pt" width="48pt" height="48pt" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
+
<!--Generated by AMDN-->
|
|
4
|
+
<g id="Layer_1">
|
|
5
|
+
<g id="Layer_1-1">
|
|
6
|
+
<g id="Layer_1_1">
|
|
7
|
+
<g id="Group">
|
|
8
|
+
<path id="Path" style="fill:#ff1c24;fill-opacity:1;fill-rule:evenodd;opacity:1;stroke:none;" d="M1,9 C1,4.58172,4.58172,1,9,1 C9,1,39,1,39,1 C43.4183,1,47,4.58172,47,9 C47,9,47,39,47,39 C47,43.4183,43.4183,47,39,47 C39,47,9,47,9,47 C4.58172,47,1,43.4183,1,39 C1,39,1,9,1,9 z"/>
|
|
9
|
+
<g id="Group_1">
|
|
10
|
+
<path id="Path_1" style="fill:#9e9e9e;fill-opacity:1;fill-rule:nonzero;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M16,29 C16,29,10,31,10,35 C10,39,16,39,16,39"/>
|
|
11
|
+
<path id="Path_Copy" style="fill:#9e9e9e;fill-opacity:1;fill-rule:nonzero;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M32.0002,29 C32.0002,29,38.0002,31,38.0002,35 C38.0002,39,32.0002,39,32.0002,39"/>
|
|
12
|
+
<path id="Path_2" style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M9,10.1818 C9,7.87226,10.7909,6,13,6 C13,6,35,6,35,6 C37.2091,6,39,7.87226,39,10.1818 C39,10.1818,39,24.8182,39,24.8182 C39,27.1277,37.2091,29,35,29 C35,29,13,29,13,29 C10.7909,29,9,27.1277,9,24.8182 C9,24.8182,9,10.1818,9,10.1818 z"/>
|
|
13
|
+
<path id="Path_3" style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M24,11 C24,11,24,23,24,23"/>
|
|
14
|
+
<path id="Path_4" style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M28,15 C28,15,28,17,28,17"/>
|
|
15
|
+
<path id="Path_Copy_1" style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M20,15 C20,15,20,17,20,17"/>
|
|
16
|
+
<path id="Path_5" style="fill:none;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M32,43 C32,43,30,41,30,41 C30,41,28,43,28,43"/>
|
|
17
|
+
<path id="Path_Copy_2" style="fill:none;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M20,43 C20,43,18,41,18,41 C18,41,16,43,16,43"/>
|
|
18
|
+
<path id="Path_6" style="fill:#e4e4e4;fill-opacity:1;fill-rule:evenodd;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M16,29 C16,29,32,29,32,29 C32,29,32,39,32,39 C32,39,16,39,16,39 C16,39,16,29,16,29 z"/>
|
|
19
|
+
</g>
|
|
20
|
+
</g>
|
|
21
|
+
</g>
|
|
22
|
+
</g>
|
|
23
|
+
<path id="Path-1" style="fill:#006736;fill-opacity:1;fill-rule:evenodd;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M27,17 C27,17,34,17,34,17 C34,17,34,22,34,22 C34,22,27,22,27,22 C27,22,27,17,27,17 z"/>
|
|
24
|
+
<path id="Path-2" style="fill:none;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M21,19 C21,19,21,19,21,19 C21,17.8954,21.8954,17,23,17 C23,17,25,17,25,17 C26.1046,17,27,17.8954,27,19 C27,19,27,19,27,19"/>
|
|
25
|
+
<path id="Path_Copy-1" style="fill:#006736;fill-opacity:1;fill-rule:evenodd;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M14,17 C14,17,21,17,21,17 C21,17,21,22,21,22 C21,22,14,22,14,22 C14,22,14,17,14,17 z"/>
|
|
26
|
+
<path id="Path_Copy-2" style="fill:#8e7f6d;fill-opacity:1;fill-rule:nonzero;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M7.31734,20.5867 C7.14208,19.7104,7.71038,18.8579,8.58668,18.6827 C8.58668,18.6827,10.4133,18.3173,10.4133,18.3173 C11.2896,18.1421,12.1421,18.7104,12.3173,19.5867 C12.3173,19.5867,12.6405,21.2026,12.6405,21.2026 C12.8314,22.157,13.8156,22.7281,14.7389,22.4204 C14.7389,22.4204,15.1785,22.2738,15.1785,22.2738 C15.6917,22.1028,16.2565,22.1995,16.6836,22.5317 C16.6836,22.5317,24.3753,28.5141,24.3753,28.5141 C24.7695,28.8207,25,29.2921,25,29.7914 C25,29.7914,25,40.3298,25,40.3298 C25,40.7589,24.8295,41.1705,24.5261,41.4739 C24.5261,41.4739,23.4739,42.5261,23.4739,42.5261 C23.1705,42.8295,22.7589,43,22.3298,43 C22.3298,43,9,43,9,43 C7.34315,43,6,41.6569,6,40 C6,40,6,26,6,26 C6,25.3871,6.3463,24.8268,6.89452,24.5527 C6.89452,24.5527,6.89452,24.5527,6.89452,24.5527 C7.5472,24.2264,7.90073,23.5036,7.75762,22.7881 C7.75762,22.7881,7.31734,20.5867,7.31734,20.5867 z"/>
|
|
27
|
+
<path id="Compound_Group" style="fill:#c6b199;fill-opacity:1;fill-rule:evenodd;opacity:1;stroke:#000000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M21.118,26.0132 C21.118,26.0132,29.4076,27.8928,29.4076,27.8928 C30.2155,28.076,30.722,28.8794,30.5388,29.6874 C30.5388,29.6874,28.3275,39.4398,28.3275,39.4398 C28.1443,40.2477,27.3409,40.7542,26.5329,40.571 C26.5329,40.571,10.929,37.0329,10.929,37.0329 C10.1211,36.8498,9.61466,36.0463,9.79785,35.2384 C9.79785,35.2384,12.2302,24.5107,12.2302,24.5107 C12.2302,24.5107,12.6725,22.5602,12.6725,22.5602 C12.8557,21.7523,13.6591,21.2458,14.4671,21.429 C14.4671,21.429,20.3185,22.7558,20.3185,22.7558 C21.1264,22.939,21.6329,23.7424,21.4497,24.5503 C21.4497,24.5503,21.118,26.0132,21.118,26.0132 z"/>
|
|
28
|
+
<path id="Path-3" style="fill:#8e7f6d;fill-opacity:1;fill-rule:nonzero;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M41,19 C41,19,36,18,36,18 C36,18,35,23,35,23 C35,23,32,22,32,22 C32,22,23,29,23,29 C23,29,23,41,23,41 C23,41,25,43,25,43 C25,43,39,43,39,43 C40.6569,43,42,41.6569,42,40 C42,40,42,25,42,25 C42,25,40,24,40,24 C40,24,41,19,41,19 z"/>
|
|
29
|
+
<path id="Path-4" style="fill:#8e7f6d;fill-opacity:1;fill-rule:nonzero;opacity:1;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-width:2;" d="M13.2766,3.05029 C13.1062,3.01931,12.9326,3.08429,12.8244,3.21952 C12.8244,3.21952,9,8,9,8 C9,8,6.05462,8.58908,6.05462,8.58908 C5.56174,8.68765,5.54512,9.38628,6.03275,9.50819 C6.03275,9.50819,24,14,24,14 C24,14,41.9672,9.50819,41.9672,9.50819 C42.4549,9.38628,42.4383,8.68765,41.9454,8.58908 C41.9454,8.58908,39,8,39,8 C39,8,35.1756,3.21952,35.1756,3.21952 C35.0674,3.08429,34.8938,3.01931,34.7234,3.05029 C34.7234,3.05029,24,5,24,5 C24,5,13.2766,3.05029,13.2766,3.05029 z"/>
|
|
30
|
+
</g>
|
|
31
|
+
</svg>
|