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.
{ return html`A template `;} // Would become; { return html`A template `;}
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: variables: '<undeclaredIdentifierName>': '<otherUndeclaredIdentifierName>': { // 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
- Handle left side of assignments by creating a variable declaration automatically (type of declaration configurable).