jashkenas / underscore

JavaScript's utility _ belt
https://underscorejs.org
MIT License
27.28k stars 5.53k forks source link

Parenthesize mixed expressions of || and && #2953

Closed jgonggrijp closed 2 years ago

jgonggrijp commented 2 years ago

ExtendScript apparently gives equal precedence to the || and && operators, so when the || appears before the &&, we need to anchor the order of evaluation with an extra pair of parentheses. See #2949.

@RaymondClr Could you test whether all of your code works correctly in ExtendScript with https://github.com/jgonggrijp/underscore/raw/extendscript-precedence/underscore-umd.js?

coveralls commented 2 years ago

Coverage Status

Coverage remained the same at 95.217% when pulling c4e092059604ae965583d2a8eff4d1cfdee5ce2d on jgonggrijp:extendscript-precedence into 0557e331e065249421ff43c42ed00787df26c657 on jashkenas:master.

captbaritone commented 2 years ago

Some thoughts (feel free to ignore if they don't seem helpful):

If we want to support this long term, there's probably an ESLint rule we could/should enable to ensure we don't regress.

Another option here would be to add these as part of our build step. I know we try to keep our build step as minimal as possible, so I can also understand the value of doing it in the code itself. This thought occurred to me because, presumably our minified bundle will strip these new parentheses.

jgonggrijp commented 2 years ago

Excellent comments, thanks @captbaritone! In one short post, you mentioned three things I didn't think of:

I plan to go through the above list within the current PR.

jgonggrijp commented 2 years ago

@captbaritone Outcome of our discussion:

jgonggrijp commented 2 years ago

@RaymondClr I'm just going to merge this now on the assumption that this solves #2949. However, please still double-check that the issue is solved on your end when you find the time. Thanks in advance!

captbaritone commented 2 years ago

Awesome. Thanks for the write up! Sounds like a great solution.

captbaritone commented 2 years ago

It might be worth adding a comment to the ESLint config explaining why the rule is enabled. Otherwise we might opt to remove in the future assuming it's purely stylistic without realizing it's load bearing.

jgonggrijp commented 2 years ago

Oops, good point. I assumed this wouldn't be allowed because the config is in JSON, but according to the eslint docs, it is allowed. I'll add it it in a separate commit on master.

dogbubu commented 1 year ago

gsdg54sdg5s4d5gドっぱくラバニラサダウのブはとてもおいしそうなりんかマカョ♂