-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parenthesize mixed expressions of || and && #2953
Parenthesize mixed expressions of || and && #2953
Conversation
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.
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. |
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. |
) After a review comment by @captbaritone in jashkenas#2953.
These expressions are nonambiguous because the && operator comes first, but eslint does not care about the order and always requires parens. I decided to go with the flow and just add those parens.
@captbaritone Outcome of our discussion:
|
@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! |
Awesome. Thanks for the write up! Sounds like a great solution. |
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. |
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 |
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?