From 39b4f935f76a1afb2a25b2b18bf43f6639eb801c Mon Sep 17 00:00:00 2001 From: Marin Minnerly Date: Sat, 7 Sep 2024 11:18:15 -0700 Subject: [PATCH] Fix remaining type errors --- src/ModuleLoader.luau | 11 ++++++++--- src/ModuleLoader.spec.luau | 2 +- src/getCallerPath.luau | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ModuleLoader.luau b/src/ModuleLoader.luau index 1dea59d..487abd0 100644 --- a/src/ModuleLoader.luau +++ b/src/ModuleLoader.luau @@ -32,7 +32,7 @@ type ModuleLoaderProps = { _cache: { [string]: CachedModule }, _loadstring: typeof(loadstring), _debugInfo: typeof(debug.info), - _janitors: { [string]: typeof(Janitor.new()) }, + _janitors: { [string]: any }, _globals: { [any]: any }, _loadedModuleChangedBindable: BindableEvent, @@ -212,6 +212,10 @@ function ModuleLoader:require(module) local cachedModule = self._cache[module:GetFullName()] local callerPath = getCallerPath() + if not callerPath then + return nil + end + if cachedModule then cachedModule.consumers[callerPath] = true return self:_loadCachedModule(module) @@ -221,7 +225,8 @@ function ModuleLoader:require(module) local moduleFn, parseError = self._loadstring(source, module:GetFullName()) if not moduleFn then - error(("Could not parse %s: %s"):format(module:GetFullName(), parseError)) + local message = if parseError then parseError else "" + error(`Could not parse {module:GetFullName()}: {message}`) end local globals = createTablePassthrough(self._globals) @@ -237,7 +242,7 @@ function ModuleLoader:require(module) } self._cache[module:GetFullName()] = newCachedModule - local env = getEnv(module, globals) + local env: any = getEnv(module, globals) env.require = bind(self, self.require) setfenv(moduleFn, env) diff --git a/src/ModuleLoader.spec.luau b/src/ModuleLoader.spec.luau index ef0a974..04382e9 100644 --- a/src/ModuleLoader.spec.luau +++ b/src/ModuleLoader.spec.luau @@ -21,7 +21,7 @@ type ModuleTestTree = { [string]: string | ModuleTestTree, } local testNumber = 0 -local function createModuleTest(tree: ModuleTestTree, parent: Instance?) +local function createModuleTest(tree: ModuleTestTree, parent: Instance?): any testNumber += 1 local root = Instance.new("Folder") diff --git a/src/getCallerPath.luau b/src/getCallerPath.luau index bb2b867..921c3f5 100644 --- a/src/getCallerPath.luau +++ b/src/getCallerPath.luau @@ -2,7 +2,7 @@ local root = script.Parent local LOADSTRING_PATH_PATTERN = '%[string "(.*)"%]' -local function getCallerPath() +local function getCallerPath(): string? local level = 1 while true do