Commit e4af537
committed
feat: improve getEcmaVersion to recognize more environment flags
Map more of webpack's `output.environment` flags to ECMAScript versions
and pick the highest matching version when several flags are set:
* ES2015 now also includes `methodShorthand` and `templateLiteral`
* ES2017 added — triggered by `asyncFunction`
* ES2020 now also includes `dynamicImportInWorker`, `globalThis`
and `optionalChaining`
Previously the function checked ES2015 before ES2020, so an environment
that supported both (e.g. webpack production defaults) was downgraded to
ES2015 — which left ES2017–ES2020 minification opportunities on the
table. Now the highest version wins.
Effect: when webpack signals modern features, swcMinify can now drop
the unused `catch (e)` binding (ES2019 optional catch binding), which
shows up in the updated snapshots.1 parent 9df66f3 commit e4af537
3 files changed
Lines changed: 92 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | | - | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
25 | 44 | | |
26 | 45 | | |
27 | 46 | | |
28 | 47 | | |
29 | 48 | | |
30 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
31 | 52 | | |
32 | 53 | | |
33 | 54 | | |
34 | 55 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 56 | | |
41 | 57 | | |
42 | 58 | | |
| |||
0 commit comments