Terser: SyntaxError: Unexpected token '??'. Coalescing and logical operators used together in the same expression; parentheses must be used to disambiguate.

Created on 24 Sep 2020  路  3Comments  路  Source: terser/terser

Bug report or Feature request?

Bug Report

Version (complete output of terser -V or specific git commit)

5.3.1

Complete CLI command or minify() options used

Run via ember-cli-terser.

terser input

return (this.span?.durationSelf && this.span.durationSelf / 1000) ?? null;

terser output or error

return this.span?.durationSelf&&this.span.durationSelf/1e3??null

Causes this error in browser:

SyntaxError: Unexpected token '??'. Coalescing and logical operators used together in the same expression; parentheses must be used to disambiguate.

Expected result

I believe it would work if the following was generated:

return (this.span?.durationSelf&&this.span.durationSelf/1e3)??null
bug

All 3 comments

Thanks for reporting!

We also experienced this issue.

The fix was relatively simple. I had to look at the spec for a bit and realized that the precedence rules are weirder than I originally thought :)

Was this page helpful?
0 / 5 - 0 ratings