Skip to content

Instantly share code, notes, and snippets.

@schmod
Last active February 10, 2016 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmod/f8bd79277e4ce556fef9 to your computer and use it in GitHub Desktop.
Save schmod/f8bd79277e4ce556fef9 to your computer and use it in GitHub Desktop.
Babel Block Scoping Transform -- Scope Bindings are not renamed
{
"plugins": ["babel-plugin-transform-es2015-block-scoping", "./plugin"]
}
{
"name": "babel-let",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.5.1",
"babel-plugin-transform-es2015-block-scoping": "^6.5.0"
}
}
module.exports = function () {
const callVisitor = function(path){
path.node.arguments.forEach(arg => {
console.log("Name: " + arg.name + ". Bindings in scope: " + Object.keys(path.scope.bindings));
});
};
return {
visitor: {
CallExpression: callVisitor
}
};
}
"use strict";
function myFn1(a, b) {
}
if (true) {
let myFn1 = function(c) {
};
doSomething(myFn1);
}
doSomething(myFn1);
@schmod
Copy link
Author

schmod commented Feb 10, 2016

babel src.js

Name: _myFn. Bindings in scope: myFn1
Name: myFn1. Bindings in scope: myFn1
"use strict";

function myFn1(a, b) {}
if (true) {
    var _myFn = function (c) {};
    doSomething(_myFn);
}
doSomething(myFn1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment