Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for definition hoisting

  • Loading branch information...
commit db87d56b65cfdd2d8000bf2cdbb182d5c8caeb2c 1 parent 22e91a4
@substack authored
View
7 example/modify.js
@@ -1,7 +1,10 @@
var fs = require('fs');
var scoper = require('../');
-var src = fs.readFileSync(process.argv[2], 'utf8');
+var src = fs.readFileSync(__dirname + '/source.js', 'utf8');
var c = Function('return ' + scoper(src))();
-console.dir(c);
c.run();
+
+setInterval(function () {
+ //c.literal['body.1'][0] += 10;
+}, 500);
View
4 example/source.js
@@ -14,4 +14,6 @@ function foo (n) {
})();
}
-console.log(foo(32));
+setInterval(function () {
+ console.log(foo(32));
+}, 500);
View
2  example/transform.js
@@ -1,6 +1,6 @@
var fs = require('fs');
var scoper = require('../');
-var src = fs.readFileSync(process.argv[2], 'utf8');
+var src = fs.readFileSync(__dirname + '/source.js', 'utf8');
var out = scoper(src);
console.log(out);
View
4 index.js
@@ -36,7 +36,9 @@ module.exports = function (src) {
+ ';return {' + Object.keys(names).map(function (name) {
return JSON.stringify(name) + ':' + names[name];
}) + ',run:function(){' + out + '}'
- + '}})()'
+ + '};\n'
+ + out // duplicate at the end won't execute, but needed for hoisting
+ + '})()'
;
function rewriteVars (node) {
View
2  test/scope.js
@@ -22,6 +22,6 @@ test('modify a literal', function (t) {
});
c.run();
- c.literal[''][1] += 100;
+ c.literal['body.1'][0] += 100;
c.run();
});
Please sign in to comment.
Something went wrong with that request. Please try again.