forked from carlosmiei/ast-transpiler
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmanual.ts
114 lines (91 loc) · 2.73 KB
/
manual.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { Transpiler } from './src/transpiler.js';
import * as fs from 'fs';
import { IInput } from './src/types.js';
const { readFileSync, writeFileSync } = fs;
const transpiler = new Transpiler({
python: {
uncamelcaseIdentifiers: true,
},
php: {
uncamelcaseIdentifiers: true,
},
csharp: {
parser: {
"ELEMENT_ACCESS_WRAPPER_OPEN": "getValue(",
"ELEMENT_ACCESS_WRAPPER_CLOSE": ")",
'VAR_TOKEN': 'var',
}
}
});
function customPropAssignment(node, identation) {
return "";
}
transpiler.csharpTranspiler.printCustomRightSidePropertyAssignment = customPropAssignment;
transpiler.setPHPPropResolution(['super', 'Precise']);
transpiler.setPythonStringLiteralReplacements({
'sha256': 'hashlib.sha256',
});
const file = "tmp.ts";
const i = 0;
// // while (i < 150) {
// const pythonRes = transpiler.transpilePythonByPath(file);
// const php = transpiler.transpilePhpByPath(file);
// // const csharp = transpiler.transpileCSharpByPath(file);
// // i++;
// // }
// const phpRes = `<?php\n${php.content}\n?>`;
// transpiler.setPhpAsyncTranspiling(false);
// const phpSyncRes = `<?php\n${transpiler.transpilePhpByPath(file).content}\n?>`;
// transpiler.setPythonAsyncTranspiling(false);
// const pythonSync = transpiler.transpilePythonByPath(file).content;
const config = [
// {
// language: "php",
// async: true
// },
// {
// language: "php",
// async: false
// },
// {
// language: "python",
// async: false
// },
{
language: "csharp",
async: true
},
{
language: "python",
async: true
},
{
language: "php",
async: true
},
{
language: "go",
async: true
},
]
const result = transpiler.transpileDifferentLanguagesByPath(config as any, file);
const phpRes = `<?php\n${result[2].content}\n?>`;
// const phpSyncRes = `<?php\n${result[1].content}\n?>`;
// const pythonSync = result[2].content;
const pythonAsync = result[1].content;
const csharp = result[0].content;
const PHP_OUTPUT = "./out/output.php";
const PHP_SYNC_OUTPUT = "./out/output-sync.php";
const PYTHON_OUTPUT = "./out/output.py";
const PYTHON_SYNC_OUTPUT = "./out/output-sync.py";
const CSHARP_OUTPUT = "./out/output.cs";
const GO_OUTPUT = "./out/output.go";
const go = result[3].content;
writeFileSync(PHP_OUTPUT, phpRes);
// // writeFileSync(PYTHON_OUTPUT, pythonRes.content ?? "");
writeFileSync(PYTHON_OUTPUT, pythonAsync ?? "");
// writeFileSync(PYTHON_SYNC_OUTPUT, pythonSync ?? "");
// writeFileSync(PHP_SYNC_OUTPUT, phpSyncRes);
writeFileSync(CSHARP_OUTPUT, csharp);
writeFileSync(GO_OUTPUT, go);
console.log("TRANSPILED!!");