Skip to content

Commit aadee81

Browse files
committed
fix(build): releaseProd died on nullish coalescing - terser 3 can't parse it
gulp-minify@3.1.0 bundles terser 3.17 (2019), which predates ES2020 syntax. A single `?? 9` in VulnerabilityInspection.js (part of the core bundle via extensionsIntegrated) crashed makeJSDist with the line-less "Cannot read properties of undefined (reading 'replace')" error. Dev builds run unminified in Chromium, which parses `??` natively - so this only surfaces in the prod pipeline. Replaced with an `in`-guarded rank lookup (same semantics: critical maps to rank 0, which is falsy, so a plain || fallback would mis-sort it - covered by the existing dedup/sort spec). Swept all shipped src for other ES2020+ syntax (?. / ?? / logical assignment): this was the only real occurrence. Constraint: shipped src/ must stay at ES2019 syntax until the minifier is upgraded; src-node, tests and src-mdviewer are exempt. releaseProd now completes: 53s, dist size validation green (72.94 MB). unit:JSONSupport 18/18.
1 parent 86604fc commit aadee81

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/extensionsIntegrated/JSONSupport/VulnerabilityInspection.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,12 @@ define(function (require, exports, module) {
172172
seen.add(advisory.id);
173173
return true;
174174
}).sort(function (a, b) {
175-
// ?? not ||: critical maps to 0, which is falsy
176-
return (SEVERITY_ORDER[a.severity] ?? 9) - (SEVERITY_ORDER[b.severity] ?? 9);
175+
// `in`-guarded, not ||: critical maps to rank 0, which is falsy. Also NOT `??` -
176+
// the prod bundle's minifier (gulp-minify's terser 3) predates nullish coalescing
177+
// and dies on it with an unhelpful "reading 'replace'" error in makeJSDist.
178+
const rankA = (a.severity in SEVERITY_ORDER) ? SEVERITY_ORDER[a.severity] : 9;
179+
const rankB = (b.severity in SEVERITY_ORDER) ? SEVERITY_ORDER[b.severity] : 9;
180+
return rankA - rankB;
177181
}).slice(0, MAX_ADVISORIES_PER_DEP).map(function (advisory) {
178182
return {
179183
pos: entry.pos,

0 commit comments

Comments
 (0)