Skip to content

Commit

Permalink
fix _FULL_SCRIPT_NAME turning into "undefined.foo"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
samualtnorman committed Apr 26, 2024
1 parent b80922d commit c2f3057
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/processScript/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`))
}
}

Expand Down

0 comments on commit c2f3057

Please sign in to comment.