typescript-to-lua 1.6.3 → 1.7.2
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/cli/parse.js +5 -0
- 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/SparseArraySpread.lua +5 -1
- package/dist/lualib/StringCharCodeAt.lua +5 -1
- package/dist/lualib/lualib_bundle.lua +38 -7
- 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 +10 -21
- 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 +23 -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/modules/import.js +2 -2
- 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/plugins.js +3 -0
- package/dist/transpilation/resolve.js +210 -186
- 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 +21 -0
- package/language-extensions/index.d.ts +167 -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
|
@@ -27,9 +27,22 @@ function hasNoSelfAncestor(declaration) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
function getExplicitThisParameter(signatureDeclaration) {
|
|
30
|
-
|
|
30
|
+
const param = signatureDeclaration.parameters[0];
|
|
31
|
+
if (param && ts.isIdentifier(param.name) && param.name.originalKeywordKind === ts.SyntaxKind.ThisKeyword) {
|
|
32
|
+
return param;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const signatureDeclarationContextTypes = new WeakMap();
|
|
36
|
+
function getDeclarationContextType(context, signatureDeclaration) {
|
|
37
|
+
const known = signatureDeclarationContextTypes.get(signatureDeclaration);
|
|
38
|
+
if (known !== undefined)
|
|
39
|
+
return known;
|
|
40
|
+
const contextType = computeDeclarationContextType(context, signatureDeclaration);
|
|
41
|
+
signatureDeclarationContextTypes.set(signatureDeclaration, contextType);
|
|
42
|
+
return contextType;
|
|
31
43
|
}
|
|
32
|
-
|
|
44
|
+
exports.getDeclarationContextType = getDeclarationContextType;
|
|
45
|
+
function computeDeclarationContextType(context, signatureDeclaration) {
|
|
33
46
|
const thisParameter = getExplicitThisParameter(signatureDeclaration);
|
|
34
47
|
if (thisParameter) {
|
|
35
48
|
// Explicit 'this'
|
|
@@ -49,15 +62,13 @@ function getDeclarationContextType({ program }, signatureDeclaration) {
|
|
|
49
62
|
(signatureDeclaration.parent && ts.isPropertySignature(signatureDeclaration.parent))) {
|
|
50
63
|
// Class/interface methods only respect @noSelf on their parent
|
|
51
64
|
const scopeDeclaration = (0, typescript_1.findFirstNodeAbove)(signatureDeclaration, (n) => ts.isClassDeclaration(n) || ts.isClassExpression(n) || ts.isInterfaceDeclaration(n));
|
|
52
|
-
if (scopeDeclaration
|
|
53
|
-
return ContextType.NonVoid;
|
|
54
|
-
}
|
|
55
|
-
if ((0, annotations_1.getNodeAnnotations)(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
65
|
+
if (scopeDeclaration !== undefined && (0, annotations_1.getNodeAnnotations)(scopeDeclaration).has(annotations_1.AnnotationKind.NoSelf)) {
|
|
56
66
|
return ContextType.Void;
|
|
57
67
|
}
|
|
58
68
|
return ContextType.NonVoid;
|
|
59
69
|
}
|
|
60
70
|
// When using --noImplicitSelf and the signature is defined in a file targeted by the program apply the @noSelf rule.
|
|
71
|
+
const program = context.program;
|
|
61
72
|
const options = program.getCompilerOptions();
|
|
62
73
|
if (options.noImplicitSelf) {
|
|
63
74
|
const sourceFile = program.getSourceFile(signatureDeclaration.getSourceFile().fileName);
|
|
@@ -73,61 +84,56 @@ function getDeclarationContextType({ program }, signatureDeclaration) {
|
|
|
73
84
|
}
|
|
74
85
|
return ContextType.NonVoid;
|
|
75
86
|
}
|
|
76
|
-
exports.getDeclarationContextType = getDeclarationContextType;
|
|
77
87
|
function reduceContextTypes(contexts) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
else if (a !== b) {
|
|
86
|
-
return ContextType.Mixed;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return a;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
return contexts.reduce(reducer, ContextType.None);
|
|
88
|
+
let type = ContextType.None;
|
|
89
|
+
for (const context of contexts) {
|
|
90
|
+
type |= context;
|
|
91
|
+
if (type === ContextType.Mixed)
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return type;
|
|
93
95
|
}
|
|
94
|
-
function getSignatureDeclarations(context,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return inferredSignatures.map(s => s.getDeclaration());
|
|
112
|
-
}
|
|
96
|
+
function getSignatureDeclarations(context, signature) {
|
|
97
|
+
const signatureDeclaration = signature.getDeclaration();
|
|
98
|
+
let inferredType;
|
|
99
|
+
if (ts.isMethodDeclaration(signatureDeclaration) &&
|
|
100
|
+
ts.isObjectLiteralExpression(signatureDeclaration.parent) &&
|
|
101
|
+
!getExplicitThisParameter(signatureDeclaration)) {
|
|
102
|
+
inferredType = context.checker.getContextualTypeForObjectLiteralElement(signatureDeclaration);
|
|
103
|
+
}
|
|
104
|
+
else if ((ts.isFunctionExpression(signatureDeclaration) || ts.isArrowFunction(signatureDeclaration)) &&
|
|
105
|
+
!getExplicitThisParameter(signatureDeclaration)) {
|
|
106
|
+
// Infer type of function expressions/arrow functions
|
|
107
|
+
inferredType = (0, typescript_1.inferAssignedType)(context, signatureDeclaration);
|
|
108
|
+
}
|
|
109
|
+
if (inferredType) {
|
|
110
|
+
const inferredSignatures = (0, typescript_1.getAllCallSignatures)(inferredType);
|
|
111
|
+
if (inferredSignatures.length > 0) {
|
|
112
|
+
return inferredSignatures.map(s => s.getDeclaration());
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
}
|
|
115
|
+
return [signatureDeclaration];
|
|
116
116
|
}
|
|
117
|
+
const typeContextTypes = new WeakMap();
|
|
117
118
|
function getFunctionContextType(context, type) {
|
|
118
|
-
|
|
119
|
+
const known = typeContextTypes.get(type);
|
|
120
|
+
if (known !== undefined)
|
|
121
|
+
return known;
|
|
122
|
+
const contextType = computeFunctionContextType(context, type);
|
|
123
|
+
typeContextTypes.set(type, contextType);
|
|
124
|
+
return contextType;
|
|
125
|
+
}
|
|
126
|
+
exports.getFunctionContextType = getFunctionContextType;
|
|
127
|
+
function computeFunctionContextType(context, type) {
|
|
119
128
|
if (type.isTypeParameter()) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return reduceContextTypes(type.types.map(t => getFunctionContextType(context, t)));
|
|
129
|
+
const constraint = type.getConstraint();
|
|
130
|
+
if (constraint)
|
|
131
|
+
return getFunctionContextType(context, constraint);
|
|
124
132
|
}
|
|
125
133
|
const signatures = context.checker.getSignaturesOfType(type, ts.SignatureKind.Call);
|
|
126
134
|
if (signatures.length === 0) {
|
|
127
135
|
return ContextType.None;
|
|
128
136
|
}
|
|
129
|
-
|
|
130
|
-
return reduceContextTypes(signatureDeclarations.map(s => getDeclarationContextType(context, s)));
|
|
137
|
+
return reduceContextTypes(signatures.flatMap(s => getSignatureDeclarations(context, s)).map(s => getDeclarationContextType(context, s)));
|
|
131
138
|
}
|
|
132
|
-
exports.getFunctionContextType = getFunctionContextType;
|
|
133
139
|
//# sourceMappingURL=function-context.js.map
|
|
@@ -2,57 +2,63 @@ import * as ts from "typescript";
|
|
|
2
2
|
import { TransformationContext } from "../context";
|
|
3
3
|
export declare enum ExtensionKind {
|
|
4
4
|
MultiFunction = "MultiFunction",
|
|
5
|
-
MultiType = "MultiType",
|
|
6
5
|
RangeFunction = "RangeFunction",
|
|
7
6
|
VarargConstant = "VarargConstant",
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
7
|
+
AdditionOperatorType = "Addition",
|
|
8
|
+
AdditionOperatorMethodType = "AdditionMethod",
|
|
9
|
+
SubtractionOperatorType = "Subtraction",
|
|
10
|
+
SubtractionOperatorMethodType = "SubtractionMethod",
|
|
11
|
+
MultiplicationOperatorType = "Multiplication",
|
|
12
|
+
MultiplicationOperatorMethodType = "MultiplicationMethod",
|
|
13
|
+
DivisionOperatorType = "Division",
|
|
14
|
+
DivisionOperatorMethodType = "DivisionMethod",
|
|
15
|
+
ModuloOperatorType = "Modulo",
|
|
16
|
+
ModuloOperatorMethodType = "ModuloMethod",
|
|
17
|
+
PowerOperatorType = "Power",
|
|
18
|
+
PowerOperatorMethodType = "PowerMethod",
|
|
19
|
+
FloorDivisionOperatorType = "FloorDivision",
|
|
20
|
+
FloorDivisionOperatorMethodType = "FloorDivisionMethod",
|
|
21
|
+
BitwiseAndOperatorType = "BitwiseAnd",
|
|
22
|
+
BitwiseAndOperatorMethodType = "BitwiseAndMethod",
|
|
23
|
+
BitwiseOrOperatorType = "BitwiseOr",
|
|
24
|
+
BitwiseOrOperatorMethodType = "BitwiseOrMethod",
|
|
25
|
+
BitwiseExclusiveOrOperatorType = "BitwiseExclusiveOr",
|
|
26
|
+
BitwiseExclusiveOrOperatorMethodType = "BitwiseExclusiveOrMethod",
|
|
27
|
+
BitwiseLeftShiftOperatorType = "BitwiseLeftShift",
|
|
28
|
+
BitwiseLeftShiftOperatorMethodType = "BitwiseLeftShiftMethod",
|
|
29
|
+
BitwiseRightShiftOperatorType = "BitwiseRightShift",
|
|
30
|
+
BitwiseRightShiftOperatorMethodType = "BitwiseRightShiftMethod",
|
|
31
|
+
ConcatOperatorType = "Concat",
|
|
32
|
+
ConcatOperatorMethodType = "ConcatMethod",
|
|
33
|
+
LessThanOperatorType = "LessThan",
|
|
34
|
+
LessThanOperatorMethodType = "LessThanMethod",
|
|
35
|
+
GreaterThanOperatorType = "GreaterThan",
|
|
36
|
+
GreaterThanOperatorMethodType = "GreaterThanMethod",
|
|
37
|
+
NegationOperatorType = "Negation",
|
|
38
|
+
NegationOperatorMethodType = "NegationMethod",
|
|
39
|
+
BitwiseNotOperatorType = "BitwiseNot",
|
|
40
|
+
BitwiseNotOperatorMethodType = "BitwiseNotMethod",
|
|
41
|
+
LengthOperatorType = "Length",
|
|
42
|
+
LengthOperatorMethodType = "LengthMethod",
|
|
43
|
+
TableNewType = "TableNew",
|
|
44
|
+
TableDeleteType = "TableDelete",
|
|
45
|
+
TableDeleteMethodType = "TableDeleteMethod",
|
|
46
|
+
TableGetType = "TableGet",
|
|
47
|
+
TableGetMethodType = "TableGetMethod",
|
|
48
|
+
TableHasType = "TableHas",
|
|
49
|
+
TableHasMethodType = "TableHasMethod",
|
|
50
|
+
TableSetType = "TableSet",
|
|
51
|
+
TableSetMethodType = "TableSetMethod",
|
|
52
|
+
TableAddKeyType = "TableAddKey",
|
|
53
|
+
TableAddKeyMethodType = "TableAddKeyMethod"
|
|
55
54
|
}
|
|
56
|
-
export declare function
|
|
57
|
-
export declare function
|
|
58
|
-
export declare function
|
|
55
|
+
export declare function getExtensionKindForType(context: TransformationContext, type: ts.Type): ExtensionKind | undefined;
|
|
56
|
+
export declare function getExtensionKindForNode(context: TransformationContext, node: ts.Node): ExtensionKind | undefined;
|
|
57
|
+
export declare function getExtensionKindForSymbol(context: TransformationContext, symbol: ts.Symbol): ExtensionKind | undefined;
|
|
58
|
+
export declare enum IterableExtensionKind {
|
|
59
|
+
Iterable = "Iterable",
|
|
60
|
+
Pairs = "Pairs",
|
|
61
|
+
PairsKey = "PairsKey"
|
|
62
|
+
}
|
|
63
|
+
export declare function getIterableExtensionTypeForType(context: TransformationContext, type: ts.Type): IterableExtensionKind | undefined;
|
|
64
|
+
export declare function getIterableExtensionKindForNode(context: TransformationContext, node: ts.Node): IterableExtensionKind | undefined;
|
|
@@ -1,131 +1,111 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getIterableExtensionKindForNode = exports.getIterableExtensionTypeForType = exports.IterableExtensionKind = exports.getExtensionKindForSymbol = exports.getExtensionKindForNode = exports.getExtensionKindForType = exports.ExtensionKind = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
4
5
|
var ExtensionKind;
|
|
5
6
|
(function (ExtensionKind) {
|
|
6
7
|
ExtensionKind["MultiFunction"] = "MultiFunction";
|
|
7
|
-
ExtensionKind["MultiType"] = "MultiType";
|
|
8
8
|
ExtensionKind["RangeFunction"] = "RangeFunction";
|
|
9
9
|
ExtensionKind["VarargConstant"] = "VarargConstant";
|
|
10
|
-
ExtensionKind["
|
|
11
|
-
ExtensionKind["
|
|
12
|
-
ExtensionKind["
|
|
13
|
-
ExtensionKind["
|
|
14
|
-
ExtensionKind["
|
|
15
|
-
ExtensionKind["
|
|
16
|
-
ExtensionKind["
|
|
17
|
-
ExtensionKind["
|
|
18
|
-
ExtensionKind["
|
|
19
|
-
ExtensionKind["
|
|
20
|
-
ExtensionKind["
|
|
21
|
-
ExtensionKind["
|
|
22
|
-
ExtensionKind["
|
|
23
|
-
ExtensionKind["
|
|
24
|
-
ExtensionKind["
|
|
25
|
-
ExtensionKind["
|
|
26
|
-
ExtensionKind["
|
|
27
|
-
ExtensionKind["
|
|
28
|
-
ExtensionKind["
|
|
29
|
-
ExtensionKind["
|
|
30
|
-
ExtensionKind["
|
|
31
|
-
ExtensionKind["
|
|
32
|
-
ExtensionKind["
|
|
33
|
-
ExtensionKind["
|
|
34
|
-
ExtensionKind["
|
|
35
|
-
ExtensionKind["
|
|
36
|
-
ExtensionKind["
|
|
37
|
-
ExtensionKind["
|
|
38
|
-
ExtensionKind["
|
|
39
|
-
ExtensionKind["
|
|
40
|
-
ExtensionKind["
|
|
41
|
-
ExtensionKind["
|
|
42
|
-
ExtensionKind["
|
|
43
|
-
ExtensionKind["
|
|
44
|
-
ExtensionKind["
|
|
45
|
-
ExtensionKind["
|
|
46
|
-
ExtensionKind["
|
|
47
|
-
ExtensionKind["
|
|
48
|
-
ExtensionKind["
|
|
49
|
-
ExtensionKind["
|
|
50
|
-
ExtensionKind["
|
|
51
|
-
ExtensionKind["
|
|
52
|
-
ExtensionKind["
|
|
53
|
-
ExtensionKind["
|
|
54
|
-
ExtensionKind["
|
|
55
|
-
ExtensionKind["
|
|
56
|
-
ExtensionKind["
|
|
10
|
+
ExtensionKind["AdditionOperatorType"] = "Addition";
|
|
11
|
+
ExtensionKind["AdditionOperatorMethodType"] = "AdditionMethod";
|
|
12
|
+
ExtensionKind["SubtractionOperatorType"] = "Subtraction";
|
|
13
|
+
ExtensionKind["SubtractionOperatorMethodType"] = "SubtractionMethod";
|
|
14
|
+
ExtensionKind["MultiplicationOperatorType"] = "Multiplication";
|
|
15
|
+
ExtensionKind["MultiplicationOperatorMethodType"] = "MultiplicationMethod";
|
|
16
|
+
ExtensionKind["DivisionOperatorType"] = "Division";
|
|
17
|
+
ExtensionKind["DivisionOperatorMethodType"] = "DivisionMethod";
|
|
18
|
+
ExtensionKind["ModuloOperatorType"] = "Modulo";
|
|
19
|
+
ExtensionKind["ModuloOperatorMethodType"] = "ModuloMethod";
|
|
20
|
+
ExtensionKind["PowerOperatorType"] = "Power";
|
|
21
|
+
ExtensionKind["PowerOperatorMethodType"] = "PowerMethod";
|
|
22
|
+
ExtensionKind["FloorDivisionOperatorType"] = "FloorDivision";
|
|
23
|
+
ExtensionKind["FloorDivisionOperatorMethodType"] = "FloorDivisionMethod";
|
|
24
|
+
ExtensionKind["BitwiseAndOperatorType"] = "BitwiseAnd";
|
|
25
|
+
ExtensionKind["BitwiseAndOperatorMethodType"] = "BitwiseAndMethod";
|
|
26
|
+
ExtensionKind["BitwiseOrOperatorType"] = "BitwiseOr";
|
|
27
|
+
ExtensionKind["BitwiseOrOperatorMethodType"] = "BitwiseOrMethod";
|
|
28
|
+
ExtensionKind["BitwiseExclusiveOrOperatorType"] = "BitwiseExclusiveOr";
|
|
29
|
+
ExtensionKind["BitwiseExclusiveOrOperatorMethodType"] = "BitwiseExclusiveOrMethod";
|
|
30
|
+
ExtensionKind["BitwiseLeftShiftOperatorType"] = "BitwiseLeftShift";
|
|
31
|
+
ExtensionKind["BitwiseLeftShiftOperatorMethodType"] = "BitwiseLeftShiftMethod";
|
|
32
|
+
ExtensionKind["BitwiseRightShiftOperatorType"] = "BitwiseRightShift";
|
|
33
|
+
ExtensionKind["BitwiseRightShiftOperatorMethodType"] = "BitwiseRightShiftMethod";
|
|
34
|
+
ExtensionKind["ConcatOperatorType"] = "Concat";
|
|
35
|
+
ExtensionKind["ConcatOperatorMethodType"] = "ConcatMethod";
|
|
36
|
+
ExtensionKind["LessThanOperatorType"] = "LessThan";
|
|
37
|
+
ExtensionKind["LessThanOperatorMethodType"] = "LessThanMethod";
|
|
38
|
+
ExtensionKind["GreaterThanOperatorType"] = "GreaterThan";
|
|
39
|
+
ExtensionKind["GreaterThanOperatorMethodType"] = "GreaterThanMethod";
|
|
40
|
+
ExtensionKind["NegationOperatorType"] = "Negation";
|
|
41
|
+
ExtensionKind["NegationOperatorMethodType"] = "NegationMethod";
|
|
42
|
+
ExtensionKind["BitwiseNotOperatorType"] = "BitwiseNot";
|
|
43
|
+
ExtensionKind["BitwiseNotOperatorMethodType"] = "BitwiseNotMethod";
|
|
44
|
+
ExtensionKind["LengthOperatorType"] = "Length";
|
|
45
|
+
ExtensionKind["LengthOperatorMethodType"] = "LengthMethod";
|
|
46
|
+
ExtensionKind["TableNewType"] = "TableNew";
|
|
47
|
+
ExtensionKind["TableDeleteType"] = "TableDelete";
|
|
48
|
+
ExtensionKind["TableDeleteMethodType"] = "TableDeleteMethod";
|
|
49
|
+
ExtensionKind["TableGetType"] = "TableGet";
|
|
50
|
+
ExtensionKind["TableGetMethodType"] = "TableGetMethod";
|
|
51
|
+
ExtensionKind["TableHasType"] = "TableHas";
|
|
52
|
+
ExtensionKind["TableHasMethodType"] = "TableHasMethod";
|
|
53
|
+
ExtensionKind["TableSetType"] = "TableSet";
|
|
54
|
+
ExtensionKind["TableSetMethodType"] = "TableSetMethod";
|
|
55
|
+
ExtensionKind["TableAddKeyType"] = "TableAddKey";
|
|
56
|
+
ExtensionKind["TableAddKeyMethodType"] = "TableAddKeyMethod";
|
|
57
57
|
})(ExtensionKind = exports.ExtensionKind || (exports.ExtensionKind = {}));
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
[ExtensionKind.MultiFunction]: "__luaMultiFunctionBrand",
|
|
65
|
-
[ExtensionKind.MultiType]: "__luaMultiReturnBrand",
|
|
66
|
-
[ExtensionKind.RangeFunction]: "__luaRangeFunctionBrand",
|
|
67
|
-
[ExtensionKind.VarargConstant]: "__luaVarargConstantBrand",
|
|
68
|
-
[ExtensionKind.IterableType]: "__luaIterableBrand",
|
|
69
|
-
[ExtensionKind.PairsIterableType]: "__luaPairsIterableBrand",
|
|
70
|
-
[ExtensionKind.AdditionOperatorType]: "__luaAdditionBrand",
|
|
71
|
-
[ExtensionKind.AdditionOperatorMethodType]: "__luaAdditionMethodBrand",
|
|
72
|
-
[ExtensionKind.SubtractionOperatorType]: "__luaSubtractionBrand",
|
|
73
|
-
[ExtensionKind.SubtractionOperatorMethodType]: "__luaSubtractionMethodBrand",
|
|
74
|
-
[ExtensionKind.MultiplicationOperatorType]: "__luaMultiplicationBrand",
|
|
75
|
-
[ExtensionKind.MultiplicationOperatorMethodType]: "__luaMultiplicationMethodBrand",
|
|
76
|
-
[ExtensionKind.DivisionOperatorType]: "__luaDivisionBrand",
|
|
77
|
-
[ExtensionKind.DivisionOperatorMethodType]: "__luaDivisionMethodBrand",
|
|
78
|
-
[ExtensionKind.ModuloOperatorType]: "__luaModuloBrand",
|
|
79
|
-
[ExtensionKind.ModuloOperatorMethodType]: "__luaModuloMethodBrand",
|
|
80
|
-
[ExtensionKind.PowerOperatorType]: "__luaPowerBrand",
|
|
81
|
-
[ExtensionKind.PowerOperatorMethodType]: "__luaPowerMethodBrand",
|
|
82
|
-
[ExtensionKind.FloorDivisionOperatorType]: "__luaFloorDivisionBrand",
|
|
83
|
-
[ExtensionKind.FloorDivisionOperatorMethodType]: "__luaFloorDivisionMethodBrand",
|
|
84
|
-
[ExtensionKind.BitwiseAndOperatorType]: "__luaBitwiseAndBrand",
|
|
85
|
-
[ExtensionKind.BitwiseAndOperatorMethodType]: "__luaBitwiseAndMethodBrand",
|
|
86
|
-
[ExtensionKind.BitwiseOrOperatorType]: "__luaBitwiseOrBrand",
|
|
87
|
-
[ExtensionKind.BitwiseOrOperatorMethodType]: "__luaBitwiseOrMethodBrand",
|
|
88
|
-
[ExtensionKind.BitwiseExclusiveOrOperatorType]: "__luaBitwiseExclusiveOrBrand",
|
|
89
|
-
[ExtensionKind.BitwiseExclusiveOrOperatorMethodType]: "__luaBitwiseExclusiveOrMethodBrand",
|
|
90
|
-
[ExtensionKind.BitwiseLeftShiftOperatorType]: "__luaBitwiseLeftShiftBrand",
|
|
91
|
-
[ExtensionKind.BitwiseLeftShiftOperatorMethodType]: "__luaBitwiseLeftShiftMethodBrand",
|
|
92
|
-
[ExtensionKind.BitwiseRightShiftOperatorType]: "__luaBitwiseRightShiftBrand",
|
|
93
|
-
[ExtensionKind.BitwiseRightShiftOperatorMethodType]: "__luaBitwiseRightShiftMethodBrand",
|
|
94
|
-
[ExtensionKind.ConcatOperatorType]: "__luaConcatBrand",
|
|
95
|
-
[ExtensionKind.ConcatOperatorMethodType]: "__luaConcatMethodBrand",
|
|
96
|
-
[ExtensionKind.LessThanOperatorType]: "__luaLessThanBrand",
|
|
97
|
-
[ExtensionKind.LessThanOperatorMethodType]: "__luaLessThanMethodBrand",
|
|
98
|
-
[ExtensionKind.GreaterThanOperatorType]: "__luaGreaterThanBrand",
|
|
99
|
-
[ExtensionKind.GreaterThanOperatorMethodType]: "__luaGreaterThanMethodBrand",
|
|
100
|
-
[ExtensionKind.NegationOperatorType]: "__luaNegationBrand",
|
|
101
|
-
[ExtensionKind.NegationOperatorMethodType]: "__luaNegationMethodBrand",
|
|
102
|
-
[ExtensionKind.BitwiseNotOperatorType]: "__luaBitwiseNotBrand",
|
|
103
|
-
[ExtensionKind.BitwiseNotOperatorMethodType]: "__luaBitwiseNotMethodBrand",
|
|
104
|
-
[ExtensionKind.LengthOperatorType]: "__luaLengthBrand",
|
|
105
|
-
[ExtensionKind.LengthOperatorMethodType]: "__luaLengthMethodBrand",
|
|
106
|
-
[ExtensionKind.TableNewType]: "__luaTableNewBrand",
|
|
107
|
-
[ExtensionKind.TableDeleteType]: "__luaTableDeleteBrand",
|
|
108
|
-
[ExtensionKind.TableDeleteMethodType]: "__luaTableDeleteMethodBrand",
|
|
109
|
-
[ExtensionKind.TableGetType]: "__luaTableGetBrand",
|
|
110
|
-
[ExtensionKind.TableGetMethodType]: "__luaTableGetMethodBrand",
|
|
111
|
-
[ExtensionKind.TableHasType]: "__luaTableHasBrand",
|
|
112
|
-
[ExtensionKind.TableHasMethodType]: "__luaTableHasMethodBrand",
|
|
113
|
-
[ExtensionKind.TableSetType]: "__luaTableSetBrand",
|
|
114
|
-
[ExtensionKind.TableSetMethodType]: "__luaTableSetMethodBrand",
|
|
115
|
-
};
|
|
116
|
-
function isExtensionType(type, extensionKind) {
|
|
117
|
-
const typeBrand = extensionKindToTypeBrand[extensionKind];
|
|
118
|
-
return typeBrand !== undefined && type.getProperty(typeBrand) !== undefined;
|
|
58
|
+
const extensionValues = new Set(Object.values(ExtensionKind));
|
|
59
|
+
function getExtensionKindForType(context, type) {
|
|
60
|
+
const value = getPropertyValue(context, type, "__tstlExtension");
|
|
61
|
+
if (value && extensionValues.has(value)) {
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
119
64
|
}
|
|
120
|
-
exports.
|
|
121
|
-
|
|
122
|
-
|
|
65
|
+
exports.getExtensionKindForType = getExtensionKindForType;
|
|
66
|
+
const excludedTypeFlags = ((1 << 18) - 1) | // All flags from Any...Never
|
|
67
|
+
ts.TypeFlags.Index |
|
|
68
|
+
ts.TypeFlags.NonPrimitive;
|
|
69
|
+
function getPropertyValue(context, type, propertyName) {
|
|
70
|
+
if (type.flags & excludedTypeFlags)
|
|
71
|
+
return;
|
|
72
|
+
const property = type.getProperty(propertyName);
|
|
73
|
+
if (!property)
|
|
74
|
+
return undefined;
|
|
75
|
+
const propertyType = context.checker.getTypeOfSymbolAtLocation(property, context.sourceFile);
|
|
76
|
+
if (propertyType.isStringLiteral())
|
|
77
|
+
return propertyType.value;
|
|
123
78
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
79
|
+
function getExtensionKindForNode(context, node) {
|
|
80
|
+
const originalNode = ts.getOriginalNode(node);
|
|
81
|
+
let type = context.checker.getTypeAtLocation(originalNode);
|
|
82
|
+
if (ts.isOptionalChain(originalNode)) {
|
|
83
|
+
type = context.checker.getNonNullableType(type);
|
|
84
|
+
}
|
|
85
|
+
return getExtensionKindForType(context, type);
|
|
129
86
|
}
|
|
130
|
-
exports.
|
|
87
|
+
exports.getExtensionKindForNode = getExtensionKindForNode;
|
|
88
|
+
function getExtensionKindForSymbol(context, symbol) {
|
|
89
|
+
const type = context.checker.getTypeOfSymbolAtLocation(symbol, context.sourceFile);
|
|
90
|
+
return getExtensionKindForType(context, type);
|
|
91
|
+
}
|
|
92
|
+
exports.getExtensionKindForSymbol = getExtensionKindForSymbol;
|
|
93
|
+
var IterableExtensionKind;
|
|
94
|
+
(function (IterableExtensionKind) {
|
|
95
|
+
IterableExtensionKind["Iterable"] = "Iterable";
|
|
96
|
+
IterableExtensionKind["Pairs"] = "Pairs";
|
|
97
|
+
IterableExtensionKind["PairsKey"] = "PairsKey";
|
|
98
|
+
})(IterableExtensionKind = exports.IterableExtensionKind || (exports.IterableExtensionKind = {}));
|
|
99
|
+
function getIterableExtensionTypeForType(context, type) {
|
|
100
|
+
const value = getPropertyValue(context, type, "__tstlIterable");
|
|
101
|
+
if (value && value in IterableExtensionKind) {
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.getIterableExtensionTypeForType = getIterableExtensionTypeForType;
|
|
106
|
+
function getIterableExtensionKindForNode(context, node) {
|
|
107
|
+
const type = context.checker.getTypeAtLocation(node);
|
|
108
|
+
return getIterableExtensionTypeForType(context, type);
|
|
109
|
+
}
|
|
110
|
+
exports.getIterableExtensionKindForNode = getIterableExtensionKindForNode;
|
|
131
111
|
//# sourceMappingURL=language-extensions.js.map
|
|
@@ -3,6 +3,5 @@ import * as lua from "../../LuaAST";
|
|
|
3
3
|
import { LuaLibFeature } from "../../LuaLib";
|
|
4
4
|
import { TransformationContext } from "../context";
|
|
5
5
|
export { LuaLibFeature };
|
|
6
|
-
export declare function getUsedLuaLibFeatures(context: TransformationContext): Set<LuaLibFeature>;
|
|
7
6
|
export declare function importLuaLibFeature(context: TransformationContext, feature: LuaLibFeature): void;
|
|
8
7
|
export declare function transformLuaLibFunction(context: TransformationContext, feature: LuaLibFeature, tsParent?: ts.Node, ...params: lua.Expression[]): lua.CallExpression;
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformLuaLibFunction = exports.importLuaLibFeature = exports.
|
|
3
|
+
exports.transformLuaLibFunction = exports.importLuaLibFeature = exports.LuaLibFeature = void 0;
|
|
4
4
|
const lua = require("../../LuaAST");
|
|
5
5
|
const LuaLib_1 = require("../../LuaLib");
|
|
6
6
|
Object.defineProperty(exports, "LuaLibFeature", { enumerable: true, get: function () { return LuaLib_1.LuaLibFeature; } });
|
|
7
|
-
const utils_1 = require("../../utils");
|
|
8
|
-
const luaLibFeatures = new WeakMap();
|
|
9
|
-
function getUsedLuaLibFeatures(context) {
|
|
10
|
-
return (0, utils_1.getOrUpdate)(luaLibFeatures, context, () => new Set());
|
|
11
|
-
}
|
|
12
|
-
exports.getUsedLuaLibFeatures = getUsedLuaLibFeatures;
|
|
13
7
|
function importLuaLibFeature(context, feature) {
|
|
14
|
-
|
|
8
|
+
context.usedLuaLibFeatures.add(feature);
|
|
15
9
|
}
|
|
16
10
|
exports.importLuaLibFeature = importLuaLibFeature;
|
|
17
11
|
function transformLuaLibFunction(context, feature, tsParent, ...params) {
|
|
@@ -6,5 +6,5 @@ export declare const isValidLuaIdentifier: (name: string, options: CompilerOptio
|
|
|
6
6
|
export declare const luaKeywords: ReadonlySet<string>;
|
|
7
7
|
export declare const isUnsafeName: (name: string, options: CompilerOptions) => boolean;
|
|
8
8
|
export declare function hasUnsafeSymbolName(context: TransformationContext, symbol: ts.Symbol, tsOriginal: ts.Identifier): boolean;
|
|
9
|
-
export declare function hasUnsafeIdentifierName(context: TransformationContext, identifier: ts.Identifier,
|
|
9
|
+
export declare function hasUnsafeIdentifierName(context: TransformationContext, identifier: ts.Identifier, symbol: ts.Symbol | undefined): boolean;
|
|
10
10
|
export declare const createSafeName: (name: string) => string;
|
|
@@ -80,12 +80,9 @@ function hasUnsafeSymbolName(context, symbol, tsOriginal) {
|
|
|
80
80
|
return (0, exports.isUnsafeName)(symbol.name, context.options) && !isAmbient && !(0, export_1.isSymbolExported)(context, symbol);
|
|
81
81
|
}
|
|
82
82
|
exports.hasUnsafeSymbolName = hasUnsafeSymbolName;
|
|
83
|
-
function hasUnsafeIdentifierName(context, identifier,
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
if (symbol) {
|
|
87
|
-
return hasUnsafeSymbolName(context, symbol, identifier);
|
|
88
|
-
}
|
|
83
|
+
function hasUnsafeIdentifierName(context, identifier, symbol) {
|
|
84
|
+
if (symbol) {
|
|
85
|
+
return hasUnsafeSymbolName(context, symbol, identifier);
|
|
89
86
|
}
|
|
90
87
|
return checkName(context, identifier.text, identifier);
|
|
91
88
|
}
|
|
@@ -36,8 +36,6 @@ export declare function walkScopesUp(context: TransformationContext): IterableIt
|
|
|
36
36
|
export declare function markSymbolAsReferencedInCurrentScopes(context: TransformationContext, symbolId: lua.SymbolId, identifier: ts.Identifier): void;
|
|
37
37
|
export declare function peekScope(context: TransformationContext): Scope;
|
|
38
38
|
export declare function findScope(context: TransformationContext, scopeTypes: ScopeType): Scope | undefined;
|
|
39
|
-
export declare function pushScope(context: TransformationContext, scopeType: ScopeType): Scope;
|
|
40
|
-
export declare function popScope(context: TransformationContext): Scope;
|
|
41
39
|
export declare function addScopeVariableDeclaration(scope: Scope, declaration: lua.VariableDeclarationStatement): void;
|
|
42
40
|
export declare function hasReferencedUndefinedLocalFunction(context: TransformationContext, scope: Scope): boolean;
|
|
43
41
|
export declare function hasReferencedSymbol(context: TransformationContext, scope: Scope, symbol: ts.Symbol): boolean | undefined;
|