Skip to content

Instantly share code, notes, and snippets.

@tivac
Created July 1, 2013 21:15
Show Gist options
  • Save tivac/5904696 to your computer and use it in GitHub Desktop.
Save tivac/5904696 to your computer and use it in GitHub Desktop.
Trying to get escodegen's source-map generation to work
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?
@tivac
Copy link
Author

tivac commented Jul 1, 2013

Also attempted in a browser here: http://jsbin.com/omakoh/2/edit

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