Donny/강동윤
39c680d814
fix(es/codegen): Fix codegen of unicode surrogates ( #7985 )
...
**Description:**
x-ref: https://vercel.slack.com/archives/C02HY34AKME/p1695334071194139
Reproduction: https://github.com/kdy1/repro-test-mdx-korean
Regression of next.js: `v13.4.11`(swc_core@v0.79.13 ) => `v13.5.2`
(swc_core@v0.83.12 )
- `next@v13.4.19` works (swc_core@v0.79.59 )
- `next@v13.4.20-canary.3` works (swc_core@v0.79.70 )
- **`next@v13.4.20-canary.32` fails** (swc_core@v0.83.12 )
Commit range:
662f236aa5...e67bf05f9d
- `swc_core@v0.79.70`:
662f236aa5
- `swc_core@v0.83.12`:
e67bf05f9d
Diff: https://gist.github.com/kdy1/047e7e5537c34180d446cb3d5b95fce8
---
I did more investigation by monkey-patching the `next` package.
`.minify()` resolved without an exception.
It means that `.minify()` is producing an invalid ES code.
So... candidates are
- https://github.com/swc-project/swc/pull/7890
- https://github.com/swc-project/swc/pull/7876
- https://github.com/swc-project/swc/pull/7858
- https://github.com/swc-project/swc/pull/7856
- https://github.com/swc-project/swc/pull/7853
- https://github.com/swc-project/swc/pull/7832
2023-09-25 23:36:05 +00:00
Donny/강동윤
b3d3a7bc73
fix(es/minifier): Do not inline into a template literal with sequential inliner ( #7971 )
...
**Related issue:**
- Closes #7969 .
2023-09-20 06:57:03 +00:00
Donny/강동윤
ee7575695d
feat(es/codegen): Add an option to print assert
for import attributes ( #7914 )
...
**Description:**
- `jsc.experimental.keepImportAssertions` is renamed to `jsc.experimental.keepImportAttributes`.
- `jsc.experimental.emitAssertForImportAttributes` is added.
**Related issue:**
- Closes #7908
2023-09-05 21:24:25 +09:00
Austaras
2db10e9fd1
fix(es/resolver): Correctly resolve global value ( #7893 )
...
**Related issue:**
- Closes #7685
2023-08-31 05:54:18 +00:00
Austaras
87a47bfb2c
fix(es/minifier): Report is_fn_local
even if var is hoisted ( #7876 )
...
**Related issue:**
- Closes #7847
2023-08-29 10:21:14 +00:00
Lewis Liu
ae8cd9430d
fix(es/minifier): Don't remove exports ( #7856 )
2023-08-25 13:47:42 +09:00
Austaras
65db1badff
refactor(es/minifier): Pre-calculate reassigned
( #7832 )
2023-08-24 07:35:26 +00:00
Donny/강동윤
7fe01e64dd
fix(es/minifier): Don't inline properties if the var is not fn-local
( #7839 )
...
**Related issue:**
- https://github.com/vercel/next.js/issues/54192 .
2023-08-22 11:04:15 +09:00
Donny/강동윤
31de19ece2
fix(es/minifier): Preserve more analysis data upon inlining ( #7823 )
...
**Related issue:**
- Closes #7821 .
2023-08-17 18:09:02 +00:00
Austaras
f8ca366cc1
fix(es/minifier): Abort seq inliner if var is not fn_local or reassigned ( #7804 )
...
**Description:**
It turns out that the original implementation of `infect`is incomplete
because it cannot cover function param, and the new implementation
introduced in #7772 is redundant because what
[terser](https://github.com/terser/terser/blob/master/lib/compress/tighten-body.js#L909C18-L909C28 )
do is basically checking `fn_local`
**Related issue:**
- Closes #7784
2023-08-17 05:15:59 +00:00
Donny/강동윤
05990a98fd
fix(es/minifier): Preserve cooked
while compressing template literals ( #7773 )
...
**Related issue:**
- Closes #7770
2023-08-17 04:35:07 +00:00
Donny/강동윤
552d9aa344
fix(es/minifier): Do not drop properties used via this
( #7785 )
...
**Related issue:**
- Closes #7783 .
2023-08-10 02:48:35 +00:00
Donny/강동윤
eff0caca2b
feat(es/minifier): Support mangle.eval
( #7777 )
...
**Related issue:**
- Closes #7754
2023-08-09 20:42:12 +00:00
Austaras
ef8d12154d
fix(es/minifier): Abort seq inliner if a same var is defined in outer scope ( #7772 )
...
**Description:**
The algorithm here is directly copied from terser, I don't if it's correct or can be improved, but it does fix the issue.
**Related issue:**
- Closes #7749
2023-08-09 20:01:59 +00:00
Donny/강동윤
b45649b8d6
fix(es/codegen): Don't strip necessary escape characters ( #7687 )
...
**Related issue:**
- Closes #7678 .
2023-08-07 22:17:59 +00:00
Donny/강동윤
36ccbec061
fix(es/minifier): Abort on Array.slice
with start >= end
( #7745 )
...
**Related issue:**
- Closes #7742 .
2023-08-07 20:36:15 +00:00
Donny/강동윤
3873f58499
fix(es/minifier): Mark args of new
s as references ( #7743 )
...
**Related issue:**
- Closes #7739 .
2023-08-03 07:02:15 +09:00
Austaras
5ea6f27eb0
fix(es/minifier): Handle synthesized export default expression ( #7707 )
...
**Related issue:**
- Closes #7634 .
2023-07-31 04:10:18 +00:00
Donny/강동윤
e8c58cfd77
fix(es/utils): Fix string evaluation of array literals ( #7731 )
...
**Related issue:**
- Closes #7714 .
2023-07-31 03:31:37 +00:00
Donny/강동윤
f901b417d1
fix(es/minifier): Do not drop used properties ( #7702 )
...
**Related issue:**
- Closes #7700 .
- Closes #7710 .
2023-07-28 16:57:07 +00:00
Donny/강동윤
a26dbce981
fix(es/minifier): Abort seq inliner using visitor ( #7699 )
...
**Related issue:**
- Closes #7697 .
2023-07-25 03:30:33 +00:00
Austaras
bf723625b0
refactor(es/minifier): Respect top-level when invoking IIFE ( #7690 )
2023-07-25 02:53:55 +00:00
magic-akari
241c04ab4a
fix(es/minifier): Only cast global Infinity
/undefined
/NaN
( #7684 )
...
**Related issue:**
- Closes #7683 .
2023-07-21 01:57:39 +00:00
Austaras
9893bd2d43
refactor(es/minifier): Respect toplevel
and module
options ( #7671 )
2023-07-20 11:35:08 +09:00
Donny/강동윤
a65be14a00
fix(es/minifier): Do not reuse identifier used for import bindings ( #7639 )
...
**Related issue:**
- Closes #7634 .
2023-07-18 04:11:00 +00:00
Donny/강동윤
6be1f7075d
fix(es/minifier): Fix a bug about eval
of name mangler ( #7615 )
...
**Description:**
- Repro: https://github.com/avitorio/swcminify-debug
**Related issue:**
- https://github.com/vercel/next.js/discussions/30237#discussioncomment-6288339
2023-07-18 01:09:00 +00:00
Austaras
04b0f6d823
feat(es/minifier): Drop recursively used var declaration ( #7649 )
2023-07-15 05:54:34 +09:00
Donny/강동윤
19ba714ea1
fix(es/minifier): Don't drop unused properties of top-level vars ( #7638 )
...
**Related issue:**
- Closes #7635 .
2023-07-07 04:07:13 +00:00
Donny/강동윤
b34f1adbcc
build(cargo): Update rustc
to 2023-07-03
( #7623 )
2023-07-05 03:50:43 +00:00
Austaras
4f866de878
fix(es/minifier): Add usage to inlined ident eagerly ( #7597 )
...
**Related issue:**
- Closes #7591 .
2023-07-04 06:23:49 +00:00
Austaras
ff1ad95b59
feat(es/minifier): Compress common sub expressions in sequences ( #7587 )
2023-07-04 05:47:37 +00:00
Donny/강동윤
47d2edd4dc
feat(es/minifier): Drop unused properties ( #7534 )
...
**Related issue:**
- Closes #7472 .
2023-07-04 05:11:33 +00:00
Donny/강동윤
a685c88c61
fix(es/minifier): Don't drop assignments to unused top-level variables ( #7581 )
...
**Related issue:**
- Closes #7568
2023-06-27 15:24:06 +00:00
Donny/강동윤
398e922ca0
feat(es/minifier): Inline constants even if they are exported ( #7583 )
...
**Related issue:**
- Closes #7575 .
2023-06-27 02:14:09 +00:00
Donny/강동윤
07a858030c
feat(es/minifier): Enable hoist_props
by default ( #7535 )
2023-06-21 18:38:35 +09:00
Donny/강동윤
3ad07a7d2e
feat(es/minifier): Support __NO_SIDE_EFFECTS__
( #7532 )
...
**Related issue:**
- Closes #7525 .
2023-06-21 07:25:29 +00:00
Donny/강동윤
aa83584634
refactor(es/ast): Reimplement optional chaining ( #7441 )
...
**Related issue:**
- Closes #7003 .
- Closes #7156 .
2023-06-12 06:47:40 +00:00
Austaras
7f9f0b8bce
fix(es/minifier): Infect mutation when assigning a property ( #7503 )
2023-06-08 04:13:42 +00:00
David Sherret
064bcf4854
fix(es/codegen): Remove extra spaces in AssignPatProp
and KeyValuePatProp
( #7488 )
...
Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
2023-06-07 05:08:35 +00:00
Austaras
62075faeaa
feat(es/minifier): Remove unused labels ( #7478 )
2023-06-07 04:23:40 +00:00
Donny/강동윤
e506635f74
fix(es/minifier): Don't generate generator arrows ( #7466 )
...
**Related issue:**
- Closes #7457 .
2023-05-31 01:57:13 +00:00
Austaras
0cd2b61b05
feat(es/minifier): Inline for loop variables ( #7445 )
2023-05-25 03:59:02 +00:00
Austaras
40d2bf7ec3
fix(es/minifier): Prevent inlining vars assigned outside current function scope ( #7414 )
...
**Related issue:**
- Closes #7412 .
2023-05-19 13:35:50 +09:00
Austaras
5dbbbea2ef
fix(es/minifier): Mark all function params as potential property mutation ( #7409 )
...
**Description:**
This issue is more severe than I originally thought. It raises not in
array indexing, but in function calls and property mutation. We should
treat all function arguments as potentially be property mutated,
otherwise following example
```js
class A {
a = 1
toString() {
return this.a
}
}
const a = new A()
function foo(x) {
x.a++
}
const b = a + 1
foo(a)
console.log(b)
```
would be error(It should log 2, but logs 3 after compress).
As the result, massive regressions is unavoidable, since some of these
optimizations may indeed cause error. Part of them can be mitigated with
following optimization -- allow inline of ident even if its original
value is mutated. Consider
```js
export function foo(x) {
const y = x
x.a = 1
y.b = 2
}
```
If x is a primitive value, all mutations to its properties are ignored;
if x is a object, then y refers to the same object no matter what
mutation is performed.
And there's still room for more, currently following code
```js
export function foo(x) {
const y = Math.floor(x);
g(y);
}
```
But I'd rather do it in a separate PR.
**Related issue:**
- Closes #7402 .
2023-05-18 01:19:17 +00:00
Donny/강동윤
f9cdd741c2
test(es/minifier): Enable more terser tests ( #7396 )
2023-05-16 03:21:08 +00:00
Donny/강동윤
041b491466
feat(es/parser): Implement explicit resource management ( #7322 )
...
**Description:**
- Add `UsingDecl`.
- Add `UsingDecl` to `Decl`.
- Rename `VarDeclOrPat` to `ForHead`.
- Add `UsingDecl` to `ForHead`.
- Implement parser for using declarations.
**Related issue:**
- #7316 .
2023-05-10 04:16:44 +00:00
Donny/강동윤
1dced17998
fix(es/minifier): Fix remapping of vars upon inlining ( #7362 )
...
**Related issue:**
- Closes #7331 .
2023-05-10 03:31:15 +00:00
Donny/강동윤
246300ae25
feat(es/minifier): Drop expressions using sequential inliner ( #6936 )
2023-04-29 22:19:00 +09:00
Donny/강동윤
0aab90c005
fix(es/minifier): Fix a inliner bug related to Script
( #7288 )
...
**Related issue:**
- Closes https://github.com/swc-project/swc/issues/7287 .
2023-04-19 07:22:48 +00:00
Donny/강동윤
4c06a56e52
fix(es/minifier): Use UTF16 length for str.length
( #7275 )
...
**Related issue:**
- Closes #7274 .
2023-04-15 14:50:52 +00:00