typescript-to-lua 1.15.0 → 1.16.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.
Files changed (43) hide show
  1. package/dist/CompilerOptions.js +3 -3
  2. package/dist/LuaAST.js +2 -2
  3. package/dist/LuaLib.d.ts +1 -0
  4. package/dist/LuaLib.js +2 -1
  5. package/dist/LuaPrinter.js +1 -1
  6. package/dist/cli/tsconfig.js +14 -1
  7. package/dist/lualib/5.0/Decorate.lua +6 -24
  8. package/dist/lualib/5.0/DecorateLegacy.lua +36 -0
  9. package/dist/lualib/5.0/Map.lua +1 -1
  10. package/dist/lualib/5.0/Set.lua +1 -1
  11. package/dist/lualib/5.0/WeakMap.lua +1 -1
  12. package/dist/lualib/5.0/WeakSet.lua +1 -1
  13. package/dist/lualib/5.0/lualib_bundle.lua +25 -5
  14. package/dist/lualib/5.0/lualib_module_info.json +8 -0
  15. package/dist/lualib/universal/Decorate.lua +6 -24
  16. package/dist/lualib/universal/DecorateLegacy.lua +36 -0
  17. package/dist/lualib/universal/Map.lua +1 -1
  18. package/dist/lualib/universal/Set.lua +1 -1
  19. package/dist/lualib/universal/WeakMap.lua +1 -1
  20. package/dist/lualib/universal/WeakSet.lua +1 -1
  21. package/dist/lualib/universal/lualib_bundle.lua +25 -5
  22. package/dist/lualib/universal/lualib_module_info.json +8 -0
  23. package/dist/lualib-build/plugin.d.ts +1 -1
  24. package/dist/transformation/utils/annotations.js +1 -1
  25. package/dist/transformation/utils/diagnostics.d.ts +3 -0
  26. package/dist/transformation/utils/diagnostics.js +2 -1
  27. package/dist/transformation/utils/function-context.js +2 -2
  28. package/dist/transformation/utils/language-extensions.js +2 -2
  29. package/dist/transformation/utils/scope.js +1 -1
  30. package/dist/transformation/visitors/class/decorators.d.ts +5 -1
  31. package/dist/transformation/visitors/class/decorators.js +112 -4
  32. package/dist/transformation/visitors/class/index.js +32 -28
  33. package/dist/transformation/visitors/class/members/accessors.js +13 -4
  34. package/dist/transformation/visitors/class/members/fields.d.ts +0 -1
  35. package/dist/transformation/visitors/class/members/fields.js +1 -15
  36. package/dist/transformation/visitors/class/members/method.d.ts +0 -1
  37. package/dist/transformation/visitors/class/members/method.js +17 -23
  38. package/dist/transformation/visitors/class/utils.d.ts +1 -0
  39. package/dist/transformation/visitors/class/utils.js +6 -1
  40. package/dist/transformation/visitors/function.js +1 -1
  41. package/dist/transformation/visitors/identifier.js +1 -1
  42. package/dist/transformation/visitors/modules/export.js +2 -2
  43. package/package.json +3 -3
@@ -9,7 +9,7 @@ var LuaLibImportKind;
9
9
  LuaLibImportKind["Inline"] = "inline";
10
10
  LuaLibImportKind["Require"] = "require";
11
11
  LuaLibImportKind["RequireMinimal"] = "require-minimal";
12
- })(LuaLibImportKind = exports.LuaLibImportKind || (exports.LuaLibImportKind = {}));
12
+ })(LuaLibImportKind || (exports.LuaLibImportKind = LuaLibImportKind = {}));
13
13
  var LuaTarget;
14
14
  (function (LuaTarget) {
15
15
  LuaTarget["Universal"] = "universal";
@@ -19,12 +19,12 @@ var LuaTarget;
19
19
  LuaTarget["Lua53"] = "5.3";
20
20
  LuaTarget["Lua54"] = "5.4";
21
21
  LuaTarget["LuaJIT"] = "JIT";
22
- })(LuaTarget = exports.LuaTarget || (exports.LuaTarget = {}));
22
+ })(LuaTarget || (exports.LuaTarget = LuaTarget = {}));
23
23
  var BuildMode;
24
24
  (function (BuildMode) {
25
25
  BuildMode["Default"] = "default";
26
26
  BuildMode["Library"] = "library";
27
- })(BuildMode = exports.BuildMode || (exports.BuildMode = {}));
27
+ })(BuildMode || (exports.BuildMode = BuildMode = {}));
28
28
  const isBundleEnabled = (options) => options.luaBundle !== undefined && options.luaBundleEntry !== undefined;
29
29
  exports.isBundleEnabled = isBundleEnabled;
30
30
  function validateOptions(options) {
package/dist/LuaAST.js CHANGED
@@ -78,14 +78,14 @@ var SyntaxKind;
78
78
  SyntaxKind[SyntaxKind["BitwiseRightShiftOperator"] = 54] = "BitwiseRightShiftOperator";
79
79
  SyntaxKind[SyntaxKind["BitwiseLeftShiftOperator"] = 55] = "BitwiseLeftShiftOperator";
80
80
  SyntaxKind[SyntaxKind["BitwiseNotOperator"] = 56] = "BitwiseNotOperator";
81
- })(SyntaxKind = exports.SyntaxKind || (exports.SyntaxKind = {}));
81
+ })(SyntaxKind || (exports.SyntaxKind = SyntaxKind = {}));
82
82
  var NodeFlags;
83
83
  (function (NodeFlags) {
84
84
  NodeFlags[NodeFlags["None"] = 0] = "None";
85
85
  NodeFlags[NodeFlags["Inline"] = 1] = "Inline";
86
86
  NodeFlags[NodeFlags["Declaration"] = 2] = "Declaration";
87
87
  NodeFlags[NodeFlags["TableUnpackCall"] = 4] = "TableUnpackCall";
88
- })(NodeFlags = exports.NodeFlags || (exports.NodeFlags = {}));
88
+ })(NodeFlags || (exports.NodeFlags = NodeFlags = {}));
89
89
  function createNode(kind, tsOriginal) {
90
90
  if (tsOriginal === undefined) {
91
91
  return { kind, flags: NodeFlags.None };
package/dist/LuaLib.d.ts CHANGED
@@ -35,6 +35,7 @@ export declare enum LuaLibFeature {
35
35
  CloneDescriptor = "CloneDescriptor",
36
36
  CountVarargs = "CountVarargs",
37
37
  Decorate = "Decorate",
38
+ DecorateLegacy = "DecorateLegacy",
38
39
  DecorateParam = "DecorateParam",
39
40
  Delete = "Delete",
40
41
  DelegatedYield = "DelegatedYield",
package/dist/LuaLib.js CHANGED
@@ -40,6 +40,7 @@ var LuaLibFeature;
40
40
  LuaLibFeature["CloneDescriptor"] = "CloneDescriptor";
41
41
  LuaLibFeature["CountVarargs"] = "CountVarargs";
42
42
  LuaLibFeature["Decorate"] = "Decorate";
43
+ LuaLibFeature["DecorateLegacy"] = "DecorateLegacy";
43
44
  LuaLibFeature["DecorateParam"] = "DecorateParam";
44
45
  LuaLibFeature["Delete"] = "Delete";
45
46
  LuaLibFeature["DelegatedYield"] = "DelegatedYield";
@@ -107,7 +108,7 @@ var LuaLibFeature;
107
108
  LuaLibFeature["SymbolRegistry"] = "SymbolRegistry";
108
109
  LuaLibFeature["TypeOf"] = "TypeOf";
109
110
  LuaLibFeature["Unpack"] = "Unpack";
110
- })(LuaLibFeature = exports.LuaLibFeature || (exports.LuaLibFeature = {}));
111
+ })(LuaLibFeature || (exports.LuaLibFeature = LuaLibFeature = {}));
111
112
  function resolveLuaLibDir(luaTarget) {
112
113
  const luaLibDir = luaTarget === CompilerOptions_1.LuaTarget.Lua50 ? "5.0" : "universal";
113
114
  return path.resolve(__dirname, path.join("..", "dist", "lualib", luaLibDir));
@@ -675,6 +675,7 @@ class LuaPrinter {
675
675
  return map;
676
676
  }
677
677
  }
