mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-12 23:33:43 +08:00
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:
@@ -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.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user