Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

return the scope object

  • Loading branch information...
commit 9542662e300dbe7c539a95f19f7951a09ff15851 1 parent 3012416
@substack authored
Showing with 7 additions and 4 deletions.
  1. +7 −4 index.js
View
11 index.js
@@ -1,17 +1,20 @@
var falafel = require('falafel');
module.exports = function (src) {
+ var scopeName = '__' + (Math.pow(16, 8) * Math.random()).toString(16);
var scope = {};
var fns = [];
var out = falafel(String(falafel(src, rewriteVars)), rewriteIds);
- return 'var __scope='
+ return 'function () {\n'
+ + 'var ' + scopeName + '='
+ JSON.stringify(Object.keys(scope).reduce(function (acc, key) {
acc[key] = {};
return acc;
}, {}))
+ ';\n'
+ out
+ + ';return {scope:' + scopeName + '}}'
;
function rewriteVars (node) {
@@ -26,9 +29,9 @@ module.exports = function (src) {
}
function rewriteIds (node) {
- if (node.type === 'Identifier') {
- var id = lookup(node);
- node.update('__scope[' + JSON.stringify(id) + '].' + node.name);
+ if (node.type === 'Identifier' && !isFunction(node.parent)) {
+ var id = JSON.stringify(lookup(node));
+ node.update(scopeName + '[' + id + '].' + node.name);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.