From 6f8bf68c63fc609f454d4e4115c202c8a3021754 Mon Sep 17 00:00:00 2001 From: SarahIsWeird Date: Tue, 18 Feb 2025 17:00:16 +0100 Subject: [PATCH] Fix `this` reference in default argument --- src/processScript/transform.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/processScript/transform.ts b/src/processScript/transform.ts index 16776e3..99eed3e 100644 --- a/src/processScript/transform.ts +++ b/src/processScript/transform.ts @@ -821,6 +821,19 @@ export function transform( let methodReferencesThis = false as boolean + for (const param of classMethod.params) { + traverse(param, { + ThisExpression(path) { + // We can't reference _abc_THIS_ here, because there would be + // nowhere to place the assignment to that! + // Hence, we just do the super thing directly. + path.replaceWith(t.callExpression( + t.memberExpression(t.super(), t.identifier(`valueOf`)), [] + )) + }, + }, scope) + } + traverse(classMethod.body, { ThisExpression(path) { methodReferencesThis = true -- knotmirror 0.0.1