tjs-lang 0.6.39 → 0.6.40
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 +92 -87
- package/dist/index.js.map +3 -3
- package/dist/tjs-full.js +92 -87
- package/dist/tjs-full.js.map +3 -3
- package/package.json +1 -1
- package/src/cli/tjs.ts +1 -1
- package/src/lang/emitters/from-ts.ts +50 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tjs-lang",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.40",
|
|
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
|
@@ -1065,8 +1065,28 @@ function transformGenericInterfaceToGeneric(
|
|
|
1065
1065
|
}
|
|
1066
1066
|
|
|
1067
1067
|
const parts = [`description: '${typeName}'`, predicateLine]
|
|
1068
|
+
|
|
1068
1069
|
if (declarationAnnotation?.text) {
|
|
1069
1070
|
parts.push(`declaration ${declarationAnnotation.text}`)
|
|
1071
|
+
} else {
|
|
1072
|
+
// Auto-generate declaration block from interface members
|
|
1073
|
+
const declMembers: string[] = []
|
|
1074
|
+
for (const member of node.members) {
|
|
1075
|
+
if (ts.isPropertySignature(member) && member.name) {
|
|
1076
|
+
const propName = member.name.getText(sourceFile)
|
|
1077
|
+
const optional = member.questionToken ? '?' : ''
|
|
1078
|
+
const typeText = member.type ? member.type.getText(sourceFile) : 'any'
|
|
1079
|
+
declMembers.push(`${propName}${optional}: ${typeText}`)
|
|
1080
|
+
} else if (ts.isMethodSignature(member) && member.name) {
|
|
1081
|
+
// Method: name(params): returnType
|
|
1082
|
+
const methodText = member.getText(sourceFile).trim()
|
|
1083
|
+
// Remove trailing semicolon if present
|
|
1084
|
+
declMembers.push(methodText.replace(/;$/, ''))
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
if (declMembers.length > 0) {
|
|
1088
|
+
parts.push(`declaration {\n ${declMembers.join('\n ')}\n }`)
|
|
1089
|
+
}
|
|
1070
1090
|
}
|
|
1071
1091
|
|
|
1072
1092
|
return `Generic ${typeName}<${typeParams.join(', ')}> {\n ${parts.join(
|
|
@@ -1366,18 +1386,41 @@ function transformGenericTypeAliasToGeneric(
|
|
|
1366
1386
|
predicateLine = `predicate(${predicateParams}) { return true }`
|
|
1367
1387
|
}
|
|
1368
1388
|
|
|
1369
|
-
// Include original TS source as a block comment for manual enhancement
|
|
1370
|
-
const originalSource = node.getText(sourceFile).trim()
|
|
1371
|
-
const comment = `/* Original TS:\n${originalSource}\n*/`
|
|
1372
|
-
|
|
1373
1389
|
const parts = [`description: '${typeName}'`, predicateLine]
|
|
1390
|
+
|
|
1374
1391
|
if (declarationAnnotation?.text) {
|
|
1375
1392
|
parts.push(`declaration ${declarationAnnotation.text}`)
|
|
1393
|
+
} else {
|
|
1394
|
+
// Auto-generate declaration block from the type body
|
|
1395
|
+
const typeBody = node.type
|
|
1396
|
+
|
|
1397
|
+
if (typeBody && ts.isTypeLiteralNode(typeBody)) {
|
|
1398
|
+
// Object type literal: { item: T; count: number }
|
|
1399
|
+
const declMembers: string[] = []
|
|
1400
|
+
for (const member of typeBody.members) {
|
|
1401
|
+
if (ts.isPropertySignature(member) && member.name) {
|
|
1402
|
+
const propName = member.name.getText(sourceFile)
|
|
1403
|
+
const optional = member.questionToken ? '?' : ''
|
|
1404
|
+
const typeText = member.type ? member.type.getText(sourceFile) : 'any'
|
|
1405
|
+
declMembers.push(`${propName}${optional}: ${typeText}`)
|
|
1406
|
+
} else if (ts.isMethodSignature(member) && member.name) {
|
|
1407
|
+
declMembers.push(member.getText(sourceFile).trim().replace(/;$/, ''))
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
if (declMembers.length > 0) {
|
|
1411
|
+
parts.push(`declaration {\n ${declMembers.join('\n ')}\n }`)
|
|
1412
|
+
}
|
|
1413
|
+
} else if (typeBody) {
|
|
1414
|
+
// Complex type (conditional, mapped, intersection, etc.)
|
|
1415
|
+
// Pass through the TS type body verbatim
|
|
1416
|
+
const typeText = typeBody.getText(sourceFile).trim()
|
|
1417
|
+
parts.push(`declaration {\n // TS: ${typeText}\n }`)
|
|
1418
|
+
}
|
|
1376
1419
|
}
|
|
1377
1420
|
|
|
1378
|
-
return
|
|
1379
|
-
'
|
|
1380
|
-
)}
|
|
1421
|
+
return `Generic ${typeName}<${typeParams.join(', ')}> {\n ${parts.join(
|
|
1422
|
+
'\n '
|
|
1423
|
+
)}\n}`
|
|
1381
1424
|
}
|
|
1382
1425
|
|
|
1383
1426
|
function transformFunctionToTJS(
|