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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tjs-lang",
3
- "version": "0.6.43",
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
@@ -20,7 +20,7 @@ import { emit } from './commands/emit'
20
20
  import { convert } from './commands/convert'
21
21
  import { test } from './commands/test'
22
22
 
23
- const VERSION = '0.6.43'
23
+ const VERSION = '0.6.44'
24
24
 
25
25
  const HELP = `
26
26
  tjs - Typed JavaScript CLI
@@ -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' — skip declaration (undeclared = any in TJS)
1265
+ // 'any' and 'undefined' — preserve original TS body for DTS round-tripping
1266
1266
  if (example === 'any' || example === 'undefined') {
1267
- return `Type ${typeName} {}`
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