Terser: ES2020 support

Created on 12 Apr 2020  路  3Comments  路  Source: terser/terser

Bug report or Feature request?

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

C:\Projects\xxx>npx terser -V
terser 4.6.7

Complete CLI command or minify() options used

npx terser C:/Projects/xxx/tmp/cart.mjs --compress --ecma 2020 --module

terser input

npx terser C:/Projects/xxx/tmp/cart.mjs --compress --ecma 2020 --module

terser output or error

Parse error at C:/Projects/xxx/tmp/cart.mjs:10,25
    const b = items[pid]?.[id] ?? false;
                         ^
ERROR: Unexpected token: punc (.)
    at js_error (C:\Projects\xxx\node_modules\terser\lib\parse.js:354:11)
    at croak (C:\Projects\xxx\node_modules\terser\lib\parse.js:1038:9)
    at token_error (C:\Projects\xxx\node_modules\terser\lib\parse.js:1046:9)
    at unexpected (C:\Projects\xxx\node_modules\terser\lib\parse.js:1052:9)
    at expr_atom (C:\Projects\xxx\node_modules\terser\lib\parse.js:2242:25)
    at maybe_unary (C:\Projects\xxx\node_modules\terser\lib\parse.js:2957:19)
    at expr_ops (C:\Projects\xxx\node_modules\terser\lib\parse.js:3008:24)
    at maybe_conditional (C:\Projects\xxx\node_modules\terser\lib\parse.js:3013:20)
    at maybe_assign (C:\Projects\xxx\node_modules\terser\lib\parse.js:3090:20)
    at et (C:\Projects\xxx\node_modules\terser\lib\parse.js:3113:24)

    at ChildProcess.exithandler (child_process.js:303:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1026:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
(node:12696) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12696) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected result

No parse error.
ES2020 features like Optional Chaining and Nullish coalescing Operator should be fine with the --ecma 2020 option

NB : This code is parsed properly by both Typescript and Chrome.

Most helpful comment

Nullish coalescing and optional chaining are both supported as of 5.2.0!

All 3 comments

Terser recently introduced support for Nullish coalescing operator (see https://github.com/terser/terser/commit/575ba807c4e5dcad9e01ea8e602bc4c2b42c9dca)

I guess optional chaining support will also appear soon

Optional chaining is way more complex to implement, and its ESTree spec is not finalised yet.

So this is going to take a while.

Nullish coalescing and optional chaining are both supported as of 5.2.0!

Was this page helpful?
0 / 5 - 0 ratings