Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Berlin Node.js Meetup #3 - Js2coffee

Berlin Node.js Meetup #3 - Js2coffee

Js2coffee helps you to migrate your projects to CoffeeScript and you can use http://js2coffee.org to learn CoffeeScript syntax.

It uses Mozilla's Narcissus interpreter to parse the JavaScript code and convert from the parsed Abstract Syntax Tree the generated CoffeeScript code.

Code snippest in my talk: https://gist.github.com/timaschew/9519475
Talk video: https://vimeo.com/88939283

Going further:
http://lisperator.net/uglifyjs/
http://esprima.org/
http://marijnhaverbeke.nl/blog/acorn.html
http://constellation.github.io/escodegen/demo/index.html

Anton Wilhelm

March 12, 2014
Tweet

More Decks by Anton Wilhelm

Other Decks in Technology

Transcript

  1. agenda history use cases online demo array appearance in v.

    0.1.4 array appearance in v. 0.2.0 how it works abstract syntax tree builder class use cases Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm | @timaschew
  2. js2coffee Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm | @timaschew

    - Rico Sta Cruz @rstacruz - written in CoffeeScript - first version June 2011 - last code change June 2012 - May 2013 Benjamin Lupton @balupton became a maintainer - my pull request in September 2013 ... I became a maintainer and then owner
  3. demo Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm | @timaschew

    http://js2coffee.org code snippets: https://gist.github.com/timaschew/9519475
  4. use cases Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm |

    @timaschew - learn CoffeeScript syntax - convert JavaScript to CoffeeScript - generate CoffeeScript
  5. arrays in v. 0.1.4 Node.js Berlin#3 | 2014-03-12 | Anton

    Wilhelm | @timaschew [ "foo", "bar", { y: 0, z: -1 }, [ 9, 8, 7, [ 71, 72, 73 ] ], "qux" ] ["foo", "bar", y: 0 z: -1 , [9, 8, 7, [71, 72, 73]], "qux"]
  6. arrays in v. 0.2.0 Node.js Berlin#3 | 2014-03-12 | Anton

    Wilhelm | @timaschew [ "foo", "bar", { y: 0, z: -1 }, [ 9, 8, 7, [ 71, 72, 73 ] ], "qux" ] [ "foo" "bar" { y: 0 z: -1 } [ 9 8 7 [ 71 72 73 ] ] "qux" ]
  7. array appearance Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm |

    @timaschew - array have different looks: [] // empty array [oneElement] // one entry [ // more than one element foo bar baz ]
  8. how it works? Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm

    | @timaschew - parse the code with Narcissus (Brendan Eich!) - return Abstract Syntax Tree (nodes) - check type of each node - identifier, number, function call, ... - run 2 steps (in series): - transform AST (Transformer) - existence check, inversible, returns - convert AST (Builder) - omit parentheses, function() {} to ->
  9. abstract syntax tree Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm

    | @timaschew children: [ { type: 60, value: 'foo', lineno: 1, start: 0, end: 3, tokenizer: [Object], children: [] }, { type: 62, value: 'bar', lineno: 1, start: 6, end: 11, tokenizer: [Object], children: [] } ], type: 4, assignOp: null } foo = ‘bar‘ Identifier Literal AssignmentExpression
  10. use cases Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm |

    @timaschew - learn all CoffeeScript features - loops and comprehensions - classes and inheritance - issues - old narcisuss version - not the latest SpiderMonkey API - some switch statements fails - warnings / errors for things which CoffeeScript doesn‘t support - variable shadowing
  11. Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm | @timaschew -

    JavaScript Parser API - Mozilla‘s Narcissus (even latest version is outdated, not maintained) - Mihai Bazon http://lisperator.net/uglifyjs/ - esprima, multipurpose analysis (Ariya Hidayat) - acorn, fastest JS parser (Marijn Haverbeke) - escodegen, AST → JS (Yusuke Suzuki) going further
  12. THAT’S IT If you're into Node.js, CoffeeScript, NoSQL, Scrum get

    in touch, we're hiring ;) Twitter: @timaschew Source: http://github.com/js2coffee/js2coffee Web: http://js2coffee.org Soon: http://js2.coffee Node.js Berlin#3 | 2014-03-12 | Anton Wilhelm | @timaschew