678
+ exports.LuaPrinter = LuaPrinter;
678
679
  LuaPrinter.operatorMap = {
679
680
  [lua.SyntaxKind.AdditionOperator]: "+",
680
681
  [lua.SyntaxKind.SubtractionOperator]: "-",
@@ -731,5 +732,4 @@ LuaPrinter.operatorPrecedence = {
731
732
  };
732
733
  LuaPrinter.rightAssociativeOperators = new Set([lua.SyntaxKind.ConcatOperator, lua.SyntaxKind.PowerOperator]);
733
734
  LuaPrinter.sourceMapTracebackPlaceholder = "{#SourceMapTraceback}";
734
- exports.LuaPrinter = LuaPrinter;
735
735
  //# sourceMappingURL=LuaPrinter.js.map
@@ -47,8 +47,21 @@ function parseConfigFileWithSystem(configFileName, commandLineOptions, system =
47
47
  return (0, parse_1.updateParsedConfigFile)(parsedConfigFile);
48
48
  }
49
49
  exports.parseConfigFileWithSystem = parseConfigFileWithSystem;
50
+ function resolveNpmModuleConfig(moduleName, configRootDir, host) {
51
+ const resolved = ts.nodeNextJsonConfigResolver(moduleName, path.join(configRootDir, "tsconfig.json"), host);
52
+ if (resolved.resolvedModule) {
53
+ return resolved.resolvedModule.resolvedFileName;
54
+ }
55
+ }
50
56
  function getExtendedTstlOptions(configFilePath, configRootDir, cycleCache, system) {
51
- const absolutePath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(configRootDir, configFilePath);
57
+ const absolutePath = ts.pathIsAbsolute(configFilePath)
58
+ ? configFilePath
59
+ : ts.pathIsRelative(configFilePath)
60
+ ? path.resolve(configRootDir, configFilePath)
61
+ : resolveNpmModuleConfig(configFilePath, configRootDir, system); // if a path is neither relative nor absolute, it is probably a npm module
62
+ if (!absolutePath) {
63
+ return {};
64
+ }
52
65
  const newConfigRoot = path.dirname(absolutePath);
53
66
  if (cycleCache.has(absolutePath)) {
54
67
  return {};
@@ -1,33 +1,15 @@
1
- local function __TS__Decorate(decorators, target, key, desc)
2
- local result = target
1
+ local function __TS__Decorate(self, originalValue, decorators, context)
2
+ local result = originalValue
3
3
  do
4
4
  local i = table.getn(decorators)
5
5
  while i >= 0 do
6
6
  local decorator = decorators[i + 1]
7
7
  if decorator ~= nil then
8
- local oldResult = result
9
- if key == nil then
10
- result = decorator(nil, result)
11
- elseif desc == true then
12
- local value = rawget(target, key)
13
- local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
14
- local desc = decorator(nil, target, key, descriptor) or descriptor
15
- local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
16
- if isSimpleValue then
17
- rawset(target, key, desc.value)
18
- else
19
- __TS__SetDescriptor(
20
- target,
21
- key,
22
- __TS__ObjectAssign({}, descriptor, desc)
23
- )
24
- end
25
- elseif desc == false then
26
- result = decorator(nil, target, key, desc)
27
- else
28
- result = decorator(nil, target, key)
8
+ local ____decorator_result_0 = decorator(self, result, context)
9
+ if ____decorator_result_0 == nil then
10
+ ____decorator_result_0 = result
29
11
  end
30
- result = result or oldResult
12
+ result = ____decorator_result_0
31
13
  end
32
14
  i = i - 1
33
15
  end
@@ -0,0 +1,36 @@
1
+ local function __TS__DecorateLegacy(decorators, target, key, desc)
2
+ local result = target
3
+ do
4
+ local i = table.getn(decorators)
5
+ while i >= 0 do
6
+ local decorator = decorators[i + 1]
7
+ if decorator ~= nil then
8
+ local oldResult = result
9
+ if key == nil then
10
+ result = decorator(nil, result)
11
+ elseif desc == true then
12
+ local value = rawget(target, key)
13
+ local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
14
+ local desc = decorator(nil, target, key, descriptor) or descriptor
15
+ local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
16
+ if isSimpleValue then
17
+ rawset(target, key, desc.value)
18
+ else
19
+ __TS__SetDescriptor(
20
+ target,
21
+ key,
22
+ __TS__ObjectAssign({}, descriptor, desc)
23
+ )
24
+ end
25
+ elseif desc == false then
26
+ result = decorator(nil, target, key, desc)
27
+ else
28
+ result = decorator(nil, target, key)
29
+ end
30
+ result = result or oldResult
31
+ end
32
+ i = i - 1
33
+ end
34
+ end
35
+ return result
36
+ end
@@ -29,6 +29,7 @@ do
29
29
  end
30
30
  end
31
31
  end
32
+ Map[Symbol.species] = Map
32
33
  function Map.prototype.clear(self)
33
34
  self.items = {}
34
35
  self.nextKey = {}
@@ -136,5 +137,4 @@ do
136
137
  end
137
138
  }
138
139
  end
139
- Map[Symbol.species] = Map
140
140
  end
@@ -27,6 +27,7 @@ do
27
27
  end
28
28
  end
29
29
  end
30
+ Set[Symbol.species] = Set
30
31
  function Set.prototype.add(self, value)
31
32
  local isNewValue = not self:has(value)
32
33
  if isNewValue then
@@ -126,5 +127,4 @@ do
126
127
  end
127
128
  }
128
129
  end
129
- Set[Symbol.species] = Set
130
130
  end
@@ -26,6 +26,7 @@ do
26
26
  end
27
27
  end
28
28
  end
29
+ WeakMap[Symbol.species] = WeakMap
29
30
  function WeakMap.prototype.delete(self, key)
30
31
  local contains = self:has(key)
31
32
  self.items[key] = nil
@@ -41,5 +42,4 @@ do
41
42
  self.items[key] = value
42
43
  return self
43
44
  end
44
- WeakMap[Symbol.species] = WeakMap
45
45
  end
@@ -25,6 +25,7 @@ do
25
25
  end
26
26
  end
27
27
  end
28
+ WeakSet[Symbol.species] = WeakSet
28
29
  function WeakSet.prototype.add(self, value)
29
30
  self.items[value] = true
30
31
  return self
@@ -37,5 +38,4 @@ do
37
38
  function WeakSet.prototype.has(self, value)
38
39
  return self.items[value] == true
39
40
  end
40
- WeakSet[Symbol.species] = WeakSet
41
41
  end
@@ -858,6 +858,25 @@ local function __TS__CloneDescriptor(____bindingPattern0)
858
858
  return descriptor
859
859
  end
860
860
 
861
+ local function __TS__Decorate(self, originalValue, decorators, context)
862
+ local result = originalValue
863
+ do
864
+ local i = table.getn(decorators)
865
+ while i >= 0 do
866
+ local decorator = decorators[i + 1]
867
+ if decorator ~= nil then
868
+ local ____decorator_result_0 = decorator(self, result, context)
869
+ if ____decorator_result_0 == nil then
870
+ ____decorator_result_0 = result
871
+ end
872
+ result = ____decorator_result_0
873
+ end
874
+ i = i - 1
875
+ end
876
+ end
877
+ return result
878
+ end
879
+
861
880
  local function __TS__ObjectAssign(target, ...)
862
881
  local sources = arg
863
882
  for i = 1, table.getn(sources) do
@@ -959,7 +978,7 @@ do
959
978
  end
960
979
  end
961
980
 
962
- local function __TS__Decorate(decorators, target, key, desc)
981
+ local function __TS__DecorateLegacy(decorators, target, key, desc)
963
982
  local result = target
964
983
  do
965
984
  local i = table.getn(decorators)
@@ -1259,6 +1278,7 @@ do
1259
1278
  end
1260
1279
  end
1261
1280
  end
1281
+ Map[Symbol.species] = Map
1262
1282
  function Map.prototype.clear(self)
1263
1283
  self.items = {}
1264
1284
  self.nextKey = {}
@@ -1366,7 +1386,6 @@ do
1366
1386
  end
1367
1387
  }
1368
1388
  end
1369
- Map[Symbol.species] = Map
1370
1389
  end
1371
1390
 
1372
1391
  local function __TS__StringSlice(self, start, ____end)
@@ -1883,6 +1902,7 @@ do
1883
1902
  end
1884
1903
  end
1885
1904
  end
1905
+ Set[Symbol.species] = Set
1886
1906
  function Set.prototype.add(self, value)
1887
1907
  local isNewValue = not self:has(value)
