From 1179148031d7352bafe92acbf7ac0f3c87905629 Mon Sep 17 00:00:00 2001 From: kuekhaoyang Date: Sat, 25 Jul 2026 14:48:28 +0800 Subject: [PATCH] fix: avoid false-positive WebView transpile guard failures Keep chrome69 downleveling for Android 9 WebViews, but only hard-fail on logical assignment after transpile. Regex/polyfill feature detects and minified ternaries can contain `??`/`?.` character sequences that are not optional chaining or nullish coalescing operators. --- scripts/transpile-client-assets.mjs | 10 ++++++---- tests/webview83-assets.test.ts | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/transpile-client-assets.mjs b/scripts/transpile-client-assets.mjs index a6a6639..84c7cc0 100644 --- a/scripts/transpile-client-assets.mjs +++ b/scripts/transpile-client-assets.mjs @@ -6,9 +6,11 @@ import { transform } from 'esbuild'; // Android 9 / Amlogic TV WebViews are often Chrome 66–74. // chrome83 still emits `??` (Chrome 80+), which white-screens those devices. +// chrome69 downlevels `??` / `?.` / logical assignment in application code. const TARGET = 'chrome69'; -// Logical assignment + nullish coalescing + optional chaining break old WebViews. -const UNSUPPORTED_MODERN_SYNTAX = /(\?\?=|\|\|=|&&=|\?\?|\?\.)/; +// Hard-fail only on logical assignment: unambiguous and never appears in polyfill +// feature-detect regexes (e.g. `/()??/`) or minified ternaries (`E?.3:1`). +const UNSUPPORTED_LOGICAL_ASSIGNMENT = /(\?\?=|\|\|=|&&=)/; async function pathExists(filePath) { try { @@ -50,8 +52,8 @@ async function transpileFile(filePath) { await fs.writeFile(filePath, result.code); - if (UNSUPPORTED_MODERN_SYNTAX.test(result.code)) { - throw new Error(`${filePath} still contains modern syntax unsupported by ${TARGET} after transpilation.`); + if (UNSUPPORTED_LOGICAL_ASSIGNMENT.test(result.code)) { + throw new Error(`${filePath} still contains logical assignment syntax after ${TARGET} transpilation.`); } } diff --git a/tests/webview83-assets.test.ts b/tests/webview83-assets.test.ts index 9904b37..085e9d4 100644 --- a/tests/webview83-assets.test.ts +++ b/tests/webview83-assets.test.ts @@ -36,7 +36,9 @@ test('client asset transpilation removes modern syntax for Android 9 WebView (Ch assert.equal(output.includes('??='), false); assert.equal(output.includes('||='), false); assert.equal(output.includes('&&='), false); - // chrome83 still emits `??`; chrome69 must not - assert.equal(output.includes('??'), false); + // chrome83 still emits bare `??` in app code; chrome69 must rewrite it. + // (Polyfill feature-detect regexes like `/()??/` may still contain the characters.) + assert.equal(output.includes('nested'), true); + assert.equal(/\?\?\s*"fallback"|\?\?\s*'fallback'/.test(output), false); assert.equal(output.includes('?.'), false); });