Unparser doesn't preserve operation precedence
- Dominant language
- JavaScript
- Stars
- 110
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
**I'm submitting a bug report**
* **Library Version:**
1.2.1
**Please tell us about your environment:**
* **Operating System:**
IRRELEVANT
* **Node Version:**
IRRELEVANT
* **NPM Version:**
IRRELEVANT
* **JSPM OR Webpack AND Version**
IRRELEVANT
* **Browser:**
IRRELEVANT
* **Language:**
IRRELEVANT
**Current behavior:**
```
const parser = new Parser();
parser.parse('a&&(b||c)').toString() // 'a&&b||c' wrong logic
parser.parse('a&&(b=1)').toString() // 'a&&b=1' syntactically wrong
parser.parse('2*(2+3)').toString() // '2*2+3' oops
```
**Expected/desired behavior:**
* **What is the expected behavior?**
Unparser should preserve operation precedence
* **What is the motivation / use case for changing the behavior?**
It's a bug to be fixed.
`unparser.spec.js` should cover this.
I tried fixing it, but failed. It looks like the unparser needs to understand the position of the expression in the tree, and also the default javascript operator precedence, in order to decide whether needs to wrap the expression in extra parenthesis.
Contributor guide
Research direction
Start with the Parser.parse(...).toString() examples and the unparser.spec.js coverage named in the issue. Trace how parsed expression tree positions are handled when unparsing, then add tests showing that logical, assignment, and arithmetic precedence is preserved; done means the output retains equivalent grouping and valid syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100