terser icon indicating copy to clipboard operation
terser copied to clipboard

Support new import attributes "with" syntax.

Open freshp86 opened this issue 1 year ago • 6 comments

The new with syntax will soon be required by Chromium (and other Chromium based browsers), and the old assert syntax will no longer work (see https://chromium-review.googlesource.com/c/v8/v8/+/5512879).

Also see [1], [2] for the status of the "import attributes" feature. The older syntax had been implemented at https://github.com/terser/terser/issues/1095, and it seems that some similar updates are needed to support the new syntax.

[1] https://caniuse.com/mdn-javascript_statements_import_import_attributes [2] https://chromestatus.com/feature/5205869105250304

Bug report or Feature request?

Bug.

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

5.31.0

Complete CLI command or minify() options used

{
  module: true,
  compress: {},
  mangle: {},
  output: {},
  parse: {},
  rename: {},
}

terser input

import mysheet from './foo.css' with {type : 'css'};

terser output or error

ERROR: Unexpected token: keyword (with)

Expected result

Should not crash.

freshp86 avatar May 09 '24 23:05 freshp86

Also possibly related bug at https://github.com/acornjs/acorn/issues/1289.

freshp86 avatar May 10 '24 00:05 freshp86

What should be the output for people who wrote assert? Should it be garbage-in-garbage-out or always output with? assert wasn't JS syntax proper, but it might be supported by some browsers that users of assert support, that wouldn't support with.

fabiosantoscode avatar May 22 '24 08:05 fabiosantoscode

This is why I should always wait for stage 4 :)

fabiosantoscode avatar May 22 '24 08:05 fabiosantoscode

What should be the output for people who wrote assert?

Whatever happens today? I don't think the feature request here to support with should affect what happens when assert is used. Terser authors can decide when/if support for assert should be completely removed.

Should it be garbage-in-garbage-out or always output with?

Personal opinion is that a minifier should not make assert -> with transformations to the code, as this is not strictly speaking a minifiers responsibility. If the code used assert it should output assert. Having said that, I am not a Terser author, so just my perspective.

freshp86 avatar May 22 '24 16:05 freshp86

You are correct that the minifier shouldn't convert between them, at least in theory.

I'll wait for Stage 4 to implement, otherwise I might have to support 3 different versions of the feature.

fabiosantoscode avatar May 23 '24 17:05 fabiosantoscode

Doh, just ran into this issue myself. Glad there is a thread on it already. +1 to get this feature added please.

bannostookaylo avatar Jun 17 '24 03:06 bannostookaylo

This became stage 4, so I implemented it, will release today or tomorrow

fabiosantoscode avatar Oct 16 '24 11:10 fabiosantoscode