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.
This commit is contained in:
kuekhaoyang
2026-07-25 14:48:28 +08:00
parent e04b306334
commit 1179148031
2 changed files with 10 additions and 6 deletions
+6 -4
View File
@@ -6,9 +6,11 @@ import { transform } from 'esbuild';
// Android 9 / Amlogic TV WebViews are often Chrome 6674.
// 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.`);
}
}
+4 -2
View File
@@ -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);
});