Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-dead-code-elimination

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-dead-code-elimination

Composable primitives for dead code elimination in Babel

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

babel-dead-code-elimination

Composable primitives for dead code elimination in Babel

This package is not a Babel plugin, but rather a set of composable primitives to author your own Babel transforms and plugins.

Install

npm install babel-dead-code-elimination

deadCodeElimination

Eliminates unused code from the Babel AST by repeatedly removing unreferenced identifiers.

import { parse } from "@babel/parser"
import generate from "@babel/generator"

import { deadCodeElimination } from "babel-dead-code-elimination"

let source = "..."
let ast = parse(source, { sourceType: "module" })
deadCodeElimination(ast)
let result = generate(ast).code

findReferencedIdentifiers

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.

import { parse } from "@babel/parser"
import generate from "@babel/generator"
import traverse from "@babel/traverse"

import {
  deadCodeElimination,
  findReferencedIdentifiers,
} from "babel-dead-code-elimination"

let source = "..."
let ast = parse(source, { sourceType: "module" })
let referenced = findReferencedIdentifiers(ast)

traverse(ast, {
  /* ... your custom transform goes here ... */
})

deadCodeElimination(ast, referenced)
let result = generate(ast).code

Prior art

Credit to Jason Miller for the initial implementation. Thanks to these projects for exploring dead code elimination:

Keywords

FAQs

Package last updated on 01 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc