Fails to parse object division in ternary alternate: `weird ? true : {}/2`
See original GitHub issueBug Report
- I would like to work on a fix!
Current Behavior Fails to parse two useless but valid pieces of JavaScript.
Input Code
weird ? true : {}/2;
Unterminated regular expression (1:18)
weird ? true : {}/2/g;
Unexpected token, expected ";" (1:17)
Note: When adding parentheses parsing succeeds:
weird ? true : ({}/2);
But Babel’s output is:
weird ? true : {} / 2;
Which means that Babel cannot parse its output.
Moving {}/2
to the consequent of the ternary parses:
weird ? {}/2 : true;
Expected behavior/code They should parse. For example Node.js, Firefox and TypeScript accept them.
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc) Defaults.
Environment
System:
OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
Binaries:
Node: 13.11.0 - /home/linuxbrew/.linuxbrew/bin/node
Yarn: 1.22.4 - /home/linuxbrew/.linuxbrew/bin/yarn
npm: 6.13.7 - /home/linuxbrew/.linuxbrew/bin/npm
npmPackages:
@babel/parser: 7.9.4 => 7.9.4
eslint: 6.8.0 => 6.8.0
jest: 25.2.3 => 25.2.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Ternary operator parse error (TS 2.5) #18204 - GitHub
The workaround is to not parenthesize the true branch of the ternary, because this makes the parser think that it could be looking...
Read more >Alternative to nested ternary operator in JS - Stack Overflow
The question was how to express the above logic without nested ternary operators or an if/else chain. The option of a switch was...
Read more >Conditional (ternary) operator - JavaScript - MDN Web Docs
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?)
Read more >Programming FAQ — Python 3.11.1 documentation
How can my code discover the name of an object? What's up with the comma operator's precedence? Is there an equivalent of C's...
Read more >Essentials - Julia Documentation
Compute the amount of memory, in bytes, used by all unique objects ... i = 0 0 julia> while true global i +=...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just wanted to say that I haven’t forgotten about this one. https://github.com/babel/babel/pull/11404 has been taking my focus, but I hope to tackle this soon.
Could I take this one? ✋