Repository navigation
Commit b4d6769
authored
feat(javascript): read a copied binding in place of a
* feat(javascript): read a copied binding in place of a `var` copying it in the minifier
The improve phase read `y` for `x` where `let x = y` or `const x = y`
only copies it. A `var` does now too, the copy TypeScript's `for…of`
loops make (`for (var _i = 0, array_1 = array; …)`) and terser leaves
after inlining among them: `x` is dropped once nothing reads it.
Neither name may be written again, `x` must be read only after it is
set (terser's `fixed`), and `y` must be what its name finds at each
read, looked up from the block around the read, since a `var`'s read
holds its function's scope. `y` must be set once each time the `var`'s
function runs (a parameter, `let` or `const` declared there or around
it), or else be a `var` or function beside it no function inside the
`var`'s reads, as a loop may set it again.
The read made is now counted among `y`'s reads: before, `y` read once
could still have its value inlined at the copy's declaration, leaving
the new read reading nothing, as `let v = this.v; let m = v;` did.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(javascript): leave a `var` read once copying a parameter of a call in place to terser in the minifier
Reading the parameter in the copy's place counted it twice, so terser kept the argument the call passes instead of writing it in, e.g. `...(e=yield,{...e})` for `...{...yield}`.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(javascript): record a copied binding as captured where its read replaces a copy in the minifier
A function reading `y` in place of a copy never listed `y` among the bindings it captures, so inlining it into a function declaring that name again read the inner binding instead.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* test: retire swc's react/9 project from the cases swc minifies smaller
Reading a copied `var` in place of the copy leaves react/9 no bigger than
swc's output.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeDvar copying it in the minifier (#22574)1 parent 6525560 commit b4d6769
4 files changed
Lines changed: 116 additions & 17 deletions
File tree
- lib/javascript
- test
- helpers
- unitCases
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20772 | 20772 | | |
20773 | 20773 | | |
20774 | 20774 | | |
20775 | | - | |
20776 | | - | |
| 20775 | + | |
| 20776 | + | |
| 20777 | + | |
| 20778 | + | |
| 20779 | + | |
| 20780 | + | |
| 20781 | + | |
| 20782 | + | |
| 20783 | + | |
| 20784 | + | |
| 20785 | + | |
| 20786 | + | |
| 20787 | + | |
| 20788 | + | |
| 20789 | + | |
| 20790 | + | |
| 20791 | + | |
| 20792 | + | |
| 20793 | + | |
| 20794 | + | |
| 20795 | + | |
| 20796 | + | |
| 20797 | + | |
| 20798 | + | |
| 20799 | + | |
| 20800 | + | |
| 20801 | + | |
| 20802 | + | |
| 20803 | + | |
| 20804 | + | |
| 20805 | + | |
| 20806 | + | |
| 20807 | + | |
| 20808 | + | |
| 20809 | + | |
| 20810 | + | |
| 20811 | + | |
| 20812 | + | |
| 20813 | + | |
| 20814 | + | |
| 20815 | + | |
| 20816 | + | |
| 20817 | + | |
| 20818 | + | |
| 20819 | + | |
| 20820 | + | |
| 20821 | + | |
20777 | 20822 | | |
20778 | 20823 | | |
20779 | 20824 | | |
| |||
20788 | 20833 | | |
20789 | 20834 | | |
20790 | 20835 | | |
20791 | | - | |
| 20836 | + | |
| 20837 | + | |
| 20838 | + | |
| 20839 | + | |
| 20840 | + | |
20792 | 20841 | | |
20793 | 20842 | | |
20794 | 20843 | | |
| |||
20823 | 20872 | | |
20824 | 20873 | | |
20825 | 20874 | | |
| 20875 | + | |
| 20876 | + | |
| 20877 | + | |
| 20878 | + | |
| 20879 | + | |
| 20880 | + | |
| 20881 | + | |
| 20882 | + | |
| 20883 | + | |
| 20884 | + | |
| 20885 | + | |
| 20886 | + | |
| 20887 | + | |
| 20888 | + | |
| 20889 | + | |
| 20890 | + | |
| 20891 | + | |
| 20892 | + | |
| 20893 | + | |
| 20894 | + | |
| 20895 | + | |
| 20896 | + | |
| 20897 | + | |
| 20898 | + | |
| 20899 | + | |
| 20900 | + | |
| 20901 | + | |
| 20902 | + | |
20826 | 20903 | | |
20827 | 20904 | | |
20828 | 20905 | | |
20829 | | - | |
| 20906 | + | |
20830 | 20907 | | |
20831 | 20908 | | |
20832 | 20909 | | |
20833 | | - | |
20834 | | - | |
20835 | | - | |
20836 | | - | |
| 20910 | + | |
| 20911 | + | |
| 20912 | + | |
20837 | 20913 | | |
| 20914 | + | |
20838 | 20915 | | |
20839 | 20916 | | |
20840 | 20917 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
204 | 203 | | |
205 | 204 | | |
206 | 205 | | |
| |||
660 | 659 | | |
661 | 660 | | |
662 | 661 | | |
663 | | - | |
664 | 662 | | |
665 | 663 | | |
666 | 664 | | |
667 | 665 | | |
668 | 666 | | |
669 | | - | |
670 | 667 | | |
671 | 668 | | |
672 | 669 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
221 | 220 | | |
222 | | - | |
223 | 221 | | |
224 | 222 | | |
225 | 223 | | |
226 | 224 | | |
227 | | - | |
228 | 225 | | |
229 | | - | |
230 | 226 | | |
231 | 227 | | |
232 | 228 | | |
| |||
744 | 740 | | |
745 | 741 | | |
746 | 742 | | |
747 | | - | |
748 | 743 | | |
749 | 744 | | |
750 | 745 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
844 | 844 | | |
845 | 845 | | |
846 | 846 | | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
847 | 859 | | |
848 | 860 | | |
849 | 861 | | |
| |||
1119 | 1131 | | |
1120 | 1132 | | |
1121 | 1133 | | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
1122 | 1138 | | |
1123 | 1139 | | |
1124 | 1140 | | |
| |||
6890 | 6906 | | |
6891 | 6907 | | |
6892 | 6908 | | |
6893 | | - | |
| 6909 | + | |
6894 | 6910 | | |
6895 | 6911 | | |
6896 | 6912 | | |
| |||
6902 | 6918 | | |
6903 | 6919 | | |
6904 | 6920 | | |
| 6921 | + | |
| 6922 | + | |
| 6923 | + | |
| 6924 | + | |
| 6925 | + | |
| 6926 | + | |
| 6927 | + | |
| 6928 | + | |
| 6929 | + | |
| 6930 | + | |
| 6931 | + | |
| 6932 | + | |
| 6933 | + | |
| 6934 | + | |
6905 | 6935 | | |
6906 | 6936 | | |
6907 | 6937 | | |
| |||
0 commit comments