typescript-to-lua 1.16.1 → 1.16.3
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/lualib/5.0/Map.lua +1 -1
- package/dist/lualib/5.0/Set.lua +1 -1
- package/dist/lualib/5.0/WeakMap.lua +1 -1
- package/dist/lualib/5.0/WeakSet.lua +1 -1
- package/dist/lualib/5.0/lualib_bundle.lua +4 -4
- package/dist/lualib/universal/Map.lua +1 -1
- package/dist/lualib/universal/Set.lua +1 -1
- package/dist/lualib/universal/WeakMap.lua +1 -1
- package/dist/lualib/universal/WeakSet.lua +1 -1
- package/dist/lualib/universal/lualib_bundle.lua +4 -4
- package/dist/transformation/utils/typescript/types.d.ts +1 -0
- package/dist/transformation/utils/typescript/types.js +19 -1
- package/dist/transformation/visitors/class/index.js +9 -5
- package/dist/transformation/visitors/spread.js +2 -1
- package/dist/transformation/visitors/switch.js +9 -3
- package/dist/transpilation/plugins.d.ts +1 -0
- package/dist/transpilation/resolve.d.ts +2 -1
- package/dist/transpilation/resolve.js +47 -11
- package/dist/transpilation/transpiler.d.ts +2 -1
- package/dist/transpilation/transpiler.js +3 -3
- package/package.json +1 -1
package/dist/lualib/5.0/Map.lua
CHANGED
package/dist/lualib/5.0/Set.lua
CHANGED
|
@@ -26,7 +26,6 @@ do
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
WeakMap[Symbol.species] = WeakMap
|
|
30
29
|
function WeakMap.prototype.delete(self, key)
|
|
31
30
|
local contains = self:has(key)
|
|
32
31
|
self.items[key] = nil
|
|
@@ -42,4 +41,5 @@ do
|
|
|
42
41
|
self.items[key] = value
|
|
43
42
|
return self
|
|
44
43
|
end
|
|
44
|
+
WeakMap[Symbol.species] = WeakMap
|
|
45
45
|
end
|
|
@@ -25,7 +25,6 @@ do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
WeakSet[Symbol.species] = WeakSet
|
|
29
28
|
function WeakSet.prototype.add(self, value)
|
|
30
29
|
self.items[value] = true
|
|
31
30
|
return self
|
|
@@ -38,4 +37,5 @@ do
|
|
|
38
37
|
function WeakSet.prototype.has(self, value)
|
|
39
38
|
return self.items[value] == true
|
|
40
39
|
end
|
|
40
|
+
WeakSet[Symbol.species] = WeakSet
|
|
41
41
|
end
|
|
@@ -1278,7 +1278,6 @@ do
|
|
|
1278
1278
|
end
|
|
1279
1279
|
end
|
|
1280
1280
|
end
|
|
1281
|
-
Map[Symbol.species] = Map
|
|
1282
1281
|
function Map.prototype.clear(self)
|
|
1283
1282
|
self.items = {}
|
|
1284
1283
|
self.nextKey = {}
|
|
@@ -1386,6 +1385,7 @@ do
|
|
|
1386
1385
|
end
|
|
1387
1386
|
}
|
|
1388
1387
|
end
|
|
1388
|
+
Map[Symbol.species] = Map
|
|
1389
1389
|
end
|
|
1390
1390
|
|
|
1391
1391
|
local function __TS__StringSlice(self, start, ____end)
|
|
@@ -1902,7 +1902,6 @@ do
|
|
|
1902
1902
|
end
|
|
1903
1903
|
end
|
|
1904
1904
|
end
|
|
1905
|
-
Set[Symbol.species] = Set
|
|
1906
1905
|
function Set.prototype.add(self, value)
|
|
1907
1906
|
local isNewValue = not self:has(value)
|
|
1908
1907
|
if isNewValue then
|
|
@@ -2002,6 +2001,7 @@ do
|
|
|
2002
2001
|
end
|
|
2003
2002
|
}
|
|
2004
2003
|
end
|
|
2004
|
+
Set[Symbol.species] = Set
|
|
2005
2005
|
end
|
|
2006
2006
|
|
|
2007
2007
|
local function __TS__SparseArrayNew(...)
|
|
@@ -2052,7 +2052,6 @@ do
|
|
|
2052
2052
|
end
|
|
2053
2053
|
end
|
|
2054
2054
|
end
|
|
2055
|
-
WeakMap[Symbol.species] = WeakMap
|
|
2056
2055
|
function WeakMap.prototype.delete(self, key)
|
|
2057
2056
|
local contains = self:has(key)
|
|
2058
2057
|
self.items[key] = nil
|
|
@@ -2068,6 +2067,7 @@ do
|
|
|
2068
2067
|
self.items[key] = value
|
|
2069
2068
|
return self
|
|
2070
2069
|
end
|
|
2070
|
+
WeakMap[Symbol.species] = WeakMap
|
|
2071
2071
|
end
|
|
2072
2072
|
|
|
2073
2073
|
local WeakSet
|
|
@@ -2097,7 +2097,6 @@ do
|
|
|
2097
2097
|
end
|
|
2098
2098
|
end
|
|
2099
2099
|
end
|
|
2100
|
-
WeakSet[Symbol.species] = WeakSet
|
|
2101
2100
|
function WeakSet.prototype.add(self, value)
|
|
2102
2101
|
self.items[value] = true
|
|
2103
2102
|
return self
|
|
@@ -2110,6 +2109,7 @@ do
|
|
|
2110
2109
|
function WeakSet.prototype.has(self, value)
|
|
2111
2110
|
return self.items[value] == true
|
|
2112
2111
|
end
|
|
2112
|
+
WeakSet[Symbol.species] = WeakSet
|
|
2113
2113
|
end
|
|
2114
2114
|
|
|
2115
2115
|
local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
@@ -26,7 +26,6 @@ do
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
WeakMap[Symbol.species] = WeakMap
|
|
30
29
|
function WeakMap.prototype.delete(self, key)
|
|
31
30
|
local contains = self:has(key)
|
|
32
31
|
self.items[key] = nil
|
|
@@ -42,4 +41,5 @@ do
|
|
|
42
41
|
self.items[key] = value
|
|
43
42
|
return self
|
|
44
43
|
end
|
|
44
|
+
WeakMap[Symbol.species] = WeakMap
|
|
45
45
|
end
|
|
@@ -25,7 +25,6 @@ do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
WeakSet[Symbol.species] = WeakSet
|
|
29
28
|
function WeakSet.prototype.add(self, value)
|
|
30
29
|
self.items[value] = true
|
|
31
30
|
return self
|
|
@@ -38,4 +37,5 @@ do
|
|
|
38
37
|
function WeakSet.prototype.has(self, value)
|
|
39
38
|
return self.items[value] == true
|
|
40
39
|
end
|
|
40
|
+
WeakSet[Symbol.species] = WeakSet
|
|
41
41
|
end
|
|
@@ -1254,7 +1254,6 @@ do
|
|
|
1254
1254
|
end
|
|
1255
1255
|
end
|
|
1256
1256
|
end
|
|
1257
|
-
Map[Symbol.species] = Map
|
|
1258
1257
|
function Map.prototype.clear(self)
|
|
1259
1258
|
self.items = {}
|
|
1260
1259
|
self.nextKey = {}
|
|
@@ -1362,6 +1361,7 @@ do
|
|
|
1362
1361
|
end
|
|
1363
1362
|
}
|
|
1364
1363
|
end
|
|
1364
|
+
Map[Symbol.species] = Map
|
|
1365
1365
|
end
|
|
1366
1366
|
|
|
1367
1367
|
local __TS__Match = string.match
|
|
@@ -1838,7 +1838,6 @@ do
|
|
|
1838
1838
|
end
|
|
1839
1839
|
end
|
|
1840
1840
|
end
|
|
1841
|
-
Set[Symbol.species] = Set
|
|
1842
1841
|
function Set.prototype.add(self, value)
|
|
1843
1842
|
local isNewValue = not self:has(value)
|
|
1844
1843
|
if isNewValue then
|
|
@@ -1938,6 +1937,7 @@ do
|
|
|
1938
1937
|
end
|
|
1939
1938
|
}
|
|
1940
1939
|
end
|
|
1940
|
+
Set[Symbol.species] = Set
|
|
1941
1941
|
end
|
|
1942
1942
|
|
|
1943
1943
|
local function __TS__SparseArrayNew(...)
|
|
@@ -1989,7 +1989,6 @@ do
|
|
|
1989
1989
|
end
|
|
1990
1990
|
end
|
|
1991
1991
|
end
|
|
1992
|
-
WeakMap[Symbol.species] = WeakMap
|
|
1993
1992
|
function WeakMap.prototype.delete(self, key)
|
|
1994
1993
|
local contains = self:has(key)
|
|
1995
1994
|
self.items[key] = nil
|
|
@@ -2005,6 +2004,7 @@ do
|
|
|
2005
2004
|
self.items[key] = value
|
|
2006
2005
|
return self
|
|
2007
2006
|
end
|
|
2007
|
+
WeakMap[Symbol.species] = WeakMap
|
|
2008
2008
|
end
|
|
2009
2009
|
|
|
2010
2010
|
local WeakSet
|
|
@@ -2034,7 +2034,6 @@ do
|
|
|
2034
2034
|
end
|
|
2035
2035
|
end
|
|
2036
2036
|
end
|
|
2037
|
-
WeakSet[Symbol.species] = WeakSet
|
|
2038
2037
|
function WeakSet.prototype.add(self, value)
|
|
2039
2038
|
self.items[value] = true
|
|
2040
2039
|
return self
|
|
@@ -2047,6 +2046,7 @@ do
|
|
|
2047
2046
|
function WeakSet.prototype.has(self, value)
|
|
2048
2047
|
return self.items[value] == true
|
|
2049
2048
|
end
|
|
2049
|
+
WeakSet[Symbol.species] = WeakSet
|
|
2050
2050
|
end
|
|
2051
2051
|
|
|
2052
2052
|
local function __TS__SourceMapTraceBack(fileName, sourceMap)
|
|
@@ -9,6 +9,7 @@ export declare function isNumberType(context: TransformationContext, type: ts.Ty
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function forTypeOrAnySupertype(context: TransformationContext, type: ts.Type, predicate: (type: ts.Type) => boolean): boolean;
|
|
11
11
|
export declare function isArrayType(context: TransformationContext, type: ts.Type): boolean;
|
|
12
|
+
export declare function isAlwaysArrayType(context: TransformationContext, type: ts.Type): boolean;
|
|
12
13
|
export declare function isFunctionType(type: ts.Type): boolean;
|
|
13
14
|
export declare function canBeFalsy(context: TransformationContext, type: ts.Type): boolean;
|
|
14
15
|
export declare function canBeFalsyWhenNotNull(context: TransformationContext, type: ts.Type): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNumberType = exports.isStringType = exports.typeCanHaveSomeOfFlags = exports.typeAlwaysHasSomeOfFlags = void 0;
|
|
3
|
+
exports.canBeFalsyWhenNotNull = exports.canBeFalsy = exports.isFunctionType = exports.isAlwaysArrayType = exports.isArrayType = exports.forTypeOrAnySupertype = exports.isNumberType = exports.isStringType = exports.typeCanHaveSomeOfFlags = exports.typeAlwaysHasSomeOfFlags = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
function typeAlwaysHasSomeOfFlags(context, type, flags) {
|
|
6
6
|
const baseConstraint = context.checker.getBaseConstraintOfType(type);
|
|
@@ -63,6 +63,20 @@ function isExplicitArrayType(context, type) {
|
|
|
63
63
|
}
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
|
+
function isAlwaysExplicitArrayType(context, type) {
|
|
67
|
+
if (context.checker.isArrayType(type) || context.checker.isTupleType(type))
|
|
68
|
+
return true;
|
|
69
|
+
if (type.symbol) {
|
|
70
|
+
const baseConstraint = context.checker.getBaseConstraintOfType(type);
|
|
71
|
+
if (baseConstraint && baseConstraint !== type) {
|
|
72
|
+
return isAlwaysExplicitArrayType(context, baseConstraint);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (type.isUnionOrIntersection()) {
|
|
76
|
+
return type.types.every(t => isAlwaysExplicitArrayType(context, t));
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
66
80
|
/**
|
|
67
81
|
* Iterate over a type and its bases until the callback returns true.
|
|
68
82
|
*/
|
|
@@ -83,6 +97,10 @@ function isArrayType(context, type) {
|
|
|
83
97
|
return forTypeOrAnySupertype(context, type, t => isExplicitArrayType(context, t));
|
|
84
98
|
}
|
|
85
99
|
exports.isArrayType = isArrayType;
|
|
100
|
+
function isAlwaysArrayType(context, type) {
|
|
101
|
+
return forTypeOrAnySupertype(context, type, t => isAlwaysExplicitArrayType(context, t));
|
|
102
|
+
}
|
|
103
|
+
exports.isAlwaysArrayType = isAlwaysArrayType;
|
|
86
104
|
function isFunctionType(type) {
|
|
87
105
|
return type.getCallSignatures().length > 0;
|
|
88
106
|
}
|
|
@@ -102,6 +102,15 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
102
102
|
result.push(lua.createAssignmentStatement((0, constructor_1.createConstructorName)(localClassName), constructorFunction, classDeclaration));
|
|
103
103
|
}
|
|
104
104
|
// Transform class members
|
|
105
|
+
// First transform the methods, in case the static properties call them
|
|
106
|
+
for (const member of classDeclaration.members) {
|
|
107
|
+
if (ts.isMethodDeclaration(member)) {
|
|
108
|
+
// Methods
|
|
109
|
+
const statements = (0, method_1.transformMethodDeclaration)(context, member, localClassName);
|
|
110
|
+
result.push(...statements);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Then transform the rest
|
|
105
114
|
for (const member of classDeclaration.members) {
|
|
106
115
|
if (ts.isAccessor(member)) {
|
|
107
116
|
// Accessors
|
|
@@ -113,11 +122,6 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
113
122
|
result.push(accessorsResult);
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
|
-
else if (ts.isMethodDeclaration(member)) {
|
|
117
|
-
// Methods
|
|
118
|
-
const statements = (0, method_1.transformMethodDeclaration)(context, member, localClassName);
|
|
119
|
-
result.push(...statements);
|
|
120
|
-
}
|
|
121
125
|
else if (ts.isPropertyDeclaration(member)) {
|
|
122
126
|
// Properties
|
|
123
127
|
if ((0, utils_1.isStaticNode)(member)) {
|
|
@@ -83,7 +83,8 @@ const transformSpreadElement = (node, context) => {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
const type = context.checker.getTypeAtLocation(node.expression); // not ts-inner expression, in case of casts
|
|
86
|
-
if ((0, typescript_1.
|
|
86
|
+
if ((0, typescript_1.isAlwaysArrayType)(context, type)) {
|
|
87
|
+
// All union members must be arrays to be able to shortcut to unpack call
|
|
87
88
|
return (0, lua_ast_1.createUnpackCall)(context, innerExpression, node);
|
|
88
89
|
}
|
|
89
90
|
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Spread, node, innerExpression);
|
|
@@ -11,11 +11,17 @@ const containsBreakOrReturn = (nodes) => {
|
|
|
11
11
|
if (ts.isBreakStatement(s) || ts.isReturnStatement(s)) {
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
|
-
else if (ts.isBlock(s) && containsBreakOrReturn(s.
|
|
14
|
+
else if (ts.isBlock(s) && containsBreakOrReturn(s.statements)) {
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
|
-
else if (s.kind === ts.SyntaxKind.SyntaxList
|
|
18
|
-
|
|
17
|
+
else if (s.kind === ts.SyntaxKind.SyntaxList) {
|
|
18
|
+
// We cannot use getChildren() because that breaks when using synthetic nodes from transformers
|
|
19
|
+
// So get children the long way
|
|
20
|
+
const children = [];
|
|
21
|
+
ts.forEachChild(s, c => children.push(c));
|
|
22
|
+
if (containsBreakOrReturn(children)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
27
|
return false;
|
|
@@ -29,6 +29,7 @@ export interface Plugin {
|
|
|
29
29
|
* This function is called after translating the input program to Lua, after resolving dependencies and after bundling.
|
|
30
30
|
*/
|
|
31
31
|
beforeEmit?: (program: ts.Program, options: CompilerOptions, emitHost: EmitHost, result: EmitFile[]) => ts.Diagnostic[] | void;
|
|
32
|
+
moduleResolution?: (moduleIdentifier: string, requiringFile: string, options: CompilerOptions, emitHost: EmitHost) => string | undefined;
|
|
32
33
|
}
|
|
33
34
|
export declare function getPlugins(program: ts.Program): {
|
|
34
35
|
diagnostics: ts.Diagnostic[];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import { EmitHost, ProcessedFile } from "./utils";
|
|
3
|
+
import { Plugin } from "./plugins";
|
|
3
4
|
interface ResolutionResult {
|
|
4
5
|
resolvedFiles: ProcessedFile[];
|
|
5
6
|
diagnostics: ts.Diagnostic[];
|
|
6
7
|
}
|
|
7
|
-
export declare function resolveDependencies(program: ts.Program, files: ProcessedFile[], emitHost: EmitHost): ResolutionResult;
|
|
8
|
+
export declare function resolveDependencies(program: ts.Program, files: ProcessedFile[], emitHost: EmitHost, plugins: Plugin[]): ResolutionResult;
|
|
8
9
|
export {};
|
|
@@ -19,10 +19,11 @@ const resolver = resolve.ResolverFactory.createResolver({
|
|
|
19
19
|
symlinks: false, // Do not resolve symlinks to their original paths (that breaks node_modules detection)
|
|
20
20
|
});
|
|
21
21
|
class ResolutionContext {
|
|
22
|
-
constructor(program, options, emitHost) {
|
|
22
|
+
constructor(program, options, emitHost, plugins) {
|
|
23
23
|
this.program = program;
|
|
24
24
|
this.options = options;
|
|
25
25
|
this.emitHost = emitHost;
|
|
26
|
+
this.plugins = plugins;
|
|
26
27
|
this.diagnostics = [];
|
|
27
28
|
this.resolvedFiles = new Map();
|
|
28
29
|
this.processedDependencies = new Set();
|
|
@@ -52,6 +53,7 @@ class ResolutionContext {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
resolveImport(file, required) {
|
|
56
|
+
var _a;
|
|
55
57
|
// Do no resolve lualib - always use the lualib of the application entry point, not the lualib from external packages
|
|
56
58
|
if (required.requirePath === "lualib_bundle") {
|
|
57
59
|
this.resolvedFiles.set("lualib_bundle", { fileName: "lualib_bundle", code: "" });
|
|
@@ -63,7 +65,7 @@ class ResolutionContext {
|
|
|
63
65
|
}
|
|
64
66
|
return;
|
|
65
67
|
}
|
|
66
|
-
const dependencyPath = this.resolveDependencyPath(file, required.requirePath);
|
|
68
|
+
const dependencyPath = (_a = this.resolveDependencyPathsWithPlugins(file, required.requirePath)) !== null && _a !== void 0 ? _a : this.resolveDependencyPath(file, required.requirePath);
|
|
67
69
|
if (!dependencyPath)
|
|
68
70
|
return this.couldNotResolveImport(required, file);
|
|
69
71
|
if (this.options.tstlVerbose) {
|
|
@@ -77,6 +79,46 @@ class ResolutionContext {
|
|
|
77
79
|
replaceRequireInSourceMap(file, required, resolvedRequire, this.options.extension);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
82
|
+
resolveDependencyPathsWithPlugins(requiringFile, dependency) {
|
|
83
|
+
const requiredFromLuaFile = requiringFile.fileName.endsWith(".lua");
|
|
84
|
+
for (const plugin of this.plugins) {
|
|
85
|
+
if (plugin.moduleResolution != null) {
|
|
86
|
+
const pluginResolvedPath = plugin.moduleResolution(dependency, requiringFile.fileName, this.options, this.emitHost);
|
|
87
|
+
if (pluginResolvedPath !== undefined) {
|
|
88
|
+
// If lua file is in node_module
|
|
89
|
+
if (requiredFromLuaFile && isNodeModulesFile(requiringFile.fileName)) {
|
|
90
|
+
// If requiring file is in lua module, try to resolve sibling in that file first
|
|
91
|
+
const resolvedNodeModulesFile = this.resolveLuaDependencyPathFromNodeModules(requiringFile, pluginResolvedPath);
|
|
92
|
+
if (resolvedNodeModulesFile) {
|
|
93
|
+
if (this.options.tstlVerbose) {
|
|
94
|
+
console.log(`Resolved file path for module ${dependency} to path ${pluginResolvedPath} using plugin.`);
|
|
95
|
+
}
|
|
96
|
+
return resolvedNodeModulesFile;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const resolvedPath = this.formatPathToFile(pluginResolvedPath, requiringFile);
|
|
100
|
+
const fileFromPath = this.getFileFromPath(resolvedPath);
|
|
101
|
+
if (fileFromPath) {
|
|
102
|
+
if (this.options.tstlVerbose) {
|
|
103
|
+
console.log(`Resolved file path for module ${dependency} to path ${pluginResolvedPath} using plugin.`);
|
|
104
|
+
}
|
|
105
|
+
return fileFromPath;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
formatPathToFile(targetPath, required) {
|
|
112
|
+
var _a;
|
|
113
|
+
const isRelative = ["/", "./", "../"].some(p => targetPath.startsWith(p));
|
|
114
|
+
// // If the import is relative, always resolve it relative to the requiring file
|
|
115
|
+
// // If the import is not relative, resolve it relative to options.baseUrl if it is set
|
|
116
|
+
const fileDirectory = path.dirname(required.fileName);
|
|
117
|
+
const relativeTo = isRelative ? fileDirectory : (_a = this.options.baseUrl) !== null && _a !== void 0 ? _a : fileDirectory;
|
|
118
|
+
// // Check if file is a file in the project
|
|
119
|
+
const resolvedPath = path.join(relativeTo, targetPath);
|
|
120
|
+
return resolvedPath;
|
|
121
|
+
}
|
|
80
122
|
processDependency(dependencyPath) {
|
|
81
123
|
if (this.processedDependencies.has(dependencyPath))
|
|
82
124
|
return;
|
|
@@ -102,7 +144,6 @@ class ResolutionContext {
|
|
|
102
144
|
this.diagnostics.push((0, diagnostics_1.couldNotResolveRequire)(required.requirePath, path.relative((0, transpiler_1.getProjectRoot)(this.program), file.fileName)));
|
|
103
145
|
}
|
|
104
146
|
resolveDependencyPath(requiringFile, dependency) {
|
|
105
|
-
var _a;
|
|
106
147
|
const fileDirectory = path.dirname(requiringFile.fileName);
|
|
107
148
|
if (this.options.tstlVerbose) {
|
|
108
149
|
console.log(`Resolving "${dependency}" from ${(0, utils_1.normalizeSlashes)(requiringFile.fileName)}`);
|
|
@@ -115,13 +156,8 @@ class ResolutionContext {
|
|
|
115
156
|
if (resolvedNodeModulesFile)
|
|
116
157
|
return resolvedNodeModulesFile;
|
|
117
158
|
}
|
|
118
|
-
// Check if the import is relative
|
|
119
|
-
const isRelative = ["/", "./", "../"].some(p => dependency.startsWith(p));
|
|
120
|
-
// If the import is relative, always resolve it relative to the requiring file
|
|
121
|
-
// If the import is not relative, resolve it relative to options.baseUrl if it is set
|
|
122
|
-
const relativeTo = isRelative ? fileDirectory : (_a = this.options.baseUrl) !== null && _a !== void 0 ? _a : fileDirectory;
|
|
123
159
|
// Check if file is a file in the project
|
|
124
|
-
const resolvedPath =
|
|
160
|
+
const resolvedPath = this.formatPathToFile(dependencyPath, requiringFile);
|
|
125
161
|
const fileFromPath = this.getFileFromPath(resolvedPath);
|
|
126
162
|
if (fileFromPath)
|
|
127
163
|
return fileFromPath;
|
|
@@ -235,9 +271,9 @@ class ResolutionContext {
|
|
|
235
271
|
}
|
|
236
272
|
}
|
|
237
273
|
}
|
|
238
|
-
function resolveDependencies(program, files, emitHost) {
|
|
274
|
+
function resolveDependencies(program, files, emitHost, plugins) {
|
|
239
275
|
const options = program.getCompilerOptions();
|
|
240
|
-
const resolutionContext = new ResolutionContext(program, options, emitHost);
|
|
276
|
+
const resolutionContext = new ResolutionContext(program, options, emitHost, plugins);
|
|
241
277
|
// Resolve dependencies for all processed files
|
|
242
278
|
for (const file of files) {
|
|
243
279
|
if (options.tstlVerbose) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
+
import { Plugin } from "./plugins";
|
|
2
3
|
import { TranspileOptions } from "./transpile";
|
|
3
4
|
import { EmitFile, EmitHost, ProcessedFile } from "./utils";
|
|
4
5
|
export interface TranspilerOptions {
|
|
@@ -16,7 +17,7 @@ export declare class Transpiler {
|
|
|
16
17
|
constructor({ emitHost }?: TranspilerOptions);
|
|
17
18
|
emit(emitOptions: EmitOptions): EmitResult;
|
|
18
19
|
private emitFiles;
|
|
19
|
-
protected getEmitPlan(program: ts.Program, diagnostics: ts.Diagnostic[], files: ProcessedFile[]): {
|
|
20
|
+
protected getEmitPlan(program: ts.Program, diagnostics: ts.Diagnostic[], files: ProcessedFile[], plugins: Plugin[]): {
|
|
20
21
|
emitPlan: EmitFile[];
|
|
21
22
|
};
|
|
22
23
|
private getLuaLibBundleContent;
|
|
@@ -23,7 +23,7 @@ class Transpiler {
|
|
|
23
23
|
...emitOptions,
|
|
24
24
|
plugins,
|
|
25
25
|
});
|
|
26
|
-
const { emitPlan } = this.getEmitPlan(program, transpileDiagnostics, freshFiles);
|
|
26
|
+
const { emitPlan } = this.getEmitPlan(program, transpileDiagnostics, freshFiles, plugins);
|
|
27
27
|
const emitDiagnostics = this.emitFiles(program, plugins, emitPlan, writeFile);
|
|
28
28
|
return {
|
|
29
29
|
diagnostics: getPluginsDiagnostics.concat(transpileDiagnostics, emitDiagnostics),
|
|
@@ -60,14 +60,14 @@ class Transpiler {
|
|
|
60
60
|
performance.endSection("emit");
|
|
61
61
|
return diagnostics;
|
|
62
62
|
}
|
|
63
|
-
getEmitPlan(program, diagnostics, files) {
|
|
63
|
+
getEmitPlan(program, diagnostics, files, plugins) {
|
|
64
64
|
performance.startSection("getEmitPlan");
|
|
65
65
|
const options = program.getCompilerOptions();
|
|
66
66
|
if (options.tstlVerbose) {
|
|
67
67
|
console.log("Constructing emit plan");
|
|
68
68
|
}
|
|
69
69
|
// Resolve imported modules and modify output Lua requires
|
|
70
|
-
const resolutionResult = (0, resolve_1.resolveDependencies)(program, files, this.emitHost);
|
|
70
|
+
const resolutionResult = (0, resolve_1.resolveDependencies)(program, files, this.emitHost, plugins);
|
|
71
71
|
diagnostics.push(...resolutionResult.diagnostics);
|
|
72
72
|
const lualibRequired = resolutionResult.resolvedFiles.some(f => f.fileName === "lualib_bundle");
|
|
73
73
|
if (lualibRequired) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-to-lua",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.3",
|
|
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/",
|