Support new import attributes "with" syntax.
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.
Also possibly related bug at https://github.com/acornjs/acorn/issues/1289.
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.
This is why I should always wait for stage 4 :)
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.
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.
Doh, just ran into this issue myself. Glad there is a thread on it already. +1 to get this feature added please.
This became stage 4, so I implemented it, will release today or tomorrow