1888
1908
  if isNewValue then
@@ -1982,7 +2002,6 @@ do
1982
2002
  end
1983
2003
  }
1984
2004
  end
1985
- Set[Symbol.species] = Set
1986
2005
  end
1987
2006
 
1988
2007
  local function __TS__SparseArrayNew(...)
@@ -2033,6 +2052,7 @@ do
2033
2052
  end
2034
2053
  end
2035
2054
  end
2055
+ WeakMap[Symbol.species] = WeakMap
2036
2056
  function WeakMap.prototype.delete(self, key)
2037
2057
  local contains = self:has(key)
2038
2058
  self.items[key] = nil
@@ -2048,7 +2068,6 @@ do
2048
2068
  self.items[key] = value
2049
2069
  return self
2050
2070
  end
2051
- WeakMap[Symbol.species] = WeakMap
2052
2071
  end
2053
2072
 
2054
2073
  local WeakSet
@@ -2078,6 +2097,7 @@ do
2078
2097
  end
2079
2098
  end
2080
2099
  end
2100
+ WeakSet[Symbol.species] = WeakSet
2081
2101
  function WeakSet.prototype.add(self, value)
2082
2102
  self.items[value] = true
2083
2103
  return self
@@ -2090,7 +2110,6 @@ do
2090
2110
  function WeakSet.prototype.has(self, value)
2091
2111
  return self.items[value] == true
2092
2112
  end
2093
- WeakSet[Symbol.species] = WeakSet
2094
2113
  end
2095
2114
 
2096
2115
  local function __TS__SourceMapTraceBack(fileName, sourceMap)
@@ -2453,6 +2472,7 @@ return {
2453
2472
  __TS__CloneDescriptor = __TS__CloneDescriptor,
2454
2473
  __TS__CountVarargs = __TS__CountVarargs,
2455
2474
  __TS__Decorate = __TS__Decorate,
2475
+ __TS__DecorateLegacy = __TS__DecorateLegacy,
2456
2476
  __TS__DecorateParam = __TS__DecorateParam,
2457
2477
  __TS__Delete = __TS__Delete,
2458
2478
  __TS__DelegatedYield = __TS__DelegatedYield,
@@ -193,6 +193,11 @@
193
193
  "Decorate": {
194
194
  "exports": [
195
195
  "__TS__Decorate"
196
+ ]
197
+ },
198
+ "DecorateLegacy": {
199
+ "exports": [
200
+ "__TS__DecorateLegacy"
196
201
  ],
197
202
  "dependencies": [
198
203
  "ObjectAssign",
@@ -203,6 +208,9 @@
203
208
  "DecorateParam": {
204
209
  "exports": [
205
210
  "__TS__DecorateParam"
211
+ ],
212
+ "dependencies": [
213
+ "DecorateLegacy"
206
214
  ]
207
215
  },
208
216
  "Delete": {
@@ -1,33 +1,15 @@
1
- local function __TS__Decorate(decorators, target, key, desc)
2
- local result = target
1
+ local function __TS__Decorate(self, originalValue, decorators, context)
2
+ local result = originalValue
3
3
  do
4
4
  local i = #decorators
5
5
  while i >= 0 do
6
6
  local decorator = decorators[i + 1]
7
7
  if decorator ~= nil then
8
- local oldResult = result
9
- if key == nil then
10
- result = decorator(nil, result)
11
- elseif desc == true then
12
- local value = rawget(target, key)
13
- local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
14
- local desc = decorator(nil, target, key, descriptor) or descriptor
15
- local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
16
- if isSimpleValue then
17
- rawset(target, key, desc.value)
18
- else
19
- __TS__SetDescriptor(
20
- target,
21
- key,
22
- __TS__ObjectAssign({}, descriptor, desc)
23
- )
24
- end
25
- elseif desc == false then
26
- result = decorator(nil, target, key, desc)
27
- else
28
- result = decorator(nil, target, key)
8
+ local ____decorator_result_0 = decorator(self, result, context)
9
+ if ____decorator_result_0 == nil then
10
+ ____decorator_result_0 = result
29
11
  end
30
- result = result or oldResult
12
+ result = ____decorator_result_0
31
13
  end
32
14
  i = i - 1
33
15
  end
@@ -0,0 +1,36 @@
1
+ local function __TS__DecorateLegacy(decorators, target, key, desc)
2
+ local result = target
3
+ do
4
+ local i = #decorators
5
+ while i >= 0 do
6
+ local decorator = decorators[i + 1]
7
+ if decorator ~= nil then
8
+ local oldResult = result
9
+ if key == nil then
10
+ result = decorator(nil, result)
11
+ elseif desc == true then
12
+ local value = rawget(target, key)
13
+ local descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) or ({configurable = true, writable = true, value = value})
14
+ local desc = decorator(nil, target, key, descriptor) or descriptor
15
+ local isSimpleValue = desc.configurable == true and desc.writable == true and not desc.get and not desc.set
16
+ if isSimpleValue then
17
+ rawset(target, key, desc.value)
18
+ else
19
+ __TS__SetDescriptor(
20
+ target,
21
+ key,
22
+ __TS__ObjectAssign({}, descriptor, desc)
23
+ )
24
+ end
25
+ elseif desc == false then
26
+ result = decorator(nil, target, key, desc)
27
+ else
28
+ result = decorator(nil, target, key)
29
+ end
30
+ result = result or oldResult
31
+ end
32
+ i = i - 1
33
+ end
34
+ end
35
+ return result
36
+ end
@@ -29,6 +29,7 @@ do
29
29
  end
30
30
  end
31
31
  end
32
+ Map[Symbol.species] = Map
32
33
  function Map.prototype.clear(self)
33
34
  self.items = {}
34
35
  self.nextKey = {}
@@ -136,5 +137,4 @@ do
136
137
  end
137
138
  }
138
139
  end
139
- Map[Symbol.species] = Map
140
140
  end
@@ -27,6 +27,7 @@ do
27
27
  end
28
28
  end
29
29
  end
30
+ Set[Symbol.species] = Set
30
31
  function Set.prototype.add(self, value)
31
32
  local isNewValue = not self:has(value)
32
33
  if isNewValue then
@@ -126,5 +127,4 @@ do
126
127
  end
127
128
  }
128
129
  end
129
- Set[Symbol.species] = Set
130
130
  end
@@ -26,6 +26,7 @@ do
26
26
  end
27
27
  end
28
28
  end
29
+ WeakMap[Symbol.species] = WeakMap
29
30
  function WeakMap.prototype.delete(self, key)
30
31
  local contains = self:has(key)
31
32
  self.items[key] = nil
@@ -41,5 +42,4 @@ do
41
42
  self.items[key] = value
42
43
  return self
43
44
  end
44
- WeakMap[Symbol.species] = WeakMap
45
45
  end
@@ -25,6 +25,7 @@ do
25
25
  end
26
26
  end
27
27
  end
28
+ WeakSet[Symbol.species] = WeakSet
28
29
  function WeakSet.prototype.add(self, value)
29
30
  self.items[value] = true
30
31
  return self
@@ -37,5 +38,4 @@ do
37
38
  function WeakSet.prototype.has(self, value)
38
39
  return self.items[value] == true
39
40
  end
40
- WeakSet[Symbol.species] = WeakSet
41
41
  end
@@ -859,6 +859,25 @@ local function __TS__CloneDescriptor(____bindingPattern0)
859
859
  return descriptor
860
860
  end
861
861
 
862
+ local function __TS__Decorate(self, originalValue, decorators, context)
863
+ local result = originalValue
864
+ do
865
+ local i = #decorators
866
+ while i >= 0 do
867
+ local decorator = decorators[i + 1]
868
+ if decorator ~= nil then
869
+ local ____decorator_result_0 = decorator(self, result, context)
870
+ if ____decorator_result_0 == nil then
871
+ ____decorator_result_0 = result
872
+ end
873
+ result = ____decorator_result_0
874
+ end
875
+ i = i - 1
876
+ end
877
+ end
878
+ return result
879
+ end
880
+
862
881
  local function __TS__ObjectAssign(target, ...)
863
882
  local sources = {...}
864
883
  for i = 1, #sources do
@@ -960,7 +979,7 @@ do
960
979
  end
961
980
  end
962
981
 
963
- local function __TS__Decorate(decorators, target, key, desc)
982
+ local function __TS__DecorateLegacy(decorators, target, key, desc)
964
983
  local result = target
965
984
  do
966
985
  local i = #decorators
@@ -1235,6 +1254,7 @@ do
1235
1254
  end
1236
1255
  end
1237
1256
  end
1257
+ Map[Symbol.species] = Map
1238
1258
  function Map.prototype.clear(self)
1239
1259
  self.items = {}
1240
1260
  self.nextKey = {}
@@ -1342,7 +1362,6 @@ do
1342
1362
  end
1343
1363
  }
