Socket
Book a DemoInstallSign in
Socket

babel-plugin-transform-undeclared-variables

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-undeclared-variables

Transforms undeclared variables into imports or getter calls

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

babel-plugin-transform-undeclared-variables

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}`;
}

Usage

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']
}

Options

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 variables
default: getter('<otherObjectName'),
variables: {
  '<undeclaredIdentifierName>': getter('<objectName>'),
  '<otherUndeclaredIdentifierName>': addImport('<package>', {name: '<exportName>'}).
  '<yetAnotherUndeclaredIdentifierName>': function(path) { 
    // Do whatever you need to transform that specific identifier
  }
}

Possible future work

  • Allow configuration through non-JS babel configuration files, by allowing arrays instead of function calls
    {
      "default": ["getter","otherObject"],
      "variables": {
        "undefinedVariable": ["addImport","package", {name: "exportName"}]
      }
    }
    
  • Handle left side of assignments by creating a variable declaration automatically (type of declaration configurable).

FAQs

Package last updated on 11 Mar 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.