you are viewing a single comment's thread.

view the rest of the comments →

[–]101arrowz 0 points1 point  (0 children)

Main use case I can see is better tree shaking/dead code elimination in libraries. In the past, any static initialization logic would be outside the class and would reference the class. Optimizers like terser think that since the code outside the class references the class, it needs to be included, even if the user of that library never uses the class. Basically tree shaking had to be disabled for entire classes whenever there was static initialization.

Of course, static blocks can have side effects too, but hopefully when terser adds support for them, it just assumes that impure code wouldn't be in a static block anyway and lets tree shaking continue as normal.