add-variable-declarations
Advanced tools
Comparing version
@@ -197,5 +197,7 @@ import MagicString from 'magic-string'; | ||
var BABYLON_PLUGINS = ['classProperties']; | ||
function addVariableDeclarations(source) { | ||
var editor = arguments.length <= 1 || arguments[1] === undefined ? new MagicString(source) : arguments[1]; | ||
var ast = arguments.length <= 2 || arguments[2] === undefined ? parse(source) : arguments[2]; | ||
var ast = arguments.length <= 2 || arguments[2] === undefined ? parse(source, { plugins: BABYLON_PLUGINS }) : arguments[2]; | ||
@@ -202,0 +204,0 @@ var state = null; |
@@ -202,5 +202,7 @@ (function (global, factory) { | ||
var BABYLON_PLUGINS = ['classProperties']; | ||
function addVariableDeclarations(source) { | ||
var editor = arguments.length <= 1 || arguments[1] === undefined ? new MagicString(source) : arguments[1]; | ||
var ast = arguments.length <= 2 || arguments[2] === undefined ? babylon.parse(source) : arguments[2]; | ||
var ast = arguments.length <= 2 || arguments[2] === undefined ? babylon.parse(source, { plugins: BABYLON_PLUGINS }) : arguments[2]; | ||
@@ -207,0 +209,0 @@ var state = null; |
{ | ||
"name": "add-variable-declarations", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Add variable declarations for global assignments.", | ||
@@ -5,0 +5,0 @@ "main": "dist/add-variable-declarations.umd.js", |
@@ -28,4 +28,6 @@ # add-variable-declarations | ||
## Why? | ||
## FAQ | ||
### Why? | ||
This project is used by [decaffeinate][decaffeinate] to add variable | ||
@@ -38,4 +40,13 @@ declarations to converted CoffeeScript code. This project is not intended to | ||
### Why `var`? Shouldn't this use `let` and `const`? | ||
Yes, but not all situations allow the use of `let` and `const`, such as when | ||
the variable binding takes advantage of | ||
[hoisting](http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html). | ||
If you want `let` and `const` you can use this library in combination with | ||
[esnext](https://github.com/esnext/esnext) which will turn all eligible `var` | ||
declarations into `let` or `const` as appropriate. | ||
## License | ||
MIT |
22620
2.79%573
0.35%50
28.21%