diff --git a/web/hwlab-cloud-web/scripts/check.mjs b/web/hwlab-cloud-web/scripts/check.mjs index 96da5176..950c12da 100644 --- a/web/hwlab-cloud-web/scripts/check.mjs +++ b/web/hwlab-cloud-web/scripts/check.mjs @@ -1340,10 +1340,26 @@ function compactLayoutFailure(failure) { } function functionBody(source, functionName) { - const match = source.match(new RegExp(`function\\s+${escapeRegExp(functionName)}\\s*\\([^)]*\\)\\s*\\{`, "u")); - if (!match) return ""; + const match = source.match(new RegExp(`(?:async\\s+)?function\\s+${escapeRegExp(functionName)}\\s*\\(`, "u")); + if (!match || typeof match.index !== "number") return ""; + let signatureIndex = match.index + match[0].length - 1; + let signatureDepth = 0; + let bodyStart = -1; + for (let index = signatureIndex; index < source.length; index += 1) { + const char = source[index]; + if (char === "(") signatureDepth += 1; + if (char === ")") { + signatureDepth -= 1; + continue; + } + if (signatureDepth === 0 && char === "{") { + bodyStart = index; + break; + } + } + if (bodyStart === -1) return ""; let depth = 0; - for (let index = match.index + match[0].length - 1; index < source.length; index += 1) { + for (let index = bodyStart; index < source.length; index += 1) { const char = source[index]; if (char === "{") depth += 1; if (char === "}") {