packages/core/parcel-bundler/src/scope-hoisting/shake.js
function treeShake(scope) {
  // Keep passing over all bindings in the scope until we don't remove any.
  // This handles cases where we remove one binding which had a reference to
  // another one. That one will get removed in the next pass if it is now unreferenced.
  let removed;
  do {
    removed = false;

    // Recrawl to get all bindings.
    scope.crawl();
    Object.keys(scope.bindings).forEach(name => {
      let binding = getUnusedBinding(scope.path, name);

      // If it is not safe to remove the binding don't touch it.
      if (!binding) {
        return;
      }

      // Remove the binding and all references to it.
      binding.path.remove();
      binding.referencePaths.concat(binding.constantViolations).forEach(remove);

      scope.removeBinding(name);
      removed = true;
    });
  } while (removed);
}
function treeShake(scope) {
  // Keep passing over all bindings in the scope until we don't remove any.
  // This handles cases where we remove one binding which had a reference to
  // another one. That one will get removed in the next pass if it is now unreferenced.
  let removed;
  do {
    removed = false;

    // Recrawl to get all bindings.
    scope.crawl();
    Object.keys(scope.bindings).forEach(name => {
      let binding = getUnusedBinding(scope.path, name);

      // If it is not safe to remove the binding don't touch it.
      if (!binding) {
        return;
      }

      // Remove the binding and all references to it.
      binding.path.remove();
      binding.referencePaths.concat(binding.constantViolations).forEach(remove);

      scope.removeBinding(name);
      removed = true;
    });
  } while (removed);
}
function treeShake ( scope ) { // Keep passing over all bindings in the scope until we don't remove any. // This handles cases where we remove one binding which had a reference to // another one. That one will get removed in the next pass if it is now unreferenced. let removed ; do { removed = false ; // Recrawl to get all bindings. scope . crawl ( ) ; Object . keys ( scope . bindings ) . forEach ( name => { let binding = getUnusedBinding ( scope . path , name ) ; // If it is not safe to remove the binding don't touch it. if ( ! binding ) { return ; } // Remove the binding and all references to it. binding . path . remove ( ) ; binding . referencePaths . concat ( binding . constantViolations ) . forEach ( remove ) ; scope . removeBinding ( name ) ; removed = true ; } ) ; } while ( removed ) ; }
This is a small small implementation of dead code removal specialized to handle
removing unused exports. All other dead code removal happens in workers on each
individual file by babel-minify.
This is a small small implementation of dead code removal specialized to handle removing unused exports . All other dead code removal happens in workers on each individual file by babel - minify .