-
c653dd3: Do not eliminate
const
- norlet
-declared for-loop iterator variablesPreviously, only
var
-declared iterator variables were preserved withinfor...of
andfor...in
loops. Now, iterator variables declared viaconst
andlet
are also preserved.
- 81ef06b:
- Do not eliminate for-loop iterator variables (
for...of
/for...in
) - Do not eliminate reassigned variables
- Do not eliminate for-loop iterator variables (
-
d4690c2: Do not eliminate empty object/array pattern function parameters
Function parameters are not dead code
-
3cf19e5: Fix: do not check function expressions for referenced variables
Function expressions do not add their names to outer scopes
-
5149b08: Do not eliminate arrow expressions
Arrow expressions do not add names to the outer scope. Arrow expressions bound to names via variable declarators are already handled by
VariableDeclarator
visitor. -
86af914: Do not eliminate unreferenced variables from array patterns and object patterns when they do not match the provided candidates
Previously, the
candidates
were passed in todeadCodeElimination
were not consulted when removing unreferenced variables from within patterns. This was a bug and has now been fixed.
-
ade9eee: Fix: do not eliminate function expressions
Function expressions do not add their names to outer scope, so they should never be dead code eliminated
- ce456b5: Fix referenced variable finding within object patterns and array patterns
-
bd5e331: Fix elimination for object patterns and array patterns
Previously, running dead code elimination on object patterns and array patterns (aka destructuring) was brittle. For example:
const { a: { b: c }, } = z console.log(c)
Dead code elimination used to incorrectly remove the entire variable declaration even though
c
is referenced:-const { - a: { b: c }, -} = z console.log(c);
This was caused by erroneous detection of
a
andb
as unreferenced variables. Buta
andb
are not variables, they are object property keys. Onlyc
is a variable and it is referenced.This is now corrected so that variables in object patterns and array patterns are detected only within values of object properties. This also correctly accounts for cases where the key and value are the same for example
{ a }
.
- c2d0e23: Provide
main
andmodule
fields inpackage.json
for older bundlers
-
8264d19: Initial release
Eliminates unused code from the Babel AST by repeatedly removing unreferenced identifiers.
deadCodeElimination(ast)
Find identifiers that are currently referenced in the Babel AST.
Useful for limiting
deadCodeElimination
to only eliminate newly unreferenced identifiers, as a best effort to preserve any intentional side-effects in the source.let ast = parse(source, { sourceType: "module" }) let referenced = findReferencedIdentifiers(ast) traverse(ast, { /* ... your custom transform goes here ... */ }) deadCodeElimination(ast, referenced)