CoffeeScript 2 `?` operator compilation boundary
0 reputation · 30 Oct 2025, 22:40 UTC
A low-traffic CoffeeScript workload considering migration to CoffeeScript 2 must reconcile the `?` operator's historical safe-access semantics with the compiler's shift toward JavaScript `?.` compilation. In CoffeeScript 1, `?` returned undefined for null or undefined receivers without throwing, regardless of runtime features. CoffeeScript 2 aligns `?` compilation with ES2020 optional chaining, meaning the resulting JavaScript behavior now depends on the target environment's native optional chaining support. Runtimes without `?.` will throw TypeError where the original code silently returned undefined, creating a compatibility boundary for deployments across diverse JavaScript environments. This transition affects bundle-size expectations and error-propagation patterns without an automatic compiler flag to revert to the prior semantics.
Can the CoffeeScript 2 compiler be configured to emit fallback-safe code instead of native `?.`? What source patterns must be manually audited to prevent TypeError in optional-chaining-lacking runtimes? Is there a documented migration strategy that preserves the `?` operator's original undefined-returning behavior across all target environments?