Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created July 20, 2011 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdickinson/75def135193cfebbde94 to your computer and use it in GitHub Desktop.
Save chrisdickinson/75def135193cfebbde94 to your computer and use it in GitHub Desktop.
parsing `x ? y : z`: got `x ? y : z;`
parsing `"anything" + (x ? y : z) + "anything"`: got `"anything" + (x ? y : z) + "anything";`
burrito `x ? y : z`: got `x ? y : z;`
burrito `"anything" + (x ? y : z) + "anything"`: got `"anything" + x ? y : z + "anything";`
var uglify = require('uglify-js');
var parser = uglify.parser;
var burrito = require('burrito');
var parse = function (expr) {
var ast = parser.parse.apply(null, arguments);
return ast;
};
var deparse = function (ast) {
return uglify.uglify.gen_code(ast, { beautify : true });
};
console.log('parsing `x ? y : z`: got `%s`', deparse(parse('x ? y : z')));
console.log('parsing `"anything" + (x ? y : z) + "anything"`: got `%s`', deparse(parse('"anything" + (x ? y : z) + "anything"')));
console.log('burrito `x ? y : z`: got `%s`', burrito('x ? y : z'));
console.log('burrito `"anything" + (x ? y : z) + "anything"`: got `%s`', burrito('"anything" + (x ? y : z) + "anything"'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment