tjs-lang 0.6.43 → 0.6.44
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/dist/index.js +55 -53
- package/dist/index.js.map +4 -4
- package/dist/tjs-full.js +55 -53
- package/dist/tjs-full.js.map +4 -4
- package/package.json +1 -1
- package/src/cli/tjs.ts +1 -1
- package/src/lang/emitters/dts.ts +14 -1
- package/src/lang/emitters/from-ts.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tjs-lang",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.44",
|
|
4
4
|
"description": "Type-safe JavaScript dialect with runtime validation, sandboxed VM execution, and AI agent orchestration. Transpiles TypeScript to validated JS with fuel-metered execution for untrusted code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
package/src/cli/tjs.ts
CHANGED
package/src/lang/emitters/dts.ts
CHANGED
|
@@ -453,6 +453,15 @@ function detectTypeDeclarations(source: string): Map<string, string> {
|
|
|
453
453
|
result.set(m[1], m[2].trim())
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
// Block with TS type body: Type Name { // TS: original type }
|
|
457
|
+
const tsBodyRe =
|
|
458
|
+
/^[ \t]*(?:export\s+)?Type\s+(\w+)\s*\{[^}]*\/\/\s*TS:\s*(.+?)(?:\n|\s*\})/gm
|
|
459
|
+
while ((m = tsBodyRe.exec(source)) !== null) {
|
|
460
|
+
if (!result.has(m[1])) {
|
|
461
|
+
result.set(m[1], `__ts__:${m[2].trim()}`) // prefix marks TS passthrough
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
456
465
|
// Empty block: Type Name {} (no example — degraded type, emit as any)
|
|
457
466
|
const emptyBlockRe = /^[ \t]*(?:export\s+)?Type\s+(\w+)\s*\{\s*\}/gm
|
|
458
467
|
while ((m = emptyBlockRe.exec(source)) !== null) {
|
|
@@ -653,7 +662,11 @@ export function generateDTS(
|
|
|
653
662
|
const isExported = hasAnyExport ? !!exportInfo?.exported : true
|
|
654
663
|
if (!isExported) continue
|
|
655
664
|
|
|
656
|
-
if (exampleStr
|
|
665
|
+
if (exampleStr.startsWith('__ts__:')) {
|
|
666
|
+
// Preserved TS type body — emit verbatim as type alias
|
|
667
|
+
const tsBody = exampleStr.slice(7)
|
|
668
|
+
lines.push(`export type ${name} = ${tsBody};`)
|
|
669
|
+
} else if (exampleStr === '') {
|
|
657
670
|
// Empty Type {} — degraded from TS type alias, emit as type = any
|
|
658
671
|
lines.push(`export type ${name} = any;`)
|
|
659
672
|
} else {
|
|
@@ -1262,9 +1262,11 @@ function transformTypeAliasToType(
|
|
|
1262
1262
|
|
|
1263
1263
|
const example = typeToExample(node.type, undefined, warnings)
|
|
1264
1264
|
|
|
1265
|
-
// 'any' and 'undefined' —
|
|
1265
|
+
// 'any' and 'undefined' — preserve original TS body for DTS round-tripping
|
|
1266
1266
|
if (example === 'any' || example === 'undefined') {
|
|
1267
|
-
|
|
1267
|
+
const originalType = node.type.getText(sourceFile).trim()
|
|
1268
|
+
// Include the TS type body so the DTS emitter can recover it
|
|
1269
|
+
return `Type ${typeName} {\n // TS: ${originalType}\n}`
|
|
1268
1270
|
}
|
|
1269
1271
|
|
|
1270
1272
|
// For simple primitive types, use short form
|