Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make expr_simplifier handle expressions when indexing strings, arrays and objects #8750

Open
wants to merge 74 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
84ec94e
Initial commit: string literals
levi-nz Mar 15, 2024
7f02ace
WIP: array literals
levi-nz Mar 15, 2024
2b94d3d
Correctly handle array indexing
levi-nz Mar 16, 2024
efec60b
Update unit test
levi-nz Mar 17, 2024
72537ac
Fix broken index logic
levi-nz Mar 17, 2024
454378d
Fix indexing `ObjectLit`s
levi-nz Mar 17, 2024
9b26630
Remove fraction check from `LiteralVisitor`
levi-nz Mar 18, 2024
677a437
cargo fmt
levi-nz Mar 18, 2024
3aa713e
Update test files
levi-nz Mar 18, 2024
8450f8b
Handle `x['0']`
levi-nz Mar 31, 2024
2b8709f
Don't return `KnownOp::Len` if `obj` is an ObjectLiteral
levi-nz Mar 31, 2024
dd4336b
Handle `x['length']`
levi-nz Mar 31, 2024
2fe5f09
Correctly handle builtin properties
levi-nz Mar 31, 2024
c902739
Don't replace ArrayLiteral if doing so may have side effects
levi-nz Mar 31, 2024
b4455c9
Update unit test
levi-nz Mar 31, 2024
ae673de
Update minifier test files
levi-nz Mar 31, 2024
4143a27
cargo fmt
levi-nz Mar 31, 2024
4b151fc
Minifier shouldn't handle potential `pristine_globals` cases
levi-nz Apr 1, 2024
c154047
cargo fmt
levi-nz Apr 1, 2024
647cfd3
Update test files
levi-nz Apr 1, 2024
9c9d141
Don't add a dummy value if no side effects exist
levi-nz Apr 1, 2024
4424755
Update test files
levi-nz Apr 1, 2024
96a1c0b
Oops
levi-nz Apr 1, 2024
5104b9a
Update unit test
levi-nz Apr 1, 2024
bfd376b
Add test case for side effects
levi-nz Apr 1, 2024
9296237
Add compression for `MemberExpr`
levi-nz Apr 1, 2024
2b26790
cargo fmt
levi-nz Apr 1, 2024
4f2c69f
String does not appear to inherit Function
levi-nz Apr 2, 2024
43fe050
Array also does not inherit Function
levi-nz Apr 2, 2024
70f6f64
Remove comment
levi-nz Apr 2, 2024
d19e907
`FUNCTION_SYMBOLS` is no longer required
levi-nz Apr 2, 2024
10c4681
Add unit test files
levi-nz Apr 2, 2024
240713a
Update test files
levi-nz Apr 2, 2024
ec03388
Update test config
levi-nz Apr 3, 2024
bfcb5cf
Better test dir names
levi-nz Apr 3, 2024
17439b9
Remove evil clone
levi-nz Apr 3, 2024
67474ef
I don't know why this changed, but it did.
levi-nz Apr 3, 2024
c92508f
Add array side effect unit test
levi-nz Apr 3, 2024
9407838
Don't optimize if inside left-hand side of AssignExpr
levi-nz Apr 3, 2024
942a343
Remove redundant import
levi-nz Apr 3, 2024
5424fed
Move call to end
levi-nz Apr 3, 2024
c6029c4
Cleanup iterator call
levi-nz Apr 3, 2024
ea89ec2
Handle side effects and `__proto__` in object compression
levi-nz Apr 8, 2024
976ddb7
Remove redundant return statement
levi-nz Apr 8, 2024
a819d98
cargo fmt
levi-nz Apr 8, 2024
b41617c
Remove redundant `Box::new` call
levi-nz Apr 8, 2024
a5df0a5
Use `preserve_effects`
levi-nz Apr 8, 2024
e47bff3
cargo fmt
levi-nz Apr 8, 2024
52dfab4
Exclude `watch` and `unwatch`
levi-nz Apr 9, 2024
4a1b6db
UPDATE=1 cargo test --test projects --test tsc
levi-nz Apr 9, 2024
d4696ed
UPDATE=1 cargo test -p swc_ecma_minifier --features concurrent
levi-nz Apr 9, 2024
7dba5ac
git merge upstream/main issue-8747
levi-nz Apr 10, 2024
00cb04f
Remove redundant import
levi-nz Apr 10, 2024
6477fbf
Fix `test_fold_array_lit_spread_get_elem`
levi-nz Apr 10, 2024
9b5239d
Fix `test_fold_get_elem1`
levi-nz Apr 10, 2024
f3cfa71
Add `self.changed = true;`
levi-nz Apr 10, 2024
b8cd66b
Use `ctx`
levi-nz Apr 22, 2024
b2a2cc6
Fix doc
levi-nz Apr 25, 2024
5458077
Handle SeqExpr in `optimize_member_expr`
levi-nz Apr 25, 2024
5e1819f
Remove dup `self.changed = true;`
levi-nz May 10, 2024
4a2d3a9
git merge upstream/main issue-8747
levi-nz May 10, 2024
45d23d3
Apply clippy suggestions
levi-nz May 10, 2024
52869c4
Cleanup `optimize_member_expr`
levi-nz May 12, 2024
aa42961
Fix optimization tests
levi-nz May 12, 2024
2b7ab8e
Fix optimization with `OptCall`
levi-nz May 25, 2024
03c7dd5
Move code into its own `eval` function
levi-nz May 25, 2024
60bcf71
Fix error
levi-nz May 25, 2024
d613a05
Remove redundant imports
levi-nz May 25, 2024
2b5da79
Optimize imports
levi-nz May 25, 2024
66c51a4
Update parserForStatement9.2.minified.js
levi-nz May 25, 2024
cc2dcab
Cleanup simplify
levi-nz May 27, 2024
dca62ff
Handle `__proto__` object when indexing known object keys
levi-nz May 30, 2024
c913a15
cargo fmt
levi-nz May 30, 2024
4e73a33
Remove `is_opt_call`
levi-nz Jun 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [destructuringArrayBindingPatternAndAssignment2.ts]
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
var _ref_1 = (_sliced_to_array([][0], 1)[0], _sliced_to_array([][1], 1));
var _ref_1 = (_sliced_to_array(void 0, 1)[0], _sliced_to_array(void 0, 1));
_sliced_to_array(_ref_1[0], 1)[0];
var _undefined = _sliced_to_array(void 0, 2), _undefined_1 = (_sliced_to_array(_undefined[0], 1)[0], _sliced_to_array(_undefined[1], 1));
_sliced_to_array(_undefined_1[0], 1)[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//// [destructuringControlFlow.ts]
import "@swc/helpers/_/_sliced_to_array";
[
"foo"
][1].toUpperCase();
(void 0).toUpperCase();
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import { _ as _to_property_key } from "@swc/helpers/_/_to_property_key";
var trace = [], order = function(n) {
return trace.push(n);
}, tmp = [][0];
}, tmp = void 0;
(void 0 === tmp ? order(0) : tmp)[order(1)];
var tmp1 = {};
(void 0 === tmp1 ? order(0) : tmp1)[order(1)];
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/tsc-references/enumBasics.2.minified.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//// [parserForStatement9.ts]
for(var tmp = [][0], x = void 0 === tmp ? ("a" in {}) : tmp; !x; x = !x)console.log(x);
for(var tmp = void 0, x = void 0 === tmp ? ("a" in {}) : tmp; !x; x = !x)console.log(x);
for(var _ref_x = {}.x, x1 = void 0 === _ref_x ? ("a" in {}) : _ref_x; !x1; x1 = !x1)console.log(x1);
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
//// [templateStringInIndexExpressionES6.ts]
"abc0abc"["0"];
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ryu-js = "1.0.0"
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.61"
tracing = "0.1.37"
phf = { version = "0.11.2", features = ["macros"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


swc_atoms = { version = "0.6.5", path = "../swc_atoms" }
swc_common = { version = "0.33.19", path = "../swc_common" }
Expand Down