From ea618e08ebf8854ae39eaffb609f0abad87e41ac Mon Sep 17 00:00:00 2001 From: Ze-Zheng Wu Date: Sun, 29 Dec 2024 00:13:59 +0800 Subject: [PATCH] chore: improve emscripten patch logger --- scripts/babel-plugin-emscripten-patch.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/babel-plugin-emscripten-patch.ts b/scripts/babel-plugin-emscripten-patch.ts index fac2df2b..c38d7854 100644 --- a/scripts/babel-plugin-emscripten-patch.ts +++ b/scripts/babel-plugin-emscripten-patch.ts @@ -13,6 +13,10 @@ import { export function emscriptenPatch(): PluginItem { return { + pre() { + this.declared = false; + this.checked = false; + }, visitor: { VariableDeclaration(path) { if ( @@ -53,6 +57,7 @@ export function emscriptenPatch(): PluginItem { ), ]), ]); + this.declared = true; } }, LogicalExpression(path) { @@ -82,8 +87,26 @@ export function emscriptenPatch(): PluginItem { path.replaceWith(newNode); } path.skip(); + this.checked = true; } }, }, + post() { + if (!this.declared) { + console.error( + "\x1b[33m! Emscripten JS Patch\x1b[0m: patch variables not declared", + ); + } + if (!this.checked) { + console.error( + "\x1b[33m! Emscripten JS Patch\x1b[0m: patch variables not checked", + ); + } + if (this.declared && this.checked) { + console.log( + "\x1b[32m✓ Emscripten JS Patch\x1b[0m: patch variables declared and checked", + ); + } + }, }; }