From 5cbbc008bb9a0e6f65dca937181b84d455f948cc Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 26 Jan 2026 00:55:16 +0800 Subject: [PATCH] Remove global error handler from `flow-parser` (#18750) --- scripts/build/packages/prettier.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/build/packages/prettier.js b/scripts/build/packages/prettier.js index e2eb1bb28..ee0179a0a 100644 --- a/scripts/build/packages/prettier.js +++ b/scripts/build/packages/prettier.js @@ -272,10 +272,26 @@ const pluginFiles = [ /,(?[\p{ID_Start}_$][\p{ID_Continue}$]*)="fs",/u, ).groups; - return text + text = text .replaceAll(`require(${fsModuleNameVariableName})`, "{}") .replaceAll('require("fs")', "{}") .replaceAll('require("constants")', "{}"); + + const { globalThisVariableName } = text.match( + /\(function\((?[\p{ID_Start}$][\p{ID_Continue}$]*)\)\{"use strict";/u, + ).groups; + + // flow-parser adds a global error handler cause the error stack been huge + // https://github.com/facebook/flow/issues/9299 + // NOTE: Can't reproduce in flow-parser@0.298.0, but the code still there + // NOTE2: This is not tested + text = text.replaceAll(`${globalThisVariableName}.process`, "({})"); + text = text.replaceAll( + `${globalThisVariableName}.addEventListener`, + "(() =>{})", + ); + + return text; }, }, ],