1344
1364
  end
1345
- Map[Symbol.species] = Map
1346
1365
  end
1347
1366
 
1348
1367
  local __TS__Match = string.match
@@ -1819,6 +1838,7 @@ do
1819
1838
  end
1820
1839
  end
1821
1840
  end
1841
+ Set[Symbol.species] = Set
1822
1842
  function Set.prototype.add(self, value)
1823
1843
  local isNewValue = not self:has(value)
1824
1844
  if isNewValue then
@@ -1918,7 +1938,6 @@ do
1918
1938
  end
1919
1939
  }
1920
1940
  end
1921
- Set[Symbol.species] = Set
1922
1941
  end
1923
1942
 
1924
1943
  local function __TS__SparseArrayNew(...)
@@ -1970,6 +1989,7 @@ do
1970
1989
  end
1971
1990
  end
1972
1991
  end
1992
+ WeakMap[Symbol.species] = WeakMap
1973
1993
  function WeakMap.prototype.delete(self, key)
1974
1994
  local contains = self:has(key)
1975
1995
  self.items[key] = nil
@@ -1985,7 +2005,6 @@ do
1985
2005
  self.items[key] = value
1986
2006
  return self
1987
2007
  end
1988
- WeakMap[Symbol.species] = WeakMap
1989
2008
  end
1990
2009
 
1991
2010
  local WeakSet
@@ -2015,6 +2034,7 @@ do
2015
2034
  end
2016
2035
  end
2017
2036
  end
2037
+ WeakSet[Symbol.species] = WeakSet
2018
2038
  function WeakSet.prototype.add(self, value)
2019
2039
  self.items[value] = true
2020
2040
  return self
@@ -2027,7 +2047,6 @@ do
2027
2047
  function WeakSet.prototype.has(self, value)
2028
2048
  return self.items[value] == true
2029
2049
  end
2030
- WeakSet[Symbol.species] = WeakSet
2031
2050
  end
2032
2051
 
2033
2052
  local function __TS__SourceMapTraceBack(fileName, sourceMap)
@@ -2398,6 +2417,7 @@ return {
2398
2417
  __TS__CloneDescriptor = __TS__CloneDescriptor,
2399
2418
  __TS__CountVarargs = __TS__CountVarargs,
2400
2419
  __TS__Decorate = __TS__Decorate,
2420
+ __TS__DecorateLegacy = __TS__DecorateLegacy,
2401
2421
  __TS__DecorateParam = __TS__DecorateParam,
2402
2422
  __TS__Delete = __TS__Delete,
2403
2423
  __TS__DelegatedYield = __TS__DelegatedYield,
@@ -193,6 +193,11 @@
193
193
  "Decorate": {
194
194
  "exports": [
195
195
  "__TS__Decorate"
196
+ ]
197
+ },
198
+ "DecorateLegacy": {
199
+ "exports": [
200
+ "__TS__DecorateLegacy"
196
201
  ],
197
202
  "dependencies": [
198
203
  "ObjectAssign",
@@ -203,6 +208,9 @@
203
208
  "DecorateParam": {
204
209
  "exports": [
205
210
  "__TS__DecorateParam"
211
+ ],
212
+ "dependencies": [
213
+ "DecorateLegacy"
206
214
  ]
207
215
  },
208
216
  "Delete": {
@@ -7,7 +7,7 @@ export declare const lualibDiagnostic: ((message: string, file?: ts.SourceFile |
7
7
  };
8
8
  declare class LuaLibPlugin implements tstl.Plugin {
9
9
  visitors: {
10
- 308: (file: ts.SourceFile, context: tstl.TransformationContext) => tstl.File;
10
+ 311: (file: ts.SourceFile, context: tstl.TransformationContext) => tstl.File;
11
11
  };
12
12
  printer: tstl.Printer;
13
13
  afterPrint(program: ts.Program, options: tstl.CompilerOptions, emitHost: EmitHost, result: ProcessedFile[]): ts.Diagnostic[];
@@ -9,7 +9,7 @@ var AnnotationKind;
9
9
  AnnotationKind["NoResolution"] = "noResolution";
10
10
  AnnotationKind["NoSelf"] = "noSelf";
11
11
  AnnotationKind["NoSelfInFile"] = "noSelfInFile";
12
- })(AnnotationKind = exports.AnnotationKind || (exports.AnnotationKind = {}));
12
+ })(AnnotationKind || (exports.AnnotationKind = AnnotationKind = {}));
13
13
  const annotationValues = new Map(Object.values(AnnotationKind).map(k => [k.toLowerCase(), k]));
14
14
  function collectAnnotations(source, annotationsMap) {
15
15
  var _a, _b;
@@ -101,3 +101,6 @@ export declare const invalidSpreadInCallExtension: ((node: ts.Node, ...args: any
101
101
  export declare const cannotAssignToNodeOfKind: ((node: ts.Node, kind: lua.SyntaxKind) => ts.Diagnostic) & {
102
102
  code: number;
103
103
  };
104
+ export declare const incompleteFieldDecoratorWarning: ((node: ts.Node, ...args: any[]) => ts.Diagnostic) & {
105
+ code: number;
106
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
3
+ exports.incompleteFieldDecoratorWarning = exports.cannotAssignToNodeOfKind = exports.invalidSpreadInCallExtension = exports.invalidMethodCallExtensionUse = exports.undefinedInArrayLiteral = exports.unsupportedOptionalCompileMembersOnly = exports.unsupportedBuiltinOptionalCall = exports.awaitMustBeInAsyncFunction = exports.notAllowedOptionalAssignment = exports.truthyOnlyConditionalValue = exports.annotationDeprecated = exports.invalidCallExtensionUse = exports.invalidMultiReturnAccess = exports.invalidMultiFunctionReturnType = exports.invalidMultiFunctionUse = exports.unsupportedVarDeclaration = exports.invalidAmbientIdentifierName = exports.unsupportedProperty = exports.unsupportedForTargetButOverrideAvailable = exports.unsupportedForTarget = exports.unsupportedRightShiftOperator = exports.unsupportedAccessorInObjectLiteral = exports.invalidPairsIterableWithoutDestructuring = exports.invalidMultiIterableWithoutDestructuring = exports.invalidRangeControlVariable = exports.invalidVarargUse = exports.invalidRangeUse = exports.annotationInvalidArgumentCount = exports.decoratorInvalidContext = exports.unsupportedOverloadAssignment = exports.unsupportedSelfFunctionConversion = exports.unsupportedNoSelfFunctionConversion = exports.forbiddenForIn = exports.unsupportedNodeKind = void 0;
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../LuaAST");
6
6
  const CompilerOptions_1 = require("../../CompilerOptions");
@@ -63,4 +63,5 @@ exports.undefinedInArrayLiteral = createErrorDiagnosticFactory("Array literals m
63
63
  exports.invalidMethodCallExtensionUse = createErrorDiagnosticFactory("This language extension must be called as a method.");
64
64
  exports.invalidSpreadInCallExtension = createErrorDiagnosticFactory("Spread elements are not supported in call extensions.");
65
65
  exports.cannotAssignToNodeOfKind = createErrorDiagnosticFactory((kind) => `Cannot create assignment assigning to a node of type ${lua.SyntaxKind[kind]}.`);
66
+ exports.incompleteFieldDecoratorWarning = createWarningDiagnosticFactory("You are using a class field decorator, note that tstl ignores returned value initializers!");
66
67
  //# sourceMappingURL=diagnostics.js.map
@@ -10,7 +10,7 @@ var ContextType;
10
10
  ContextType[ContextType["Void"] = 1] = "Void";
11
11
  ContextType[ContextType["NonVoid"] = 2] = "NonVoid";
12
12
  ContextType[ContextType["Mixed"] = 3] = "Mixed";
13
- })(ContextType = exports.ContextType || (exports.ContextType = {}));
13
+ })(ContextType || (exports.ContextType = ContextType = {}));
14
14
  function hasNoSelfAncestor(declaration) {
15
15
  const scopeDeclaration = (0, typescript_1.findFirstNodeAbove)(declaration, (node) => ts.isSourceFile(node) || ts.isModuleDeclaration(node));
16
16
  if (!scopeDeclaration) {
@@ -28,7 +28,7 @@ function hasNoSelfAncestor(declaration) {
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) {
31
+ if (param && ts.isIdentifier(param.name) && ts.identifierToKeywordKind(param.name) === ts.SyntaxKind.ThisKeyword) {
32
32
  return param;
33
33
  }
34
34
  }
@@ -55,7 +55,7 @@ var ExtensionKind;
55
55
  ExtensionKind["TableSetMethodType"] = "TableSetMethod";
56
56
  ExtensionKind["TableAddKeyType"] = "TableAddKey";
57
57
  ExtensionKind["TableAddKeyMethodType"] = "TableAddKeyMethod";
58
- })(ExtensionKind = exports.ExtensionKind || (exports.ExtensionKind = {}));
58
+ })(ExtensionKind || (exports.ExtensionKind = ExtensionKind = {}));
59
59
  const extensionValues = new Set(Object.values(ExtensionKind));
60
60
  function getExtensionKindForType(context, type) {
61
61
  const value = getPropertyValue(context, type, "__tstlExtension");
@@ -96,7 +96,7 @@ var IterableExtensionKind;
96
96
  IterableExtensionKind["Iterable"] = "Iterable";
97
97
  IterableExtensionKind["Pairs"] = "Pairs";
98
98
  IterableExtensionKind["PairsKey"] = "PairsKey";
99
- })(IterableExtensionKind = exports.IterableExtensionKind || (exports.IterableExtensionKind = {}));
99
+ })(IterableExtensionKind || (exports.IterableExtensionKind = IterableExtensionKind = {}));
100
100
  function isLuaIterable(context, type) {
101
101
  return getPropertyValue(context, type, "__tstlIterable") !== undefined;
102
102
  }
