typescript-to-lua 1.3.4 → 1.4.0
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/CompilerOptions.d.ts +1 -1
- package/dist/CompilerOptions.js +0 -1
- package/dist/LuaLib.d.ts +12 -1
- package/dist/LuaLib.js +61 -65
- package/dist/LuaPrinter.js +9 -8
- package/dist/cli/parse.js +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -1
- package/dist/lualib/ArrayConcat.lua +1 -1
- package/dist/lualib/ArrayEntries.lua +1 -1
- package/dist/lualib/ArrayEvery.lua +2 -2
- package/dist/lualib/ArrayFilter.lua +2 -2
- package/dist/lualib/ArrayFind.lua +2 -2
- package/dist/lualib/ArrayFindIndex.lua +2 -2
- package/dist/lualib/ArrayFlat.lua +1 -1
- package/dist/lualib/ArrayFlatMap.lua +2 -2
- package/dist/lualib/ArrayForEach.lua +2 -2
- package/dist/lualib/ArrayIncludes.lua +1 -1
- package/dist/lualib/ArrayIndexOf.lua +1 -1
- package/dist/lualib/ArrayIsArray.lua +1 -1
- package/dist/lualib/ArrayJoin.lua +1 -1
- package/dist/lualib/ArrayMap.lua +2 -2
- package/dist/lualib/ArrayPush.lua +1 -1
- package/dist/lualib/ArrayReduce.lua +2 -2
- package/dist/lualib/ArrayReduceRight.lua +2 -2
- package/dist/lualib/ArrayReverse.lua +1 -1
- package/dist/lualib/ArraySetLength.lua +1 -1
- package/dist/lualib/ArrayShift.lua +1 -1
- package/dist/lualib/ArraySlice.lua +1 -1
- package/dist/lualib/ArraySome.lua +2 -2
- package/dist/lualib/ArraySort.lua +2 -2
- package/dist/lualib/ArraySplice.lua +1 -1
- package/dist/lualib/ArrayToObject.lua +1 -1
- package/dist/lualib/ArrayUnshift.lua +1 -1
- package/dist/lualib/Await.lua +13 -13
- package/dist/lualib/Class.lua +1 -1
- package/dist/lualib/ClassExtends.lua +1 -1
- package/dist/lualib/CloneDescriptor.lua +1 -1
- package/dist/lualib/Decorate.lua +5 -5
- package/dist/lualib/DecorateParam.lua +2 -2
- package/dist/lualib/DelegatedYield.lua +1 -1
- package/dist/lualib/Delete.lua +1 -1
- package/dist/lualib/Error.lua +68 -69
- package/dist/lualib/FunctionBind.lua +1 -1
- package/dist/lualib/Generator.lua +26 -23
- package/dist/lualib/InstanceOf.lua +1 -1
- package/dist/lualib/InstanceOfObject.lua +1 -1
- package/dist/lualib/Iterator.lua +35 -32
- package/dist/lualib/Map.lua +131 -129
- package/dist/lualib/MathAtan2.lua +1 -1
- package/dist/lualib/MathSign.lua +1 -1
- package/dist/lualib/New.lua +1 -1
- package/dist/lualib/Number.lua +1 -1
- package/dist/lualib/NumberIsFinite.lua +1 -1
- package/dist/lualib/NumberIsNaN.lua +1 -1
- package/dist/lualib/NumberToString.lua +42 -39
- package/dist/lualib/ObjectAssign.lua +1 -1
- package/dist/lualib/ObjectDefineProperty.lua +1 -1
- package/dist/lualib/ObjectEntries.lua +1 -1
- package/dist/lualib/ObjectFromEntries.lua +1 -1
- package/dist/lualib/ObjectGetOwnPropertyDescriptor.lua +1 -1
- package/dist/lualib/ObjectGetOwnPropertyDescriptors.lua +1 -1
- package/dist/lualib/ObjectKeys.lua +1 -1
- package/dist/lualib/ObjectRest.lua +1 -1
- package/dist/lualib/ObjectValues.lua +1 -1
- package/dist/lualib/ParseFloat.lua +1 -1
- package/dist/lualib/ParseInt.lua +39 -36
- package/dist/lualib/Promise.lua +148 -152
- package/dist/lualib/PromiseAll.lua +5 -5
- package/dist/lualib/PromiseAllSettled.lua +5 -5
- package/dist/lualib/PromiseAny.lua +5 -5
- package/dist/lualib/PromiseRace.lua +5 -5
- package/dist/lualib/Set.lua +120 -118
- package/dist/lualib/SetDescriptor.lua +67 -64
- package/dist/lualib/SourceMapTraceBack.lua +7 -6
- package/dist/lualib/SparseArrayNew.lua +1 -1
- package/dist/lualib/SparseArrayPush.lua +1 -1
- package/dist/lualib/SparseArraySpread.lua +1 -1
- package/dist/lualib/Spread.lua +1 -1
- package/dist/lualib/StringAccess.lua +1 -1
- package/dist/lualib/StringCharAt.lua +1 -1
- package/dist/lualib/StringCharCodeAt.lua +1 -1
- package/dist/lualib/StringConcat.lua +1 -1
- package/dist/lualib/StringEndsWith.lua +1 -1
- package/dist/lualib/StringIncludes.lua +1 -1
- package/dist/lualib/StringPadEnd.lua +1 -1
- package/dist/lualib/StringPadStart.lua +1 -1
- package/dist/lualib/StringReplace.lua +2 -2
- package/dist/lualib/StringReplaceAll.lua +4 -4
- package/dist/lualib/StringSlice.lua +1 -1
- package/dist/lualib/StringSplit.lua +1 -1
- package/dist/lualib/StringStartsWith.lua +1 -1
- package/dist/lualib/StringSubstr.lua +1 -1
- package/dist/lualib/StringSubstring.lua +1 -1
- package/dist/lualib/StringTrim.lua +1 -1
- package/dist/lualib/StringTrimEnd.lua +1 -1
- package/dist/lualib/StringTrimStart.lua +1 -1
- package/dist/lualib/Symbol.lua +14 -11
- package/dist/lualib/SymbolRegistry.lua +13 -10
- package/dist/lualib/TypeOf.lua +1 -1
- package/dist/lualib/Unpack.lua +1 -1
- package/dist/lualib/WeakMap.lua +41 -39
- package/dist/lualib/WeakSet.lua +37 -35
- package/dist/lualib/lualib_bundle.lua +1054 -924
- package/dist/lualib/lualib_module_info.json +619 -0
- package/dist/lualib-build/plugin.d.ts +23 -0
- package/dist/lualib-build/plugin.js +138 -0
- package/dist/lualib-build/util.d.ts +19 -0
- package/dist/lualib-build/util.js +43 -0
- package/dist/transformation/builtins/function.js +2 -1
- package/dist/transformation/builtins/index.d.ts +1 -0
- package/dist/transformation/builtins/index.js +63 -16
- package/dist/transformation/context/index.js +5 -1
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +2 -1
- package/dist/transformation/utils/typescript/index.js +5 -1
- package/dist/transformation/utils/typescript/types.d.ts +2 -0
- package/dist/transformation/utils/typescript/types.js +10 -1
- package/dist/transformation/visitors/class/index.js +1 -5
- package/dist/transformation/visitors/class/new.d.ts +1 -2
- package/dist/transformation/visitors/class/new.js +1 -40
- package/dist/transformation/visitors/conditional.js +15 -14
- package/dist/transformation/visitors/identifier.js +5 -0
- package/dist/transformation/visitors/literal.js +22 -0
- package/dist/transformation/visitors/modules/import.js +4 -14
- package/dist/transpilation/bundle.js +1 -1
- package/dist/transpilation/index.js +5 -1
- package/dist/transpilation/plugins.d.ts +11 -0
- package/dist/transpilation/transpile.js +13 -0
- package/dist/transpilation/transpiler.js +6 -2
- package/package.json +12 -11
- package/CHANGELOG.md +0 -703
|
@@ -48,13 +48,8 @@ const transformImportDeclaration = (statement, context) => {
|
|
|
48
48
|
// require("module")
|
|
49
49
|
if (statement.importClause === undefined) {
|
|
50
50
|
result.push(lua.createExpressionStatement(requireCall));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
51
|
+
scope.importStatements.push(...result);
|
|
52
|
+
return undefined;
|
|
58
53
|
}
|
|
59
54
|
const importPath = ts.isStringLiteral(statement.moduleSpecifier)
|
|
60
55
|
? statement.moduleSpecifier.text.replace(/"/g, "")
|
|
@@ -100,13 +95,8 @@ const transformImportDeclaration = (statement, context) => {
|
|
|
100
95
|
if (usingRequireStatement) {
|
|
101
96
|
result.unshift(lua.createVariableDeclarationStatement(importUniqueName, requireCall, statement));
|
|
102
97
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
98
|
+
scope.importStatements.push(...result);
|
|
99
|
+
return undefined;
|
|
110
100
|
};
|
|
111
101
|
exports.transformImportDeclaration = transformImportDeclaration;
|
|
112
102
|
const transformExternalModuleReference = (node, context) => createModuleRequire(context, node.expression, node);
|
|
@@ -85,7 +85,7 @@ function getBundleResult(program, files) {
|
|
|
85
85
|
const footers = [];
|
|
86
86
|
if (options.sourceMapTraceback) {
|
|
87
87
|
// Generates SourceMapTraceback for the entire file
|
|
88
|
-
footers.push('require("lualib_bundle")\n');
|
|
88
|
+
footers.push('local __TS__SourceMapTraceBack = require("lualib_bundle").__TS__SourceMapTraceBack\n');
|
|
89
89
|
footers.push(`${exports.sourceMapTracebackBundlePlaceholder}\n`);
|
|
90
90
|
}
|
|
91
91
|
const sourceChunks = [requireOverride, moduleTable, ...footers, entryPoint];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
+
import { EmitHost } from "..";
|
|
3
|
+
import { CompilerOptions } from "../CompilerOptions";
|
|
2
4
|
import { Printer } from "../LuaPrinter";
|
|
3
5
|
import { Visitors } from "../transformation/context";
|
|
6
|
+
import { ProcessedFile } from "./utils";
|
|
4
7
|
export interface Plugin {
|
|
5
8
|
/**
|
|
6
9
|
* An augmentation to the map of visitors that transform TypeScript AST to Lua AST.
|
|
@@ -14,5 +17,13 @@ export interface Plugin {
|
|
|
14
17
|
* At most one custom printer can be provided across all plugins.
|
|
15
18
|
*/
|
|
16
19
|
printer?: Printer;
|
|
20
|
+
/**
|
|
21
|
+
* This function is called before transpilation of the TypeScript program starts.
|
|
22
|
+
*/
|
|
23
|
+
beforeTransform?: (program: ts.Program, options: CompilerOptions, emitHost: EmitHost) => ts.Diagnostic[] | void;
|
|
24
|
+
/**
|
|
25
|
+
* This function is called after TypeScriptToLua has translated the input program to Lua.
|
|
26
|
+
*/
|
|
27
|
+
afterPrint?: (program: ts.Program, options: CompilerOptions, emitHost: EmitHost, result: ProcessedFile[]) => ts.Diagnostic[] | void;
|
|
17
28
|
}
|
|
18
29
|
export declare function getPlugins(program: ts.Program, diagnostics: ts.Diagnostic[], customPlugins: Plugin[]): Plugin[];
|
|
@@ -10,6 +10,7 @@ const utils_1 = require("../utils");
|
|
|
10
10
|
const plugins_1 = require("./plugins");
|
|
11
11
|
const transformers_1 = require("./transformers");
|
|
12
12
|
function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceFiles: targetSourceFiles, customTransformers = {}, plugins: customPlugins = [] }) {
|
|
13
|
+
var _a, _b;
|
|
13
14
|
const options = program.getCompilerOptions();
|
|
14
15
|
if (options.tstlVerbose) {
|
|
15
16
|
console.log("Parsing project settings");
|
|
@@ -43,6 +44,12 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
43
44
|
if (options.tstlVerbose) {
|
|
44
45
|
console.log(`Successfully loaded ${plugins.length} plugins`);
|
|
45
46
|
}
|
|
47
|
+
for (const plugin of plugins) {
|
|
48
|
+
if (plugin.beforeTransform) {
|
|
49
|
+
const pluginDiagnostics = (_a = plugin.beforeTransform(program, options, emitHost)) !== null && _a !== void 0 ? _a : [];
|
|
50
|
+
diagnostics.push(...pluginDiagnostics);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
46
53
|
const visitorMap = (0, transformation_1.createVisitorMap)(plugins.map(p => p.visitors).filter(utils_1.isNonNull));
|
|
47
54
|
const printer = (0, LuaPrinter_1.createPrinter)(plugins.map(p => p.printer).filter(utils_1.isNonNull));
|
|
48
55
|
const processSourceFile = (sourceFile) => {
|
|
@@ -95,6 +102,12 @@ function getProgramTranspileResult(emitHost, writeFileResult, { program, sourceF
|
|
|
95
102
|
if (options.noEmit || (options.noEmitOnError && diagnostics.length > 0)) {
|
|
96
103
|
transpiledFiles = [];
|
|
97
104
|
}
|
|
105
|
+
for (const plugin of plugins) {
|
|
106
|
+
if (plugin.afterPrint) {
|
|
107
|
+
const pluginDiagnostics = (_b = plugin.afterPrint(program, options, emitHost, transpiledFiles)) !== null && _b !== void 0 ? _b : [];
|
|
108
|
+
diagnostics.push(...pluginDiagnostics);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
98
111
|
return { diagnostics, transpiledFiles };
|
|
99
112
|
}
|
|
100
113
|
exports.getProgramTranspileResult = getProgramTranspileResult;
|
|
@@ -80,6 +80,7 @@ function getEmitPath(file, program) {
|
|
|
80
80
|
}
|
|
81
81
|
exports.getEmitPath = getEmitPath;
|
|
82
82
|
function getEmitPathRelativeToOutDir(fileName, program) {
|
|
83
|
+
var _a;
|
|
83
84
|
const sourceDir = getSourceDir(program);
|
|
84
85
|
// Default output path is relative path in source dir
|
|
85
86
|
let emitPathSplits = path.relative(sourceDir, fileName).split(path.sep);
|
|
@@ -89,8 +90,11 @@ function getEmitPathRelativeToOutDir(fileName, program) {
|
|
|
89
90
|
if (emitPathSplits[0] === "node_modules") {
|
|
90
91
|
emitPathSplits[0] = "lua_modules";
|
|
91
92
|
}
|
|
92
|
-
//
|
|
93
|
-
|
|
93
|
+
// Set extension
|
|
94
|
+
const extension = ((_a = program.getCompilerOptions().extension) !== null && _a !== void 0 ? _a : "lua").trim();
|
|
95
|
+
const trimmedExtension = extension.startsWith(".") ? extension.substring(1) : extension;
|
|
96
|
+
emitPathSplits[emitPathSplits.length - 1] =
|
|
97
|
+
(0, utils_1.trimExtension)(emitPathSplits[emitPathSplits.length - 1]) + "." + trimmedExtension;
|
|
94
98
|
return path.join(...emitPathSplits);
|
|
95
99
|
}
|
|
96
100
|
exports.getEmitPathRelativeToOutDir = getEmitPathRelativeToOutDir;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
|
|
5
5
|
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
|
|
6
6
|
"homepage": "https://typescripttolua.github.io/",
|
|
@@ -18,13 +18,14 @@
|
|
|
18
18
|
"dist/**/*.js",
|
|
19
19
|
"dist/**/*.lua",
|
|
20
20
|
"dist/**/*.ts",
|
|
21
|
+
"dist/lualib/*.json",
|
|
21
22
|
"language-extensions/**/*.ts"
|
|
22
23
|
],
|
|
23
24
|
"main": "dist/index.js",
|
|
24
25
|
"types": "dist/index.d.ts",
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "tsc && npm run build-lualib",
|
|
27
|
-
"build-lualib": "node
|
|
28
|
+
"build-lualib": "node dist/tstl.js -p src/lualib/tsconfig.json",
|
|
28
29
|
"pretest": "npm run lint && npm run check:language-extensions && npm run build-lualib",
|
|
29
30
|
"test": "jest",
|
|
30
31
|
"lint": "npm run lint:eslint && npm run lint:prettier",
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"node": ">=12.13.0"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
|
-
"typescript": "~4.
|
|
46
|
+
"typescript": "~4.6.2"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"enhanced-resolve": "^5.8.2",
|
|
@@ -52,14 +53,14 @@
|
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@types/fs-extra": "^8.1.0",
|
|
54
55
|
"@types/glob": "^7.1.1",
|
|
55
|
-
"@types/jest": "^
|
|
56
|
+
"@types/jest": "^27.4.1",
|
|
56
57
|
"@types/node": "^13.7.7",
|
|
57
58
|
"@types/resolve": "1.14.0",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
59
|
-
"@typescript-eslint/parser": "^5.
|
|
60
|
-
"eslint": "^
|
|
61
|
-
"eslint-plugin-import": "^2.
|
|
62
|
-
"eslint-plugin-jest": "^
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.13.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.13.0",
|
|
61
|
+
"eslint": "^8.10.0",
|
|
62
|
+
"eslint-plugin-import": "^2.25.4",
|
|
63
|
+
"eslint-plugin-jest": "^26.1.1",
|
|
63
64
|
"fs-extra": "^8.1.0",
|
|
64
65
|
"javascript-stringify": "^2.0.1",
|
|
65
66
|
"jest": "^27.3.0",
|
|
@@ -67,8 +68,8 @@
|
|
|
67
68
|
"lua-types": "2.10.1",
|
|
68
69
|
"lua-wasm-bindings": "^0.2.2",
|
|
69
70
|
"prettier": "^2.3.2",
|
|
70
|
-
"ts-jest": "^27.
|
|
71
|
+
"ts-jest": "^27.1.3",
|
|
71
72
|
"ts-node": "^10.3.0",
|
|
72
|
-
"typescript": "~4.
|
|
73
|
+
"typescript": "~4.6.2"
|
|
73
74
|
}
|
|
74
75
|
}
|