Coder Social home page Coder Social logo

harmonizr's Introduction

Harmonizr

A "transpiler" that brings tomorrow's Harmony to today's JavaScript.

Features:

  • Harmony modules to AMD, Node.js, or Revealing Module Pattern
  • Shorthand properties
  • Method definitions
  • Arrow functions (requires Function.prototype.bind)
  • Class declarations
  • Maintains line numbers

Demo

Look in the demo directory or try it here.

Installation

$ npm install harmonizr

Usage

$ ./node_modules/.bin/harmonizr [options] path/to/input

If you install Harmonizr globally or have ./node_modules/.bin in your PATH, you can omit the path to the harmonizr script.

Specify --amd, --node, or --revealing to transform Harmony-style modules into AMD, Node.js, or JavaScript Revealing Module Pattern- style modules.

This transpiles src/foo.js into a Node.js-compatible version at lib/foo.js:

$ harmonizr --node --output lib/foo.js src/foo.js

Use --module to implicitly wrap the entire file in a module declaration. The name of the module is required, but only appears in the output when using --revealing.

Use --relatives with --node to indicate what modules should be loaded from the local directory and not the node_modules directory.

For example, if a foo module needs to load bar and baz modules from the same directory as it (not from node_modules), you could do this:

$ harmonizr --node --relatives bar,baz --output lib/foo.js src/foo.js

Limitations

  • No nested modules.
  • No import * from module;.
  • export is only allowed when in front of a simple function or variable declaration.
  • Probably bugged.

Code

Harmonizr uses the excellent Esprima parser. A copy of Esprima from its "harmony" branch is embedded into Harmonizr in the lib directory.

The actual source code for Harmonizr is in the src directory. The Makefile transpiles that into a Node.js-style module in lib, AMD-style in demo, and Revealing Module Pattern-style in test.

Harmonizr transpiles itself. Since Node.js doesn't support the newer syntax harmonizr.js uses in the src directory, it loads the harmonizr module out of the lib directory. Be careful when building.

Tests are in the test directory. Run them with npm test or by opening test.html.

If you'd like to contribute, please try to include tests, ensure the code coverage stays at 100%, and that JSHint doesn't complain.

Execute make to build, run JSHint, and run the tests (with code coverage).

harmonizr's People

Contributors

jdiamond avatar swatinem avatar talltyler avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.