typescript-to-lua 0.42.0 → 1.1.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.
- package/CHANGELOG.md +31 -1
- package/dist/CompilerOptions.d.ts +4 -3
- package/dist/LuaAST.js +4 -4
- package/dist/LuaLib.d.ts +7 -0
- package/dist/LuaLib.js +32 -1
- package/dist/LuaPrinter.d.ts +6 -2
- package/dist/LuaPrinter.js +25 -16
- package/dist/cli/diagnostics.js +2 -2
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +14 -0
- package/dist/cli/report.js +1 -1
- package/dist/cli/tsconfig.js +4 -4
- package/dist/lualib/Await.lua +59 -0
- package/dist/lualib/OptionalMethodCall.lua +3 -1
- package/dist/lualib/Promise.lua +172 -0
- package/dist/lualib/PromiseAll.lua +44 -0
- package/dist/lualib/PromiseAllSettled.lua +48 -0
- package/dist/lualib/PromiseAny.lua +41 -0
- package/dist/lualib/PromiseRace.lua +28 -0
- package/dist/lualib/SourceMapTraceBack.lua +20 -10
- package/dist/lualib/StringReplace.lua +8 -13
- package/dist/lualib/StringReplaceAll.lua +35 -0
- package/dist/lualib/lualib_bundle.lua +503 -62
- package/dist/transformation/builtins/array.js +29 -29
- package/dist/transformation/builtins/console.js +2 -2
- package/dist/transformation/builtins/function.js +9 -9
- package/dist/transformation/builtins/global.js +8 -8
- package/dist/transformation/builtins/index.js +35 -32
- package/dist/transformation/builtins/math.js +4 -4
- package/dist/transformation/builtins/number.js +7 -7
- package/dist/transformation/builtins/object.js +11 -11
- package/dist/transformation/builtins/promise.d.ts +7 -0
- package/dist/transformation/builtins/promise.js +46 -0
- package/dist/transformation/builtins/string.js +32 -30
- package/dist/transformation/builtins/symbol.js +3 -3
- package/dist/transformation/context/context.js +5 -5
- package/dist/transformation/index.js +1 -1
- package/dist/transformation/utils/annotations.d.ts +1 -4
- package/dist/transformation/utils/annotations.js +2 -39
- package/dist/transformation/utils/assignment-validation.js +8 -7
- package/dist/transformation/utils/diagnostics.d.ts +3 -0
- package/dist/transformation/utils/diagnostics.js +6 -5
- package/dist/transformation/utils/export.d.ts +3 -2
- package/dist/transformation/utils/export.js +14 -7
- package/dist/transformation/utils/function-context.js +19 -13
- package/dist/transformation/utils/lua-ast.js +18 -19
- package/dist/transformation/utils/lualib.js +1 -1
- package/dist/transformation/utils/safe-names.js +5 -5
- package/dist/transformation/utils/scope.d.ts +6 -0
- package/dist/transformation/utils/scope.js +70 -40
- package/dist/transformation/utils/symbols.js +6 -6
- package/dist/transformation/utils/transform.js +3 -3
- package/dist/transformation/utils/typescript/nodes.d.ts +2 -0
- package/dist/transformation/utils/typescript/nodes.js +21 -1
- package/dist/transformation/visitors/access.js +16 -16
- package/dist/transformation/visitors/async-await.d.ts +6 -0
- package/dist/transformation/visitors/async-await.js +38 -0
- package/dist/transformation/visitors/binary-expression/assignments.js +29 -29
- package/dist/transformation/visitors/binary-expression/bit.js +4 -4
- package/dist/transformation/visitors/binary-expression/compound.js +18 -18
- package/dist/transformation/visitors/binary-expression/destructuring-assignments.js +17 -17
- package/dist/transformation/visitors/binary-expression/index.js +21 -21
- package/dist/transformation/visitors/block.js +6 -6
- package/dist/transformation/visitors/break-continue.js +4 -9
- package/dist/transformation/visitors/call.js +38 -33
- package/dist/transformation/visitors/class/decorators.js +3 -3
- package/dist/transformation/visitors/class/index.js +41 -34
- package/dist/transformation/visitors/class/members/accessors.js +6 -6
- package/dist/transformation/visitors/class/members/constructor.js +7 -7
- package/dist/transformation/visitors/class/members/fields.js +6 -6
- package/dist/transformation/visitors/class/members/method.js +6 -6
- package/dist/transformation/visitors/class/new.js +13 -13
- package/dist/transformation/visitors/class/setup.js +11 -11
- package/dist/transformation/visitors/class/utils.js +2 -2
- package/dist/transformation/visitors/conditional.js +6 -6
- package/dist/transformation/visitors/delete.js +4 -4
- package/dist/transformation/visitors/enum.js +8 -8
- package/dist/transformation/visitors/errors.js +30 -31
- package/dist/transformation/visitors/expression-statement.js +10 -6
- package/dist/transformation/visitors/function.js +33 -21
- package/dist/transformation/visitors/identifier.js +25 -19
- package/dist/transformation/visitors/index.js +4 -2
- package/dist/transformation/visitors/language-extensions/iterable.js +7 -7
- package/dist/transformation/visitors/language-extensions/multi.d.ts +1 -1
- package/dist/transformation/visitors/language-extensions/multi.js +5 -7
- package/dist/transformation/visitors/language-extensions/operators.js +6 -6
- package/dist/transformation/visitors/language-extensions/range.js +6 -6
- package/dist/transformation/visitors/language-extensions/table.js +5 -5
- package/dist/transformation/visitors/literal.d.ts +1 -2
- package/dist/transformation/visitors/literal.js +19 -42
- package/dist/transformation/visitors/loops/do-while.js +2 -2
- package/dist/transformation/visitors/loops/for-in.js +4 -4
- package/dist/transformation/visitors/loops/for-of.js +13 -13
- package/dist/transformation/visitors/loops/for.js +3 -3
- package/dist/transformation/visitors/loops/utils.js +9 -9
- package/dist/transformation/visitors/modules/export.js +13 -14
- package/dist/transformation/visitors/modules/import.js +10 -10
- package/dist/transformation/visitors/namespace.js +13 -13
- package/dist/transformation/visitors/return.d.ts +1 -0
- package/dist/transformation/visitors/return.js +41 -49
- package/dist/transformation/visitors/sourceFile.js +8 -8
- package/dist/transformation/visitors/spread.js +16 -11
- package/dist/transformation/visitors/switch.js +132 -30
- package/dist/transformation/visitors/template.js +5 -5
- package/dist/transformation/visitors/typeof.js +2 -2
- package/dist/transformation/visitors/typescript.js +1 -1
- package/dist/transformation/visitors/unary-expression.js +9 -9
- package/dist/transformation/visitors/variable-declaration.js +28 -28
- package/dist/transformation/visitors/void.d.ts +6 -0
- package/dist/transformation/visitors/void.js +23 -0
- package/dist/transpilation/bundle.d.ts +3 -0
- package/dist/transpilation/bundle.js +56 -13
- package/dist/transpilation/diagnostics.js +3 -3
- package/dist/transpilation/index.js +2 -2
- package/dist/transpilation/output-collector.js +2 -2
- package/dist/transpilation/plugins.js +1 -1
- package/dist/transpilation/resolve.js +28 -15
- package/dist/transpilation/transformers.d.ts +1 -0
- package/dist/transpilation/transformers.js +61 -25
- package/dist/transpilation/transpile.js +7 -7
- package/dist/transpilation/transpiler.js +8 -8
- package/dist/transpilation/utils.js +3 -2
- package/dist/tstl.js +8 -8
- package/dist/utils.js +2 -2
- package/package.json +15 -12
- package/dist/transformation/visitors/jsx/jsx.d.ts +0 -9
- package/dist/transformation/visitors/jsx/jsx.js +0 -237
- package/dist/transformation/visitors/jsx/xhtml.d.ts +0 -3
- package/dist/transformation/visitors/jsx/xhtml.js +0 -260
|
@@ -46,7 +46,7 @@ function transformSpreadableExpressionsIntoArrayConcatArguments(context, express
|
|
|
46
46
|
lastChunk.push(expression);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
return chunks.map(chunk => lua_ast_1.wrapInTable(...chunk.map(expression => context.transformExpression(expression))));
|
|
49
|
+
return chunks.map(chunk => (0, lua_ast_1.wrapInTable)(...chunk.map(expression => context.transformExpression(expression))));
|
|
50
50
|
}
|
|
51
51
|
function flattenSpreadExpressions(context, expressions) {
|
|
52
52
|
const [preSpreadExpressions, postSpreadExpressions] = getExpressionsBeforeAndAfterFirstSpread(expressions);
|
|
@@ -61,7 +61,7 @@ function flattenSpreadExpressions(context, expressions) {
|
|
|
61
61
|
}
|
|
62
62
|
// Use Array.concat and unpack the result of that as the last Expression
|
|
63
63
|
const concatArguments = transformSpreadableExpressionsIntoArrayConcatArguments(context, postSpreadExpressions);
|
|
64
|
-
const lastExpression = lua_ast_1.createUnpackCall(context, lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.ArrayConcat, undefined, ...concatArguments));
|
|
64
|
+
const lastExpression = (0, lua_ast_1.createUnpackCall)(context, (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ArrayConcat, undefined, ...concatArguments));
|
|
65
65
|
return [...transformedPreSpreadExpressions, lastExpression];
|
|
66
66
|
}
|
|
67
67
|
exports.flattenSpreadExpressions = flattenSpreadExpressions;
|
|
@@ -77,7 +77,7 @@ function transformArguments(context, params, signature, callContext) {
|
|
|
77
77
|
const paramType = context.checker.getTypeAtLocation(param);
|
|
78
78
|
if (signatureParameter.valueDeclaration !== undefined) {
|
|
79
79
|
const signatureType = context.checker.getTypeAtLocation(signatureParameter.valueDeclaration);
|
|
80
|
-
assignment_validation_1.validateAssignment(context, param, paramType, signatureType, signatureParameter.name);
|
|
80
|
+
(0, assignment_validation_1.validateAssignment)(context, param, paramType, signatureType, signatureParameter.name);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -89,7 +89,7 @@ function transformElementAccessCall(context, left, args, signature) {
|
|
|
89
89
|
// Cache left-side if it has effects
|
|
90
90
|
// (function() local ____self = context; return ____self[argument](parameters); end)()
|
|
91
91
|
const argument = ts.isElementAccessExpression(left)
|
|
92
|
-
? access_1.transformElementAccessArgument(context, left)
|
|
92
|
+
? (0, access_1.transformElementAccessArgument)(context, left)
|
|
93
93
|
: lua.createStringLiteral(left.name.text);
|
|
94
94
|
const selfIdentifier = lua.createIdentifier("____self");
|
|
95
95
|
const callContext = context.transformExpression(left.expression);
|
|
@@ -100,19 +100,20 @@ function transformElementAccessCall(context, left, args, signature) {
|
|
|
100
100
|
}
|
|
101
101
|
function transformContextualCallExpression(context, node, args, signature) {
|
|
102
102
|
const left = ts.isCallExpression(node) ? node.expression : node.tag;
|
|
103
|
-
if (ts.isPropertyAccessExpression(left) && ts.isIdentifier(left.name) && safe_names_1.isValidLuaIdentifier(left.name.text)) {
|
|
103
|
+
if (ts.isPropertyAccessExpression(left) && ts.isIdentifier(left.name) && (0, safe_names_1.isValidLuaIdentifier)(left.name.text)) {
|
|
104
104
|
// table:name()
|
|
105
105
|
const table = context.transformExpression(left.expression);
|
|
106
106
|
if (ts.isOptionalChain(node)) {
|
|
107
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.OptionalMethodCall, node, table, lua.createStringLiteral(left.name.text, left.name),
|
|
107
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.OptionalMethodCall, node, table, lua.createStringLiteral(left.name.text, left.name), lua.createBooleanLiteral(node.questionDotToken !== undefined), // Require method is present if no ?.() call
|
|
108
|
+
...transformArguments(context, args, signature));
|
|
108
109
|
}
|
|
109
110
|
else {
|
|
110
111
|
return lua.createMethodCallExpression(table, lua.createIdentifier(left.name.text, left.name), transformArguments(context, args, signature), node);
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
else if (ts.isElementAccessExpression(left) || ts.isPropertyAccessExpression(left)) {
|
|
114
|
-
if (typescript_1.isExpressionWithEvaluationEffect(left.expression)) {
|
|
115
|
-
return transform_1.transformToImmediatelyInvokedFunctionExpression(context, () => transformElementAccessCall(context, left, args, signature), node);
|
|
115
|
+
if ((0, typescript_1.isExpressionWithEvaluationEffect)(left.expression)) {
|
|
116
|
+
return (0, transform_1.transformToImmediatelyInvokedFunctionExpression)(context, () => transformElementAccessCall(context, left, args, signature), node);
|
|
116
117
|
}
|
|
117
118
|
else {
|
|
118
119
|
const callContext = context.transformExpression(left.expression);
|
|
@@ -140,7 +141,7 @@ function transformPropertyCall(context, node) {
|
|
|
140
141
|
return lua.createCallExpression(context.transformExpression(node.expression), parameters);
|
|
141
142
|
}
|
|
142
143
|
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
|
|
143
|
-
if (!signatureDeclaration || function_context_1.getDeclarationContextType(context, signatureDeclaration) !== function_context_1.ContextType.Void) {
|
|
144
|
+
if (!signatureDeclaration || (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void) {
|
|
144
145
|
// table:name()
|
|
145
146
|
return transformContextualCallExpression(context, node, node.arguments, signature);
|
|
146
147
|
}
|
|
@@ -149,7 +150,7 @@ function transformPropertyCall(context, node) {
|
|
|
149
150
|
const callPath = context.transformExpression(node.expression);
|
|
150
151
|
const parameters = transformArguments(context, node.arguments, signature);
|
|
151
152
|
if (ts.isOptionalChain(node)) {
|
|
152
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.OptionalFunctionCall, node, callPath, ...parameters);
|
|
153
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.OptionalFunctionCall, node, callPath, ...parameters);
|
|
153
154
|
}
|
|
154
155
|
else {
|
|
155
156
|
return lua.createCallExpression(callPath, parameters, node);
|
|
@@ -159,7 +160,7 @@ function transformPropertyCall(context, node) {
|
|
|
159
160
|
function transformElementCall(context, node) {
|
|
160
161
|
const signature = context.checker.getResolvedSignature(node);
|
|
161
162
|
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
|
|
162
|
-
if (!signatureDeclaration || function_context_1.getDeclarationContextType(context, signatureDeclaration) !== function_context_1.ContextType.Void) {
|
|
163
|
+
if (!signatureDeclaration || (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) !== function_context_1.ContextType.Void) {
|
|
163
164
|
// A contextual parameter must be given to this call expression
|
|
164
165
|
return transformContextualCallExpression(context, node, node.arguments, signature);
|
|
165
166
|
}
|
|
@@ -171,38 +172,41 @@ function transformElementCall(context, node) {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
const transformCallExpression = (node, context) => {
|
|
174
|
-
const wrapResultInTable = multi_1.isMultiReturnCall(context, node) && multi_1.shouldMultiReturnCallBeWrapped(context, node);
|
|
175
|
+
const wrapResultInTable = (0, multi_1.isMultiReturnCall)(context, node) && (0, multi_1.shouldMultiReturnCallBeWrapped)(context, node);
|
|
175
176
|
const wrapResultInOptional = ts.isOptionalChain(node);
|
|
176
|
-
const builtinResult = builtins_1.transformBuiltinCallExpression(context, node);
|
|
177
|
+
const builtinResult = (0, builtins_1.transformBuiltinCallExpression)(context, node);
|
|
177
178
|
if (builtinResult) {
|
|
178
|
-
return wrapResultInTable ? lua_ast_1.wrapInTable(builtinResult) : builtinResult;
|
|
179
|
+
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(builtinResult) : builtinResult;
|
|
179
180
|
}
|
|
180
|
-
if (
|
|
181
|
-
|
|
181
|
+
if ((0, annotations_1.isTupleReturnCall)(context, node)) {
|
|
182
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
182
183
|
}
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
return transform_1.transformToImmediatelyInvokedFunctionExpression(context, () => ({ statements: table_1.transformTableDeleteExpression(context, node), result: lua.createNilLiteral() }), node);
|
|
184
|
+
if ((0, operators_1.isOperatorMapping)(context, node)) {
|
|
185
|
+
return (0, operators_1.transformOperatorMappingExpression)(context, node);
|
|
186
186
|
}
|
|
187
|
-
if (table_1.
|
|
188
|
-
|
|
187
|
+
if ((0, table_1.isTableDeleteCall)(context, node)) {
|
|
188
|
+
context.diagnostics.push((0, diagnostics_1.invalidTableDeleteExpression)(node));
|
|
189
|
+
return (0, transform_1.transformToImmediatelyInvokedFunctionExpression)(context, () => ({ statements: (0, table_1.transformTableDeleteExpression)(context, node), result: lua.createNilLiteral() }), node);
|
|
189
190
|
}
|
|
190
|
-
if (table_1.
|
|
191
|
-
return table_1.
|
|
191
|
+
if ((0, table_1.isTableGetCall)(context, node)) {
|
|
192
|
+
return (0, table_1.transformTableGetExpression)(context, node);
|
|
192
193
|
}
|
|
193
|
-
if (table_1.
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
if ((0, table_1.isTableHasCall)(context, node)) {
|
|
195
|
+
return (0, table_1.transformTableHasExpression)(context, node);
|
|
196
|
+
}
|
|
197
|
+
if ((0, table_1.isTableSetCall)(context, node)) {
|
|
198
|
+
context.diagnostics.push((0, diagnostics_1.invalidTableSetExpression)(node));
|
|
199
|
+
return (0, transform_1.transformToImmediatelyInvokedFunctionExpression)(context, () => ({ statements: (0, table_1.transformTableSetExpression)(context, node), result: lua.createNilLiteral() }), node);
|
|
196
200
|
}
|
|
197
201
|
if (ts.isPropertyAccessExpression(node.expression)) {
|
|
198
202
|
const ownerType = context.checker.getTypeAtLocation(node.expression.expression);
|
|
199
|
-
const annotations = annotations_1.getTypeAnnotations(ownerType);
|
|
203
|
+
const annotations = (0, annotations_1.getTypeAnnotations)(ownerType);
|
|
200
204
|
if (annotations.has(annotations_1.AnnotationKind.LuaTable)) {
|
|
201
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node, annotations_1.AnnotationKind.LuaTable));
|
|
205
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.LuaTable));
|
|
202
206
|
}
|
|
203
207
|
const result = transformPropertyCall(context, node);
|
|
204
208
|
// transformPropertyCall already wraps optional so no need to do so here
|
|
205
|
-
return wrapResultInTable ? lua_ast_1.wrapInTable(result) : result;
|
|
209
|
+
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(result) : result;
|
|
206
210
|
}
|
|
207
211
|
if (ts.isElementAccessExpression(node.expression)) {
|
|
208
212
|
const result = transformElementCall(context, node);
|
|
@@ -217,7 +221,7 @@ const transformCallExpression = (node, context) => {
|
|
|
217
221
|
const callPath = context.transformExpression(node.expression);
|
|
218
222
|
const signatureDeclaration = signature === null || signature === void 0 ? void 0 : signature.getDeclaration();
|
|
219
223
|
let parameters = [];
|
|
220
|
-
if (signatureDeclaration && function_context_1.getDeclarationContextType(context, signatureDeclaration) === function_context_1.ContextType.Void) {
|
|
224
|
+
if (signatureDeclaration && (0, function_context_1.getDeclarationContextType)(context, signatureDeclaration) === function_context_1.ContextType.Void) {
|
|
221
225
|
parameters = transformArguments(context, node.arguments, signature);
|
|
222
226
|
}
|
|
223
227
|
else {
|
|
@@ -230,14 +234,15 @@ const transformCallExpression = (node, context) => {
|
|
|
230
234
|
exports.transformCallExpression = transformCallExpression;
|
|
231
235
|
function wrapIfRequired(context, shouldWrapInTable, shouldWrapOptional, call, node) {
|
|
232
236
|
const wrappedOptional = shouldWrapOptional ? wrapOptionalCall(context, call, node) : call;
|
|
233
|
-
return shouldWrapInTable ? lua_ast_1.wrapInTable(wrappedOptional) : wrappedOptional;
|
|
237
|
+
return shouldWrapInTable ? (0, lua_ast_1.wrapInTable)(wrappedOptional) : wrappedOptional;
|
|
234
238
|
}
|
|
235
239
|
function wrapOptionalCall(context, call, node) {
|
|
236
240
|
if (lua.isMethodCallExpression(call)) {
|
|
237
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.OptionalMethodCall, node, call.prefixExpression, lua.createStringLiteral(call.name.text),
|
|
241
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.OptionalMethodCall, node, call.prefixExpression, lua.createStringLiteral(call.name.text), lua.createBooleanLiteral(node.questionDotToken !== undefined), // Require method is present if no ?.() call
|
|
242
|
+
...call.params);
|
|
238
243
|
}
|
|
239
244
|
else {
|
|
240
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.OptionalFunctionCall, node, call.expression, ...call.params);
|
|
245
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.OptionalFunctionCall, node, call.expression, ...call.params);
|
|
241
246
|
}
|
|
242
247
|
}
|
|
243
248
|
//# sourceMappingURL=call.js.map
|
|
@@ -9,9 +9,9 @@ const lualib_1 = require("../../utils/lualib");
|
|
|
9
9
|
function transformDecoratorExpression(context, decorator) {
|
|
10
10
|
const expression = decorator.expression;
|
|
11
11
|
const type = context.checker.getTypeAtLocation(expression);
|
|
12
|
-
const callContext = function_context_1.getFunctionContextType(context, type);
|
|
12
|
+
const callContext = (0, function_context_1.getFunctionContextType)(context, type);
|
|
13
13
|
if (callContext === function_context_1.ContextType.Void) {
|
|
14
|
-
context.diagnostics.push(diagnostics_1.decoratorInvalidContext(decorator));
|
|
14
|
+
context.diagnostics.push((0, diagnostics_1.decoratorInvalidContext)(decorator));
|
|
15
15
|
}
|
|
16
16
|
return context.transformExpression(expression);
|
|
17
17
|
}
|
|
@@ -26,7 +26,7 @@ function createDecoratingExpression(context, kind, decorators, targetTableName,
|
|
|
26
26
|
kind === ts.SyntaxKind.SetAccessor;
|
|
27
27
|
trailingExpressions.push(isMethodOrAccessor ? lua.createBooleanLiteral(true) : lua.createNilLiteral());
|
|
28
28
|
}
|
|
29
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.Decorate, undefined, ...trailingExpressions);
|
|
29
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Decorate, undefined, ...trailingExpressions);
|
|
30
30
|
}
|
|
31
31
|
exports.createDecoratingExpression = createDecoratingExpression;
|
|
32
32
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -21,8 +21,8 @@ const setup_1 = require("./setup");
|
|
|
21
21
|
const utils_2 = require("./utils");
|
|
22
22
|
const transformClassDeclaration = (declaration, context) => {
|
|
23
23
|
// If declaration is a default export, transform to export variable assignment instead
|
|
24
|
-
if (export_1.hasDefaultExportModifier(declaration)) {
|
|
25
|
-
const left =
|
|
24
|
+
if ((0, export_1.hasDefaultExportModifier)(declaration)) {
|
|
25
|
+
const left = (0, export_1.createDefaultExportExpression)(declaration);
|
|
26
26
|
const right = transformClassAsExpression(declaration, context);
|
|
27
27
|
return [lua.createAssignmentStatement(left, right, declaration)];
|
|
28
28
|
}
|
|
@@ -30,12 +30,12 @@ const transformClassDeclaration = (declaration, context) => {
|
|
|
30
30
|
return statements;
|
|
31
31
|
};
|
|
32
32
|
exports.transformClassDeclaration = transformClassDeclaration;
|
|
33
|
-
const transformThisExpression = node => lua_ast_1.createSelfIdentifier(node);
|
|
33
|
+
const transformThisExpression = node => (0, lua_ast_1.createSelfIdentifier)(node);
|
|
34
34
|
exports.transformThisExpression = transformThisExpression;
|
|
35
35
|
function transformClassAsExpression(expression, context) {
|
|
36
|
-
return transform_1.transformToImmediatelyInvokedFunctionExpression(context, () => {
|
|
36
|
+
return (0, transform_1.transformToImmediatelyInvokedFunctionExpression)(context, () => {
|
|
37
37
|
const { statements, name } = transformClassLikeDeclaration(expression, context);
|
|
38
|
-
return { statements: lua_ast_1.unwrapVisitorResult(statements), result: name };
|
|
38
|
+
return { statements: (0, lua_ast_1.unwrapVisitorResult)(statements), result: name };
|
|
39
39
|
}, expression);
|
|
40
40
|
}
|
|
41
41
|
exports.transformClassAsExpression = transformClassAsExpression;
|
|
@@ -46,52 +46,52 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
46
46
|
className = nameOverride;
|
|
47
47
|
}
|
|
48
48
|
else if (classDeclaration.name !== undefined) {
|
|
49
|
-
className = identifier_1.transformIdentifier(context, classDeclaration.name);
|
|
49
|
+
className = (0, identifier_1.transformIdentifier)(context, classDeclaration.name);
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
52
|
// TypeScript error
|
|
53
53
|
className = lua.createAnonymousIdentifier();
|
|
54
54
|
}
|
|
55
|
-
const annotations = annotations_1.getTypeAnnotations(context.checker.getTypeAtLocation(classDeclaration));
|
|
55
|
+
const annotations = (0, annotations_1.getTypeAnnotations)(context.checker.getTypeAtLocation(classDeclaration));
|
|
56
56
|
if (annotations.has(annotations_1.AnnotationKind.Extension)) {
|
|
57
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(classDeclaration, annotations_1.AnnotationKind.Extension));
|
|
57
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(classDeclaration, annotations_1.AnnotationKind.Extension));
|
|
58
58
|
}
|
|
59
59
|
if (annotations.has(annotations_1.AnnotationKind.MetaExtension)) {
|
|
60
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(classDeclaration, annotations_1.AnnotationKind.MetaExtension));
|
|
60
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(classDeclaration, annotations_1.AnnotationKind.MetaExtension));
|
|
61
61
|
}
|
|
62
62
|
// Get type that is extended
|
|
63
|
-
const extendedTypeNode = utils_2.getExtendedNode(context, classDeclaration);
|
|
64
|
-
const extendedType = utils_2.getExtendedType(context, classDeclaration);
|
|
65
|
-
const superInfo = utils_1.getOrUpdate(classSuperInfos, context, () => []);
|
|
63
|
+
const extendedTypeNode = (0, utils_2.getExtendedNode)(context, classDeclaration);
|
|
64
|
+
const extendedType = (0, utils_2.getExtendedType)(context, classDeclaration);
|
|
65
|
+
const superInfo = (0, utils_1.getOrUpdate)(classSuperInfos, context, () => []);
|
|
66
66
|
superInfo.push({ className, extendedTypeNode });
|
|
67
67
|
if (extendedType) {
|
|
68
|
-
new_1.checkForLuaLibType(context, extendedType);
|
|
68
|
+
(0, new_1.checkForLuaLibType)(context, extendedType);
|
|
69
69
|
}
|
|
70
70
|
// Get all properties with value
|
|
71
71
|
const properties = classDeclaration.members.filter(ts.isPropertyDeclaration).filter(member => member.initializer);
|
|
72
72
|
// Divide properties into static and non-static
|
|
73
|
-
const instanceFields = properties.filter(prop => !utils_2.isStaticNode(prop));
|
|
73
|
+
const instanceFields = properties.filter(prop => !(0, utils_2.isStaticNode)(prop));
|
|
74
74
|
const result = [];
|
|
75
75
|
let localClassName;
|
|
76
|
-
if (safe_names_1.isUnsafeName(className.text)) {
|
|
77
|
-
localClassName = lua.createIdentifier(safe_names_1.createSafeName(className.text), undefined, className.symbolId, className.text);
|
|
76
|
+
if ((0, safe_names_1.isUnsafeName)(className.text)) {
|
|
77
|
+
localClassName = lua.createIdentifier((0, safe_names_1.createSafeName)(className.text), undefined, className.symbolId, className.text);
|
|
78
78
|
lua.setNodePosition(localClassName, className);
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
81
|
localClassName = className;
|
|
82
82
|
}
|
|
83
|
-
result.push(...setup_1.createClassSetup(context, classDeclaration, className, localClassName, extendedType));
|
|
83
|
+
result.push(...(0, setup_1.createClassSetup)(context, classDeclaration, className, localClassName, extendedType));
|
|
84
84
|
// Find first constructor with body
|
|
85
85
|
const constructor = classDeclaration.members.find((n) => ts.isConstructorDeclaration(n) && n.body !== undefined);
|
|
86
86
|
if (constructor) {
|
|
87
87
|
// Add constructor plus initialization of instance fields
|
|
88
|
-
const constructorResult = constructor_1.transformConstructorDeclaration(context, constructor, localClassName, instanceFields, classDeclaration);
|
|
88
|
+
const constructorResult = (0, constructor_1.transformConstructorDeclaration)(context, constructor, localClassName, instanceFields, classDeclaration);
|
|
89
89
|
if (constructorResult)
|
|
90
90
|
result.push(constructorResult);
|
|
91
91
|
}
|
|
92
92
|
else if (!extendedType) {
|
|
93
93
|
// Generate a constructor if none was defined in a base class
|
|
94
|
-
const constructorResult = constructor_1.transformConstructorDeclaration(context, ts.factory.createConstructorDeclaration([], [], [], ts.factory.createBlock([], true)), localClassName, instanceFields, classDeclaration);
|
|
94
|
+
const constructorResult = (0, constructor_1.transformConstructorDeclaration)(context, ts.factory.createConstructorDeclaration([], [], [], ts.factory.createBlock([], true)), localClassName, instanceFields, classDeclaration);
|
|
95
95
|
if (constructorResult)
|
|
96
96
|
result.push(constructorResult);
|
|
97
97
|
}
|
|
@@ -100,11 +100,11 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
100
100
|
// localClassName.prototype.____constructor = function(self, ...)
|
|
101
101
|
// baseClassName.prototype.____constructor(self, ...)
|
|
102
102
|
// ...
|
|
103
|
-
const constructorBody = fields_1.transformClassInstanceFields(context, instanceFields);
|
|
104
|
-
const superCall = lua.createExpressionStatement(lua.createCallExpression(lua.createTableIndexExpression(context.transformExpression(ts.factory.createSuper()), lua.createStringLiteral("____constructor")), [lua_ast_1.createSelfIdentifier(), lua.createDotsLiteral()]));
|
|
103
|
+
const constructorBody = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
|
|
104
|
+
const superCall = lua.createExpressionStatement(lua.createCallExpression(lua.createTableIndexExpression(context.transformExpression(ts.factory.createSuper()), lua.createStringLiteral("____constructor")), [(0, lua_ast_1.createSelfIdentifier)(), lua.createDotsLiteral()]));
|
|
105
105
|
constructorBody.unshift(superCall);
|
|
106
|
-
const constructorFunction = lua.createFunctionExpression(lua.createBlock(constructorBody), [lua_ast_1.createSelfIdentifier()], lua.createDotsLiteral(), lua.FunctionExpressionFlags.Declaration);
|
|
107
|
-
result.push(lua.createAssignmentStatement(constructor_1.createConstructorName(localClassName), constructorFunction, classDeclaration));
|
|
106
|
+
const constructorFunction = lua.createFunctionExpression(lua.createBlock(constructorBody), [(0, lua_ast_1.createSelfIdentifier)()], lua.createDotsLiteral(), lua.FunctionExpressionFlags.Declaration);
|
|
107
|
+
result.push(lua.createAssignmentStatement((0, constructor_1.createConstructorName)(localClassName), constructorFunction, classDeclaration));
|
|
108
108
|
}
|
|
109
109
|
// Transform accessors
|
|
110
110
|
for (const member of classDeclaration.members) {
|
|
@@ -113,7 +113,7 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
113
113
|
const accessors = context.resolver.getAllAccessorDeclarations(member);
|
|
114
114
|
if (accessors.firstAccessor !== member)
|
|
115
115
|
continue;
|
|
116
|
-
const accessorsResult = accessors_1.transformAccessorDeclarations(context, accessors, localClassName);
|
|
116
|
+
const accessorsResult = (0, accessors_1.transformAccessorDeclarations)(context, accessors, localClassName);
|
|
117
117
|
if (accessorsResult) {
|
|
118
118
|
result.push(accessorsResult);
|
|
119
119
|
}
|
|
@@ -121,27 +121,27 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
121
121
|
const decorationStatements = [];
|
|
122
122
|
for (const member of classDeclaration.members) {
|
|
123
123
|
if (ts.isAccessor(member)) {
|
|
124
|
-
const expression = fields_1.createPropertyDecoratingExpression(context, member, localClassName);
|
|
124
|
+
const expression = (0, fields_1.createPropertyDecoratingExpression)(context, member, localClassName);
|
|
125
125
|
if (expression)
|
|
126
126
|
decorationStatements.push(lua.createExpressionStatement(expression));
|
|
127
127
|
}
|
|
128
128
|
else if (ts.isMethodDeclaration(member)) {
|
|
129
|
-
const statement = method_1.transformMethodDeclaration(context, member, localClassName);
|
|
129
|
+
const statement = (0, method_1.transformMethodDeclaration)(context, member, localClassName);
|
|
130
130
|
if (statement)
|
|
131
131
|
result.push(statement);
|
|
132
132
|
if (member.body) {
|
|
133
|
-
const statement = method_1.createMethodDecoratingExpression(context, member, localClassName);
|
|
133
|
+
const statement = (0, method_1.createMethodDecoratingExpression)(context, member, localClassName);
|
|
134
134
|
if (statement)
|
|
135
135
|
decorationStatements.push(statement);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
else if (ts.isPropertyDeclaration(member)) {
|
|
139
|
-
if (utils_2.isStaticNode(member)) {
|
|
140
|
-
const statement = fields_1.transformStaticPropertyDeclaration(context, member, localClassName);
|
|
139
|
+
if ((0, utils_2.isStaticNode)(member)) {
|
|
140
|
+
const statement = (0, fields_1.transformStaticPropertyDeclaration)(context, member, localClassName);
|
|
141
141
|
if (statement)
|
|
142
142
|
decorationStatements.push(statement);
|
|
143
143
|
}
|
|
144
|
-
const expression = fields_1.createPropertyDecoratingExpression(context, member, localClassName);
|
|
144
|
+
const expression = (0, fields_1.createPropertyDecoratingExpression)(context, member, localClassName);
|
|
145
145
|
if (expression)
|
|
146
146
|
decorationStatements.push(lua.createExpressionStatement(expression));
|
|
147
147
|
}
|
|
@@ -149,15 +149,22 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
149
149
|
result.push(...decorationStatements);
|
|
150
150
|
// Decorate the class
|
|
151
151
|
if (classDeclaration.decorators) {
|
|
152
|
-
const decoratingExpression = decorators_1.createDecoratingExpression(context, classDeclaration.kind, classDeclaration.decorators.map(d => decorators_1.transformDecoratorExpression(context, d)), localClassName);
|
|
152
|
+
const decoratingExpression = (0, decorators_1.createDecoratingExpression)(context, classDeclaration.kind, classDeclaration.decorators.map(d => (0, decorators_1.transformDecoratorExpression)(context, d)), localClassName);
|
|
153
153
|
const decoratingStatement = lua.createAssignmentStatement(localClassName, decoratingExpression);
|
|
154
154
|
result.push(decoratingStatement);
|
|
155
|
+
if ((0, export_1.hasExportModifier)(classDeclaration)) {
|
|
156
|
+
const exportExpression = (0, export_1.hasDefaultExportModifier)(classDeclaration)
|
|
157
|
+
? (0, export_1.createDefaultExportExpression)(classDeclaration)
|
|
158
|
+
: (0, export_1.createExportedIdentifier)(context, className);
|
|
159
|
+
const classAssignment = lua.createAssignmentStatement(exportExpression, localClassName);
|
|
160
|
+
result.push(classAssignment);
|
|
161
|
+
}
|
|
155
162
|
}
|
|
156
163
|
superInfo.pop();
|
|
157
164
|
return { statements: result, name: className };
|
|
158
165
|
}
|
|
159
166
|
const transformSuperExpression = (expression, context) => {
|
|
160
|
-
const superInfos = utils_1.getOrUpdate(classSuperInfos, context, () => []);
|
|
167
|
+
const superInfos = (0, utils_1.getOrUpdate)(classSuperInfos, context, () => []);
|
|
161
168
|
const superInfo = superInfos[superInfos.length - 1];
|
|
162
169
|
if (!superInfo)
|
|
163
170
|
return lua.createAnonymousIdentifier(expression);
|
|
@@ -167,9 +174,9 @@ const transformSuperExpression = (expression, context) => {
|
|
|
167
174
|
let baseClassName;
|
|
168
175
|
if (extendsExpression && ts.isIdentifier(extendsExpression)) {
|
|
169
176
|
const symbol = context.checker.getSymbolAtLocation(extendsExpression);
|
|
170
|
-
if (symbol && !export_1.isSymbolExported(context, symbol)) {
|
|
177
|
+
if (symbol && !(0, export_1.isSymbolExported)(context, symbol)) {
|
|
171
178
|
// Use "baseClassName" if base is a simple identifier
|
|
172
|
-
baseClassName = identifier_1.transformIdentifier(context, extendsExpression);
|
|
179
|
+
baseClassName = (0, identifier_1.transformIdentifier)(context, extendsExpression);
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
182
|
if (!baseClassName) {
|
|
@@ -9,12 +9,12 @@ const literal_1 = require("../../literal");
|
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
10
|
const constructor_1 = require("./constructor");
|
|
11
11
|
function transformAccessor(context, node) {
|
|
12
|
-
const [params, dot, restParam] = function_1.transformParameters(context, node.parameters, lua_ast_1.createSelfIdentifier());
|
|
13
|
-
const body = node.body ? function_1.transformFunctionBody(context, node.parameters, node.body, restParam)[0] : [];
|
|
12
|
+
const [params, dot, restParam] = (0, function_1.transformParameters)(context, node.parameters, (0, lua_ast_1.createSelfIdentifier)());
|
|
13
|
+
const body = node.body ? (0, function_1.transformFunctionBody)(context, node.parameters, node.body, restParam)[0] : [];
|
|
14
14
|
return lua.createFunctionExpression(lua.createBlock(body), params, dot, lua.FunctionExpressionFlags.Declaration);
|
|
15
15
|
}
|
|
16
16
|
function transformAccessorDeclarations(context, { firstAccessor, getAccessor, setAccessor }, className) {
|
|
17
|
-
const propertyName = literal_1.transformPropertyName(context, firstAccessor.name);
|
|
17
|
+
const propertyName = (0, literal_1.transformPropertyName)(context, firstAccessor.name);
|
|
18
18
|
const descriptor = lua.createTableExpression([]);
|
|
19
19
|
if (getAccessor) {
|
|
20
20
|
const getterFunction = transformAccessor(context, getAccessor);
|
|
@@ -24,13 +24,13 @@ function transformAccessorDeclarations(context, { firstAccessor, getAccessor, se
|
|
|
24
24
|
const setterFunction = transformAccessor(context, setAccessor);
|
|
25
25
|
descriptor.fields.push(lua.createTableFieldExpression(setterFunction, lua.createStringLiteral("set")));
|
|
26
26
|
}
|
|
27
|
-
const isStatic = utils_1.isStaticNode(firstAccessor);
|
|
28
|
-
const target = isStatic ? lua.cloneIdentifier(className) : constructor_1.createPrototypeName(className);
|
|
27
|
+
const isStatic = (0, utils_1.isStaticNode)(firstAccessor);
|
|
28
|
+
const target = isStatic ? lua.cloneIdentifier(className) : (0, constructor_1.createPrototypeName)(className);
|
|
29
29
|
const feature = isStatic ? lualib_1.LuaLibFeature.ObjectDefineProperty : lualib_1.LuaLibFeature.SetDescriptor;
|
|
30
30
|
const parameters = [target, propertyName, descriptor];
|
|
31
31
|
if (!isStatic)
|
|
32
32
|
parameters.push(lua.createBooleanLiteral(true));
|
|
33
|
-
const call = lualib_1.transformLuaLibFunction(context, feature, undefined, ...parameters);
|
|
33
|
+
const call = (0, lualib_1.transformLuaLibFunction)(context, feature, undefined, ...parameters);
|
|
34
34
|
return lua.createExpressionStatement(call);
|
|
35
35
|
}
|
|
36
36
|
exports.transformAccessorDeclarations = transformAccessorDeclarations;
|
|
@@ -22,14 +22,14 @@ function transformConstructorDeclaration(context, statement, className, instance
|
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
24
|
// Transform body
|
|
25
|
-
const scope = scope_1.pushScope(context, scope_1.ScopeType.Function);
|
|
26
|
-
const body = function_1.transformFunctionBodyContent(context, statement.body);
|
|
27
|
-
const [params, dotsLiteral, restParamName] = function_1.transformParameters(context, statement.parameters, lua_ast_1.createSelfIdentifier());
|
|
25
|
+
const scope = (0, scope_1.pushScope)(context, scope_1.ScopeType.Function);
|
|
26
|
+
const body = (0, function_1.transformFunctionBodyContent)(context, statement.body);
|
|
27
|
+
const [params, dotsLiteral, restParamName] = (0, function_1.transformParameters)(context, statement.parameters, (0, lua_ast_1.createSelfIdentifier)());
|
|
28
28
|
// Make sure default parameters are assigned before fields are initialized
|
|
29
|
-
const bodyWithFieldInitializers = function_1.transformFunctionBodyHeader(context, scope, statement.parameters, restParamName);
|
|
29
|
+
const bodyWithFieldInitializers = (0, function_1.transformFunctionBodyHeader)(context, scope, statement.parameters, restParamName);
|
|
30
30
|
// Check for field declarations in constructor
|
|
31
31
|
const constructorFieldsDeclarations = statement.parameters.filter(p => p.modifiers !== undefined);
|
|
32
|
-
const classInstanceFields = fields_1.transformClassInstanceFields(context, instanceFields);
|
|
32
|
+
const classInstanceFields = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
|
|
33
33
|
// If there are field initializers and the first statement is a super call,
|
|
34
34
|
// move super call between default assignments and initializers
|
|
35
35
|
if ((constructorFieldsDeclarations.length > 0 || classInstanceFields.length > 0) &&
|
|
@@ -49,7 +49,7 @@ function transformConstructorDeclaration(context, statement, className, instance
|
|
|
49
49
|
for (const declaration of constructorFieldsDeclarations) {
|
|
50
50
|
if (ts.isIdentifier(declaration.name)) {
|
|
51
51
|
// self.declarationName = declarationName
|
|
52
|
-
const assignment = lua.createAssignmentStatement(lua.createTableIndexExpression(lua_ast_1.createSelfIdentifier(), lua.createStringLiteral(declaration.name.text)), identifier_1.transformIdentifier(context, declaration.name));
|
|
52
|
+
const assignment = lua.createAssignmentStatement(lua.createTableIndexExpression((0, lua_ast_1.createSelfIdentifier)(), lua.createStringLiteral(declaration.name.text)), (0, identifier_1.transformIdentifier)(context, declaration.name));
|
|
53
53
|
bodyWithFieldInitializers.push(assignment);
|
|
54
54
|
}
|
|
55
55
|
// else { TypeScript error: A parameter property may not be declared using a binding pattern }
|
|
@@ -58,7 +58,7 @@ function transformConstructorDeclaration(context, statement, className, instance
|
|
|
58
58
|
bodyWithFieldInitializers.push(...body);
|
|
59
59
|
const block = lua.createBlock(bodyWithFieldInitializers);
|
|
60
60
|
const constructorWasGenerated = statement.pos === -1;
|
|
61
|
-
scope_1.popScope(context);
|
|
61
|
+
(0, scope_1.popScope)(context);
|
|
62
62
|
return lua.createAssignmentStatement(createConstructorName(className), lua.createFunctionExpression(block, params, dotsLiteral, lua.FunctionExpressionFlags.Declaration), constructorWasGenerated ? classDeclaration : statement);
|
|
63
63
|
}
|
|
64
64
|
exports.transformConstructorDeclaration = transformConstructorDeclaration;
|
|
@@ -9,19 +9,19 @@ const method_1 = require("./method");
|
|
|
9
9
|
function createPropertyDecoratingExpression(context, node, className) {
|
|
10
10
|
if (!node.decorators)
|
|
11
11
|
return;
|
|
12
|
-
const propertyName = literal_1.transformPropertyName(context, node.name);
|
|
13
|
-
const propertyOwnerTable = method_1.transformMemberExpressionOwnerName(node, className);
|
|
14
|
-
return decorators_1.createDecoratingExpression(context, node.kind, node.decorators.map(d => decorators_1.transformDecoratorExpression(context, d)), propertyOwnerTable, propertyName);
|
|
12
|
+
const propertyName = (0, literal_1.transformPropertyName)(context, node.name);
|
|
13
|
+
const propertyOwnerTable = (0, method_1.transformMemberExpressionOwnerName)(node, className);
|
|
14
|
+
return (0, decorators_1.createDecoratingExpression)(context, node.kind, node.decorators.map(d => (0, decorators_1.transformDecoratorExpression)(context, d)), propertyOwnerTable, propertyName);
|
|
15
15
|
}
|
|
16
16
|
exports.createPropertyDecoratingExpression = createPropertyDecoratingExpression;
|
|
17
17
|
function transformClassInstanceFields(context, instanceFields) {
|
|
18
18
|
const statements = [];
|
|
19
19
|
for (const f of instanceFields) {
|
|
20
20
|
// Get identifier
|
|
21
|
-
const fieldName = literal_1.transformPropertyName(context, f.name);
|
|
21
|
+
const fieldName = (0, literal_1.transformPropertyName)(context, f.name);
|
|
22
22
|
const value = f.initializer ? context.transformExpression(f.initializer) : undefined;
|
|
23
23
|
// self[fieldName]
|
|
24
|
-
const selfIndex = lua.createTableIndexExpression(lua_ast_1.createSelfIdentifier(), fieldName);
|
|
24
|
+
const selfIndex = lua.createTableIndexExpression((0, lua_ast_1.createSelfIdentifier)(), fieldName);
|
|
25
25
|
// self[fieldName] = value
|
|
26
26
|
const assignClassField = lua.createAssignmentStatement(selfIndex, value, f);
|
|
27
27
|
statements.push(assignClassField);
|
|
@@ -32,7 +32,7 @@ exports.transformClassInstanceFields = transformClassInstanceFields;
|
|
|
32
32
|
function transformStaticPropertyDeclaration(context, field, className) {
|
|
33
33
|
if (!field.initializer)
|
|
34
34
|
return;
|
|
35
|
-
const fieldName = literal_1.transformPropertyName(context, field.name);
|
|
35
|
+
const fieldName = (0, literal_1.transformPropertyName)(context, field.name);
|
|
36
36
|
const value = context.transformExpression(field.initializer);
|
|
37
37
|
const classField = lua.createTableIndexExpression(lua.cloneIdentifier(className), fieldName);
|
|
38
38
|
return lua.createAssignmentStatement(classField, value);
|
|
@@ -10,11 +10,11 @@ const constructor_1 = require("./constructor");
|
|
|
10
10
|
const lualib_1 = require("../../../utils/lualib");
|
|
11
11
|
const utils_2 = require("../../../../utils");
|
|
12
12
|
function transformMemberExpressionOwnerName(node, className) {
|
|
13
|
-
return utils_1.isStaticNode(node) ? lua.cloneIdentifier(className) : constructor_1.createPrototypeName(className);
|
|
13
|
+
return (0, utils_1.isStaticNode)(node) ? lua.cloneIdentifier(className) : (0, constructor_1.createPrototypeName)(className);
|
|
14
14
|
}
|
|
15
15
|
exports.transformMemberExpressionOwnerName = transformMemberExpressionOwnerName;
|
|
16
16
|
function transformMethodName(context, node) {
|
|
17
|
-
const methodName = literal_1.transformPropertyName(context, node.name);
|
|
17
|
+
const methodName = (0, literal_1.transformPropertyName)(context, node.name);
|
|
18
18
|
if (lua.isStringLiteral(methodName) && methodName.value === "toString") {
|
|
19
19
|
return lua.createStringLiteral("__tostring", node.name);
|
|
20
20
|
}
|
|
@@ -27,7 +27,7 @@ function transformMethodDeclaration(context, node, className) {
|
|
|
27
27
|
return;
|
|
28
28
|
const methodTable = transformMemberExpressionOwnerName(node, className);
|
|
29
29
|
const methodName = transformMethodName(context, node);
|
|
30
|
-
const [functionExpression] = function_1.transformFunctionToExpression(context, node);
|
|
30
|
+
const [functionExpression] = (0, function_1.transformFunctionToExpression)(context, node);
|
|
31
31
|
return lua.createAssignmentStatement(lua.createTableIndexExpression(methodTable, methodName), functionExpression, node);
|
|
32
32
|
}
|
|
33
33
|
exports.transformMethodDeclaration = transformMethodDeclaration;
|
|
@@ -38,12 +38,12 @@ function createMethodDecoratingExpression(context, node, className) {
|
|
|
38
38
|
const parameterDecorators = node.parameters
|
|
39
39
|
.flatMap((parameter, index) => {
|
|
40
40
|
var _a;
|
|
41
|
-
return (_a = parameter.decorators) === null || _a === void 0 ? void 0 : _a.map(decorator => lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.DecorateParam, node, lua.createNumericLiteral(index), decorators_1.transformDecoratorExpression(context, decorator)));
|
|
41
|
+
return (_a = parameter.decorators) === null || _a === void 0 ? void 0 : _a.map(decorator => (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DecorateParam, node, lua.createNumericLiteral(index), (0, decorators_1.transformDecoratorExpression)(context, decorator)));
|
|
42
42
|
})
|
|
43
43
|
.filter(utils_2.isNonNull);
|
|
44
|
-
const methodDecorators = (_b = (_a = node.decorators) === null || _a === void 0 ? void 0 : _a.map(d => decorators_1.transformDecoratorExpression(context, d))) !== null && _b !== void 0 ? _b : [];
|
|
44
|
+
const methodDecorators = (_b = (_a = node.decorators) === null || _a === void 0 ? void 0 : _a.map(d => (0, decorators_1.transformDecoratorExpression)(context, d))) !== null && _b !== void 0 ? _b : [];
|
|
45
45
|
if (methodDecorators.length > 0 || parameterDecorators.length > 0) {
|
|
46
|
-
const decorateMethod = decorators_1.createDecoratingExpression(context, node.kind, [...methodDecorators, ...parameterDecorators], methodTable, methodName);
|
|
46
|
+
const decorateMethod = (0, decorators_1.createDecoratingExpression)(context, node.kind, [...methodDecorators, ...parameterDecorators], methodTable, methodName);
|
|
47
47
|
return lua.createExpressionStatement(decorateMethod);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -28,49 +28,49 @@ function checkForLuaLibType(context, type) {
|
|
|
28
28
|
const name = context.checker.getFullyQualifiedName(type.symbol);
|
|
29
29
|
switch (name) {
|
|
30
30
|
case "Map":
|
|
31
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.Map);
|
|
31
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Map);
|
|
32
32
|
return;
|
|
33
33
|
case "Set":
|
|
34
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.Set);
|
|
34
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Set);
|
|
35
35
|
return;
|
|
36
36
|
case "WeakMap":
|
|
37
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.WeakMap);
|
|
37
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.WeakMap);
|
|
38
38
|
return;
|
|
39
39
|
case "WeakSet":
|
|
40
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.WeakSet);
|
|
40
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.WeakSet);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
if (builtinErrorTypeNames.has(name)) {
|
|
44
|
-
lualib_1.importLuaLibFeature(context, lualib_1.LuaLibFeature.Error);
|
|
44
|
+
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Error);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
exports.checkForLuaLibType = checkForLuaLibType;
|
|
48
48
|
const transformNewExpression = (node, context) => {
|
|
49
49
|
var _a;
|
|
50
50
|
const type = context.checker.getTypeAtLocation(node);
|
|
51
|
-
const annotations = annotations_1.getTypeAnnotations(type);
|
|
51
|
+
const annotations = (0, annotations_1.getTypeAnnotations)(type);
|
|
52
52
|
if (annotations.has(annotations_1.AnnotationKind.LuaTable)) {
|
|
53
|
-
context.diagnostics.push(diagnostics_1.annotationRemoved(node, annotations_1.AnnotationKind.LuaTable));
|
|
53
|
+
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.LuaTable));
|
|
54
54
|
}
|
|
55
|
-
if (table_1.isTableNewCall(context, node)) {
|
|
55
|
+
if ((0, table_1.isTableNewCall)(context, node)) {
|
|
56
56
|
return lua.createTableExpression(undefined, node);
|
|
57
57
|
}
|
|
58
|
-
const name = context.transformExpression(node.expression);
|
|
59
58
|
const signature = context.checker.getResolvedSignature(node);
|
|
60
59
|
const params = node.arguments
|
|
61
|
-
? call_1.transformArguments(context, node.arguments, signature)
|
|
60
|
+
? (0, call_1.transformArguments)(context, node.arguments, signature)
|
|
62
61
|
: [lua.createBooleanLiteral(true)];
|
|
63
62
|
checkForLuaLibType(context, type);
|
|
63
|
+
const name = context.transformExpression(node.expression);
|
|
64
64
|
const customConstructorAnnotation = annotations.get(annotations_1.AnnotationKind.CustomConstructor);
|
|
65
65
|
if (customConstructorAnnotation) {
|
|
66
66
|
if (customConstructorAnnotation.args.length === 1) {
|
|
67
|
-
return lua.createCallExpression(lua.createIdentifier(customConstructorAnnotation.args[0]), call_1.transformArguments(context, (_a = node.arguments) !== null && _a !== void 0 ? _a : []), node);
|
|
67
|
+
return lua.createCallExpression(lua.createIdentifier(customConstructorAnnotation.args[0]), (0, call_1.transformArguments)(context, (_a = node.arguments) !== null && _a !== void 0 ? _a : []), node);
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
|
-
context.diagnostics.push(diagnostics_1.annotationInvalidArgumentCount(node, annotations_1.AnnotationKind.CustomConstructor, customConstructorAnnotation.args.length, 1));
|
|
70
|
+
context.diagnostics.push((0, diagnostics_1.annotationInvalidArgumentCount)(node, annotations_1.AnnotationKind.CustomConstructor, customConstructorAnnotation.args.length, 1));
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
return lualib_1.transformLuaLibFunction(context, lualib_1.LuaLibFeature.New, node, name, ...params);
|
|
73
|
+
return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.New, node, name, ...params);
|
|
74
74
|
};
|
|
75
75
|
exports.transformNewExpression = transformNewExpression;
|
|
76
76
|
//# sourceMappingURL=new.js.map
|