From faf34ad45d662471462300b3844275b12fd81b92 Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Sat, 25 Jan 2025 00:09:06 +0700 Subject: [PATCH] BUGFIX: Static RAM calculator cannot process abstract methods (#1921) --- src/ThirdParty/acorn-typescript-walk/index.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ThirdParty/acorn-typescript-walk/index.ts b/src/ThirdParty/acorn-typescript-walk/index.ts index 91a575f5e..a4e72d2dd 100644 --- a/src/ThirdParty/acorn-typescript-walk/index.ts +++ b/src/ThirdParty/acorn-typescript-walk/index.ts @@ -85,4 +85,25 @@ export function extendAcornWalkForTypeScriptNodes(base: any) { base.TSModuleDeclaration = (node: any, state: any, callback: any) => { callback(node.body, state); }; + /** + * Override the behavior of acorn-walk. When parsing a function, the function body is expected. However, the function + * body may not exist in TypeScript code (e.g., abstract methods within an abstract class). + * + * The following code was copied from acorn-walk. There are 2 changes: + * - Use const instead of let in the loop. + * - Check node.body before using it. + * + * Ref: https://github.com/acornjs/acorn/blob/a707bfefd73515efd759b7638c30281d775cd043/acorn-walk/src/index.js#L262 + */ + base.Function = (node: any, st: any, c: any) => { + if (node.id) { + c(node.id, st, "Pattern"); + } + for (const param of node.params) { + c(param, st, "Pattern"); + } + if (node.body) { + c(node.body, st, node.expression ? "Expression" : "Statement"); + } + }; }