
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
babel-plugin-ast-literal
Advanced tools
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.
+ 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).
Install from npm:
% npm install babel-plugin-ast-literal
Add to you Babel config (probably .babelrc
):
{
"plugins": ["ast-literal"]
}
Enjoy!
FAQs
AST literals via ES2015 tagged template strings
We found that babel-plugin-ast-literal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.