From 6bd5ce38d5a4acabc9882dcee8f4d59a53f692ce Mon Sep 17 00:00:00 2001 From: G4mingJon4s <40526179+G4mingJon4s@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:09:23 +0200 Subject: [PATCH] Fixed ram evaluation to include more edge-cases (#665) --- src/Script/RamCalculations.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Script/RamCalculations.ts b/src/Script/RamCalculations.ts index f16d71565..394858581 100644 --- a/src/Script/RamCalculations.ts +++ b/src/Script/RamCalculations.ts @@ -270,13 +270,13 @@ function parseOnlyCalculateDeps(code: string, currentModule: string): ParseDepsR // References get added pessimistically. They are added for thisModule.name, name, and for // any aliases. - function addRef(key: string, name: string): void { + function addRef(key: string, name: string, module = currentModule): void { const s = dependencyMap[key] || (dependencyMap[key] = new Set()); const external = internalToExternal[name]; if (external !== undefined) { s.add(external); } - s.add(currentModule + "." + name); + s.add(module + "." + name); s.add(name); // For builtins like hack. } @@ -366,10 +366,19 @@ function parseOnlyCalculateDeps(code: string, currentModule: string): ParseDepsR walkDeeper(node.declaration, st); return; } - const specifiers = node.specifiers; - for (const specifier of specifiers) { - addRef(st.key, specifier.local.name); + for (const specifier of node.specifiers) { + const exportedDepName = currentModule + "." + specifier.exported.name; + + if (node.source !== null) { + // if this is true, we are re-exporting something + addRef(exportedDepName, specifier.local.name, node.source.value); + additionalModules.push(node.source.value); + } else if (specifier.exported.name !== specifier.local.name) { + // this makes sure we are not refering to ourselves + // if this is not true, we don't need to add anything + addRef(exportedDepName, specifier.local.name); + } } }, },