From a3acf524af915b97fc4c317841fa87a3c534e45d Mon Sep 17 00:00:00 2001 From: VincentGuinaudeau Date: Tue, 21 May 2024 19:51:05 +0200 Subject: [PATCH] Implement feedback from PR, restore old substitution to not break quine cheating --- src/processScript/postprocess.ts | 3 ++- src/processScript/transform.ts | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/processScript/postprocess.ts b/src/processScript/postprocess.ts index 4fadfdc..dced38c 100644 --- a/src/processScript/postprocess.ts +++ b/src/processScript/postprocess.ts @@ -5,7 +5,8 @@ export const postprocess = (code: string, uniqueId: string) => code .replace(new RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$D\\$`, `g`), `_\\_D_S`) .replace(new RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$FMCL\\$`, `g`), `_\\_FMCL_`) .replace(new RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$G\\$`, `g`), `_\\_G_`) - .replace(new RegExp(`\\$${uniqueId}\\$(\\d)\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, `g`), (_, seclevel, user, script) => `#${'nlmhf'[seclevel]}s.${user}.${script}`) + .replace(new RegExp(`\\$${uniqueId}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, `g`), `#fs.$1.$2`) + .replace(new RegExp(`\\$${uniqueId}\\$(\\d)\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, `g`), `#$1s.$2.$3`) .replace(new RegExp(`\\$${uniqueId}\\$DEBUG\\$`, `g`), `#D`) .replace(new RegExp(`\\$${uniqueId}\\$FMCL\\$`, `g`), `#FMCL`) .replace(new RegExp(`\\$${uniqueId}\\$GLOBAL\\$`, `g`), `#G`) diff --git a/src/processScript/transform.ts b/src/processScript/transform.ts index 2d9f8ba..210321b 100644 --- a/src/processScript/transform.ts +++ b/src/processScript/transform.ts @@ -633,12 +633,12 @@ export function transform( if (neededSubscriptLets.size) { mainFunction.body.body.unshift(t.variableDeclaration( `let`, - [ ...neededSubscriptLets.entries() ].map(([name, secLevel]) => t.variableDeclarator( + [ ...neededSubscriptLets ].map(([ name, seclevel ]) => t.variableDeclarator( t.identifier(`_${uniqueId}_SUBSCRIPT_${name}_`), t.arrowFunctionExpression( [ t.restElement(t.identifier(`args`)) ], t.callExpression( - t.identifier(`$${uniqueId}$${secLevel}$SUBSCRIPT$${name}$`), + t.identifier(`$${uniqueId}$${seclevel}$SUBSCRIPT$${name}$`), [ t.spreadElement(t.identifier(`args`)) ] ) ) @@ -780,7 +780,7 @@ export function transform( ) } - function processFakeSubscriptObject(fakeSubscriptObjectName: string, secLevel: number) { + function processFakeSubscriptObject(fakeSubscriptObjectName: string, seclevel: number) { for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) { assert(referencePath.parent.type == `MemberExpression`, HERE) assert(referencePath.parent.property.type == `Identifier`) @@ -799,7 +799,7 @@ export function transform( if (referencePath.parentPath.parentPath.parentPath?.type == `CallExpression`) { // BUG this is causing typescript to be slow - referencePath.parentPath.parentPath.replaceWith(t.identifier(`$${uniqueId}$${secLevel}$SUBSCRIPT$${ + referencePath.parentPath.parentPath.replaceWith(t.identifier(`$${uniqueId}$${seclevel}$SUBSCRIPT$${ referencePath.parent.property.name }$${referencePath.parentPath.parentPath.node.property.name}$`)) } else { @@ -807,7 +807,7 @@ export function transform( `${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}` referencePath.parentPath.parentPath.replaceWith(t.identifier(`_${uniqueId}_SUBSCRIPT_${name}_`)) - const maxSecLevel = Math.max(neededSubscriptLets.get(name) || 0, secLevel) + const maxSecLevel = Math.max(neededSubscriptLets.get(name) || 0, seclevel) neededSubscriptLets.set(name, maxSecLevel) } } -- knotmirror 0.0.1