tools
tools copied to clipboard
Parenthesize expressions
trafficstars
Prettier uses an exhaustive heuristic of when it should insert parentheses or not. Rome should implement a similar heuristic.
https://github.com/prettier/prettier/blob/6d02cd9650be29d1b11ab6ff1442eac4f5415c06/src/language-js/needs-parens.js#L20-L793
Relevant test cases with differences:
- js/assignment/sequence.js
- js/async/await-parse.js
- js/async/conditional-expression.js
- js/async/inline-await.js
- js/async/nested.js
- js/babel-plugins/private-fields-in-in.js
- js/binary-expressions/equality.js
- js/binary-expressions/exp.js
- js/binary-expressions/math.js
- js/binary_math/parens.js
- js/class-extends/extends.js
- js/classes/binary.js
- js/classes/call.js
- js/classes/member.js
- js/classes/new.js
- js/classes/ternary.js
- js/conditional/no-confusing-arrow.js
- js/export-default/function_tostring.js
- js/for-of/async-identifier.js
- js/function/function_expression.js
- js/in/arrow-function.js
- js/logical_expressions/issue-7024.js
- js/logical_expressions/logical_expression_operators.js
- js/new-expression/new_expression.js
- js/nullish-coalescing/nullish_coalesing_operator.js
- js/objects/expand.js
- js/optional-chaining/chaining.js
- js/optional-chaining/eval.js
- js/reserved-word/interfaces.js
- js/spread/spread.js
- js/template/parenthesis.js
- js/unary-expression/urnary_expression.js
- js/yield/arrow.js
- js/yield/conditional.js
- js/yield/jsx.js
FYI, our formatting architecture is different from prettier's:
- By default they always remove parenthesis and they have a function that tells the IR to not remove them.
- We format by node, they use a different strategy. Which means that check of parenthesis in our case must be done on node level, no need to recreate prettier's function.
Closed by #3057