New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-ast-literal

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-ast-literal

AST literals via ES2015 tagged template strings

  • 0.5.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Babel Plugin AST Literal

Babel plugin which processes expr and stmt tagged template strings into Babylon (Babel JS parser) AST nodes:

let exportReactComponentNode = stmt`
  export function ${name}(props) {
    return React.createElement(
      ${component},
      {...props, className: styles.${className}}
    );
  }
`; // {type: 'ExportNamedDeclaration', ...}

let jsxNode = expr`<div a="${some}" />` // {type: 'JSXElement', ...}

This is mostly useful for code generation.

Why not babel-template

  • + It handles more cases, like:

      stmt`import Lib from "${lib}"`
    

    which can't be handled by babel-template (it can only fill identifiers).

  • + It inlines AST Node generation in code instead of doing a pass over AST Node template as babel-template does. This should be faster.

  • - It is somewhat hacky but it works!

  • It allows to specify template right in place rather than defining template and then applying it.

  • I wrote it when babel-template wasn't a thing (previous versions were even targeting Babel 5).

Installation & Usage

Install from npm:

% npm install babel-plugin-ast-literal

Add to you Babel config (probably .babelrc):

{
  "plugins": ["ast-literal"]
}

Enjoy!

Keywords

FAQs

Package last updated on 07 Jun 2016

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