typescript-to-lua 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CompilerOptions.d.ts +1 -0
- package/dist/LuaPrinter.js +1 -0
- package/dist/cli/diagnostics.d.ts +3 -0
- package/dist/cli/diagnostics.js +2 -1
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +47 -11
- package/dist/lualib/ArraySlice.lua +10 -2
- package/dist/lualib/ArraySplice.lua +5 -1
- package/dist/lualib/Generator.lua +8 -1
- package/dist/lualib/ParseFloat.lua +5 -1
- package/dist/lualib/Promise.lua +6 -3
- package/dist/lualib/SparseArraySpread.lua +5 -1
- package/dist/lualib/StringCharCodeAt.lua +5 -1
- package/dist/lualib/lualib_bundle.lua +44 -10
- package/dist/lualib-build/plugin.js +1 -2
- package/dist/measure-performance.d.ts +15 -0
- package/dist/measure-performance.js +83 -0
- package/dist/transformation/builtins/array.js +2 -1
- package/dist/transformation/builtins/function.js +1 -1
- package/dist/transformation/builtins/global.d.ts +1 -1
- package/dist/transformation/builtins/global.js +13 -12
- package/dist/transformation/builtins/index.d.ts +2 -2
- package/dist/transformation/builtins/index.js +87 -89
- package/dist/transformation/builtins/object.d.ts +1 -1
- package/dist/transformation/builtins/object.js +4 -4
- package/dist/transformation/builtins/promise.js +4 -2
- package/dist/transformation/builtins/string.js +2 -0
- package/dist/transformation/context/context.d.ts +15 -0
- package/dist/transformation/context/context.js +66 -24
- package/dist/transformation/context/visitors.d.ts +1 -1
- package/dist/transformation/index.js +6 -5
- package/dist/transformation/utils/annotations.d.ts +1 -17
- package/dist/transformation/utils/annotations.js +48 -88
- package/dist/transformation/utils/assignment-validation.js +27 -23
- package/dist/transformation/utils/diagnostics.d.ts +1 -4
- package/dist/transformation/utils/diagnostics.js +2 -3
- package/dist/transformation/utils/function-context.d.ts +1 -1
- package/dist/transformation/utils/function-context.js +57 -51
- package/dist/transformation/utils/language-extensions.d.ts +57 -51
- package/dist/transformation/utils/language-extensions.js +99 -119
- package/dist/transformation/utils/lualib.d.ts +0 -1
- package/dist/transformation/utils/lualib.js +2 -8
- package/dist/transformation/utils/safe-names.d.ts +1 -1
- package/dist/transformation/utils/safe-names.js +3 -6
- package/dist/transformation/utils/scope.d.ts +0 -2
- package/dist/transformation/utils/scope.js +10 -27
- package/dist/transformation/utils/symbols.d.ts +1 -1
- package/dist/transformation/utils/symbols.js +7 -20
- package/dist/transformation/utils/typescript/index.d.ts +1 -0
- package/dist/transformation/utils/typescript/index.js +2 -1
- package/dist/transformation/utils/typescript/types.d.ts +2 -5
- package/dist/transformation/utils/typescript/types.js +27 -37
- package/dist/transformation/visitors/access.js +1 -4
- package/dist/transformation/visitors/block.js +4 -4
- package/dist/transformation/visitors/call.js +7 -18
- package/dist/transformation/visitors/class/index.js +8 -20
- package/dist/transformation/visitors/class/members/constructor.js +2 -2
- package/dist/transformation/visitors/class/new.js +2 -5
- package/dist/transformation/visitors/class/setup.d.ts +1 -1
- package/dist/transformation/visitors/class/setup.js +4 -4
- package/dist/transformation/visitors/class/utils.d.ts +1 -1
- package/dist/transformation/visitors/class/utils.js +2 -9
- package/dist/transformation/visitors/conditional.js +4 -4
- package/dist/transformation/visitors/function.d.ts +1 -1
- package/dist/transformation/visitors/function.js +8 -16
- package/dist/transformation/visitors/identifier.d.ts +1 -0
- package/dist/transformation/visitors/identifier.js +40 -44
- package/dist/transformation/visitors/language-extensions/call-extension.d.ts +10 -0
- package/dist/transformation/visitors/language-extensions/call-extension.js +23 -0
- package/dist/transformation/visitors/language-extensions/identifier.d.ts +5 -0
- package/dist/transformation/visitors/language-extensions/identifier.js +27 -0
- package/dist/transformation/visitors/language-extensions/iterable.d.ts +2 -3
- package/dist/transformation/visitors/language-extensions/iterable.js +21 -22
- package/dist/transformation/visitors/language-extensions/multi.d.ts +0 -1
- package/dist/transformation/visitors/language-extensions/multi.js +10 -24
- package/dist/transformation/visitors/language-extensions/operators.d.ts +2 -5
- package/dist/transformation/visitors/language-extensions/operators.js +89 -96
- package/dist/transformation/visitors/language-extensions/range.js +4 -2
- package/dist/transformation/visitors/language-extensions/table.d.ts +6 -3
- package/dist/transformation/visitors/language-extensions/table.js +46 -75
- package/dist/transformation/visitors/language-extensions/vararg.js +7 -3
- package/dist/transformation/visitors/literal.js +2 -23
- package/dist/transformation/visitors/loops/for-of.js +18 -18
- package/dist/transformation/visitors/loops/utils.js +5 -5
- package/dist/transformation/visitors/namespace.js +5 -14
- package/dist/transformation/visitors/return.js +2 -3
- package/dist/transformation/visitors/sourceFile.js +3 -4
- package/dist/transformation/visitors/spread.js +0 -5
- package/dist/transformation/visitors/switch.js +2 -2
- package/dist/transformation/visitors/variable-declaration.js +1 -1
- package/dist/transpilation/index.js +4 -8
- package/dist/transpilation/plugins.js +3 -0
- package/dist/transpilation/resolve.js +144 -161
- package/dist/transpilation/transpile.js +10 -0
- package/dist/transpilation/transpiler.d.ts +1 -0
- package/dist/transpilation/transpiler.js +18 -5
- package/dist/tstl.js +23 -4
- package/language-extensions/index.d.ts +156 -67
- package/package.json +2 -2
- package/dist/transformation/visitors/language-extensions/index.d.ts +0 -4
- package/dist/transformation/visitors/language-extensions/index.js +0 -17
- package/dist/transformation/visitors/language-extensions/pairsIterable.d.ts +0 -5
- package/dist/transformation/visitors/language-extensions/pairsIterable.js +0 -53
|
@@ -76,10 +76,6 @@ function transformPropertyAccessExpressionWithCapture(context, node, thisValueCa
|
|
|
76
76
|
const property = node.name.text;
|
|
77
77
|
const type = context.checker.getTypeAtLocation(node.expression);
|
|
78
78
|
const isOptionalLeft = (0, optional_chaining_1.isOptionalContinuation)(node.expression);
|
|
79
|
-
const annotations = (0, annotations_1.getTypeAnnotations)(type);
|
|
80
|
-
if (annotations.has(annotations_1.AnnotationKind.LuaTable)) {
|
|
81
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.LuaTable));
|
|
82
|
-
}
|
|
83
79
|
const constEnumValue = (0, enum_1.tryGetConstEnumValue)(context, node);
|
|
84
80
|
if (constEnumValue) {
|
|
85
81
|
return { expression: constEnumValue };
|
|
@@ -91,6 +87,7 @@ function transformPropertyAccessExpressionWithCapture(context, node, thisValueCa
|
|
|
91
87
|
return (0, optional_chaining_1.transformOptionalChainWithCapture)(context, node, thisValueCapture);
|
|
92
88
|
}
|
|
93
89
|
// Do not output path for member only enums
|
|
90
|
+
const annotations = (0, annotations_1.getTypeAnnotations)(type);
|
|
94
91
|
if (annotations.has(annotations_1.AnnotationKind.CompileMembersOnly)) {
|
|
95
92
|
if (isOptionalLeft) {
|
|
96
93
|
context.diagnostics.push((0, diagnostics_1.unsupportedOptionalCompileMembersOnly)(node));
|
|
@@ -9,16 +9,16 @@ function transformBlockOrStatement(context, statement) {
|
|
|
9
9
|
}
|
|
10
10
|
exports.transformBlockOrStatement = transformBlockOrStatement;
|
|
11
11
|
function transformScopeBlock(context, node, scopeType) {
|
|
12
|
-
|
|
12
|
+
context.pushScope(scopeType);
|
|
13
13
|
const statements = (0, scope_1.performHoisting)(context, context.transformStatements(node.statements));
|
|
14
|
-
const scope =
|
|
14
|
+
const scope = context.popScope();
|
|
15
15
|
return [lua.createBlock(statements, node), scope];
|
|
16
16
|
}
|
|
17
17
|
exports.transformScopeBlock = transformScopeBlock;
|
|
18
18
|
const transformBlock = (node, context) => {
|
|
19
|
-
|
|
19
|
+
context.pushScope(scope_1.ScopeType.Block);
|
|
20
20
|
const statements = (0, scope_1.performHoisting)(context, context.transformStatements(node.statements));
|
|
21
|
-
|
|
21
|
+
context.popScope();
|
|
22
22
|
return lua.createDoStatement(statements, node);
|
|
23
23
|
};
|
|
24
24
|
exports.transformBlock = transformBlock;
|
|
@@ -4,7 +4,6 @@ exports.getCalledExpression = exports.transformCallExpression = exports.transfor
|
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const builtins_1 = require("../builtins");
|
|
7
|
-
const annotations_1 = require("../utils/annotations");
|
|
8
7
|
const assignment_validation_1 = require("../utils/assignment-validation");
|
|
9
8
|
const function_context_1 = require("../utils/function-context");
|
|
10
9
|
const lua_ast_1 = require("../utils/lua-ast");
|
|
@@ -16,17 +15,17 @@ const diagnostics_1 = require("../utils/diagnostics");
|
|
|
16
15
|
const expression_list_1 = require("./expression-list");
|
|
17
16
|
const preceding_statements_1 = require("../utils/preceding-statements");
|
|
18
17
|
const optional_chaining_1 = require("./optional-chaining");
|
|
19
|
-
const language_extensions_1 = require("./language-extensions");
|
|
20
18
|
const import_1 = require("./modules/import");
|
|
19
|
+
const call_extension_1 = require("./language-extensions/call-extension");
|
|
21
20
|
function validateArguments(context, params, signature) {
|
|
22
21
|
if (!signature || signature.parameters.length < params.length) {
|
|
23
22
|
return;
|
|
24
23
|
}
|
|
25
24
|
for (const [index, param] of params.entries()) {
|
|
26
25
|
const signatureParameter = signature.parameters[index];
|
|
27
|
-
const paramType = context.checker.getTypeAtLocation(param);
|
|
28
26
|
if (signatureParameter.valueDeclaration !== undefined) {
|
|
29
27
|
const signatureType = context.checker.getTypeAtLocation(signatureParameter.valueDeclaration);
|
|
28
|
+
const paramType = context.checker.getTypeAtLocation(param);
|
|
30
29
|
(0, assignment_validation_1.validateAssignment)(context, param, paramType, signatureType, signatureParameter.name);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
@@ -157,20 +156,14 @@ const transformCallExpression = (node, context) => {
|
|
|
157
156
|
? (0, optional_chaining_1.getOptionalContinuationData)(calledExpression)
|
|
158
157
|
: undefined;
|
|
159
158
|
const wrapResultInTable = (0, multi_1.isMultiReturnCall)(context, node) && (0, multi_1.shouldMultiReturnCallBeWrapped)(context, node);
|
|
160
|
-
|
|
161
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
162
|
-
}
|
|
163
|
-
const builtinOrExtensionResult = (_a = (0, builtins_1.transformBuiltinCallExpression)(context, node, optionalContinuation !== undefined)) !== null && _a !== void 0 ? _a : (0, language_extensions_1.transformLanguageExtensionCallExpression)(context, node, optionalContinuation !== undefined);
|
|
159
|
+
const builtinOrExtensionResult = (_a = (0, builtins_1.transformBuiltinCallExpression)(context, node)) !== null && _a !== void 0 ? _a : (0, call_extension_1.transformLanguageExtensionCallExpression)(context, node);
|
|
164
160
|
if (builtinOrExtensionResult) {
|
|
165
|
-
|
|
161
|
+
if (optionalContinuation !== undefined) {
|
|
162
|
+
context.diagnostics.push((0, diagnostics_1.unsupportedBuiltinOptionalCall)(node));
|
|
163
|
+
}
|
|
166
164
|
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(builtinOrExtensionResult) : builtinOrExtensionResult;
|
|
167
165
|
}
|
|
168
166
|
if (ts.isPropertyAccessExpression(calledExpression)) {
|
|
169
|
-
const ownerType = context.checker.getTypeAtLocation(calledExpression.expression);
|
|
170
|
-
const annotations = (0, annotations_1.getTypeAnnotations)(ownerType);
|
|
171
|
-
if (annotations.has(annotations_1.AnnotationKind.LuaTable)) {
|
|
172
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.LuaTable));
|
|
173
|
-
}
|
|
174
167
|
const result = transformPropertyCall(context, node, calledExpression);
|
|
175
168
|
return wrapResultInTable ? (0, lua_ast_1.wrapInTable)(result) : result;
|
|
176
169
|
}
|
|
@@ -211,11 +204,7 @@ function isContextualCallExpression(context, signature) {
|
|
|
211
204
|
return (0, function_context_1.getDeclarationContextType)(context, declaration) !== function_context_1.ContextType.Void;
|
|
212
205
|
}
|
|
213
206
|
function getCalledExpression(node) {
|
|
214
|
-
|
|
215
|
-
expression = ts.skipOuterExpressions(expression);
|
|
216
|
-
return ts.isNonNullExpression(expression) ? unwrapExpression(expression.expression) : expression;
|
|
217
|
-
}
|
|
218
|
-
return unwrapExpression(node.expression);
|
|
207
|
+
return ts.skipOuterExpressions(node.expression);
|
|
219
208
|
}
|
|
220
209
|
exports.getCalledExpression = getCalledExpression;
|
|
221
210
|
//# sourceMappingURL=call.js.map
|
|
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformSuperExpression = exports.transformClassAsExpression = exports.transformThisExpression = exports.transformClassDeclaration = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../../LuaAST");
|
|
6
|
-
const utils_1 = require("../../../utils");
|
|
7
|
-
const annotations_1 = require("../../utils/annotations");
|
|
8
|
-
const diagnostics_1 = require("../../utils/diagnostics");
|
|
9
6
|
const export_1 = require("../../utils/export");
|
|
10
7
|
const lua_ast_1 = require("../../utils/lua-ast");
|
|
11
8
|
const safe_names_1 = require("../../utils/safe-names");
|
|
@@ -15,7 +12,7 @@ const accessors_1 = require("./members/accessors");
|
|
|
15
12
|
const constructor_1 = require("./members/constructor");
|
|
16
13
|
const fields_1 = require("./members/fields");
|
|
17
14
|
const method_1 = require("./members/method");
|
|
18
|
-
const
|
|
15
|
+
const utils_1 = require("./utils");
|
|
19
16
|
const setup_1 = require("./setup");
|
|
20
17
|
const transformClassDeclaration = (declaration, context) => {
|
|
21
18
|
// If declaration is a default export, transform to export variable assignment instead
|
|
@@ -36,7 +33,6 @@ function transformClassAsExpression(expression, context) {
|
|
|
36
33
|
return name;
|
|
37
34
|
}
|
|
38
35
|
exports.transformClassAsExpression = transformClassAsExpression;
|
|
39
|
-
const classSuperInfos = new WeakMap();
|
|
40
36
|
function transformClassLikeDeclaration(classDeclaration, context, nameOverride) {
|
|
41
37
|
let className;
|
|
42
38
|
if (nameOverride !== undefined) {
|
|
@@ -48,22 +44,14 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
48
44
|
else {
|
|
49
45
|
className = lua.createIdentifier(context.createTempName("class"), classDeclaration);
|
|
50
46
|
}
|
|
51
|
-
const annotations = (0, annotations_1.getTypeAnnotations)(context.checker.getTypeAtLocation(classDeclaration));
|
|
52
|
-
if (annotations.has(annotations_1.AnnotationKind.Extension)) {
|
|
53
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(classDeclaration, annotations_1.AnnotationKind.Extension));
|
|
54
|
-
}
|
|
55
|
-
if (annotations.has(annotations_1.AnnotationKind.MetaExtension)) {
|
|
56
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(classDeclaration, annotations_1.AnnotationKind.MetaExtension));
|
|
57
|
-
}
|
|
58
47
|
// Get type that is extended
|
|
59
|
-
const extendedTypeNode = (0,
|
|
60
|
-
const extendedType = (0,
|
|
61
|
-
|
|
62
|
-
superInfo.push({ className, extendedTypeNode });
|
|
48
|
+
const extendedTypeNode = (0, utils_1.getExtendedNode)(classDeclaration);
|
|
49
|
+
const extendedType = (0, utils_1.getExtendedType)(context, classDeclaration);
|
|
50
|
+
context.classSuperInfos.push({ className, extendedTypeNode });
|
|
63
51
|
// Get all properties with value
|
|
64
52
|
const properties = classDeclaration.members.filter(ts.isPropertyDeclaration).filter(member => member.initializer);
|
|
65
53
|
// Divide properties into static and non-static
|
|
66
|
-
const instanceFields = properties.filter(prop => !(0,
|
|
54
|
+
const instanceFields = properties.filter(prop => !(0, utils_1.isStaticNode)(prop));
|
|
67
55
|
const result = [];
|
|
68
56
|
let localClassName;
|
|
69
57
|
if ((0, safe_names_1.isUnsafeName)(className.text, context.options)) {
|
|
@@ -129,7 +117,7 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
129
117
|
}
|
|
130
118
|
}
|
|
131
119
|
else if (ts.isPropertyDeclaration(member)) {
|
|
132
|
-
if ((0,
|
|
120
|
+
if ((0, utils_1.isStaticNode)(member)) {
|
|
133
121
|
const statement = (0, fields_1.transformStaticPropertyDeclaration)(context, member, localClassName);
|
|
134
122
|
if (statement)
|
|
135
123
|
decorationStatements.push(statement);
|
|
@@ -153,11 +141,11 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
|
|
|
153
141
|
result.push(classAssignment);
|
|
154
142
|
}
|
|
155
143
|
}
|
|
156
|
-
|
|
144
|
+
context.classSuperInfos.pop();
|
|
157
145
|
return { statements: result, name: className };
|
|
158
146
|
}
|
|
159
147
|
const transformSuperExpression = (expression, context) => {
|
|
160
|
-
const superInfos =
|
|
148
|
+
const superInfos = context.classSuperInfos;
|
|
161
149
|
const superInfo = superInfos[superInfos.length - 1];
|
|
162
150
|
if (!superInfo)
|
|
163
151
|
return lua.createAnonymousIdentifier(expression);
|
|
@@ -22,7 +22,7 @@ function transformConstructorDeclaration(context, statement, className, instance
|
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
24
|
// Transform body
|
|
25
|
-
const scope =
|
|
25
|
+
const scope = context.pushScope(scope_1.ScopeType.Function);
|
|
26
26
|
const body = (0, function_1.transformFunctionBodyContent)(context, statement.body);
|
|
27
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
|
|
@@ -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
|
-
|
|
61
|
+
context.popScope();
|
|
62
62
|
return lua.createAssignmentStatement(createConstructorName(className), lua.createFunctionExpression(block, params, dotsLiteral, lua.NodeFlags.Declaration), constructorWasGenerated ? classDeclaration : statement);
|
|
63
63
|
}
|
|
64
64
|
exports.transformConstructorDeclaration = transformConstructorDeclaration;
|
|
@@ -10,16 +10,13 @@ const call_1 = require("../call");
|
|
|
10
10
|
const table_1 = require("../language-extensions/table");
|
|
11
11
|
const transformNewExpression = (node, context) => {
|
|
12
12
|
var _a, _b;
|
|
13
|
-
const type = context.checker.getTypeAtLocation(node);
|
|
14
|
-
const annotations = (0, annotations_1.getTypeAnnotations)(type);
|
|
15
|
-
if (annotations.has(annotations_1.AnnotationKind.LuaTable)) {
|
|
16
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.LuaTable));
|
|
17
|
-
}
|
|
18
13
|
if ((0, table_1.isTableNewCall)(context, node)) {
|
|
19
14
|
return lua.createTableExpression(undefined, node);
|
|
20
15
|
}
|
|
21
16
|
const signature = context.checker.getResolvedSignature(node);
|
|
22
17
|
const [name, params] = (0, call_1.transformCallAndArguments)(context, node.expression, (_a = node.arguments) !== null && _a !== void 0 ? _a : [ts.factory.createTrue()], signature);
|
|
18
|
+
const type = context.checker.getTypeAtLocation(node);
|
|
19
|
+
const annotations = (0, annotations_1.getTypeAnnotations)(type);
|
|
23
20
|
const customConstructorAnnotation = annotations.get(annotations_1.AnnotationKind.CustomConstructor);
|
|
24
21
|
if (customConstructorAnnotation) {
|
|
25
22
|
if (customConstructorAnnotation.args.length === 1) {
|
|
@@ -2,4 +2,4 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../../LuaAST";
|
|
3
3
|
import { TransformationContext } from "../../context";
|
|
4
4
|
export declare function createClassSetup(context: TransformationContext, statement: ts.ClassLikeDeclarationBase, className: lua.Identifier, localClassName: lua.Identifier, extendsType?: ts.Type): lua.Statement[];
|
|
5
|
-
export declare function getReflectionClassName(
|
|
5
|
+
export declare function getReflectionClassName(declaration: ts.ClassLikeDeclarationBase, className: lua.Identifier): lua.Expression;
|
|
@@ -34,16 +34,16 @@ function createClassSetup(context, statement, className, localClassName, extends
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
// localClassName.name = className
|
|
37
|
-
result.push(lua.createAssignmentStatement(lua.createTableIndexExpression(lua.cloneIdentifier(localClassName), lua.createStringLiteral("name")), getReflectionClassName(
|
|
37
|
+
result.push(lua.createAssignmentStatement(lua.createTableIndexExpression(lua.cloneIdentifier(localClassName), lua.createStringLiteral("name")), getReflectionClassName(statement, className), statement));
|
|
38
38
|
if (extendsType) {
|
|
39
|
-
const extendedNode = (0, utils_2.getExtendedNode)(
|
|
39
|
+
const extendedNode = (0, utils_2.getExtendedNode)(statement);
|
|
40
40
|
(0, utils_1.assert)(extendedNode);
|
|
41
41
|
result.push(lua.createExpressionStatement((0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.ClassExtends, (0, utils_2.getExtendsClause)(statement), lua.cloneIdentifier(localClassName), context.transformExpression(extendedNode.expression))));
|
|
42
42
|
}
|
|
43
43
|
return result;
|
|
44
44
|
}
|
|
45
45
|
exports.createClassSetup = createClassSetup;
|
|
46
|
-
function getReflectionClassName(
|
|
46
|
+
function getReflectionClassName(declaration, className) {
|
|
47
47
|
if (declaration.name) {
|
|
48
48
|
return lua.createStringLiteral(declaration.name.text);
|
|
49
49
|
}
|
|
@@ -53,7 +53,7 @@ function getReflectionClassName(context, declaration, className) {
|
|
|
53
53
|
else if ((0, export_1.hasDefaultExportModifier)(declaration)) {
|
|
54
54
|
return lua.createStringLiteral("default");
|
|
55
55
|
}
|
|
56
|
-
if ((0, utils_2.getExtendedNode)(
|
|
56
|
+
if ((0, utils_2.getExtendedNode)(declaration)) {
|
|
57
57
|
return lua.createTableIndexExpression(className, lua.createStringLiteral("name"));
|
|
58
58
|
}
|
|
59
59
|
return lua.createStringLiteral("");
|
|
@@ -2,5 +2,5 @@ import * as ts from "typescript";
|
|
|
2
2
|
import { TransformationContext } from "../../context";
|
|
3
3
|
export declare function isStaticNode(node: ts.Node): boolean;
|
|
4
4
|
export declare function getExtendsClause(node: ts.ClassLikeDeclarationBase): ts.HeritageClause | undefined;
|
|
5
|
-
export declare function getExtendedNode(
|
|
5
|
+
export declare function getExtendedNode(node: ts.ClassLikeDeclarationBase): ts.ExpressionWithTypeArguments | undefined;
|
|
6
6
|
export declare function getExtendedType(context: TransformationContext, node: ts.ClassLikeDeclarationBase): ts.Type | undefined;
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getExtendedType = exports.getExtendedNode = exports.getExtendsClause = exports.isStaticNode = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
-
const annotations_1 = require("../../utils/annotations");
|
|
6
|
-
const diagnostics_1 = require("../../utils/diagnostics");
|
|
7
5
|
function isStaticNode(node) {
|
|
8
6
|
var _a;
|
|
9
7
|
return ((_a = node.modifiers) !== null && _a !== void 0 ? _a : []).some(m => m.kind === ts.SyntaxKind.StaticKeyword);
|
|
@@ -14,20 +12,15 @@ function getExtendsClause(node) {
|
|
|
14
12
|
return ((_a = node.heritageClauses) !== null && _a !== void 0 ? _a : []).find(clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
|
|
15
13
|
}
|
|
16
14
|
exports.getExtendsClause = getExtendsClause;
|
|
17
|
-
function getExtendedNode(
|
|
15
|
+
function getExtendedNode(node) {
|
|
18
16
|
const extendsClause = getExtendsClause(node);
|
|
19
17
|
if (!extendsClause)
|
|
20
18
|
return;
|
|
21
|
-
const superType = context.checker.getTypeAtLocation(extendsClause.types[0]);
|
|
22
|
-
const annotations = (0, annotations_1.getTypeAnnotations)(superType);
|
|
23
|
-
if (annotations.has(annotations_1.AnnotationKind.PureAbstract)) {
|
|
24
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(extendsClause, annotations_1.AnnotationKind.PureAbstract));
|
|
25
|
-
}
|
|
26
19
|
return extendsClause.types[0];
|
|
27
20
|
}
|
|
28
21
|
exports.getExtendedNode = getExtendedNode;
|
|
29
22
|
function getExtendedType(context, node) {
|
|
30
|
-
const extendedNode = getExtendedNode(
|
|
23
|
+
const extendedNode = getExtendedNode(node);
|
|
31
24
|
return extendedNode && context.checker.getTypeAtLocation(extendedNode);
|
|
32
25
|
}
|
|
33
26
|
exports.getExtendedType = getExtendedType;
|
|
@@ -34,10 +34,10 @@ const transformConditionalExpression = (expression, context) => {
|
|
|
34
34
|
};
|
|
35
35
|
exports.transformConditionalExpression = transformConditionalExpression;
|
|
36
36
|
function transformIfStatement(statement, context) {
|
|
37
|
-
|
|
37
|
+
context.pushScope(scope_1.ScopeType.Conditional);
|
|
38
38
|
const condition = context.transformExpression(statement.expression);
|
|
39
39
|
const statements = (0, scope_1.performHoisting)(context, (0, block_1.transformBlockOrStatement)(context, statement.thenStatement));
|
|
40
|
-
|
|
40
|
+
context.popScope();
|
|
41
41
|
const ifBlock = lua.createBlock(statements);
|
|
42
42
|
if (statement.elseStatement) {
|
|
43
43
|
if (ts.isIfStatement(statement.elseStatement)) {
|
|
@@ -60,9 +60,9 @@ function transformIfStatement(statement, context) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
|
-
|
|
63
|
+
context.pushScope(scope_1.ScopeType.Conditional);
|
|
64
64
|
const elseStatements = (0, scope_1.performHoisting)(context, (0, block_1.transformBlockOrStatement)(context, statement.elseStatement));
|
|
65
|
-
|
|
65
|
+
context.popScope();
|
|
66
66
|
const elseBlock = lua.createBlock(elseStatements);
|
|
67
67
|
return lua.createIfStatement(condition, ifBlock, elseBlock);
|
|
68
68
|
}
|
|
@@ -3,7 +3,7 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../context";
|
|
4
4
|
import { Scope } from "../utils/scope";
|
|
5
5
|
export declare function createCallableTable(functionExpression: lua.Expression): lua.Expression;
|
|
6
|
-
export declare function isFunctionTypeWithProperties(functionType: ts.Type): boolean;
|
|
6
|
+
export declare function isFunctionTypeWithProperties(context: TransformationContext, functionType: ts.Type): boolean;
|
|
7
7
|
export declare function transformFunctionBodyContent(context: TransformationContext, body: ts.ConciseBody): lua.Statement[];
|
|
8
8
|
export declare function transformFunctionBodyHeader(context: TransformationContext, bodyScope: Scope, parameters: ts.NodeArray<ts.ParameterDeclaration>, spreadIdentifier?: lua.Identifier): lua.Statement[];
|
|
9
9
|
export declare function transformFunctionBody(context: TransformationContext, parameters: ts.NodeArray<ts.ParameterDeclaration>, body: ts.ConciseBody, spreadIdentifier?: lua.Identifier, node?: ts.FunctionLikeDeclaration): [lua.Statement[], Scope];
|
|
@@ -4,8 +4,6 @@ exports.transformYieldExpression = exports.transformFunctionDeclaration = export
|
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
|
-
const annotations_1 = require("../utils/annotations");
|
|
8
|
-
const diagnostics_1 = require("../utils/diagnostics");
|
|
9
7
|
const export_1 = require("../utils/export");
|
|
10
8
|
const function_context_1 = require("../utils/function-context");
|
|
11
9
|
const language_extensions_1 = require("../utils/language-extensions");
|
|
@@ -56,14 +54,14 @@ function createCallableTable(functionExpression) {
|
|
|
56
54
|
]);
|
|
57
55
|
}
|
|
58
56
|
exports.createCallableTable = createCallableTable;
|
|
59
|
-
function isFunctionTypeWithProperties(functionType) {
|
|
57
|
+
function isFunctionTypeWithProperties(context, functionType) {
|
|
60
58
|
if (functionType.isUnion()) {
|
|
61
|
-
return functionType.types.some(isFunctionTypeWithProperties);
|
|
59
|
+
return functionType.types.some(t => isFunctionTypeWithProperties(context, t));
|
|
62
60
|
}
|
|
63
61
|
else {
|
|
64
62
|
return ((0, typescript_1.isFunctionType)(functionType) &&
|
|
65
63
|
functionType.getProperties().length > 0 &&
|
|
66
|
-
(0, language_extensions_1.
|
|
64
|
+
(0, language_extensions_1.getExtensionKindForType)(context, functionType) === undefined // ignore TSTL extension functions like $range
|
|
67
65
|
);
|
|
68
66
|
}
|
|
69
67
|
}
|
|
@@ -110,14 +108,14 @@ function transformFunctionBodyHeader(context, bodyScope, parameters, spreadIdent
|
|
|
110
108
|
}
|
|
111
109
|
exports.transformFunctionBodyHeader = transformFunctionBodyHeader;
|
|
112
110
|
function transformFunctionBody(context, parameters, body, spreadIdentifier, node) {
|
|
113
|
-
const scope =
|
|
111
|
+
const scope = context.pushScope(scope_1.ScopeType.Function);
|
|
114
112
|
scope.node = node;
|
|
115
113
|
let bodyStatements = transformFunctionBodyContent(context, body);
|
|
116
114
|
if (node && (0, async_await_1.isAsyncFunction)(node)) {
|
|
117
115
|
bodyStatements = [lua.createReturnStatement([(0, async_await_1.wrapInAsyncAwaiter)(context, bodyStatements)])];
|
|
118
116
|
}
|
|
119
117
|
const headerStatements = transformFunctionBodyHeader(context, scope, parameters, spreadIdentifier);
|
|
120
|
-
|
|
118
|
+
context.popScope();
|
|
121
119
|
return [[...headerStatements, ...bodyStatements], scope];
|
|
122
120
|
}
|
|
123
121
|
exports.transformFunctionBody = transformFunctionBody;
|
|
@@ -191,9 +189,6 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
191
189
|
// This code can be reached only from object methods, which is TypeScript error
|
|
192
190
|
return lua.createNilLiteral();
|
|
193
191
|
}
|
|
194
|
-
if ((0, annotations_1.getNodeAnnotations)(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
195
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
196
|
-
}
|
|
197
192
|
const [functionExpression, functionScope] = transformFunctionToExpression(context, node);
|
|
198
193
|
const isNamedFunctionExpression = ts.isFunctionExpression(node) && node.name;
|
|
199
194
|
// Handle named function expressions which reference themselves
|
|
@@ -205,7 +200,7 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
205
200
|
// Only handle if the name is actually referenced inside the function
|
|
206
201
|
if (isReferenced) {
|
|
207
202
|
const nameIdentifier = (0, identifier_1.transformIdentifier)(context, node.name);
|
|
208
|
-
if (isFunctionTypeWithProperties(context.checker.getTypeAtLocation(node))) {
|
|
203
|
+
if (isFunctionTypeWithProperties(context, context.checker.getTypeAtLocation(node))) {
|
|
209
204
|
context.addPrecedingStatements([
|
|
210
205
|
lua.createVariableDeclarationStatement(nameIdentifier),
|
|
211
206
|
lua.createAssignmentStatement(nameIdentifier, createCallableTable(functionExpression)),
|
|
@@ -218,16 +213,13 @@ function transformFunctionLikeDeclaration(node, context) {
|
|
|
218
213
|
}
|
|
219
214
|
}
|
|
220
215
|
}
|
|
221
|
-
return isNamedFunctionExpression && isFunctionTypeWithProperties(context.checker.getTypeAtLocation(node))
|
|
216
|
+
return isNamedFunctionExpression && isFunctionTypeWithProperties(context, context.checker.getTypeAtLocation(node))
|
|
222
217
|
? createCallableTable(functionExpression)
|
|
223
218
|
: functionExpression;
|
|
224
219
|
}
|
|
225
220
|
exports.transformFunctionLikeDeclaration = transformFunctionLikeDeclaration;
|
|
226
221
|
const transformFunctionDeclaration = (node, context) => {
|
|
227
222
|
var _a;
|
|
228
|
-
if ((0, annotations_1.getNodeAnnotations)(node).has(annotations_1.AnnotationKind.TupleReturn)) {
|
|
229
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(node, annotations_1.AnnotationKind.TupleReturn));
|
|
230
|
-
}
|
|
231
223
|
// Don't transform functions without body (overload declarations)
|
|
232
224
|
if (node.body === undefined) {
|
|
233
225
|
return undefined;
|
|
@@ -248,7 +240,7 @@ const transformFunctionDeclaration = (node, context) => {
|
|
|
248
240
|
scope.functionDefinitions.set(name.symbolId, functionInfo);
|
|
249
241
|
}
|
|
250
242
|
// Wrap functions with properties into a callable table
|
|
251
|
-
const wrappedFunction = node.name && isFunctionTypeWithProperties(context.checker.getTypeAtLocation(node.name))
|
|
243
|
+
const wrappedFunction = node.name && isFunctionTypeWithProperties(context, context.checker.getTypeAtLocation(node.name))
|
|
252
244
|
? createCallableTable(functionExpression)
|
|
253
245
|
: functionExpression;
|
|
254
246
|
return (0, lua_ast_1.createLocalOrExportedOrGlobalDeclaration)(context, name, wrappedFunction, node);
|
|
@@ -2,4 +2,5 @@ import * as ts from "typescript";
|
|
|
2
2
|
import * as lua from "../../LuaAST";
|
|
3
3
|
import { FunctionVisitor, TransformationContext } from "../context";
|
|
4
4
|
export declare function transformIdentifier(context: TransformationContext, identifier: ts.Identifier): lua.Identifier;
|
|
5
|
+
export declare function transformIdentifierWithSymbol(context: TransformationContext, node: ts.Identifier, symbol: ts.Symbol | undefined): lua.Expression;
|
|
5
6
|
export declare const transformIdentifierExpression: FunctionVisitor<ts.Identifier>;
|
|
@@ -1,82 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformIdentifierExpression = exports.transformIdentifier = void 0;
|
|
3
|
+
exports.transformIdentifierExpression = exports.transformIdentifierWithSymbol = exports.transformIdentifier = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const lua = require("../../LuaAST");
|
|
6
6
|
const builtins_1 = require("../builtins");
|
|
7
7
|
const promise_1 = require("../builtins/promise");
|
|
8
8
|
const context_1 = require("../context");
|
|
9
|
-
const annotations_1 = require("../utils/annotations");
|
|
10
9
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
11
10
|
const export_1 = require("../utils/export");
|
|
12
|
-
const lualib_1 = require("../utils/lualib");
|
|
13
11
|
const safe_names_1 = require("../utils/safe-names");
|
|
14
12
|
const symbols_1 = require("../utils/symbols");
|
|
15
|
-
const multi_1 = require("./language-extensions/multi");
|
|
16
|
-
const operators_1 = require("./language-extensions/operators");
|
|
17
|
-
const range_1 = require("./language-extensions/range");
|
|
18
|
-
const table_1 = require("./language-extensions/table");
|
|
19
|
-
const vararg_1 = require("./language-extensions/vararg");
|
|
20
13
|
const optional_chaining_1 = require("./optional-chaining");
|
|
21
14
|
const typescript_1 = require("../utils/typescript");
|
|
15
|
+
const language_extensions_1 = require("../utils/language-extensions");
|
|
16
|
+
const call_extension_1 = require("./language-extensions/call-extension");
|
|
17
|
+
const identifier_1 = require("./language-extensions/identifier");
|
|
22
18
|
function transformIdentifier(context, identifier) {
|
|
19
|
+
return transformNonValueIdentifier(context, identifier, context.checker.getSymbolAtLocation(identifier));
|
|
20
|
+
}
|
|
21
|
+
exports.transformIdentifier = transformIdentifier;
|
|
22
|
+
function transformNonValueIdentifier(context, identifier, symbol) {
|
|
23
23
|
if ((0, optional_chaining_1.isOptionalContinuation)(identifier)) {
|
|
24
24
|
return lua.createIdentifier(identifier.text, undefined, context_1.tempSymbolId);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return lua.createAnonymousIdentifier(identifier);
|
|
39
|
-
}
|
|
40
|
-
if ((0, vararg_1.isVarargConstantNode)(context, identifier)) {
|
|
41
|
-
context.diagnostics.push((0, diagnostics_1.invalidVarargUse)(identifier));
|
|
42
|
-
return lua.createAnonymousIdentifier(identifier);
|
|
43
|
-
}
|
|
44
|
-
if ((0, annotations_1.isForRangeType)(context, identifier)) {
|
|
45
|
-
context.diagnostics.push((0, diagnostics_1.annotationRemoved)(identifier, annotations_1.AnnotationKind.ForRange));
|
|
46
|
-
}
|
|
47
|
-
if ((0, promise_1.isPromiseClass)(context, identifier)) {
|
|
48
|
-
(0, lualib_1.importLuaLibFeature)(context, lualib_1.LuaLibFeature.Promise);
|
|
49
|
-
return (0, promise_1.createPromiseIdentifier)(identifier);
|
|
26
|
+
const extensionKind = symbol
|
|
27
|
+
? (0, language_extensions_1.getExtensionKindForSymbol)(context, symbol)
|
|
28
|
+
: (0, language_extensions_1.getExtensionKindForNode)(context, identifier);
|
|
29
|
+
if (extensionKind) {
|
|
30
|
+
if (call_extension_1.callExtensions.has(extensionKind)) {
|
|
31
|
+
context.diagnostics.push((0, diagnostics_1.invalidCallExtensionUse)(identifier));
|
|
32
|
+
// fall through
|
|
33
|
+
}
|
|
34
|
+
else if ((0, identifier_1.isIdentifierExtensionValue)(symbol, extensionKind)) {
|
|
35
|
+
(0, identifier_1.reportInvalidExtensionValue)(context, identifier, extensionKind);
|
|
36
|
+
return lua.createAnonymousIdentifier(identifier);
|
|
37
|
+
}
|
|
50
38
|
}
|
|
51
39
|
const type = context.checker.getTypeAtLocation(identifier);
|
|
52
40
|
if ((0, typescript_1.isStandardLibraryType)(context, type, undefined)) {
|
|
53
41
|
(0, builtins_1.checkForLuaLibType)(context, type);
|
|
42
|
+
if ((0, promise_1.isPromiseClass)(context, identifier)) {
|
|
43
|
+
return (0, promise_1.createPromiseIdentifier)(identifier);
|
|
44
|
+
}
|
|
54
45
|
}
|
|
55
|
-
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, identifier
|
|
56
|
-
|
|
46
|
+
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, identifier, symbol)
|
|
47
|
+
? (0, safe_names_1.createSafeName)(identifier.text)
|
|
48
|
+
: identifier.text;
|
|
49
|
+
const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, identifier, symbol);
|
|
57
50
|
return lua.createIdentifier(text, identifier, symbolId, identifier.text);
|
|
58
51
|
}
|
|
59
|
-
|
|
60
|
-
const transformIdentifierExpression = (node, context) => {
|
|
61
|
-
const symbol = context.checker.getSymbolAtLocation(node);
|
|
52
|
+
function transformIdentifierWithSymbol(context, node, symbol) {
|
|
62
53
|
if (symbol) {
|
|
63
54
|
const exportScope = (0, export_1.getSymbolExportScope)(context, symbol);
|
|
64
55
|
if (exportScope) {
|
|
65
56
|
const name = symbol.name;
|
|
66
|
-
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, node) ? (0, safe_names_1.createSafeName)(name) : name;
|
|
67
|
-
const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, node);
|
|
57
|
+
const text = (0, safe_names_1.hasUnsafeIdentifierName)(context, node, symbol) ? (0, safe_names_1.createSafeName)(name) : name;
|
|
58
|
+
const symbolId = (0, symbols_1.getIdentifierSymbolId)(context, node, symbol);
|
|
68
59
|
const identifier = lua.createIdentifier(text, node, symbolId, name);
|
|
69
60
|
return (0, export_1.createExportedIdentifier)(context, identifier, exportScope);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
|
-
|
|
73
|
-
return lua.createNilLiteral();
|
|
74
|
-
}
|
|
75
|
-
const builtinResult = (0, builtins_1.transformBuiltinIdentifierExpression)(context, node);
|
|
63
|
+
const builtinResult = (0, builtins_1.transformBuiltinIdentifierExpression)(context, node, symbol);
|
|
76
64
|
if (builtinResult) {
|
|
77
65
|
return builtinResult;
|
|
78
66
|
}
|
|
79
|
-
return
|
|
67
|
+
return transformNonValueIdentifier(context, node, symbol);
|
|
68
|
+
}
|
|
69
|
+
exports.transformIdentifierWithSymbol = transformIdentifierWithSymbol;
|
|
70
|
+
const transformIdentifierExpression = (node, context) => {
|
|
71
|
+
if (node.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword) {
|
|
72
|
+
return lua.createNilLiteral(node);
|
|
73
|
+
}
|
|
74
|
+
const symbol = context.checker.getSymbolAtLocation(node);
|
|
75
|
+
return transformIdentifierWithSymbol(context, node, symbol);
|
|
80
76
|
};
|
|
81
77
|
exports.transformIdentifierExpression = transformIdentifierExpression;
|
|
82
78
|
//# sourceMappingURL=identifier.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TransformationContext } from "../../context";
|
|
2
|
+
import * as ts from "typescript";
|
|
3
|
+
import { ExtensionKind } from "../../utils/language-extensions";
|
|
4
|
+
import * as lua from "../../../LuaAST";
|
|
5
|
+
export declare const callExtensions: Set<ExtensionKind>;
|
|
6
|
+
export declare type LanguageExtensionCallTransformer = (context: TransformationContext, node: ts.CallExpression, extensionKind: ExtensionKind) => lua.Expression;
|
|
7
|
+
export declare type LanguageExtensionCallTransformerMap = {
|
|
8
|
+
[P in ExtensionKind]?: LanguageExtensionCallTransformer;
|
|
9
|
+
};
|
|
10
|
+
export declare function transformLanguageExtensionCallExpression(context: TransformationContext, node: ts.CallExpression): lua.Expression | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformLanguageExtensionCallExpression = exports.callExtensions = void 0;
|
|
4
|
+
const language_extensions_1 = require("../../utils/language-extensions");
|
|
5
|
+
const operators_1 = require("./operators");
|
|
6
|
+
const table_1 = require("./table");
|
|
7
|
+
const allCallExtensionHandlers = {
|
|
8
|
+
...operators_1.operatorExtensionTransformers,
|
|
9
|
+
...table_1.tableExtensionTransformers,
|
|
10
|
+
};
|
|
11
|
+
exports.callExtensions = new Set(Object.keys(allCallExtensionHandlers));
|
|
12
|
+
table_1.tableNewExtensions.forEach(kind => exports.callExtensions.add(kind));
|
|
13
|
+
function transformLanguageExtensionCallExpression(context, node) {
|
|
14
|
+
const extensionKind = (0, language_extensions_1.getExtensionKindForNode)(context, node.expression);
|
|
15
|
+
if (!extensionKind)
|
|
16
|
+
return;
|
|
17
|
+
const transformer = allCallExtensionHandlers[extensionKind];
|
|
18
|
+
if (transformer) {
|
|
19
|
+
return transformer(context, node, extensionKind);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.transformLanguageExtensionCallExpression = transformLanguageExtensionCallExpression;
|
|
23
|
+
//# sourceMappingURL=call-extension.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { ExtensionKind } from "../../utils/language-extensions";
|
|
3
|
+
import { TransformationContext } from "../../context";
|
|
4
|
+
export declare function isIdentifierExtensionValue(symbol: ts.Symbol | undefined, extensionKind: ExtensionKind): boolean;
|
|
5
|
+
export declare function reportInvalidExtensionValue(context: TransformationContext, identifier: ts.Identifier, extensionKind: ExtensionKind): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reportInvalidExtensionValue = exports.isIdentifierExtensionValue = void 0;
|
|
4
|
+
const language_extensions_1 = require("../../utils/language-extensions");
|
|
5
|
+
const diagnostics_1 = require("../../utils/diagnostics");
|
|
6
|
+
const extensionKindToValueName = {
|
|
7
|
+
[language_extensions_1.ExtensionKind.MultiFunction]: "$multi",
|
|
8
|
+
[language_extensions_1.ExtensionKind.RangeFunction]: "$range",
|
|
9
|
+
[language_extensions_1.ExtensionKind.VarargConstant]: "$vararg",
|
|
10
|
+
};
|
|
11
|
+
function isIdentifierExtensionValue(symbol, extensionKind) {
|
|
12
|
+
return symbol !== undefined && extensionKindToValueName[extensionKind] === symbol.name;
|
|
13
|
+
}
|
|
14
|
+
exports.isIdentifierExtensionValue = isIdentifierExtensionValue;
|
|
15
|
+
function reportInvalidExtensionValue(context, identifier, extensionKind) {
|
|
16
|
+
if (extensionKind === language_extensions_1.ExtensionKind.MultiFunction) {
|
|
17
|
+
context.diagnostics.push((0, diagnostics_1.invalidMultiFunctionUse)(identifier));
|
|
18
|
+
}
|
|
19
|
+
else if (extensionKind === language_extensions_1.ExtensionKind.RangeFunction) {
|
|
20
|
+
context.diagnostics.push((0, diagnostics_1.invalidRangeUse)(identifier));
|
|
21
|
+
}
|
|
22
|
+
else if (extensionKind === language_extensions_1.ExtensionKind.VarargConstant) {
|
|
23
|
+
context.diagnostics.push((0, diagnostics_1.invalidVarargUse)(identifier));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.reportInvalidExtensionValue = reportInvalidExtensionValue;
|
|
27
|
+
//# sourceMappingURL=identifier.js.map
|