Semantic Diff

#9503 Merge null and undefined checks with source maps on too

1 commit

69e11bfe7acda5984c1bf6bb2e7b10c320cd7df6..pr-9503

0af703747 · cknitt + Claude · Dec 01, 2026, 21:15 UTC

Merge null and undefined checks with source maps on too

Why

With source maps on, the two reads of e in e === null || e === undefined carry different source locations. Js_dump compared them with =, which includes the locations, so it printed both checks instead of e == null, and the JavaScript depended on whether source maps were on. It now compares them with Js_analyzer.eq_expression, which ignores locations. Fixes #9502.

modifiedJS null and undefined checks with source maps

let r = opaque({v: Nullable.null})eq(__LOC__, r.v === Nullable.null || r.v === Nullable.undefined, true)
js
Before tests/compiler_tests/src/null_check_merge_test.res, with source maps
After with source maps, the same as without them
Test_utils.eq("…", r.v === null || r.v === undefined, true);Test_utils.eq("…", r.v == null, true);

Review

  • Can eq_expression stop a merge that = allowed? It answers false for some shapes, such as floats or Length. Building tests/compiler_tests without source maps gives the committed output, so no merge there is lost.