From ef80984a4dc49da5de0f836d29c090600d2eefdd Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Mon, 22 Jan 2024 15:32:32 -0800 Subject: [PATCH] chore(compartment-mapper): fix type of internal function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This addresses the `@ts-ignore` found in `makeFauxModuleExportsNamespace()`, which was renamed from `makeFeauxModuleExportsNamespace()`, because "féaux" translates to "loyal supporters" and not "fake" or "false" like was presumably intended. I am not so bold to rename it `makeErsatzModuleExportsNamespace()`, despite "ersatz" being a wholly superior word to either of the above alternatives. --- packages/compartment-mapper/src/import-archive.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/compartment-mapper/src/import-archive.js b/packages/compartment-mapper/src/import-archive.js index c3248cfdad..5eeffd8065 100644 --- a/packages/compartment-mapper/src/import-archive.js +++ b/packages/compartment-mapper/src/import-archive.js @@ -208,9 +208,13 @@ const makeArchiveImportHookMaker = ( return makeImportHook; }; -const makeFeauxModuleExportsNamespace = Compartment => { - // @ts-ignore Unclear at time of writing why Compartment type is not - // constructible. +/** + * Creates a fake module namespace object that passes a brand check. + * + * @param {typeof Compartment} Compartment + * @returns {import('ses').ModuleExportsNamespace} + */ +const makeFauxModuleExportsNamespace = Compartment => { const compartment = new Compartment( {}, {}, @@ -218,10 +222,11 @@ const makeFeauxModuleExportsNamespace = Compartment => { resolveHook() { return '.'; }, - importHook() { + async importHook() { return { imports: [], execute() {}, + exports: [], }; }, }, @@ -336,7 +341,7 @@ export const parseArchive = async ( parserForLanguage, modules: Object.fromEntries( Object.keys(modules || {}).map(specifier => { - return [specifier, makeFeauxModuleExportsNamespace(Compartment)]; + return [specifier, makeFauxModuleExportsNamespace(Compartment)]; }), ), Compartment,