Created
August 8, 2013 18:12
-
-
Save pd/6187126 to your computer and use it in GitHub Desktop.
let's call it an mvp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm i esprima falafel | |
$ node sib.js | node | |
{ '4': [ [ 2, 'big' ], [ 2, 'big' ] ], | |
'8': [ [ 6, 'little' ] ], | |
'11': [ [ 11, 'big' ], [ 11, 'little' ] ] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x; | |
x = sth( | |
true | |
); | |
var y = sth( | |
false | |
); | |
function sth(big) { | |
return big ? 'big' : 'little'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esprima = require('esprima'), | |
falafel = require('falafel'); | |
var src = require('fs').readFileSync('./lol.js', 'utf8'); | |
var transformed = falafel(src, { loc: true }, function(node) { | |
var loc = node.loc; | |
if (node.type.match(/Expression$/)) | |
node.update('(__jsib.record(' + loc.end.line + ',' + loc.start.line + ',( ' + node.source() + ' )))'); | |
}); | |
var output = | |
"(function() {var __jsib={r:{}}; __jsib.record = function(end,start,val){(this.r[end] = this.r[end] || []).push([start, val]); return val;};\n\n" + | |
transformed + "\n\n" + | |
"console.dir(__jsib.r); return __jsib.r;})();"; | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment