typescript-to-lua 1.4.4 → 1.6.1

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.
Files changed (48) hide show
  1. package/dist/CompilerOptions.d.ts +1 -0
  2. package/dist/cli/parse.js +5 -0
  3. package/dist/lualib/Await.lua +21 -34
  4. package/dist/lualib/Map.lua +4 -6
  5. package/dist/lualib/lualib_bundle.lua +25 -40
  6. package/dist/lualib-build/plugin.d.ts +1 -1
  7. package/dist/transformation/builtins/array.d.ts +2 -3
  8. package/dist/transformation/builtins/array.js +8 -10
  9. package/dist/transformation/builtins/console.d.ts +2 -2
  10. package/dist/transformation/builtins/console.js +8 -9
  11. package/dist/transformation/builtins/function.d.ts +1 -2
  12. package/dist/transformation/builtins/function.js +5 -6
  13. package/dist/transformation/builtins/index.js +22 -23
  14. package/dist/transformation/builtins/math.d.ts +1 -2
  15. package/dist/transformation/builtins/math.js +3 -4
  16. package/dist/transformation/builtins/number.d.ts +3 -3
  17. package/dist/transformation/builtins/number.js +10 -12
  18. package/dist/transformation/builtins/object.d.ts +2 -3
  19. package/dist/transformation/builtins/object.js +16 -17
  20. package/dist/transformation/builtins/promise.d.ts +1 -2
  21. package/dist/transformation/builtins/promise.js +5 -6
  22. package/dist/transformation/builtins/string.d.ts +2 -3
  23. package/dist/transformation/builtins/string.js +7 -9
  24. package/dist/transformation/builtins/symbol.d.ts +2 -2
  25. package/dist/transformation/builtins/symbol.js +6 -7
  26. package/dist/transformation/context/context.d.ts +2 -2
  27. package/dist/transformation/context/context.js +1 -1
  28. package/dist/transformation/utils/export.d.ts +1 -1
  29. package/dist/transformation/utils/function-context.js +7 -2
  30. package/dist/transformation/utils/lua-ast.d.ts +1 -1
  31. package/dist/transformation/utils/lua-ast.js +83 -1
  32. package/dist/transformation/visitors/async-await.d.ts +1 -1
  33. package/dist/transformation/visitors/async-await.js +7 -14
  34. package/dist/transformation/visitors/binary-expression/assignments.js +9 -23
  35. package/dist/transformation/visitors/binary-expression/compound.d.ts +4 -1
  36. package/dist/transformation/visitors/binary-expression/compound.js +10 -19
  37. package/dist/transformation/visitors/call.d.ts +1 -3
  38. package/dist/transformation/visitors/call.js +31 -16
  39. package/dist/transformation/visitors/errors.js +52 -11
  40. package/dist/transformation/visitors/expression-list.js +4 -1
  41. package/dist/transformation/visitors/function.js +1 -1
  42. package/dist/transformation/visitors/return.js +5 -4
  43. package/dist/transformation/visitors/variable-declaration.d.ts +1 -1
  44. package/dist/transformation/visitors/variable-declaration.js +11 -14
  45. package/dist/transpilation/index.js +9 -4
  46. package/dist/transpilation/resolve.js +1 -1
  47. package/dist/transpilation/transpiler.js +3 -2
  48. package/package.json +9 -9
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformCallExpression = exports.transformContextualCallExpression = exports.transformCallAndArguments = exports.transformArguments = exports.validateArguments = void 0;
3
+ exports.getCalledExpression = exports.transformCallExpression = exports.transformContextualCallExpression = exports.transformCallAndArguments = exports.transformArguments = exports.validateArguments = void 0;
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../LuaAST");
6
6
  const builtins_1 = require("../builtins");
@@ -82,7 +82,7 @@ function transformContextualCallExpression(context, node, args, signature) {
82
82
  if (ts.isOptionalChain(node)) {
83
83
  return (0, optional_chaining_1.transformOptionalChain)(context, node);
84
84
  }
85
- const left = ts.isCallExpression(node) ? node.expression : node.tag;
85
+ const left = ts.isCallExpression(node) ? getCalledExpression(node) : node.tag;
86
86
  let [argPrecedingStatements, transformedArguments] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => transformArguments(context, args, signature));