@@ -17,7 +17,7 @@ var ScopeType;
17
17
  ScopeType[ScopeType["Try"] = 64] = "Try";
18
18
  ScopeType[ScopeType["Catch"] = 128] = "Catch";
19
19
  ScopeType[ScopeType["LoopInitializer"] = 256] = "LoopInitializer";
20
- })(ScopeType = exports.ScopeType || (exports.ScopeType = {}));
20
+ })(ScopeType || (exports.ScopeType = ScopeType = {}));
21
21
  function* walkScopesUp(context) {
22
22
  const scopeStack = context.scopeStack;
23
23
  for (let i = scopeStack.length - 1; i >= 0; --i) {
@@ -2,4 +2,8 @@ import * as ts from "typescript";
2
2
  import * as lua from "../../../LuaAST";
3
3
  import { TransformationContext } from "../../context";
4
4
  export declare function transformDecoratorExpression(context: TransformationContext, decorator: ts.Decorator): lua.Expression;
5
- export declare function createDecoratingExpression(context: TransformationContext, kind: ts.SyntaxKind, decorators: lua.Expression[], targetTableName: lua.Expression, targetFieldExpression?: lua.Expression): lua.Expression;
5
+ export declare function createClassDecoratingExpression(context: TransformationContext, classDeclaration: ts.ClassDeclaration | ts.ClassExpression, className: lua.Expression): lua.Expression;
6
+ export declare function createClassMethodDecoratingExpression(context: TransformationContext, methodDeclaration: ts.MethodDeclaration, originalMethod: lua.Expression, className: lua.Identifier): lua.Expression;
7
+ export declare function createClassAccessorDecoratingExpression(context: TransformationContext, accessor: ts.AccessorDeclaration, originalAccessor: lua.Expression, className: lua.Identifier): lua.Expression;
8
+ export declare function createClassPropertyDecoratingExpression(context: TransformationContext, property: ts.PropertyDeclaration, className: lua.Identifier): lua.Expression;
9
+ export declare function createConstructorDecoratingExpression(context: TransformationContext, node: ts.ConstructorDeclaration, className: lua.Identifier): lua.Statement | undefined;
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDecoratingExpression = exports.transformDecoratorExpression = void 0;
3
+ exports.createConstructorDecoratingExpression = exports.createClassPropertyDecoratingExpression = exports.createClassAccessorDecoratingExpression = exports.createClassMethodDecoratingExpression = exports.createClassDecoratingExpression = exports.transformDecoratorExpression = void 0;
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../../LuaAST");
6
6
  const diagnostics_1 = require("../../utils/diagnostics");
7
7
  const function_context_1 = require("../../utils/function-context");
8
8
  const lualib_1 = require("../../utils/lualib");
9
+ const utils_1 = require("../../../utils");
10
+ const method_1 = require("./members/method");
11
+ const literal_1 = require("../literal");
12
+ const utils_2 = require("./utils");
9
13
  function transformDecoratorExpression(context, decorator) {
10
14
  const expression = decorator.expression;
11
15
  const type = context.checker.getTypeAtLocation(expression);
@@ -16,7 +20,95 @@ function transformDecoratorExpression(context, decorator) {
16
20
  return context.transformExpression(expression);
17
21
  }
18
22
  exports.transformDecoratorExpression = transformDecoratorExpression;
19
- function createDecoratingExpression(context, kind, decorators, targetTableName, targetFieldExpression) {
23
+ function createClassDecoratingExpression(context, classDeclaration, className) {
24
+ var _a, _b, _c, _d;
25
+ const classDecorators = (_b = (_a = ts.getDecorators(classDeclaration)) === null || _a === void 0 ? void 0 : _a.map(d => transformDecoratorExpression(context, d))) !== null && _b !== void 0 ? _b : [];
26
+ // If experimentalDecorators flag is set, decorate with legacy decorator logic
27
+ if (context.options.experimentalDecorators) {
28
+ return createLegacyDecoratingExpression(context, classDeclaration.kind, classDecorators, className);
29
+ }
30
+ // Else: TypeScript 5.0 decorator
31
+ return createDecoratingExpression(context, className, className, classDecorators, {
32
+ kind: lua.createStringLiteral("class"),
33
+ name: lua.createStringLiteral((_d = (_c = classDeclaration.name) === null || _c === void 0 ? void 0 : _c.getText()) !== null && _d !== void 0 ? _d : ""),
34
+ });
35
+ }
36
+ exports.createClassDecoratingExpression = createClassDecoratingExpression;
37
+ function createClassMethodDecoratingExpression(context, methodDeclaration, originalMethod, className) {
38
+ var _a, _b;
39
+ const parameterDecorators = getParameterDecorators(context, methodDeclaration);
40
+ const methodDecorators = (_b = (_a = ts.getDecorators(methodDeclaration)) === null || _a === void 0 ? void 0 : _a.map(d => transformDecoratorExpression(context, d))) !== null && _b !== void 0 ? _b : [];
41
+ const methodName = (0, method_1.transformMethodName)(context, methodDeclaration);
42
+ // If experimentalDecorators flag is set, decorate with legacy decorator logic
43
+ if (context.options.experimentalDecorators) {
44
+ const methodTable = (0, method_1.transformMemberExpressionOwnerName)(methodDeclaration, className);
45
+ return createLegacyDecoratingExpression(context, methodDeclaration.kind, [...methodDecorators, ...parameterDecorators], methodTable, methodName);
46
+ }
47
+ // Else: TypeScript 5.0 decorator
48
+ return createDecoratingExpression(context, className, originalMethod, methodDecorators, {
49
+ kind: lua.createStringLiteral("method"),
50
+ name: methodName,
51
+ private: lua.createBooleanLiteral((0, utils_2.isPrivateNode)(methodDeclaration)),
52
+ static: lua.createBooleanLiteral((0, utils_2.isStaticNode)(methodDeclaration)),
53
+ });
54
+ }
55
+ exports.createClassMethodDecoratingExpression = createClassMethodDecoratingExpression;
56
+ function createClassAccessorDecoratingExpression(context, accessor, originalAccessor, className) {
57
+ var _a, _b;
58
+ const accessorDecorators = (_b = (_a = ts.getDecorators(accessor)) === null || _a === void 0 ? void 0 : _a.map(d => transformDecoratorExpression(context, d))) !== null && _b !== void 0 ? _b : [];
59
+ const propertyName = (0, literal_1.transformPropertyName)(context, accessor.name);
60
+ // If experimentalDecorators flag is set, decorate with legacy decorator logic
61
+ if (context.options.experimentalDecorators) {
62
+ const propertyOwnerTable = (0, method_1.transformMemberExpressionOwnerName)(accessor, className);
63
+ return createLegacyDecoratingExpression(context, accessor.kind, accessorDecorators, propertyOwnerTable, propertyName);
64
+ }
65
+ // Else: TypeScript 5.0 decorator
66
+ return createDecoratingExpression(context, className, originalAccessor, accessorDecorators, {
67
+ kind: lua.createStringLiteral(accessor.kind === ts.SyntaxKind.SetAccessor ? "setter" : "getter"),
68
+ name: propertyName,
69
+ private: lua.createBooleanLiteral((0, utils_2.isPrivateNode)(accessor)),
70
+ static: lua.createBooleanLiteral((0, utils_2.isStaticNode)(accessor)),
71
+ });
72
+ }
73
+ exports.createClassAccessorDecoratingExpression = createClassAccessorDecoratingExpression;
74
+ function createClassPropertyDecoratingExpression(context, property, className) {
75
+ var _a;
76
+ const decorators = (_a = ts.getDecorators(property)) !== null && _a !== void 0 ? _a : [];
77
+ const propertyDecorators = decorators.map(d => transformDecoratorExpression(context, d));
78
+ // If experimentalDecorators flag is set, decorate with legacy decorator logic
79
+ if (context.options.experimentalDecorators) {
80
+ const propertyName = (0, literal_1.transformPropertyName)(context, property.name);
81
+ const propertyOwnerTable = (0, method_1.transformMemberExpressionOwnerName)(property, className);
82
+ return createLegacyDecoratingExpression(context, property.kind, propertyDecorators, propertyOwnerTable, propertyName);
83
+ }
84
+ // Else: TypeScript 5.0 decorator
85
+ // Add a diagnostic when something is returned from a field decorator
86
+ for (const decorator of decorators) {
87
+ const signature = context.checker.getResolvedSignature(decorator);
88
+ const decoratorReturnType = signature === null || signature === void 0 ? void 0 : signature.getReturnType();
89
+ // If return type of decorator is NOT void
90
+ if (decoratorReturnType && (decoratorReturnType.flags & ts.TypeFlags.Void) === 0) {
91
+ context.diagnostics.push((0, diagnostics_1.incompleteFieldDecoratorWarning)(property));
92
+ }
93
+ }
94
+ return createDecoratingExpression(context, className, lua.createNilLiteral(), propertyDecorators, {
95
+ kind: lua.createStringLiteral("field"),
96
+ name: lua.createStringLiteral(property.name.getText()),
97
+ private: lua.createBooleanLiteral((0, utils_2.isPrivateNode)(property)),
98
+ static: lua.createBooleanLiteral((0, utils_2.isStaticNode)(property)),
99
+ });
100
+ }
101
+ exports.createClassPropertyDecoratingExpression = createClassPropertyDecoratingExpression;
102
+ function createDecoratingExpression(context, className, originalValue, decorators, decoratorContext) {
103
+ const decoratorTable = lua.createTableExpression(decorators.map(d => lua.createTableFieldExpression(d)));
104
+ const decoratorContextTable = objectToLuaTableLiteral(decoratorContext);
105
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Decorate, undefined, className, originalValue, decoratorTable, decoratorContextTable);
106
+ }
107
+ function objectToLuaTableLiteral(obj) {
108
+ return lua.createTableExpression(Object.entries(obj).map(([key, value]) => lua.createTableFieldExpression(value, lua.createStringLiteral(key))));
109
+ }
110
+ // Legacy decorators:
111
+ function createLegacyDecoratingExpression(context, kind, decorators, targetTableName, targetFieldExpression) {
20
112
  const decoratorTable = lua.createTableExpression(decorators.map(e => lua.createTableFieldExpression(e)));
21
113
  const trailingExpressions = [decoratorTable, targetTableName];
22
114
  if (targetFieldExpression) {
@@ -26,7 +118,23 @@ function createDecoratingExpression(context, kind, decorators, targetTableName,
26
118
  kind === ts.SyntaxKind.SetAccessor;
27
119
  trailingExpressions.push(isMethodOrAccessor ? lua.createBooleanLiteral(true) : lua.createNilLiteral());
28
120
  }
29
- return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.Decorate, undefined, ...trailingExpressions);
121
+ return (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DecorateLegacy, undefined, ...trailingExpressions);
122
+ }
123
+ function getParameterDecorators(context, node) {
124
+ return node.parameters
125
+ .flatMap((parameter, index) => {
126
+ var _a;
127
+ return (_a = ts
128
+ .getDecorators(parameter)) === null || _a === void 0 ? void 0 : _a.map(decorator => (0, lualib_1.transformLuaLibFunction)(context, lualib_1.LuaLibFeature.DecorateParam, node, lua.createNumericLiteral(index), transformDecoratorExpression(context, decorator)));
129
+ })
130
+ .filter(utils_1.isNonNull);
131
+ }
132
+ function createConstructorDecoratingExpression(context, node, className) {
133
+ const parameterDecorators = getParameterDecorators(context, node);
134
+ if (parameterDecorators.length > 0) {
135
+ const decorateMethod = createLegacyDecoratingExpression(context, node.kind, parameterDecorators, className);
136
+ return lua.createExpressionStatement(decorateMethod);
137
+ }
30
138
  }
31
- exports.createDecoratingExpression = createDecoratingExpression;
139
+ exports.createConstructorDecoratingExpression = createConstructorDecoratingExpression;
32
140
  //# sourceMappingURL=decorators.js.map
@@ -16,6 +16,7 @@ const utils_1 = require("./utils");
16
16
  const setup_1 = require("./setup");
17
17
  const CompilerOptions_1 = require("../../../CompilerOptions");
18
18
  const preceding_statements_1 = require("../../utils/preceding-statements");
19
+ const decorators_2 = require("./decorators");
19
20
  const transformClassDeclaration = (declaration, context) => {
20
21
  // If declaration is a default export, transform to export variable assignment instead
21
22
  if ((0, export_1.hasDefaultExportModifier)(declaration)) {
@@ -39,7 +40,7 @@ function transformClassAsExpression(expression, context) {
39
40
  }
40
41
  exports.transformClassAsExpression = transformClassAsExpression;
41
42
  function transformClassLikeDeclaration(classDeclaration, context, nameOverride) {
42
- var _a, _b;
43
+ var _a;
43
44
  let className;
44
45
  if (nameOverride !== undefined) {
45
46
  className = nameOverride;
@@ -75,6 +76,10 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
75
76
  const constructorResult = (0, constructor_1.transformConstructorDeclaration)(context, constructor, localClassName, instanceFields, classDeclaration);
76
77
  if (constructorResult)
77
78
  result.push(constructorResult);
79
+ // Legacy constructor decorator
80
+ const decoratingExpression = (0, decorators_1.createConstructorDecoratingExpression)(context, constructor, localClassName);
81
+ if (decoratingExpression)
82
+ result.push(decoratingExpression);
78
83
  }
79
84
  else if (!extendedType) {
80
85
  // Generate a constructor if none was defined in a base class
@@ -96,50 +101,49 @@ function transformClassLikeDeclaration(classDeclaration, context, nameOverride)
96
101
  const constructorFunction = lua.createFunctionExpression(lua.createBlock(constructorBody), [(0, lua_ast_1.createSelfIdentifier)()], lua.createDotsLiteral(), lua.NodeFlags.Declaration);
97
102
  result.push(lua.createAssignmentStatement((0, constructor_1.createConstructorName)(localClassName), constructorFunction, classDeclaration));
98
103
  }
99
- // Transform accessors
100
- for (const member of classDeclaration.members) {
101
- if (!ts.isAccessor(member))
102
- continue;
103
- const accessors = context.resolver.getAllAccessorDeclarations(member);
104
- if (accessors.firstAccessor !== member)
105
- continue;
106
- const accessorsResult = (0, accessors_1.transformAccessorDeclarations)(context, accessors, localClassName);
107
- if (accessorsResult) {
108
- result.push(accessorsResult);
109
- }
110
- }
111
- const decorationStatements = [];
104
+ // Transform class members
112
105
  for (const member of classDeclaration.members) {
113
106
  if (ts.isAccessor(member)) {
114
- const expression = (0, fields_1.createPropertyDecoratingExpression)(context, member, localClassName);
115
- if (expression)
116
- decorationStatements.push(lua.createExpressionStatement(expression));
107
+ // Accessors
108
+ const accessors = context.resolver.getAllAccessorDeclarations(member);
109
+ if (accessors.firstAccessor !== member)
110
+ continue;
111
+ const accessorsResult = (0, accessors_1.transformAccessorDeclarations)(context, accessors, localClassName);
112
+ if (accessorsResult) {
113
+ result.push(accessorsResult);
114
+ }
117
115
  }
118
116
  else if (ts.isMethodDeclaration(member)) {
117
+ // Methods
119
118
  const statement = (0, method_1.transformMethodDeclaration)(context, member, localClassName);
120
119
  if (statement)
121
120
  result.push(statement);
122
- if (member.body) {
123
- const statement = (0, method_1.createMethodDecoratingExpression)(context, member, localClassName);
124
- if (statement)
125
- decorationStatements.push(statement);
126
- }
127
121
  }
128
122
  else if (ts.isPropertyDeclaration(member)) {
123
+ // Properties
129
124
  if ((0, utils_1.isStaticNode)(member)) {
130
125
  const statement = (0, fields_1.transformStaticPropertyDeclaration)(context, member, localClassName);
131
126
  if (statement)
132
- decorationStatements.push(statement);
127
+ result.push(statement);
128
+ }
129
+ if ((_a = ts.getDecorators(member)) === null || _a === void 0 ? void 0 : _a.length) {
130
+ result.push(lua.createExpressionStatement((0, decorators_2.createClassPropertyDecoratingExpression)(context, member, className)));
131
+ }
132
+ }
133
+ else if (ts.isClassStaticBlockDeclaration(member)) {
134
+ if (member.body.statements.length > 0) {
135
+ const bodyStatements = context.transformStatements(member.body.statements);
136
+ const iif = lua.createFunctionExpression(lua.createBlock(bodyStatements), [
137
+ lua.createIdentifier("self"),
138
+ ]);
139
+ const iife = lua.createCallExpression(iif, [className]);
140
+ result.push(lua.createExpressionStatement(iife, member));
133
141
  }
134
- const expression = (0, fields_1.createPropertyDecoratingExpression)(context, member, localClassName);
135
- if (expression)
136
- decorationStatements.push(lua.createExpressionStatement(expression));
137
142
  }
138
143
  }
139
- result.push(...decorationStatements);
140
144
  // Decorate the class
141
145
  if (ts.canHaveDecorators(classDeclaration) && ts.getDecorators(classDeclaration)) {
142
- const decoratingExpression = (0, decorators_1.createDecoratingExpression)(context, classDeclaration.kind, (_b = (_a = ts.getDecorators(classDeclaration)) === null || _a === void 0 ? void 0 : _a.map(d => (0, decorators_1.transformDecoratorExpression)(context, d))) !== null && _b !== void 0 ? _b : [], localClassName);
146
+ const decoratingExpression = (0, decorators_1.createClassDecoratingExpression)(context, classDeclaration, localClassName);
143
147
  const decoratingStatement = lua.createAssignmentStatement(localClassName, decoratingExpression);
144
148
  result.push(decoratingStatement);
145
149
  if ((0, export_1.hasExportModifier)(classDeclaration)) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformAccessorDeclarations = void 0;
4
+ const ts = require("typescript");
4
5
  const lua = require("../../../../LuaAST");
5
6
  const lua_ast_1 = require("../../../utils/lua-ast");
6
7
  const lualib_1 = require("../../../utils/lualib");
@@ -8,20 +9,28 @@ const function_1 = require("../../function");
8
9
  const literal_1 = require("../../literal");
9
10
  const utils_1 = require("../utils");
10
11
  const constructor_1 = require("./constructor");
11
- function transformAccessor(context, node) {
12
+ const decorators_1 = require("../decorators");
13
+ function transformAccessor(context, node, className) {
14
+ var _a;
12
15
  const [params, dot, restParam] = (0, function_1.transformParameters)(context, node.parameters, (0, lua_ast_1.createSelfIdentifier)());
13
16
  const body = node.body ? (0, function_1.transformFunctionBody)(context, node.parameters, node.body, restParam)[0] : [];
14
- return lua.createFunctionExpression(lua.createBlock(body), params, dot, lua.NodeFlags.Declaration);
17
+ const accessorFunction = lua.createFunctionExpression(lua.createBlock(body), params, dot, lua.NodeFlags.Declaration);
18
+ if ((_a = ts.getDecorators(node)) === null || _a === void 0 ? void 0 : _a.length) {
19
+ return (0, decorators_1.createClassAccessorDecoratingExpression)(context, node, accessorFunction, className);
20
+ }
21
+ else {
22
+ return accessorFunction;
23
+ }
15
24
  }
16
25
  function transformAccessorDeclarations(context, { firstAccessor, getAccessor, setAccessor }, className) {
17
26
  const propertyName = (0, literal_1.transformPropertyName)(context, firstAccessor.name);
18
27
  const descriptor = lua.createTableExpression([]);
19
28
  if (getAccessor) {
20
- const getterFunction = transformAccessor(context, getAccessor);
29
+ const getterFunction = transformAccessor(context, getAccessor, className);
21
30
  descriptor.fields.push(lua.createTableFieldExpression(getterFunction, lua.createStringLiteral("get")));
22
31
  }
23
32
  if (setAccessor) {
24
- const setterFunction = transformAccessor(context, setAccessor);
33
+ const setterFunction = transformAccessor(context, setAccessor, className);
25
34
  descriptor.fields.push(lua.createTableFieldExpression(setterFunction, lua.createStringLiteral("set")));
26
35
  }
27
36
  const isStatic = (0, utils_1.isStaticNode)(firstAccessor);
@@ -1,6 +1,5 @@
1
1
  import * as ts from "typescript";
2
2
  import * as lua from "../../../../LuaAST";
3
3
  import { TransformationContext } from "../../../context";
4
- export declare function createPropertyDecoratingExpression(context: TransformationContext, node: ts.PropertyDeclaration | ts.AccessorDeclaration, className: lua.Identifier): lua.Expression | undefined;
5
4
  export declare function transformClassInstanceFields(context: TransformationContext, instanceFields: ts.PropertyDeclaration[]): lua.Statement[];
6
5
  export declare function transformStaticPropertyDeclaration(context: TransformationContext, field: ts.PropertyDeclaration, className: lua.Identifier): lua.AssignmentStatement | undefined;
@@ -1,24 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformStaticPropertyDeclaration = exports.transformClassInstanceFields = exports.createPropertyDecoratingExpression = void 0;
4
- const ts = require("typescript");
3
+ exports.transformStaticPropertyDeclaration = exports.transformClassInstanceFields = void 0;
5
4
  const lua = require("../../../../LuaAST");
6
5
  const lua_ast_1 = require("../../../utils/lua-ast");
7
6
  const preceding_statements_1 = require("../../../utils/preceding-statements");
8
7
  const literal_1 = require("../../literal");
9
- const decorators_1 = require("../decorators");
10
- const method_1 = require("./method");
11
- function createPropertyDecoratingExpression(context, node, className) {
12
- if (!ts.canHaveDecorators(node))
13
- return;
14
- const decorators = ts.getDecorators(node);
15
- if (!decorators)
16
- return;
17
- const propertyName = (0, literal_1.transformPropertyName)(context, node.name);
18
- const propertyOwnerTable = (0, method_1.transformMemberExpressionOwnerName)(node, className);
19
- return (0, decorators_1.createDecoratingExpression)(context, node.kind, decorators.map(d => (0, decorators_1.transformDecoratorExpression)(context, d)), propertyOwnerTable, propertyName);
20
- }
21
- exports.createPropertyDecoratingExpression = createPropertyDecoratingExpression;
22
8
  function transformClassInstanceFields(context, instanceFields) {
23
9
  const statements = [];
24
10
  for (const f of instanceFields) {
@@ -4,4 +4,3 @@ import { TransformationContext } from "../../../context";
4
4
  export declare function transformMemberExpressionOwnerName(node: ts.PropertyDeclaration | ts.MethodDeclaration | ts.AccessorDeclaration, className: lua.Identifier): lua.Expression;
5
5
  export declare function transformMethodName(context: TransformationContext, node: ts.MethodDeclaration): lua.Expression;
6
6
  export declare function transformMethodDeclaration(context: TransformationContext, node: ts.MethodDeclaration, className: lua.Identifier): lua.Statement | undefined;
7
- export declare function createMethodDecoratingExpression(context: TransformationContext, node: ts.MethodDeclaration, className: lua.Identifier): lua.Statement | undefined;
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMethodDecoratingExpression = exports.transformMethodDeclaration = exports.transformMethodName = exports.transformMemberExpressionOwnerName = void 0;
3
+ exports.transformMethodDeclaration = exports.transformMethodName = exports.transformMemberExpressionOwnerName = void 0;
4
4
  const ts = require("typescript");
5
5
  const lua = require("../../../../LuaAST");
6
6
  const function_1 = require("../../function");
7
7
  const literal_1 = require("../../literal");
8
8
  const utils_1 = require("../utils");
9
- const decorators_1 = require("../decorators");
10
9
  const constructor_1 = require("./constructor");
11
- const lualib_1 = require("../../../utils/lualib");
12
- const utils_2 = require("../../../../utils");
10
+ const decorators_1 = require("../decorators");
13
11
  function transformMemberExpressionOwnerName(node, className) {
14
12
  return (0, utils_1.isStaticNode)(node) ? lua.cloneIdentifier(className) : (0, constructor_1.createPrototypeName)(className);
15
13
  }
@@ -23,31 +21,27 @@ function transformMethodName(context, node) {
23
21
  }
24
22
  exports.transformMethodName = transformMethodName;
25
23
  function transformMethodDeclaration(context, node, className) {
24
+ var _a, _b;
26
25
  // Don't transform methods without body (overload declarations)
27
26
  if (!node.body)
28
27
  return;
29
28
  const methodTable = transformMemberExpressionOwnerName(node, className);
30
29
  const methodName = transformMethodName(context, node);
31
30
  const [functionExpression] = (0, function_1.transformFunctionToExpression)(context, node);
32
- return lua.createAssignmentStatement(lua.createTableIndexExpression(methodTable, methodName), functionExpression, node);
33
- }
34
- exports.transformMethodDeclaration = transformMethodDeclaration;
35
- function createMethodDecoratingExpression(context, node, className) {
36
- var _a, _b;
37
- const methodTable = transformMemberExpressionOwnerName(node, className);
38
- const methodName = transformMethodName(context, node);
39
- const parameterDecorators = node.parameters
40
- .flatMap((parameter, index) => {
41
- var _a;
42
- return (_a = ts
43
- .getDecorators(parameter)) === 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)));
44
- })
45
- .filter(utils_2.isNonNull);
46
- const methodDecorators = (_b = (_a = ts.getDecorators(node)) === null || _a === void 0 ? void 0 : _a.map(d => (0, decorators_1.transformDecoratorExpression)(context, d))) !== null && _b !== void 0 ? _b : [];
47
- if (methodDecorators.length > 0 || parameterDecorators.length > 0) {
48
- const decorateMethod = (0, decorators_1.createDecoratingExpression)(context, node.kind, [...methodDecorators, ...parameterDecorators], methodTable, methodName);
49
- return lua.createExpressionStatement(decorateMethod);
31
+ const methodHasDecorators = ((_b = (_a = ts.getDecorators(node)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0;
32
+ const methodHasParameterDecorators = node.parameters.some(p => { var _a, _b; return ((_b = (_a = ts.getDecorators(p)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0; }); // Legacy decorators
33
+ if (methodHasDecorators || methodHasParameterDecorators) {
34
+ if (context.options.experimentalDecorators) {
35
+ // Legacy decorator statement
36
+ return lua.createExpressionStatement((0, decorators_1.createClassMethodDecoratingExpression)(context, node, functionExpression, className));
37
+ }
38
+ else {
39
+ return lua.createAssignmentStatement(lua.createTableIndexExpression(methodTable, methodName), (0, decorators_1.createClassMethodDecoratingExpression)(context, node, functionExpression, className), node);
40
+ }
41
+ }
42
+ else {
43
+ return lua.createAssignmentStatement(lua.createTableIndexExpression(methodTable, methodName), functionExpression, node);
50
44
  }
51
45
  }
52
- exports.createMethodDecoratingExpression = createMethodDecoratingExpression;
46
+ exports.transformMethodDeclaration = transformMethodDeclaration;
53
47
  //# sourceMappingURL=method.js.map
@@ -1,5 +1,6 @@
1
1
  import * as ts from "typescript";
2
2
  import { TransformationContext } from "../../context";
3
+ export declare function isPrivateNode(node: ts.HasModifiers): boolean;
3
4
  export declare function isStaticNode(node: ts.HasModifiers): boolean;
4
5
  export declare function getExtendsClause(node: ts.ClassLikeDeclarationBase): ts.HeritageClause | undefined;
5
6
  export declare function getExtendedNode(node: ts.ClassLikeDeclarationBase): ts.ExpressionWithTypeArguments | undefined;
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExtendedType = exports.getExtendedNode = exports.getExtendsClause = exports.isStaticNode = void 0;
3
+ exports.getExtendedType = exports.getExtendedNode = exports.getExtendsClause = exports.isStaticNode = exports.isPrivateNode = void 0;
4
4
  const ts = require("typescript");
5
+ function isPrivateNode(node) {
6
+ var _a;
7
+ return ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.PrivateKeyword)) === true;
8
+ }
9
+ exports.isPrivateNode = isPrivateNode;
5
10
  function isStaticNode(node) {
6
11
  var _a;
7
12
  return ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some(m => m.kind === ts.SyntaxKind.StaticKeyword)) === true;
@@ -139,7 +139,7 @@ function transformParameters(context, parameters, functionContext) {
139
139
  let identifierIndex = 0;
140
140
  // Only push parameter name to paramName array if it isn't a spread parameter
141
141
  for (const param of parameters) {
142
- if (ts.isIdentifier(param.name) && param.name.originalKeywordKind === ts.SyntaxKind.ThisKeyword) {
142
+ if (ts.isIdentifier(param.name) && ts.identifierToKeywordKind(param.name) === ts.SyntaxKind.ThisKeyword) {
143
143
  continue;
144
144
  }
145
145
  // Binding patterns become ____bindingPattern0, ____bindingPattern1, etc as function parameters
@@ -73,7 +73,7 @@ function transformIdentifierWithSymbol(context, node, symbol) {
73
73
  }
74
74
  exports.transformIdentifierWithSymbol = transformIdentifierWithSymbol;
75
75
  const transformIdentifierExpression = (node, context) => {
76
- if (node.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword) {
76
+ if (ts.identifierToKeywordKind(node) === ts.SyntaxKind.UndefinedKeyword) {
77
77
  return lua.createNilLiteral(node);
78
78
  }
79
79
  const symbol = context.checker.getSymbolAtLocation(node);
@@ -65,8 +65,8 @@ function transformExportAll(context, node) {
65
65
  // Wrap this in a DoStatement to prevent polluting the scope.
66
66
  return lua.createDoStatement(result, node);
67
67
  }
68
- const isDefaultExportSpecifier = (node) => (node.name && node.name.originalKeywordKind === ts.SyntaxKind.DefaultKeyword) ||
69
- (node.propertyName && node.propertyName.originalKeywordKind === ts.SyntaxKind.DefaultKeyword);
68
+ const isDefaultExportSpecifier = (node) => (node.name && ts.identifierToKeywordKind(node.name) === ts.SyntaxKind.DefaultKeyword) ||
69
+ (node.propertyName && ts.identifierToKeywordKind(node.propertyName) === ts.SyntaxKind.DefaultKeyword);
70
70
  function transformExportSpecifier(context, node) {
71
71
  const exportedSymbol = context.checker.getExportSpecifierLocalTargetSymbol(node);
72
72
  const exportedIdentifier = node.propertyName ? node.propertyName : node.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-to-lua",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
5
5
  "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
6
6
  "homepage": "https://typescripttolua.github.io/",
@@ -42,7 +42,7 @@
42
42
  "node": ">=16.10.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "typescript": "^5.0.2"
45
+ "typescript": "~5.1.3"
46
46
  },
47
47
  "dependencies": {
48
48
  "@typescript-to-lua/language-extensions": "1.0.0",
@@ -70,6 +70,6 @@
70
70
  "prettier": "^2.8.4",
71
71
  "ts-jest": "^29.1.0",
72
72
  "ts-node": "^10.9.1",
73
- "typescript": "^5.0.2"
73
+ "typescript": "~5.1.3"
74
74
  }
75
75
  }