@flamework-experimental/core 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
@@ -0,0 +1,64 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ --[[
3
+ *
4
+ * The Flamework classes each module defined as it loaded, by the module's `script`, in the order
5
+ * they were defined: what path registration finds in a module besides what it exports.
6
+ *
7
+ * The transformer records a class with `Reflect.defineMetadata(class, "flamework:module", script)`,
8
+ * and only a class the module creates once per load -- declared at the top level of the file, or
9
+ * of a namespace in it. A class declared inside a function is created by every call and is never
10
+ * recorded, so nothing here grows with calls, and a later path registration never finds a class
11
+ * that belongs to a test case or a factory. Keyed by the ModuleScript rather than read off the
12
+ * class's identifier, which says nothing about where the class came from once ids are short, tiny
13
+ * or obfuscated.
14
+ *
15
+ * Held for good, as the module's own exports are held by the require cache: a module loads once.
16
+
17
+ ]]
18
+ local classesByModule = {}
19
+ --* Records a class against the module that defined it. Called by `Reflect.defineMetadata`.
20
+ local function recordModuleClass(moduleScript, value)
21
+ if moduleScript == nil then
22
+ return nil
23
+ end
24
+ local _moduleScript = moduleScript
25
+ local classes = classesByModule[_moduleScript]
26
+ if classes == nil then
27
+ classes = {}
28
+ local _moduleScript_1 = moduleScript
29
+ local _classes = classes
30
+ classesByModule[_moduleScript_1] = _classes
31
+ end
32
+ local _classes = classes
33
+ local _value = value
34
+ if not (table.find(_classes, _value) ~= nil) then
35
+ local _classes_1 = classes
36
+ local _value_1 = value
37
+ table.insert(_classes_1, _value_1)
38
+ end
39
+ end
40
+ --* The classes a module defined as it loaded, in definition order, or none.
41
+ local function getModuleClasses(moduleScript)
42
+ local _moduleScript = moduleScript
43
+ return classesByModule[_moduleScript]
44
+ end
45
+ --[[
46
+ *
47
+ * Every recorded class, with the module that defined it, until the callback answers `true`. For
48
+ * explaining a failed resolution, which is rare: nothing here is indexed for it.
49
+
50
+ ]]
51
+ local function findModuleClass(predicate)
52
+ for moduleScript, classes in classesByModule do
53
+ for _, value in classes do
54
+ if predicate(value) then
55
+ return { value, moduleScript }
56
+ end
57
+ end
58
+ end
59
+ end
60
+ return {
61
+ recordModuleClass = recordModuleClass,
62
+ getModuleClasses = getModuleClasses,
63
+ findModuleClass = findModuleClass,
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flamework-experimental/core",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "main": "out/init.luau",
5
5
  "types": "out/index.d.ts",
6
6
  "scripts": {