
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-transform-undeclared-variables
Advanced tools
Transforms undeclared variables into imports or getter calls
A Babel transform to transform undeclared variables into a getter call or an import.
Note: undeclared variables on the left hand side of assignments are ignored.
function template(data) {
return html`A template ${literal}`;
}
// Would become
import html from './templateTag';
function template(data) {
return html`A template ${data.literal}`;
}
Install the plugin with your favourite package manager. For example, with NPM:
npm install --save-dev babel-plugin-transform-last-statement
Then in your Babel configuration, add it to the list of plugins:
{
plugins:['transform-undeclared-variables']
}
By default, the transform will turn all undeclared variables into a getter call on the data
object. You can configure:
default
: the default behaviour,variables
: the behaviour for specific variablesdefault: getter('<otherObjectName'),
variables: {
'<undeclaredIdentifierName>': getter('<objectName>'),
'<otherUndeclaredIdentifierName>': addImport('<package>', {name: '<exportName>'}).
'<yetAnotherUndeclaredIdentifierName>': function(path) {
// Do whatever you need to transform that specific identifier
}
}
{
"default": ["getter","otherObject"],
"variables": {
"undefinedVariable": ["addImport","package", {name: "exportName"}]
}
}
FAQs
Transforms undeclared variables into imports or getter calls
We found that babel-plugin-transform-undeclared-variables 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.