isaacscript-common 84.2.0 → 84.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,OAAO,EAC5C,MAAM,EAAE,KAAK,EACb,WAAW,EAAE,MAAM,KAAK,GACvB,IAAI,CAeN"}
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAGzD,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,OAAO,EAC5C,MAAM,EAAE,KAAK,EACb,WAAW,EAAE,MAAM,KAAK,GACvB,IAAI,CAuBN"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Exported = exports.EXPORTED_METHOD_NAMES_KEY = void 0;
4
+ const tstlClass_1 = require("./functions/tstlClass");
4
5
  exports.EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames";
5
6
  /**
6
7
  * A decorator function that signifies that the decorated class method should be added to the
@@ -12,10 +13,15 @@ function Exported(target, propertyKey) {
12
13
  // Since the decorator runs prior to instantiation, we only have access to get and set static
13
14
  // properties, which are located on the "constructor" table.
14
15
  const constructor = target.constructor;
15
- if (!constructor.has(exports.EXPORTED_METHOD_NAMES_KEY)) {
16
- constructor.set(exports.EXPORTED_METHOD_NAMES_KEY, []);
16
+ if (constructor === undefined) {
17
+ const tstlClassName = (0, tstlClass_1.getTSTLClassName)(target) ?? "Unknown";
18
+ error(`Failed to get the constructor for class "${tstlClassName}". Did you decorate a static method? You can only decorate non-static class methods.`);
19
+ }
20
+ let exportedMethodNames = constructor[exports.EXPORTED_METHOD_NAMES_KEY];
21
+ if (exportedMethodNames === undefined) {
22
+ exportedMethodNames = [];
23
+ constructor[exports.EXPORTED_METHOD_NAMES_KEY] = exportedMethodNames;
17
24
  }
18
- const exportedMethodNames = constructor.get(exports.EXPORTED_METHOD_NAMES_KEY);
19
25
  exportedMethodNames.push(propertyKey);
20
26
  }
21
27
  exports.Exported = Exported;
@@ -1,4 +1,6 @@
1
1
  local ____exports = {}
2
+ local ____tstlClass = require("functions.tstlClass")
3
+ local getTSTLClassName = ____tstlClass.getTSTLClassName
2
4
  ____exports.EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames"
3
5
  --- A decorator function that signifies that the decorated class method should be added to the
4
6
  -- `ModUpgraded` object.
@@ -6,10 +8,15 @@ ____exports.EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames"
6
8
  -- This is only meant to be used internally.
7
9
  function ____exports.Exported(self, target, propertyKey)
8
10
  local constructor = target.constructor
9
- if not (constructor[____exports.EXPORTED_METHOD_NAMES_KEY] ~= nil) then
10
- constructor[____exports.EXPORTED_METHOD_NAMES_KEY] = {}
11
+ if constructor == nil then
12
+ local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
13
+ error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods.")
11
14
  end
12
15
  local exportedMethodNames = constructor[____exports.EXPORTED_METHOD_NAMES_KEY]
16
+ if exportedMethodNames == nil then
17
+ exportedMethodNames = {}
18
+ constructor[____exports.EXPORTED_METHOD_NAMES_KEY] = exportedMethodNames
19
+ end
13
20
  exportedMethodNames[#exportedMethodNames + 1] = propertyKey
14
21
  end
15
22
  return ____exports
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/funct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,10 +73,12 @@ function PriorityCallback(modCallback, priority, ...optionalArgs) {
73
73
  const tstlClassName = (0, tstlClass_1.getTSTLClassName)(target) ?? "Unknown";
74
74
  error(`Failed to get the constructor for class "${tstlClassName}". Did you decorate a static method? You can only decorate non-static class methods, because the "Mod" object is not present before the class is instantiated.`);
75
75
  }
76
- if (!constructor.has(ModFeature_1.MOD_FEATURE_CALLBACKS_KEY)) {
77
- constructor.set(ModFeature_1.MOD_FEATURE_CALLBACKS_KEY, []);
76
+ const key = ModFeature_1.MOD_FEATURE_CALLBACKS_KEY;
77
+ let callbackTuples = constructor[key];
78
+ if (callbackTuples === undefined) {
79
+ callbackTuples = [];
80
+ constructor[key] = callbackTuples;
78
81
  }
79
- const callbackTuples = constructor.get(ModFeature_1.MOD_FEATURE_CALLBACKS_KEY);
80
82
  callbackTuples.push(callbackTuple);
81
83
  };
82
84
  }
@@ -103,10 +105,12 @@ function PriorityCallbackCustom(modCallbackCustom, priority, ...optionalArgs) {
103
105
  const tstlClassName = (0, tstlClass_1.getTSTLClassName)(target) ?? "Unknown";
104
106
  error(`Failed to get the constructor for class "${tstlClassName}". Did you decorate a static method? You can only decorate non-static class methods, because the "Mod" object is not present before the class is instantiated.`);
105
107
  }
106
- if (!constructor.has(ModFeature_1.MOD_FEATURE_CUSTOM_CALLBACKS_KEY)) {
107
- constructor.set(ModFeature_1.MOD_FEATURE_CUSTOM_CALLBACKS_KEY, []);
108
+ const key = ModFeature_1.MOD_FEATURE_CUSTOM_CALLBACKS_KEY;
109
+ let callbackTuples = constructor[key];
110
+ if (callbackTuples === undefined) {
111
+ callbackTuples = [];
112
+ constructor[key] = callbackTuples;
108
113
  }
109
- const callbackTuples = constructor.get(ModFeature_1.MOD_FEATURE_CUSTOM_CALLBACKS_KEY);
110
114
  callbackTuples.push(callbackTuple);
111
115
  };
112
116
  }
@@ -22,10 +22,12 @@ function ____exports.PriorityCallback(self, modCallback, priority, ...)
22
22
  local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
23
23
  error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods, because the \"Mod\" object is not present before the class is instantiated.")
24
24
  end
25
- if not (constructor[MOD_FEATURE_CALLBACKS_KEY] ~= nil) then
26
- constructor[MOD_FEATURE_CALLBACKS_KEY] = {}
25
+ local key = MOD_FEATURE_CALLBACKS_KEY
26
+ local callbackTuples = constructor[key]
27
+ if callbackTuples == nil then
28
+ callbackTuples = {}
29
+ constructor[key] = callbackTuples
27
30
  end
28
- local callbackTuples = constructor[MOD_FEATURE_CALLBACKS_KEY]
29
31
  callbackTuples[#callbackTuples + 1] = callbackTuple
30
32
  end
31
33
  end
@@ -45,10 +47,12 @@ function ____exports.PriorityCallbackCustom(self, modCallbackCustom, priority, .
45
47
  local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
46
48
  error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods, because the \"Mod\" object is not present before the class is instantiated.")
47
49
  end
48
- if not (constructor[MOD_FEATURE_CUSTOM_CALLBACKS_KEY] ~= nil) then
49
- constructor[MOD_FEATURE_CUSTOM_CALLBACKS_KEY] = {}
50
+ local key = MOD_FEATURE_CUSTOM_CALLBACKS_KEY
51
+ local callbackTuples = constructor[key]
52
+ if callbackTuples == nil then
53
+ callbackTuples = {}
54
+ constructor[key] = callbackTuples
50
55
  end
51
- local callbackTuples = constructor[MOD_FEATURE_CUSTOM_CALLBACKS_KEY]
52
56
  callbackTuples[#callbackTuples + 1] = callbackTuple
53
57
  end
54
58
  end
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 84.1.2
3
+ isaacscript-common 84.2.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -40299,6 +40299,8 @@ return ____exports
40299
40299
  end,
40300
40300
  ["decorators"] = function(...)
40301
40301
  local ____exports = {}
40302
+ local ____tstlClass = require("functions.tstlClass")
40303
+ local getTSTLClassName = ____tstlClass.getTSTLClassName
40302
40304
  ____exports.EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames"
40303
40305
  --- A decorator function that signifies that the decorated class method should be added to the
40304
40306
  -- `ModUpgraded` object.
@@ -40306,10 +40308,15 @@ ____exports.EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames"
40306
40308
  -- This is only meant to be used internally.
40307
40309
  function ____exports.Exported(self, target, propertyKey)
40308
40310
  local constructor = target.constructor
40309
- if not (constructor[____exports.EXPORTED_METHOD_NAMES_KEY] ~= nil) then
40310
- constructor[____exports.EXPORTED_METHOD_NAMES_KEY] = {}
40311
+ if constructor == nil then
40312
+ local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
40313
+ error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods.")
40311
40314
  end
40312
40315
  local exportedMethodNames = constructor[____exports.EXPORTED_METHOD_NAMES_KEY]
40316
+ if exportedMethodNames == nil then
40317
+ exportedMethodNames = {}
40318
+ constructor[____exports.EXPORTED_METHOD_NAMES_KEY] = exportedMethodNames
40319
+ end
40313
40320
  exportedMethodNames[#exportedMethodNames + 1] = propertyKey
40314
40321
  end
40315
40322
  return ____exports
@@ -64959,10 +64966,12 @@ function ____exports.PriorityCallback(self, modCallback, priority, ...)
64959
64966
  local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
64960
64967
  error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods, because the \"Mod\" object is not present before the class is instantiated.")
64961
64968
  end
64962
- if not (constructor[MOD_FEATURE_CALLBACKS_KEY] ~= nil) then
64963
- constructor[MOD_FEATURE_CALLBACKS_KEY] = {}
64969
+ local key = MOD_FEATURE_CALLBACKS_KEY
64970
+ local callbackTuples = constructor[key]
64971
+ if callbackTuples == nil then
64972
+ callbackTuples = {}
64973
+ constructor[key] = callbackTuples
64964
64974
  end
64965
- local callbackTuples = constructor[MOD_FEATURE_CALLBACKS_KEY]
64966
64975
  callbackTuples[#callbackTuples + 1] = callbackTuple
64967
64976
  end
64968
64977
  end
@@ -64982,10 +64991,12 @@ function ____exports.PriorityCallbackCustom(self, modCallbackCustom, priority, .
64982
64991
  local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
64983
64992
  error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods, because the \"Mod\" object is not present before the class is instantiated.")
64984
64993
  end
64985
- if not (constructor[MOD_FEATURE_CUSTOM_CALLBACKS_KEY] ~= nil) then
64986
- constructor[MOD_FEATURE_CUSTOM_CALLBACKS_KEY] = {}
64994
+ local key = MOD_FEATURE_CUSTOM_CALLBACKS_KEY
64995
+ local callbackTuples = constructor[key]
64996
+ if callbackTuples == nil then
64997
+ callbackTuples = {}
64998
+ constructor[key] = callbackTuples
64987
64999
  end
64988
- local callbackTuples = constructor[MOD_FEATURE_CUSTOM_CALLBACKS_KEY]
64989
65000
  callbackTuples[#callbackTuples + 1] = callbackTuple
64990
65001
  end
64991
65002
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "84.2.0",
3
+ "version": "84.2.1",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
package/src/decorators.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Feature } from "./classes/private/Feature";
2
+ import { getTSTLClassName } from "./functions/tstlClass";
2
3
 
3
4
  export const EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames";
4
5
 
@@ -14,16 +15,24 @@ export function Exported<Class extends Feature>(
14
15
  ): void {
15
16
  // Since the decorator runs prior to instantiation, we only have access to get and set static
16
17
  // properties, which are located on the "constructor" table.
17
- const constructor = target.constructor as unknown as LuaMap<
18
- AnyNotNil,
19
- unknown
20
- >;
21
- if (!constructor.has(EXPORTED_METHOD_NAMES_KEY)) {
22
- constructor.set(EXPORTED_METHOD_NAMES_KEY, []);
18
+ const constructor = target.constructor as unknown as
19
+ | Record<string, unknown>
20
+ | undefined;
21
+
22
+ if (constructor === undefined) {
23
+ const tstlClassName = getTSTLClassName(target) ?? "Unknown";
24
+ error(
25
+ `Failed to get the constructor for class "${tstlClassName}". Did you decorate a static method? You can only decorate non-static class methods.`,
26
+ );
27
+ }
28
+
29
+ let exportedMethodNames = constructor[EXPORTED_METHOD_NAMES_KEY] as
30
+ | unknown[]
31
+ | undefined;
32
+ if (exportedMethodNames === undefined) {
33
+ exportedMethodNames = [];
34
+ constructor[EXPORTED_METHOD_NAMES_KEY] = exportedMethodNames;
23
35
  }
24
36
 
25
- const exportedMethodNames = constructor.get(
26
- EXPORTED_METHOD_NAMES_KEY,
27
- ) as string[];
28
37
  exportedMethodNames.push(propertyKey as string);
29
38
  }
@@ -99,7 +99,7 @@ export function PriorityCallback<T extends ModCallback>(
99
99
  // properties, which are located on the "constructor" table. Thus, we store the callback
100
100
  // arguments for later.
101
101
  const constructor = target.constructor as unknown as
102
- | LuaMap<AnyNotNil, unknown>
102
+ | Record<string, unknown>
103
103
  | undefined;
104
104
 
105
105
  if (constructor === undefined) {
@@ -109,13 +109,13 @@ export function PriorityCallback<T extends ModCallback>(
109
109
  );
110
110
  }
111
111
 
112
- if (!constructor.has(MOD_FEATURE_CALLBACKS_KEY)) {
113
- constructor.set(MOD_FEATURE_CALLBACKS_KEY, []);
112
+ const key = MOD_FEATURE_CALLBACKS_KEY;
113
+ let callbackTuples = constructor[key] as unknown[] | undefined;
114
+ if (callbackTuples === undefined) {
115
+ callbackTuples = [];
116
+ constructor[key] = callbackTuples;
114
117
  }
115
118
 
116
- const callbackTuples = constructor.get(
117
- MOD_FEATURE_CALLBACKS_KEY,
118
- ) as unknown[];
119
119
  callbackTuples.push(callbackTuple);
120
120
  };
121
121
  }
@@ -150,7 +150,7 @@ export function PriorityCallbackCustom<T extends ModCallbackCustom>(
150
150
  // properties, which are located on the "constructor" table. Thus, we store the callback
151
151
  // arguments for later.
152
152
  const constructor = target.constructor as unknown as
153
- | LuaMap<AnyNotNil, unknown>
153
+ | Record<string, unknown>
154
154
  | undefined;
155
155
 
156
156
  if (constructor === undefined) {
@@ -160,13 +160,12 @@ export function PriorityCallbackCustom<T extends ModCallbackCustom>(
160
160
  );
161
161
  }
162
162
 
163
- if (!constructor.has(MOD_FEATURE_CUSTOM_CALLBACKS_KEY)) {
164
- constructor.set(MOD_FEATURE_CUSTOM_CALLBACKS_KEY, []);
163
+ const key = MOD_FEATURE_CUSTOM_CALLBACKS_KEY;
164
+ let callbackTuples = constructor[key] as unknown[] | undefined;
165
+ if (callbackTuples === undefined) {
166
+ callbackTuples = [];
167
+ constructor[key] = callbackTuples;
165
168
  }
166
-
167
- const callbackTuples = constructor.get(
168
- MOD_FEATURE_CUSTOM_CALLBACKS_KEY,
169
- ) as unknown[];
170
169
  callbackTuples.push(callbackTuple);
171
170
  };
172
171
  }