Tenderlove Making

Clean it up! RKelly::Nodes::Node#to_ecma

Last night at Nerd Club, I decided to add a “to_ecma” method to <a href=“http://rubyforge.org/projects/rkelly/"">RKelly. This means you can turn your ECMA AST back in to ECMAScript, with the added bonus of properly indenting your code. For example:

require 'rkelly'

parser = RKelly::Parser.new
puts parser.parse(DATA.read).to_ecma

__END__
function yo(a,b,a) { this.be.some(); if(nasty) { code();} }

will output this:

function yo(a, b, a){
  this.be.some();
  if(nasty) {
    code();
  }
}

Now you should be able to modify your AST and generate javascript. Next I want to add finders to easily find nodes in the tree.

« go back