Skip to content

Instantly share code, notes, and snippets.

@icefapper
Last active November 30, 2017 16:23
Show Gist options
  • Save icefapper/a76b47a236c7cdd478d776342fe088d8 to your computer and use it in GitHub Desktop.
Save icefapper/a76b47a236c7cdd478d776342fe088d8 to your computer and use it in GitHub Desktop.
var src = 'var a, b, l = {a, [b]: {l}} = ({A}=a) => a = ({B=b}) => b = ({L=l}=40) => l';
// parse it
var syntaxNode = new Parser(src).parseProgram();
// transform what was parsed
var transformer = new Transformer();
transformer.renamer = renamer_minify;
var transformedNode = transformer.tr(syntaxNode, false);
// emit what was transformed
var emitter = new Emitter();
emitter.allow.space = false;
emitter.allow.nl = false;
emitter.allow.comments.l = false;
emitter.allow.comments.m = false;
emitter.startFreshLine()
emitter.emitStmt(transformedNode);
emitter.flushCurrentLine(); // flush whatever output that is still pending
// the compiled code:
console.log(emitter.out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment