@grey-ts/transpiler 1.4.0 → 1.4.2
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 +25 -22
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -746,7 +746,7 @@ NodeHandler.register(ts7.SyntaxKind.BinaryExpression, (node) => {
|
|
|
746
746
|
}
|
|
747
747
|
switch (operatorToken) {
|
|
748
748
|
case "instanceof":
|
|
749
|
-
return
|
|
749
|
+
return `${left} isa ${right}`;
|
|
750
750
|
case "??":
|
|
751
751
|
return callUtilFunction("nullish_coalescing_op", left, right);
|
|
752
752
|
case "??=":
|
|
@@ -1059,6 +1059,28 @@ NodeHandler.register(ts10.SyntaxKind.ImportDeclaration, (node, ctx) => {
|
|
|
1059
1059
|
|
|
1060
1060
|
// src/visitors/objects.ts
|
|
1061
1061
|
import ts11 from "typescript";
|
|
1062
|
+
function shouldGetSafely(node) {
|
|
1063
|
+
if (ts11.isNonNullExpression(node.parent))
|
|
1064
|
+
return false;
|
|
1065
|
+
if (valueIsBeingAssignedToNode(node))
|
|
1066
|
+
return false;
|
|
1067
|
+
if (ts11.isPropertyAccessExpression(node)) {
|
|
1068
|
+
const rightType = checker.getTypeAtLocation(node.name);
|
|
1069
|
+
if (!rightType.isUnion())
|
|
1070
|
+
return !!node.questionDotToken;
|
|
1071
|
+
const hasUndefined = rightType.types.some((t) => t.flags === ts11.TypeFlags.Undefined);
|
|
1072
|
+
if (!hasUndefined)
|
|
1073
|
+
return false;
|
|
1074
|
+
if (!ts11.isCallExpression(node.parent))
|
|
1075
|
+
return true;
|
|
1076
|
+
if (node.parent.arguments.length)
|
|
1077
|
+
return false;
|
|
1078
|
+
} else {
|
|
1079
|
+
if (ts11.isNumericLiteral(node.argumentExpression) && !node.questionDotToken)
|
|
1080
|
+
return false;
|
|
1081
|
+
}
|
|
1082
|
+
return true;
|
|
1083
|
+
}
|
|
1062
1084
|
NodeHandler.register(ts11.SyntaxKind.PropertyAccessExpression, (node, ctx) => {
|
|
1063
1085
|
const left = NodeHandler.handle(node.expression);
|
|
1064
1086
|
let right = NodeHandler.handle(node.name);
|
|
@@ -1066,14 +1088,7 @@ NodeHandler.register(ts11.SyntaxKind.PropertyAccessExpression, (node, ctx) => {
|
|
|
1066
1088
|
const nodeSymbol = checker.getSymbolAtLocation(node);
|
|
1067
1089
|
if (ctx.namespaceImports[ctx.currentFilePath]?.has(left))
|
|
1068
1090
|
return right;
|
|
1069
|
-
|
|
1070
|
-
const rightType = checker.getTypeAtLocation(node.name);
|
|
1071
|
-
if (rightType.isUnion()) {
|
|
1072
|
-
const hasUndefined = rightType.types.some((t) => t.flags === ts11.TypeFlags.Undefined);
|
|
1073
|
-
if (hasUndefined)
|
|
1074
|
-
getSafely = true;
|
|
1075
|
-
}
|
|
1076
|
-
if (!valueIsBeingAssignedToNode(node) && getSafely)
|
|
1091
|
+
if (shouldGetSafely(node))
|
|
1077
1092
|
return callUtilFunction("get_property", left, `"${right}"`);
|
|
1078
1093
|
let output = `${left}.${right}`;
|
|
1079
1094
|
output = replacePropertyAccess(output, nodeSymbol);
|
|
@@ -1090,7 +1105,7 @@ NodeHandler.register(ts11.SyntaxKind.ElementAccessExpression, (node, ctx) => {
|
|
|
1090
1105
|
} else {
|
|
1091
1106
|
right = NodeHandler.handle(node.argumentExpression);
|
|
1092
1107
|
}
|
|
1093
|
-
if (
|
|
1108
|
+
if (shouldGetSafely(node)) {
|
|
1094
1109
|
return callUtilFunction("get_property", left, `${right}`);
|
|
1095
1110
|
}
|
|
1096
1111
|
return `${left}[${right}]`;
|
|
@@ -1724,18 +1739,6 @@ var utilFunctions = {
|
|
|
1724
1739
|
"\treturn target",
|
|
1725
1740
|
"end function"
|
|
1726
1741
|
].join(`
|
|
1727
|
-
`),
|
|
1728
|
-
instance_of: [
|
|
1729
|
-
"instance_of = function(obj, class)",
|
|
1730
|
-
'\tif not obj.hasIndex("__isa") then return 0',
|
|
1731
|
-
"\tisaobj = obj",
|
|
1732
|
-
'\twhile isaobj.hasIndex("__isa")',
|
|
1733
|
-
'\t\tif isaobj["__isa"] == class then return 1',
|
|
1734
|
-
'\t\tisaobj = isaobj["__isa"]',
|
|
1735
|
-
"\tend while",
|
|
1736
|
-
"\treturn 0",
|
|
1737
|
-
"end function"
|
|
1738
|
-
].join(`
|
|
1739
1742
|
`),
|
|
1740
1743
|
nullish_coalescing_op: `nullish_coalescing_op = function(left, right)
|
|
1741
1744
|
if left == null then return @right
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grey-ts/transpiler",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Transpiles TypeScript into GreyScript",
|
|
5
5
|
"author": "Okka",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -34,12 +34,11 @@
|
|
|
34
34
|
"build": "bun run scripts/build.ts"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/bun": "latest"
|
|
37
|
+
"@types/bun": "latest",
|
|
38
|
+
"@grey-ts/types": "latest"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
|
-
"typescript": "^5"
|
|
41
|
-
},
|
|
42
|
-
"dependencies": {
|
|
41
|
+
"typescript": "^5",
|
|
43
42
|
"@grey-ts/types": "^2.2.0"
|
|
44
43
|
}
|
|
45
44
|
}
|