From a187d78a1ca1d1d0c8acc46fc80203f21d2397a9 Mon Sep 17 00:00:00 2001 From: kdletters Date: Tue, 1 Sep 2026 18:37:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=9F=E7=94=9F=E5=A3=B3?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=AD=E8=A8=80=E6=A0=BC=E5=BC=8F=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 放宽能力文档方法表的 Markdown 空白解析 统一源码片段断言的空白、括号与尾逗号归一化 --- scripts/check-native-shells.mjs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/check-native-shells.mjs b/scripts/check-native-shells.mjs index f6f30f3c6..9cf61e5a8 100644 --- a/scripts/check-native-shells.mjs +++ b/scripts/check-native-shells.mjs @@ -3608,7 +3608,7 @@ function extractDocumentMethodTable(source) { throw new Error('native shell plan method table missing end marker'); } - return [...source.slice(start, end).matchAll(/^\| `([^`]+)` \|/gm)].map( + return [...source.slice(start, end).matchAll(/^\|\s*`([^`]+)`\s*\|/gm)].map( (entry) => entry[1], ); } @@ -3831,7 +3831,7 @@ function assertNativeShellCapabilityPlan() { ], ]) { for (const snippet of snippets) { - if (!source.includes(snippet)) { + if (!sourceIncludesSnippet(source, snippet)) { throw new Error( `${label} must derive unsupported methods from shared method list`, ); @@ -4118,7 +4118,7 @@ function assertWechatMiniProgramRouteParity() { "readWebViewSourceQueryValue('clientType')", "readWebViewSourceQueryValue('clientRuntime')", ]) { - if (!webViewShellSource.includes(snippet)) { + if (!sourceIncludesSnippet(webViewShellSource, snippet)) { throw new Error( 'wechat request headers must read runtime markers from WEB_VIEW_SOURCE_QUERY', ); @@ -4136,11 +4136,22 @@ function assertWechatMiniProgramRouteParity() { function assertFileIncludesSnippet(filePath, snippet, label) { const source = fs.readFileSync(filePath, 'utf8'); - if (!source.includes(snippet)) { + if (!sourceIncludesSnippet(source, snippet)) { throw new Error(`${label} must include ${snippet} in ${filePath}`); } } +function sourceIncludesSnippet(source, snippet) { + const compact = (value) => + value + .replace(/\s+/g, ' ') + .replace(/\s*([()[\]{}])\s*/g, '$1') + .replace(/\s*,\s*/g, ',') + .replace(/,\)/g, ')') + .trim(); + return source.includes(snippet) || compact(source).includes(compact(snippet)); +} + function assertWechatMiniProgramCapabilityFlows() { const protocol = requireCommonJsModule('miniprogram/host-bridge/protocol.js'); const declaredCapabilities = protocol.WECHAT_HOST_CAPABILITIES ?? []; @@ -4461,7 +4472,7 @@ function assertWechatAuthFailureBoundaries() { "console.warn('[web-view] read mini program env failed')", 'logMiniProgramEnvReadFailure(error)', ]) { - if (!webViewShellSource.includes(snippet)) { + if (!sourceIncludesSnippet(webViewShellSource, snippet)) { throw new Error( `wechat web-view env diagnostics must include ${snippet}`, ); @@ -4497,7 +4508,7 @@ function assertWechatAuthFailureBoundaries() { 'errorMessage: WECHAT_BIND_PHONE_UNAVAILABLE_MESSAGE', 'errorMessage: WECHAT_BIND_PHONE_AUTH_REQUIRED_MESSAGE', ]) { - if (!webViewShellSource.includes(snippet)) { + if (!sourceIncludesSnippet(webViewShellSource, snippet)) { throw new Error(`wechat auth shell must include ${snippet}`); } } @@ -4566,7 +4577,7 @@ function assertWechatWebViewPageEventBoundaries() { "logWebViewPageFailure('load failed', event.detail)", "logWebViewPageEvent('message', event.detail)", ]) { - if (!webViewShellSource.includes(snippet)) { + if (!sourceIncludesSnippet(webViewShellSource, snippet)) { throw new Error( `wechat web-view page event diagnostics must include ${snippet}`, );