87
87
  if (ts.isPropertyAccessExpression(left) &&
88
88
  ts.isIdentifier(left.name) &&
@@ -113,9 +113,9 @@ function transformContextualCallExpression(context, node, args, signature) {
113
113
  }
114
114
  }
115
115
  exports.transformContextualCallExpression = transformContextualCallExpression;
116
- function transformPropertyCall(context, node) {
116
+ function transformPropertyCall(context, node, calledMethod) {
117
117
  const signature = context.checker.getResolvedSignature(node);
118
- if (node.expression.expression.kind === ts.SyntaxKind.SuperKeyword) {
118
+ if (calledMethod.expression.kind === ts.SyntaxKind.SuperKeyword) {
119
119
  // Super calls take the format of super.call(self,...)
120
120
  const parameters = transformArguments(context, node.arguments, signature, ts.factory.createThis());
121
121
  return lua.createCallExpression(context.transformExpression(node.expression), parameters);
@@ -146,14 +146,15 @@ function transformElementCall(context, node) {
146
146
  }
147
147
  const transformCallExpression = (node, context) => {
148
148
  var _a;
149
- if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
149
+ const calledExpression = getCalledExpression(node);
150
+ if (calledExpression.kind === ts.SyntaxKind.ImportKeyword) {
150
151
  return (0, import_1.transformImportExpression)(node, context);
151
152
  }
152
153
  if (ts.isOptionalChain(node)) {
153
154
  return (0, optional_chaining_1.transformOptionalChain)(context, node);
154
155
  }
155
- const optionalContinuation = ts.isIdentifier(node.expression)
156
- ? (0, optional_chaining_1.getOptionalContinuationData)(node.expression)
156
+ const optionalContinuation = ts.isIdentifier(calledExpression)
157
+ ? (0, optional_chaining_1.getOptionalContinuationData)(calledExpression)
157
158
  : undefined;
158
159
  const wrapResultInTable = (0, multi_1.isMultiReturnCall)(context, node) && (0, multi_1.shouldMultiReturnCallBeWrapped)(context, node);
159
160
  if ((0, annotations_1.isTupleReturnCall)(context, node)) {
@@ -164,37 +165,36 @@ const transformCallExpression = (node, context) => {
164
165
  // unsupportedOptionalCall diagnostic already present
165
166
  return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(builtinOrExtensionResult) : builtinOrExtensionResult;
166
167
  }
167
- if (ts.isPropertyAccessExpression(node.expression)) {
168
- const ownerType = context.checker.getTypeAtLocation(node.expression.expression);
168
+ if (ts.isPropertyAccessExpression(calledExpression)) {
169
+ const ownerType = context.checker.getTypeAtLocation(calledExpression.expression);
169
170
  const annotations = (0, annotations_1.getTypeAnnotations)(ownerType);
170
171
  if (annotations.has(annotations_1.AnnotationKind.LuaTable)) {
171
172
  context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.LuaTable));
172
173
  }
173
- const result = transformPropertyCall(context, node);
174
+ const result = transformPropertyCall(context, node, calledExpression);
174
175
  return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(result) : result;
175
176
  }
176
- if (ts.isElementAccessExpression(node.expression)) {
177
+ if (ts.isElementAccessExpression(calledExpression)) {
177
178
  const result = transformElementCall(context, node);
178
179
  return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(result) : result;
179
180
  }
180
181
  const signature = context.checker.getResolvedSignature(node);
181
182
  // Handle super calls properly
182
- if (node.expression.kind === ts.SyntaxKind.SuperKeyword) {
183
+ if (calledExpression.kind === ts.SyntaxKind.SuperKeyword) {
183
184
  const parameters = transformArguments(context, node.arguments, signature, ts.factory.createThis());
184
185
  return lua.createCallExpression(lua.createTableIndexExpression(context.transformExpression(ts.factory.createSuper()), lua.createStringLiteral("____constructor")), parameters);
185
186
  }
186
- const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
187
187
  let callPath;
188
188
  let parameters;
189
- const isContextualCall = !signatureDeclaration || (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void;
189
+ const isContextualCall = isContextualCallExpression(context, signature);
190
190
  if (!isContextualCall) {
191
- [callPath, parameters] = transformCallAndArguments(context, node.expression, node.arguments, signature);
191
+ [callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature);
192
192
  }
193
193
  else {
194
194
  // if is optionalContinuation, context will be handled by transformOptionalChain.
195
195
  const useGlobalContext = !context.isStrict && optionalContinuation === undefined;
196
196
  const callContext = useGlobalContext ? ts.factory.createIdentifier("_G") : ts.factory.createNull();
197
- [callPath, parameters] = transformCallAndArguments(context, node.expression, node.arguments, signature, callContext);
197
+ [callPath, parameters] = transformCallAndArguments(context, calledExpression, node.arguments, signature, callContext);
198
198
  }
199
199
  const callExpression = lua.createCallExpression(callPath, parameters, node);
200
200
  if (optionalContinuation && isContextualCall) {
@@ -203,4 +203,19 @@ const transformCallExpression = (node, context) => {
203
203
  return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(callExpression) : callExpression;
204
204
  };
205
205
  exports.transformCallExpression = transformCallExpression;
206
+ function isContextualCallExpression(context, signature) {
207
+ const declaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
208
+ if (!declaration) {
209
+ return !context.options.noImplicitSelf;
210
+ }
211
+ return (0, function_context_1.getDeclarationContextType)(context, declaration) !== function_context_1.ContextType.Void;
212
+ }
213
+ function getCalledExpression(node) {
214
+ function unwrapExpression(expression) {
215
+ expression = ts.skipOuterExpressions(expression);
216
+ return ts.isNonNullExpression(expression) ? unwrapExpression(expression.expression) : expression;
217
+ }
218
+ return unwrapExpression(node.expression);
219
+ }
220
+ exports.getCalledExpression = getCalledExpression;
206
221
  //# sourceMappingURL=call.js.map
@@ -5,21 +5,58 @@ const __1 = require("../..");
5
5
  const lua = require("../../LuaAST");
6
6
  const diagnostics_1 = require("../utils/diagnostics");
7
7
  const lua_ast_1 = require("../utils/lua-ast");
8
+ const lualib_1 = require("../utils/lualib");
8
9
  const scope_1 = require("../utils/scope");
9
10
  const typescript_1 = require("../utils/typescript");
11
+ const async_await_1 = require("./async-await");
10
12
  const block_1 = require("./block");
11
13
  const identifier_1 = require("./identifier");
12
14
  const multi_1 = require("./language-extensions/multi");
13
15
  const return_1 = require("./return");
14
- const transformTryStatement = (statement, context) => {
15
- var _a;
16
- const [tryBlock, tryScope] = (0, block_1.transformScopeBlock)(context, statement.tryBlock, scope_1.ScopeType.Try);
17
- if (context.options.luaTarget === __1.LuaTarget.Lua51 &&
18
- (0, typescript_1.isInAsyncFunction)(statement) &&
19
- !context.options.lua51AllowTryCatchInAsyncAwait) {
16
+ const transformAsyncTry = (statement, context) => {
17
+ const [tryBlock] = (0, block_1.transformScopeBlock)(context, statement.tryBlock, scope_1.ScopeType.Try);
18
+ if (context.options.luaTarget === __1.LuaTarget.Lua51 && !context.options.lua51AllowTryCatchInAsyncAwait) {
20
19
  context.diagnostics.push((0, diagnostics_1.unsupportedForTargetButOverrideAvailable)(statement, "try/catch inside async functions", __1.LuaTarget.Lua51, "lua51AllowTryCatchInAsyncAwait"));
21
20
  return tryBlock.statements;
22
21
  }
22
+ // __TS__AsyncAwaiter(<catch block>)
23
+ const awaiter = (0, async_await_1.wrapInAsyncAwaiter)(context, tryBlock.statements, false);
24
+ const awaiterIdentifier = lua.createIdentifier("____try");
25
+ const awaiterDefinition = lua.createVariableDeclarationStatement(awaiterIdentifier, awaiter);
26
+ // local ____try = __TS__AsyncAwaiter(<catch block>)
27
+ const result = [awaiterDefinition];
28
+ if (statement.finallyBlock) {
29
+ const awaiterFinally = lua.createTableIndexExpression(awaiterIdentifier, lua.createStringLiteral("finally"));
30
+ const finallyFunction = lua.createFunctionExpression(lua.createBlock(context.transformStatements(statement.finallyBlock.statements)));
31
+ const finallyCall = lua.createCallExpression(awaiterFinally, [awaiterIdentifier, finallyFunction], statement.finallyBlock);
32
+ // ____try.finally(<finally function>)
33
+ result.push(lua.createExpressionStatement(finallyCall));
34
+ }
35
+ if (statement.catchClause) {
36
+ // ____try.catch(<catch function>)
37
+ const [catchFunction] = transformCatchClause(context, statement.catchClause);
38
+ if (catchFunction.params) {
39
+ catchFunction.params.unshift(lua.createAnonymousIdentifier());
40
+ }
41
+ const awaiterCatch = lua.createTableIndexExpression(awaiterIdentifier, lua.createStringLiteral("catch"));
42
+ const catchCall = lua.createCallExpression(awaiterCatch, [awaiterIdentifier, catchFunction]);
43
+ // await ____try.catch(<catch function>)
44
+ const promiseAwait = (0, lualib_1.transformLuaLibFunction)(context, __1.LuaLibFeature.Await, statement, catchCall);
45
+ result.push(lua.createExpressionStatement(promiseAwait, statement));
46
+ }
47
+ else {
48
+ // await ____try
49
+ const promiseAwait = (0, lualib_1.transformLuaLibFunction)(context, __1.LuaLibFeature.Await, statement, awaiterIdentifier);
50
+ result.push(lua.createExpressionStatement(promiseAwait, statement));
51
+ }
52
+ return result;
53
+ };
54
+ const transformTryStatement = (statement, context) => {
55
+ var _a;
56
+ if ((0, typescript_1.isInAsyncFunction)(statement)) {
57
+ return transformAsyncTry(statement, context);
58
+ }
59
+ const [tryBlock, tryScope] = (0, block_1.transformScopeBlock)(context, statement.tryBlock, scope_1.ScopeType.Try);
23
60
  if (context.options.luaTarget === __1.LuaTarget.Lua51 && (0, typescript_1.isInGeneratorFunction)(statement)) {
24
61
  context.diagnostics.push((0, diagnostics_1.unsupportedForTarget)(statement, "try/catch inside generator functions", __1.LuaTarget.Lua51));
25
62
  return tryBlock.statements;
@@ -33,11 +70,7 @@ const transformTryStatement = (statement, context) => {
33
70
  const tryCall = lua.createCallExpression(pCall, [lua.createFunctionExpression(tryBlock)]);
34
71
  if (statement.catchClause && statement.catchClause.block.statements.length > 0) {
35
72
  // try with catch
36
- const [catchBlock, catchScope] = (0, block_1.transformScopeBlock)(context, statement.catchClause.block, scope_1.ScopeType.Catch);
37
- const catchParameter = statement.catchClause.variableDeclaration
38
- ? (0, identifier_1.transformIdentifier)(context, statement.catchClause.variableDeclaration.name)
39
- : undefined;
40
- const catchFunction = lua.createFunctionExpression(catchBlock, catchParameter ? [lua.cloneIdentifier(catchParameter)] : []);
73
+ const [catchFunction, catchScope] = transformCatchClause(context, statement.catchClause);
41
74
  const catchIdentifier = lua.createIdentifier("____catch");
42
75
  result.push(lua.createVariableDeclarationStatement(catchIdentifier, catchFunction));
43
76
  const hasReturn = (_a = tryScope.functionReturned) !== null && _a !== void 0 ? _a : catchScope.functionReturned;
@@ -96,4 +129,12 @@ const transformThrowStatement = (statement, context) => {
96
129
  return lua.createExpressionStatement(lua.createCallExpression(lua.createIdentifier("error"), parameters), statement);
97
130
  };
98
131
  exports.transformThrowStatement = transformThrowStatement;
132
+ function transformCatchClause(context, catchClause) {
133
+ const [catchBlock, catchScope] = (0, block_1.transformScopeBlock)(context, catchClause.block, scope_1.ScopeType.Catch);
134
+ const catchParameter = catchClause.variableDeclaration
135
+ ? (0, identifier_1.transformIdentifier)(context, catchClause.variableDeclaration.name)
136
+ : undefined;
137
+ const catchFunction = lua.createFunctionExpression(catchBlock, catchParameter ? [lua.cloneIdentifier(catchParameter)] : []);
138
+ return [catchFunction, catchScope];
139
+ }
99
140
  //# sourceMappingURL=errors.js.map
@@ -12,7 +12,10 @@ const optional_chaining_1 = require("./optional-chaining");
12
12
  function shouldMoveToTemp(context, expression, tsOriginal) {
13
13
  return (!lua.isLiteral(expression) &&
14
14
  !(lua.isIdentifier(expression) && expression.symbolId === context_1.tempSymbolId) && // Treat generated temps as consts
15
- !(tsOriginal && ((0, typescript_1.isConstIdentifier)(context, tsOriginal) || (0, optional_chaining_1.isOptionalContinuation)(tsOriginal))));
15
+ !(tsOriginal &&
16
+ ((0, typescript_1.isConstIdentifier)(context, tsOriginal) ||
17
+ (0, optional_chaining_1.isOptionalContinuation)(tsOriginal) ||
18
+ tsOriginal.kind === ts.SyntaxKind.ThisKeyword)));
16
19
  }
17
20
  exports.shouldMoveToTemp = shouldMoveToTemp;
18
21
  // Cache an expression in a preceding statement and return the temp identifier
@@ -114,7 +114,7 @@ function transformFunctionBody(context, parameters, body, spreadIdentifier, node
114
114
  scope.node = node;
115
115
  let bodyStatements = transformFunctionBodyContent(context, body);
116
116
  if (node && (0, async_await_1.isAsyncFunction)(node)) {
117
- bodyStatements = (0, async_await_1.wrapInAsyncAwaiter)(context, bodyStatements);
117
+ bodyStatements = [lua.createReturnStatement([(0, async_await_1.wrapInAsyncAwaiter)(context, bodyStatements)])];
118
118
  }
119
119
  const headerStatements = transformFunctionBodyHeader(context, scope, parameters, spreadIdentifier);
120
120
  (0, scope_1.popScope)(context);
@@ -61,14 +61,15 @@ const transformReturnStatement = (statement, context) => {
61
61
  exports.transformReturnStatement = transformReturnStatement;
62
62
  function createReturnStatement(context, values, node) {
63
63
  const results = [...values];
64
+ if ((0, typescript_1.isInAsyncFunction)(node)) {
65
+ return lua.createReturnStatement([
66
+ lua.createCallExpression(lua.createIdentifier("____awaiter_resolve"), [lua.createNilLiteral(), ...values]),
67
+ ]);
68
+ }
64
69
  if (isInTryCatch(context)) {
65
70
  // Bubble up explicit return flag and check if we're inside a try/catch block
66
71
  results.unshift(lua.createBooleanLiteral(true));
67
72
  }
68
- else if ((0, typescript_1.isInAsyncFunction)(node)) {
69
- // Add nil error handler in async function and not in try
70
- results.unshift(lua.createNilLiteral());
71
- }
72
73
  return lua.createReturnStatement(results, node);
73
74
  }
74
75
  exports.createReturnStatement = createReturnStatement;
@@ -2,7 +2,7 @@ import * as ts from "typescript";
2
2
  import * as lua from "../../LuaAST";
3
3
  import { FunctionVisitor, TransformationContext } from "../context";
4
4
  export declare function transformArrayBindingElement(context: TransformationContext, name: ts.ArrayBindingElement): lua.Identifier;
5
- export declare function transformBindingPattern(context: TransformationContext, pattern: ts.BindingPattern, table: lua.Identifier, propertyAccessStack?: ts.PropertyName[]): lua.Statement[];
5
+ export declare function transformBindingPattern(context: TransformationContext, pattern: ts.BindingPattern, table: lua.Expression, propertyAccessStack?: ts.PropertyName[]): lua.Statement[];
6
6
  export declare function transformBindingVariableDeclaration(context: TransformationContext, bindingPattern: ts.BindingPattern, initializer?: ts.Expression): lua.Statement[];
7
7
  export declare function transformVariableDeclaration(context: TransformationContext, statement: ts.VariableDeclaration): lua.Statement[];
8
8
  export declare function checkVariableDeclarationList(context: TransformationContext, node: ts.VariableDeclarationList): void;
@@ -14,6 +14,7 @@ const function_1 = require("./function");
14
14
  const identifier_1 = require("./identifier");
15
15
  const multi_1 = require("./language-extensions/multi");
16
16
  const literal_1 = require("./literal");
17
+ const expression_list_1 = require("./expression-list");
17
18
  function transformArrayBindingElement(context, name) {
18
19
  if (ts.isOmittedExpression(name)) {
19
20
  return lua.createAnonymousIdentifier(name);
@@ -117,22 +118,18 @@ function transformBindingVariableDeclaration(context, bindingPattern, initialize
117
118
  const isComplexBindingElement = (e) => ts.isBindingElement(e) && (!ts.isIdentifier(e.name) || e.dotDotDotToken);
118
119
  if (ts.isObjectBindingPattern(bindingPattern) || bindingPattern.elements.some(isComplexBindingElement)) {
119
120
  let table;
120
- if (initializer !== undefined && ts.isIdentifier(initializer)) {
121
- table = (0, identifier_1.transformIdentifier)(context, initializer);
122
- }
123
- else {
121
+ if (initializer) {
124
122
  // Contain the expression in a temporary variable
125
- if (initializer) {
126
- table = context.createTempNameForNode(initializer);
127
- let expression = context.transformExpression(initializer);
128
- if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
129
- expression = (0, lua_ast_1.wrapInTable)(expression);
130
- }
131
- statements.push(lua.createVariableDeclarationStatement(table, expression));
132
- }
133
- else {
134
- table = lua.createAnonymousIdentifier();
123
+ let expression = context.transformExpression(initializer);
124
+ if ((0, multi_1.isMultiReturnCall)(context, initializer)) {
125
+ expression = (0, lua_ast_1.wrapInTable)(expression);
135
126
  }
127
+ const [moveStatements, movedExpr] = (0, preceding_statements_1.transformInPrecedingStatementScope)(context, () => (0, expression_list_1.moveToPrecedingTemp)(context, expression, initializer));
128
+ statements.push(...moveStatements);
129
+ table = movedExpr;
130
+ }
131
+ else {
132
+ table = lua.createAnonymousIdentifier();
136
133
  }
137
134
  statements.push(...transformBindingPattern(context, bindingPattern, table));
138
135
  return statements;
@@ -19,6 +19,7 @@ const fs = require("fs");
19
19
  const path = require("path");
20
20
  const ts = require("typescript");
21
21
  const tsconfig_1 = require("../cli/tsconfig");
22
+ const utils_1 = require("../utils");
22
23
  const output_collector_1 = require("./output-collector");
23
24
  const transpiler_1 = require("./transpiler");
24
25
  __exportStar(require("./transpile"), exports);
@@ -44,8 +45,12 @@ exports.transpileProject = transpileProject;
44
45
  const libCache = {};
45
46
  /** @internal */
46
47
  function createVirtualProgram(input, options = {}) {
48
+ const normalizedFiles = {};
49
+ for (const [path, file] of Object.entries(input)) {
50
+ normalizedFiles[(0, utils_1.normalizeSlashes)(path)] = file;
51
+ }
47
52
  const compilerHost = {
48
- fileExists: fileName => fileName in input || ts.sys.fileExists(fileName),
53
+ fileExists: fileName => fileName in normalizedFiles || ts.sys.fileExists(fileName),
49
54
  getCanonicalFileName: fileName => fileName,
50
55
  getCurrentDirectory: () => "",
51
56
  getDefaultLibFileName: ts.getDefaultLibFileName,
@@ -54,8 +59,8 @@ function createVirtualProgram(input, options = {}) {
54
59
  useCaseSensitiveFileNames: () => false,
55
60
  writeFile() { },
56
61
  getSourceFile(fileName) {
57
- if (fileName in input) {
58
- return ts.createSourceFile(fileName, input[fileName], ts.ScriptTarget.Latest, false);
62
+ if (fileName in normalizedFiles) {
63
+ return ts.createSourceFile(fileName, normalizedFiles[fileName], ts.ScriptTarget.Latest, false);
59
64
  }
60
65
  let filePath;
61
66
  if (fileName.startsWith("lib.")) {
@@ -75,7 +80,7 @@ function createVirtualProgram(input, options = {}) {
75
80
  }
76
81
  },
77
82
  };
78
- return ts.createProgram(Object.keys(input), options, compilerHost);
83
+ return ts.createProgram(Object.keys(normalizedFiles), options, compilerHost);
79
84
  }
80
85
  exports.createVirtualProgram = createVirtualProgram;
81
86
  function transpileVirtualProject(files, options = {}) {
@@ -115,7 +115,7 @@ function resolveFileDependencies(file, context) {
115
115
  const dependencies = [];
116
116
  const diagnostics = [];
117
117
  for (const required of findRequiredPaths(file.code)) {
118
- // Do no resolve lualib
118
+ // Do no resolve lualib - always use the lualib of the application entry point, not the lualib from external packages
119
119
  if (required === "lualib_bundle") {
120
120
  dependencies.push({ fileName: "lualib_bundle", code: "" });
121
121
  continue;
@@ -16,9 +16,10 @@ class Transpiler {
16
16
  }
17
17
  emit(emitOptions) {
18
18
  var _a, _b;
19
- const { program, writeFile = this.emitHost.writeFile } = emitOptions;
19
+ const { program, writeFile = this.emitHost.writeFile, plugins: optionsPlugins = [] } = emitOptions;
20
20
  const options = program.getCompilerOptions();
21
- const { diagnostics: getPluginsDiagnostics, plugins } = (0, plugins_1.getPlugins)(program);
21
+ const { diagnostics: getPluginsDiagnostics, plugins: configPlugins } = (0, plugins_1.getPlugins)(program);
22
+ const plugins = [...optionsPlugins, ...configPlugins];
22
23
  const { diagnostics, transpiledFiles: freshFiles } = (0, transpile_1.getProgramTranspileResult)(this.emitHost, writeFile, {
23
24
  ...emitOptions,
24
25
  plugins,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.4.4",
3
+ "version": "1.6.1",
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/",
@@ -43,7 +43,7 @@
43
43
  "node": ">=12.13.0"
44
44
  },
45
45
  "peerDependencies": {
46
- "typescript": "~4.6.2"
46
+ "typescript": "~4.7.3"
47
47
  },
48
48
  "dependencies": {
49
49
  "enhanced-resolve": "^5.8.2",
@@ -53,14 +53,14 @@
53
53
  "devDependencies": {
54
54
  "@types/fs-extra": "^8.1.0",
55
55
  "@types/glob": "^7.1.1",
56
- "@types/jest": "^27.4.1",
56
+ "@types/jest": "^27.5.2",
57
57
  "@types/node": "^13.7.7",
58
58
  "@types/resolve": "1.14.0",
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",
59
+ "@typescript-eslint/eslint-plugin": "^5.27.0",
60
+ "@typescript-eslint/parser": "^5.27.0",
61
+ "eslint": "^8.17.0",
62
+ "eslint-plugin-import": "^2.26.0",
63
+ "eslint-plugin-jest": "^26.4.6",
64
64
  "fs-extra": "^8.1.0",
65
65
  "javascript-stringify": "^2.0.1",
66
66
  "jest": "^27.3.0",
@@ -70,6 +70,6 @@
70
70
  "prettier": "^2.3.2",
71
71
  "ts-jest": "^27.1.3",
72
72
  "ts-node": "^10.3.0",
73
- "typescript": "~4.6.2"
73
+ "typescript": "~4.7.3"
74
74
  }
75
75
  }