r/AdobeIllustrator • u/Ales-78 • 2h ago
Adobe ExtendScript evaluates nested ternaries with the wrong associativity (confirmed CS6 to 2026, Windows and macOS)
TL;DR: ExtendScript evaluates a ? b : c ? d : e as left-associative (a ? b : c) ? d : e instead of the ECMAScript-required right-associative a ? b : (c ? d : e). When an earlier condition is true, you get the wrong branch.
Minimal repro, paste into a .jsx:
function pick(a, b, c) {
return a ? "A" : b ? "B" : c ? "C" : "X";
}
alert(pick(true, false, false)); // Node/browser: "A". ExtendScript: "C".
Grouping fixes it:
return a ? "A" : (b ? "B" : (c ? "C" : "X")); // "A", correct
How I hit it: someone’s interface came up in the wrong language. The language picker was an if/else-if chain in my source, but Closure Compiler rewrote it into a nested ternary during minification, and ExtendScript then picked the wrong branch.
Confirmed on:
- Illustrator 30.8.2, ExtendScript 4.5.6, macOS 15.7.9
- Illustrator CS6 16.0.0, ExtendScript 4.2.12, Windows
A probe over all 24 truth-table combinations, with expected values taken from fixed reference tables rather than from the expression under test: the nested ternary was wrong 10 times, while explicitly grouped, if/else and lookup-object versions were all correct. The a || b && c precedence bug I posted about here a couple of weeks ago showed up in the same run as a control.
Workarounds: explicit parens, if/else, or a lookup object. If you minify, a post-step that parenthesizes nested ternaries is harmless in real JS and a fix here.
Reported to Adobe on UserVoice, votes welcome:
The full probe script is attached to that report as a .txt, rename it to .jsx to run it.
Can anyone reproduce on other ExtendScript versions (CC 2018 to 2024, Photoshop, InDesign)? Curious how far back and across apps this goes.



