From fe80d52c9e994154c3a373c29f04e00f46e2e208 Mon Sep 17 00:00:00 2001 From: gensokyo-dev Date: Sat, 14 Nov 2026 13:26:17 +0000 Subject: [PATCH] fix(javascript): read a BigInt literal's truthiness from any spelling Older Babel keeps a BigInt literal's source digits, which may carry a 0x/0o/0b prefix, so a hexadecimal zero read as truthy and a falsy socket host such as 0x0n could drop a valid acquisition. Parse the value with BigInt. Refs #10002 Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --- src/domain/javascript/javascriptAstValues.ts | 11 +++++++++-- ...ascriptSemanticAnalysis.socket_host_member.test.ts | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/domain/javascript/javascriptAstValues.ts b/src/domain/javascript/javascriptAstValues.ts index 2f26a7ecba..0ec62c2593 100644 --- a/src/domain/javascript/javascriptAstValues.ts +++ b/src/domain/javascript/javascriptAstValues.ts @@ -173,8 +173,15 @@ export const staticJavaScriptTruthiness = ( if (t.isStringLiteral(value)) return value.value.length > 0; if (t.isNumericLiteral(value)) return value.value !== 0 && !Number.isNaN(value.value); - // Babel exposes a BigIntLiteral value as either "0" or 0n depending on version. - if (t.isBigIntLiteral(value)) return String(value.value) !== "0"; + // Babel exposes a BigIntLiteral value as a bigint or, in older versions, its + // source digits, which may carry a 0x/0o/0b prefix; BigInt reads both. + if (t.isBigIntLiteral(value)) { + try { + return BigInt(value.value as string | bigint) !== 0n; + } catch { + return undefined; + } + } if ( t.isUnaryExpression(value) && value.operator === "-" && diff --git a/src/domain/javascript/javascriptSemanticAnalysis.socket_host_member.test.ts b/src/domain/javascript/javascriptSemanticAnalysis.socket_host_member.test.ts index f3e44ceced..94a7e5a974 100644 --- a/src/domain/javascript/javascriptSemanticAnalysis.socket_host_member.test.ts +++ b/src/domain/javascript/javascriptSemanticAnalysis.socket_host_member.test.ts @@ -78,6 +78,9 @@ it.each([ ["a negative-zero host", `net.connect({ port: 0, host: -0 })`], ["a false host", `net.connect({ port: 0, host: false })`], ["a zero BigInt host", `net.connect({ port: 0, host: 0n })`], + ["a hexadecimal zero BigInt host", `net.connect({ port: 0, host: 0x0n })`], + ["an octal zero BigInt host", `net.connect({ port: 0, host: 0o0n })`], + ["a binary zero BigInt host", `net.connect({ port: 0, host: 0b0n })`], ["a NaN host", `net.connect({ port: 0, host: NaN })`], ["a void host", `net.connect({ port: 0, host: void 0 })`], ["a negated host", `net.connect({ port: 0, host: !1 })`],