From 84b60a92e0e50f3e585d1b1fb835c17c7c524a00 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Thu, 19 Nov 2026 18:59:10 -0800 Subject: [PATCH 1/3] Read the weather texture limit and the reveal time in the body, not in a parameter default esbuild compiles an optional method call reached through an optional chain (`a?.b?.()`) in a parameter's default, for browsers it lowers optional chaining for (Chrome and Edge before 91), into code that reads a variable out of its scope. The weather shell's texture limit was read that way, so every satellite frame threw a ReferenceError in the built app and the layer showed "Weather imagery unavailable"; the leader and card reveal took their default time the same way. A test now refuses the form anywhere under src/. --- src/layers/weather/shellRendering.js | 13 +++- src/overlays/worldOverlayDraw.js | 24 +++---- src/parameterDefaults.test.mjs | 93 ++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 14 deletions(-) create mode 100644 src/parameterDefaults.test.mjs diff --git a/src/layers/weather/shellRendering.js b/src/layers/weather/shellRendering.js index 0391c2752f..06972473c5 100644 --- a/src/layers/weather/shellRendering.js +++ b/src/layers/weather/shellRendering.js @@ -177,13 +177,20 @@ export function createWeatherShell({ drawOf = findDraw, cameraOf = findCamera, frameOf = findFrame, - maxTextureSize = rendererOf(viewer)?.quality?.device?.().maxTextureSize ?? 0, + maxTextureSize, frameSource = null, }) { if (!Object.hasOwn(WEATHER_IMAGE_SIZES, product)) throw new TypeError('Unknown weather product'); - const size = fitTexture(WEATHER_IMAGE_SIZES[product], maxTextureSize); - const detailSize = fitTexture(WEATHER_DETAIL_SIZE, maxTextureSize); + // Read in the body, not as the parameter's default: an optional method call + // in a default parameter is compiled for older browsers into code that + // throws (esbuild). + const textureLimit = + maxTextureSize === undefined + ? (rendererOf(viewer)?.quality?.device?.().maxTextureSize ?? 0) + : maxTextureSize; + const size = fitTexture(WEATHER_IMAGE_SIZES[product], textureLimit); + const detailSize = fitTexture(WEATHER_DETAIL_SIZE, textureLimit); const infrared = product === 'clouds' || product === 'clouds-regional'; // Global infrared contrast depends on the requested extent, so a window would // not match the image around it; the globe host also shows one mosaic. diff --git a/src/overlays/worldOverlayDraw.js b/src/overlays/worldOverlayDraw.js index e5db5d5b7f..4a32b89437 100644 --- a/src/overlays/worldOverlayDraw.js +++ b/src/overlays/worldOverlayDraw.js @@ -709,29 +709,31 @@ function leaderDrawRatio(entry) { return Number.isFinite(ratio) ? Math.max(0.1, Math.min(0.9, ratio)) : 0.68; } -export function leaderRevealProgress( - entry, - timestamp = globalThis.performance?.now?.() ?? Date.now(), -) { +/** Now, for a reveal given no time. Not a parameter default: an optional + * method call in a default parameter is compiled for older browsers into code + * that throws (esbuild). */ +function revealNow() { + return globalThis.performance?.now?.() ?? Date.now(); +} + +export function leaderRevealProgress(entry, timestamp) { + const at = timestamp === undefined ? revealNow() : timestamp; const linear = Math.min( 1, - animationLinearProgress(entry, timestamp) / leaderDrawRatio(entry), + animationLinearProgress(entry, at) / leaderDrawRatio(entry), ); return 1 - Math.pow(1 - linear, 3); } -export function tacticalCardRevealAlpha( - entry, - timestamp = globalThis.performance?.now?.() ?? Date.now(), -) { +export function tacticalCardRevealAlpha(entry, timestamp) { if (!(Math.max(0, Number(entry?.leaderAnimationMs) || 0) > 0)) return 1; + const at = timestamp === undefined ? revealNow() : timestamp; const start = leaderDrawRatio(entry); const linear = Math.max( 0, Math.min( 1, - (animationLinearProgress(entry, timestamp) - start) / - Math.max(0.1, 1 - start), + (animationLinearProgress(entry, at) - start) / Math.max(0.1, 1 - start), ), ); return linear * linear * (3 - 2 * linear); diff --git a/src/parameterDefaults.test.mjs b/src/parameterDefaults.test.mjs new file mode 100644 index 0000000000..8314bc5138 --- /dev/null +++ b/src/parameterDefaults.test.mjs @@ -0,0 +1,93 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync, readdirSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import ts from 'typescript'; + +const SRC_ROOT = fileURLToPath(new URL('.', import.meta.url)); + +/** Every browser-built module under src/ — the test files are Node-only. */ +function browserModules(directory = SRC_ROOT) { + const files = []; + for (const entry of readdirSync(directory, { withFileTypes: true })) { + const absolute = path.join(directory, entry.name); + if (entry.isDirectory()) files.push(...browserModules(absolute)); + else if ( + entry.isFile() && + entry.name.endsWith('.js') && + !entry.name.endsWith('.test.js') + ) + files.push(absolute); + } + return files.sort(); +} + +/** + * Whether `node` is an optional call of a method reached through an optional + * chain: `a?.b?.()`, `f()?.g?.h?.()`. The forms esbuild compiles correctly, + * `a?.b()` and `a.b?.()`, are not. + */ +function optionalMethodCall(node) { + if (!ts.isCallExpression(node) || !node.questionDotToken) return false; + const callee = node.expression; + const member = + ts.isPropertyAccessExpression(callee) || + ts.isElementAccessExpression(callee); + return member && (callee.flags & ts.NodeFlags.OptionalChain) !== 0; +} + +/** Such calls in `node`, a default's expression, outside nested functions. */ +function callsIn(node, found = []) { + if (ts.isFunctionLike(node)) return found; + if (optionalMethodCall(node)) found.push(node); + ts.forEachChild(node, (child) => callsIn(child, found)); + return found; +} + +/** The defaults of a parameter: its own and those inside a destructuring pattern. */ +function defaultsOf(binding, found = []) { + if (binding.initializer) found.push(binding.initializer); + if ( + ts.isObjectBindingPattern(binding.name) || + ts.isArrayBindingPattern(binding.name) + ) + for (const element of binding.name.elements) + if (ts.isBindingElement(element)) defaultsOf(element, found); + return found; +} + +test('no parameter default calls a method through an optional chain', () => { + // esbuild compiles `a?.b?.()` in a parameter's default, for the browsers a + // build still lowers optional chaining for (Chrome and Edge before 91), into + // code that reads a variable out of its scope: the call throws a + // ReferenceError in the built app, never under node:test. The weather shell + // read its texture limit this way, so every satellite frame failed. Compute + // such a value in the function's body instead. + const offenders = []; + for (const file of browserModules()) { + const source = ts.createSourceFile( + file, + readFileSync(file, 'utf8'), + ts.ScriptTarget.Latest, + true, + ts.ScriptKind.JS, + ); + const visit = (node) => { + if (ts.isFunctionLike(node)) + for (const parameter of node.parameters ?? []) + for (const initializer of defaultsOf(parameter)) + for (const call of callsIn(initializer)) { + const { line } = source.getLineAndCharacterOfPosition( + call.getStart(source), + ); + offenders.push( + `${path.relative(SRC_ROOT, file)}:${line + 1} ${call.getText(source)}`, + ); + } + ts.forEachChild(node, visit); + }; + visit(source); + } + assert.deepEqual(offenders, []); +}); From 3e6d2165fd6c0400205a84d2bc33dfb13b9852f3 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Thu, 19 Nov 2026 18:59:36 -0800 Subject: [PATCH 2/3] Changelog: #1873 --- changelog.d/1873-weather-texture-limit.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/1873-weather-texture-limit.md diff --git a/changelog.d/1873-weather-texture-limit.md b/changelog.d/1873-weather-texture-limit.md new file mode 100644 index 0000000000..fdb351c1a2 --- /dev/null +++ b/changelog.d/1873-weather-texture-limit.md @@ -0,0 +1,4 @@ +- Satellite clouds draw again in a built app instead of showing "Weather + imagery unavailable": the weather shell read its texture limit in a + parameter default, which esbuild compiles for older browsers into code that + throws. A test now refuses the form under `src/` (samehkhamis, #1873). From e3a17c527bb0091a76cb91025d29cbfa5607f1d1 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Thu, 19 Nov 2026 19:02:10 -0800 Subject: [PATCH 3/3] Parameter defaults test: name the forms that break, and read single-file components and .mjs modules too --- src/parameterDefaults.test.mjs | 42 +++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/parameterDefaults.test.mjs b/src/parameterDefaults.test.mjs index 8314bc5138..97e107b82e 100644 --- a/src/parameterDefaults.test.mjs +++ b/src/parameterDefaults.test.mjs @@ -7,26 +7,45 @@ import ts from 'typescript'; const SRC_ROOT = fileURLToPath(new URL('.', import.meta.url)); -/** Every browser-built module under src/ — the test files are Node-only. */ -function browserModules(directory = SRC_ROOT) { +/** Every module under src/ the build compiles: scripts and single-file + * components, not the Node-only tests. */ +function builtModules(directory = SRC_ROOT) { const files = []; for (const entry of readdirSync(directory, { withFileTypes: true })) { const absolute = path.join(directory, entry.name); - if (entry.isDirectory()) files.push(...browserModules(absolute)); + if (entry.isDirectory()) files.push(...builtModules(absolute)); else if ( entry.isFile() && - entry.name.endsWith('.js') && - !entry.name.endsWith('.test.js') + /\.(js|mjs|vue)$/.test(entry.name) && + !/\.test\.(js|mjs)$/.test(entry.name) ) files.push(absolute); } return files.sort(); } +/** The code of `file` to parse: a component's script blocks in place (every + * other character a space, so lines keep their numbers), else the file. */ +function scriptOf(file) { + const text = readFileSync(file, 'utf8'); + if (!file.endsWith('.vue')) return { code: text, kind: ts.ScriptKind.JS }; + const kept = text.replace(/[^\n]/g, ' ').split(''); + let kind = ts.ScriptKind.JS; + for (const match of text.matchAll(/]*)>([\s\S]*?)<\/script>/g)) { + if (/lang=["']ts["']/.test(match[1])) kind = ts.ScriptKind.TS; + const start = match.index + match[0].indexOf('>') + 1; + for (let i = 0; i < match[2].length; i += 1) + kept[start + i] = text[start + i]; + } + return { code: kept.join(''), kind }; +} + /** * Whether `node` is an optional call of a method reached through an optional - * chain: `a?.b?.()`, `f()?.g?.h?.()`. The forms esbuild compiles correctly, - * `a?.b()` and `a.b?.()`, are not. + * chain: `a?.b?.()`, `a.b?.c?.()`, `f()?.g?.()`. Of these esbuild breaks the + * ones whose optional property is read from a property or a call + * (`a.b?.c?.()`, `f()?.g?.()`); the rule is kept stricter than that, as such a + * value is as easily read in the body. `a?.b()` and `a.b?.()` are not matched. */ function optionalMethodCall(node) { if (!ts.isCallExpression(node) || !node.questionDotToken) return false; @@ -58,20 +77,21 @@ function defaultsOf(binding, found = []) { } test('no parameter default calls a method through an optional chain', () => { - // esbuild compiles `a?.b?.()` in a parameter's default, for the browsers a + // esbuild compiles `a.b?.c?.()` in a parameter's default, for the browsers a // build still lowers optional chaining for (Chrome and Edge before 91), into // code that reads a variable out of its scope: the call throws a // ReferenceError in the built app, never under node:test. The weather shell // read its texture limit this way, so every satellite frame failed. Compute // such a value in the function's body instead. const offenders = []; - for (const file of browserModules()) { + for (const file of builtModules()) { + const { code, kind } = scriptOf(file); const source = ts.createSourceFile( file, - readFileSync(file, 'utf8'), + code, ts.ScriptTarget.Latest, true, - ts.ScriptKind.JS, + kind, ); const visit = (node) => { if (ts.isFunctionLike(node))