Created
July 1, 2013 21:15
-
-
Save tivac/5904696 to your computer and use it in GitHub Desktop.
Trying to get escodegen's source-map generation to work
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"), | |
esmangle = require("esmangle"), | |
escodegen = require("escodegen"), | |
src = "var fooga = \"wooga\";\n\nconsole.log(fooga);\n\nfooga += 1;", | |
ast, result; | |
ast = esprima.parse(src, { | |
loc : true, | |
tokens : true, | |
}); | |
ast = esmangle.optimize(ast, null); | |
ast = esmangle.mangle(ast, null, { | |
destructive : true | |
}); | |
result = escodegen.generate(ast, { | |
sourceMap : "test", | |
sourceMapWithCode : true, | |
format : { | |
renumber : true, | |
hexadecimal : true, | |
escapeless : true, | |
compact : true, | |
semicolons : false, | |
parentheses : false | |
} | |
}); | |
console.log(JSON.parse(result.map.toString())); | |
// OUTPUT | |
/* | |
C:\Users\pcavit\Documents\GitHub\node-web-build>node source-map.js | |
{ version: 3, | |
file: 'test', | |
sources: [ 'test' ], | |
names: [], | |
mappings: 'AAAA,GAAA,CAAI,MAAQ,OAAZ,CAEA,OAAA,IAAA,CAAY,KAAZ,C,CAEA,KAAA,EAAS' } | |
*/ | |
// Where's the names? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also attempted in a browser here: http://jsbin.com/omakoh/2/edit