From c2f305709e30089a47a1d12f6bf0ee200dfbb5ae Mon Sep 17 00:00:00 2001 From: Samual Date: Fri, 26 Apr 2024 19:18:29 +0100 Subject: [PATCH] fix `_FULL_SCRIPT_NAME` turning into `"undefined.foo"` this is the last step for replace `"UNKNOWN"`s with something better #151 this fix doesn't actually replace `"UNKNOWN"`, there was a bug that meant there was no `"UNKNOWN"` where there probably should have been one but I've skipped the middle step --- src/processScript/transform.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/processScript/transform.ts b/src/processScript/transform.ts index bf746a1..2e8faad 100644 --- a/src/processScript/transform.ts +++ b/src/processScript/transform.ts @@ -77,11 +77,18 @@ export function transform( if (program.scope.hasGlobal(`_FULL_SCRIPT_NAME`)) { for (const referencePath of getReferencePathsToGlobal(`_FULL_SCRIPT_NAME`, program)) { - referencePath.replaceWith(t.stringLiteral( - scriptUser == true || scriptName == true - ? `$${uniqueID}$FULL_SCRIPT_NAME$` - : `${scriptUser}.${scriptName}` - )) + if (scriptUser == true || scriptName == true) + referencePath.replaceWith(t.stringLiteral(`$${uniqueID}$FULL_SCRIPT_NAME$`)) + else if (scriptUser == undefined) { + uniqueIdScriptUserNeeded = true + + referencePath.replaceWith(t.binaryExpression( + `+`, + t.identifier(`_${uniqueID}_SCRIPT_USER_`), + t.stringLiteral(`.${scriptName}`) + )) + } else + referencePath.replaceWith(t.stringLiteral(`${scriptUser}.${scriptName}`)) } } -- knotmirror 0.0.1