Git Product home page Git Product logo

lebab's Introduction

Build Status Coverage Status Dependencies License Version

Lebab

Lebab

Lebab transpiles your ES5 code to ES6/ES7. It does exactly the opposite of what Babel does. If you want to understand what Lebab exactly does, try the live demo.

Install

Install it using npm:

$ npm install -g lebab

Usage

Convert your old-fashioned code using the lebab cli tool, enabling a specific transformation:

$ lebab es5.js -o es6.js --transform let

Or transform an entire directory of files in-place:

# .js files only
$ lebab --replace src/js/ --transform arrow
# For other file extensions, use explicit globbing
$ lebab --replace 'src/js/**/*.jsx' --transform arrow

For all the possible values for --transform option see the detailed docs below or use --help from command line.

Features and known limitations

The recommended way of using Lebab is to apply one transform at a time, read what exactly the transform does and what are its limitations, apply it for your code and inspect the diff carefully.

Safe transforms

These transforms can be applied with relatively high confidence. They use pretty straight-forward and strict rules for changing the code. The resulting code should be almost 100% equivalent of the original code.

  • arrow - callbacks to arrow functions
  • arrow-return - drop return statements in arrow functions
    • converts immediate return { return x; } to => x
    • applies to arrow functions and nested arrow functions
    • LIMITATION only applies to arrow functions (run the arrow transform first)
  • for-of - for loop to for-of loop
  • for-each - for loop to Array.forEach()
  • arg-rest - use of arguments to function(...args)
  • arg-spread - use of apply() to spread operator
    • recognizes obj.method.apply(obj, args)
    • recognizes func.apply(undefined, args)
  • obj-method - function values in object to methods
  • obj-shorthand - {foo: foo} to {foo}
    • ignores numeric and NaN properties
    • does not convert string properties
  • no-strict - removal of "use strict" directives
    • does not touch stuff like x = "use strict";
  • exponent - Math.pow() to ** operator (ES7)
    • Full support for all new syntax from ES7
  • multi-var - single var x,y; declaration to multiple var x; var y; (refactor)

Unsafe transforms

These transforms should be applied with caution. They either use heuristics which can't guarantee that the resulting code is equivalent of the original code, or they have significant bugs which can result in breaking your code.

  • let - var to let/const
  • class - function/prototypes to classes
  • commonjs - CommonJS module definition to ES6 modules
    • converts var foo = require("foo") to import foo from "foo"
    • converts var bar = require("foo").bar to import {bar} from "foo"
    • converts var {bar} = require("foo") to import {bar} from "foo"
    • converts module.exports = <anything> to export default <anything>
    • converts exports.foo = function(){} to export function foo(){}
    • converts exports.Foo = class {} to export class Foo {}
    • converts exports.foo = 123 to export var foo = 123
    • converts exports.foo = bar to export {bar as foo}
    • LIMITATION does not check if named export conflicts with existing variable names
    • LIMITATION Ignores imports/exports inside nested blocks/functions
    • LIMITATION only handles require() calls in var declarations
    • LIMITATION does not ensure that imported variable is treated as const
    • LIMITATION does not ensure named exports are imported with correct ES6 syntax
  • template - string concatenation to template strings
  • default-param - default parameters instead of a = a || 2
  • destruct-param - use destructuring for objects in function parameters
  • includes - array.indexOf(foo) !== -1 to array.includes(foo) (ES7)
    • works for both strings and arrays
    • converts !== -1 to array.includes(foo)
    • converts === -1 to !array.includes(foo)
    • recognizes all kinds of comparisons >= 0, > -1, etc
    • recognizes both indexOf() != -1 and -1 != indexOf()
    • LIMITATION does not detect that indexOf() is called on an actual Array or String.

Programming API

Simply import and call the transform() function:

import {transform} from 'lebab';
const {code, warnings} = transform(
  'var f = function(a) { return a; };', // code to transform
  ['let', 'arrow', 'arrow-return'] // transforms to apply
);
console.log(code); // -> "const f = a => a;"

The warnings will be an array of objects like:

[
  {line: 12, msg: 'Unable to transform var', type: 'let'},
  {line: 45, msg: 'Can not use arguments in arrow function', type: 'arrow'},
]

Most of the time there won't be any warnings and the array will be empty.

Editor plugins

Alternatively one can use Lebab through plugins in the following editors:

What's next?

Which feature should Lebab implement next? Let us know by creating an issue or voicing your opinion in existing one.

Want to contribute? Read how Lebab looks for patterns in syntax trees.

lebab's People

Contributors

addityasingh avatar andywer avatar apexearth avatar atjn avatar brendanannable avatar dependabot-preview[bot] avatar dependabot[bot] avatar e-cloud avatar hallazzang avatar josephfrazier avatar kira0x1 avatar kramerc avatar lfilho avatar lingsamuel avatar mdebbar avatar mohebifar avatar nene avatar owenvoke avatar peet avatar pionxzh avatar rreverser avatar tb avatar uniibu avatar wilfred avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lebab's Issues

Convert callbacks to =>

If a function doesn't use this convert it to an arrow function.

Bonus points for replacing self when there's var self = this.

Constructor parameters are lost on conversion

function TestClass(arg) {
  this.arg = arg;
}

TestClass.prototype.method = function() {
  console.log(this.arg);
}

is transformed to

class TestClass {
    // where is arg?
    constructor() {
        this.arg = arg;
    }
    method() {
        console.log(this.arg);
    }
}

Support ES6 on input

I tried this simple example on the website:

const a = 1;

Unfortunately it didn't parse the example (SyntaxError: Unexpected token (1:6)). This means the library is not useful for converting files which are mix of ES5 and ES6 code.

Symbol is not defined

I tried to run the very same website example:

xto6 person.js -o person-es6.js

Then i have the following error:

 throw _iteratorError;
                  ^
ReferenceError: Symbol is not defined

npm install fails

following the readme and entering

$ sudo npm i -g xto6

throws errors

npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "xto6"
npm ERR! node v0.12.5
npm ERR! npm  v2.11.2
npm ERR! code ETARGET

npm ERR! notarget No compatible version found: xto6@'*'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["1.0.0-alpha","1.0.1-alpha","1.0.2-alpha","1.0.3-alpha","1.0.4-alpha","1.0.5-alpha","1.0.6-alpha","1.0.7-alpha","1.1.0-alpha","1.1.1-alpha","1.1.2-alpha"]
npm ERR! notarget 
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/hrvoje/lessonhub/frontend/npm-debug.log

probably update readme to

$ sudo npm i -g [email protected]

I would suggest releasing a 0.0.1 version or something to denote instability, but it doesn't make much sense now after all these alpha versions have been released.

Unpack closure

Coffee class

class Animal
  constructor: (@name) ->

  move: (meters) ->
    alert @name + " moved #{meters}m."

Compiles to

var Animal;
Animal = (function() {
  function Animal(name) {
    this.name = name;
  }

  Animal.prototype.move = function(meters) {
    return alert(this.name + (" moved " + meters + "m."));
  };

  return Animal;

})();

xto6 compiles this code to

var Animal;
Animal = function () {
    class Animal {
        constructor() {
            this.name = name;
        }
        move(meters) {
            return alert(this.name + (' moved ' + meters + 'm.'));
        }
    }
    return Animal;
}();

So I suggest to remove closure wrapper, if it possible.

Incorrect detection of a member assignation as a local binding

function foo(b) {
    var a = 3;
    b.a = 42;
}

oddly generates

function foo(b) {
    let a = 3;
    b.a = 42;
}

note the let binding for a rather than the expected const. Replacing the name of the property on b "fixes" the unrelated binding to the a local variable:

function foo(b) {
    const a = 3;
    b.c = 42;
}

Possible merge with 5to6?

5to6 project has same goals and list of other transformations, while xto6 supports only class transformation. My thought is that both projects would benefit from merge or collaboration.

/cc @thomasloh @benjamn

Large amount of errors

Here are the results of running lebab on every .js file in slap-editor/slap@c2d05cd. The affected files are listed after the tracebacks.

$ find . -type f -not -path '*/node_modules/*' -iname '*.js' -exec sh -c 'lebab {} -o {} || echo {}' \;
/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7736
            throw e;
            ^

Error: Line 1: Unexpected token (
  at throwError (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:2819:21)
  at throwUnexpected (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:2881:9)
  at consumeSemicolon (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:3004:13)
  at parseExpressionStatement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5173:9)
  at parseStatement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5665:24)
  at parseSourceElement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6486:20)
  at parseFunctionSourceElements (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5791:29)
  at parseFunctionDeclaration (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5991:16)
  at parseSourceElement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6441:24)
  at parseFunctionSourceElements (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5791:29)
  at parseConciseBody (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5738:20)
  at parseArrowFunctionExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4117:16)
  at parseAssignmentExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4178:24)
  at parseExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4250:16)
  at parseExpressionStatement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5172:45)
  at parseStatement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5665:24)
  at parseSourceElement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6486:20)
  at parseProgramElement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6502:16)
  at parseProgramElements (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6534:29)
  at parseProgram (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6547:16)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7724:23)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/lib/parser.js:26:34)
  at Object.read (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:66:33)
  at Object.readFile (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:42:17)
  at Transformer.readFile (/usr/local/lib/node_modules/lebab/lib/transformer.js:113:51)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:13:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./coverage/lcov-report/prettify.js
/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7736
            throw e;
            ^

Error: Line 3: Const must be initialized
  at throwError (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:2824:21)
  at parseVariableDeclaration (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4839:17)
  at parseVariableDeclarationList (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4855:23)
  at parseConstLetDeclaration (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4886:24)
  at parseSourceElement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6439:24)
  at parseFunctionSourceElements (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5791:29)
  at parseConciseBody (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:5738:20)
  at parseArrowFunctionExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4117:16)
  at parseAssignmentExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4178:24)
  at parseExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4250:16)
  at parseGroupExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:3482:16)
  at parsePrimaryExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:3575:20)
  at parseLeftHandSideExpressionAllowCall (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:3683:61)
  at parsePostfixExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:3723:20)
  at parseUnaryExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:3790:16)
  at parseBinaryExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:3880:16)
  at parseConditionalExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:3940:16)
  at parseAssignmentExpression (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4193:16)
  at parseVariableDeclaration (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4842:20)
  at parseVariableDeclarationList (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4855:23)
  at parseConstLetDeclaration (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:4886:24)
  at parseSourceElement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6439:24)
  at parseProgramElement (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6502:16)
  at parseProgramElements (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6534:29)
  at parseProgram (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6547:16)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7724:23)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/lib/parser.js:26:34)
  at Object.read (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:66:33)
  at Object.readFile (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:42:17)
  at Transformer.readFile (/usr/local/lib/node_modules/lebab/lib/transformer.js:113:51)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:13:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./coverage/lcov-report/sorter.js
/usr/local/lib/node_modules/lebab/lib/transformation/object-methods.js:25
      if (property.value.type === 'FunctionExpression') {
                        ^

TypeError: Cannot read property 'type' of undefined
  at Controller.functionToMethod (/usr/local/lib/node_modules/lebab/lib/transformation/object-methods.js:25:25)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/object-methods.js:14:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/cli.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/BaseFindForm.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/BaseForm.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/Button.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/FileBrowser.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/FindForm.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/GoLineForm.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/Header.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/Pane.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/SaveAsCloseForm.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/SaveAsForm.js
/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^

TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/lebab/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/lebab/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/lebab/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/lebab/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./lib/ui/Slap.js
/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7736
            throw e;
            ^

Error: Line 1: Unexpected token ILLEGAL
  at throwError (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:2824:21)
  at scanPunctuator (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1011:9)
  at advance (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1747:16)
  at peek (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1773:21)
  at parseProgram (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6546:9)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7724:23)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/lib/parser.js:26:34)
  at Object.read (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:66:33)
  at Object.readFile (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:42:17)
  at Transformer.readFile (/usr/local/lib/node_modules/lebab/lib/transformer.js:113:51)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:13:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./slap.js
/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7736
            throw e;
            ^

Error: Line 1: Unexpected token ILLEGAL
  at throwError (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:2824:21)
  at scanPunctuator (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1011:9)
  at advance (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1747:16)
  at peek (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1773:21)
  at parseProgram (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6546:9)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7724:23)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/lib/parser.js:26:34)
  at Object.read (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:66:33)
  at Object.readFile (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:42:17)
  at Transformer.readFile (/usr/local/lib/node_modules/lebab/lib/transformer.js:113:51)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:13:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./spec/cli.js
/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7736
            throw e;
            ^

Error: Line 1: Unexpected token ILLEGAL
  at throwError (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:2824:21)
  at scanPunctuator (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1011:9)
  at advance (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1747:16)
  at peek (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:1773:21)
  at parseProgram (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:6546:9)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/node_modules/esprima-fb/esprima.js:7724:23)
  at Object.parse (/usr/local/lib/node_modules/lebab/node_modules/recast/lib/parser.js:26:34)
  at Object.read (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:66:33)
  at Object.readFile (/usr/local/lib/node_modules/lebab/lib/utils/ast-generator.js:42:17)
  at Transformer.readFile (/usr/local/lib/node_modules/lebab/lib/transformer.js:113:51)
  at module.exports (/usr/local/lib/node_modules/lebab/bin/file.js:13:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/lebab/bin/index.js:37:3)
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:134:18)
  at node.js:961:3

./spec/index.js

: No such file or directory using ubuntu

I've tried to use xto6 on ubuntu but the execution fails because the package on npm contains windows line breaks instead of unix.

$ npm i xto6 -g
$ xto6 test.js
: No such file or directory
$ cat -v /home/ubuntu/.nvm/v0.10.35/lib/node_modules/xto6/bin/index.js | head -n 3
#!/usr/bin/env node^M
var program = require('commander');^M
var fs = require("fs");^M

When I fix the line breaks xto6 executes correctly.

$ dos2unix  /home/ubuntu/.nvm/v0.10.35/lib/node_modules/xto6/bin/index.js
dos2unix: converting file /home/ubuntu/.nvm/v0.10.35/lib/node_modules/xto6/bin/index.js to Unix format ...
$ xto6 test.js                                                   
The file "output.js" has been written.

When I install from github directly using npm i mohebifar/xto6 -g there is no such problem,
so probably there is something going wrong during the publishing process to npm.

Error: Cannot find module './block-statement.js'

module.js:340
    throw err;
          ^
Error: Cannot find module './block-statement.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/xto6/lib/syntax/function-expression.js:15:38)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

lebab!

Took me a minute to get it, but I think it's pretty funny.

Destructuring

Some examples:

function foo(array) {
  var a = array[0], b = array[1];
  // ...
}
let o = getSomeObject();
let a = o.a, b = o.b, c = o.d;

To

function foo([a, b]) {
  // ...
}
let {a, b, d: c} = getSomeObject()

Handle files with `#!/usr/bin/env node`

Throws error when processing a file containing #!/usr/bin/env node

/usr/local/lib/node_modules/xto6/node_modules/esprima-fb/esprima.js:7736
            throw e;
            ^

Error: Line 1: Unexpected token ILLEGAL
  at throwError (/usr/local/lib/node_modules/xto6/node_modules/esprima-fb/esprima.js:2824:21)
  at scanPunctuator (/usr/local/lib/node_modules/xto6/node_modules/esprima-fb/esprima.js:1011:9)
  at advance (/usr/local/lib/node_modules/xto6/node_modules/esprima-fb/esprima.js:1747:16)
  at peek (/usr/local/lib/node_modules/xto6/node_modules/esprima-fb/esprima.js:1773:21)
  at parseProgram (/usr/local/lib/node_modules/xto6/node_modules/esprima-fb/esprima.js:6546:9)
  at Object.parse (/usr/local/lib/node_modules/xto6/node_modules/esprima-fb/esprima.js:7724:23)
  at Object.parse (/usr/local/lib/node_modules/xto6/node_modules/recast/lib/parser.js:26:34)
  at Object.read (/usr/local/lib/node_modules/xto6/lib/utils/ast-generator.js:66:33)
  at Object.readFile (/usr/local/lib/node_modules/xto6/lib/utils/ast-generator.js:42:17)
  at Transformer.readFile (/usr/local/lib/node_modules/xto6/lib/transformer.js:113:51)
  at module.exports (/usr/local/lib/node_modules/xto6/bin/file.js:13:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/xto6/bin/index.js:37:3)
  at Module._compile (module.js:425:26)
  at Object.Module._extensions..js (module.js:432:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:313:12)
  at Function.Module.runMain (module.js:457:10)
  at startup (node.js:138:18)
  at node.js:974:3

Future Roadmap

Hi. Is there a timeline for when the rest of the ES6 features will be supported ?

Conversion to arrow functions should bail in of reference to `arguments`

As MDN notes, in arrow functions the arguments object is lexically scoped (like this) rather than a local override. This means arguments in an anonymous function and in an arrow function have a different behavior:

> function f() { (function () { console.log(arguments); })(); }
> function g() { (() => console.log(arguments))(); }
> f(1, 2, 3)
{}
> g(1, 2, 3)
{ '0': 1, '1': 2, '2': 3 }

Ideally the bailout should only occur if arguments is not declared in the anonymous function, but given the this bailout is fairly conservative (it doesn't seem to take in account this-binding) it would be logical to do the same for arguments.

A more involved long-term alternative could be to convert arguments-using anonymous functions to rest parameters, but it'd be significantly more involved to correctly handle aliasing and arguments object properties (arguments.caller and arguments.callee).

Crash inside transformation/default-arguments, cannot read map of undefined

Trying to use your tool on this code from Mike Chambers

https://github.com/mikechambers/ExamplesByMesh/blob/master/JavaScript/QuadTree/src/QuadTree.js

and got the following message.

โ†’ xto6 QuadTree.js -o qqq.js
/usr/local/lib/node_modules/xto6/lib/transformation/default-arguments.js:29
    lastFunction._args = node.params.map(function (arg) {
                                    ^
TypeError: Cannot read property 'map' of undefined
  at Controller.findDefaultAssignments (/usr/local/lib/node_modules/xto6/lib/transformation/default-arguments.js:29:37)
  at Controller.__execute (/usr/local/lib/node_modules/xto6/node_modules/estraverse/estraverse.js:399:31)
  at Controller.replace (/usr/local/lib/node_modules/xto6/node_modules/estraverse/estraverse.js:633:27)
  at Object.replace (/usr/local/lib/node_modules/xto6/node_modules/estraverse/estraverse.js:714:27)
  at exports.default (/usr/local/lib/node_modules/xto6/lib/transformation/default-arguments.js:16:27)
  at Transformer.applyTransformation (/usr/local/lib/node_modules/xto6/lib/transformer.js:140:7)
  at Transformer.applyTransformations (/usr/local/lib/node_modules/xto6/lib/transformer.js:152:14)
  at module.exports (/usr/local/lib/node_modules/xto6/bin/file.js:14:15)
  at Object.<anonymous> (/usr/local/lib/node_modules/xto6/bin/index.js:37:3)
  at Module._compile (module.js:460:26)
  at Object.Module._extensions..js (module.js:478:10)
  at Module.load (module.js:355:32)
  at Function.Module._load (module.js:310:12)
  at Function.Module.runMain (module.js:501:10)
  at startup (node.js:129:16)
  at node.js:814:3

Any ideas where to start debugging this?

Option to output to STDOUT

I'm planning to integrate this awesome tool into my editor and having the option to run the command and read the STDOUT output would make it much easier.
Sticking to UNIX paradigms would help us to pipe the output to other commands as well.

Make it a UNIXy tool please.

great job btw ๐Ÿ‘

"Cannot set property 'kind' of undefined" in "Try It Live" on Chrome

// when trying to es5 to es6 this code:
var makePayloadConfig = function(){
    var person = {};

    person.guest = 1;  //  <----- this line triggers it
};
Uncaught TypeError: Cannot set property 'kind' of undefinedd 
@ app.js:22k.__execute 
@ app.js:19k.traverse 
@ app.js:19n 
@ app.js:18b.exports 
@ app.js:22e.applyTransformation.value 
@ app.js:22e.applyTransformations.value 
@ app.js:22transpile 
@ app.js:1(anonymous function) 
@ app.js:22

Support extending classes

Edited by @nene:
The initial implementation has been merged in from #183, some things remain to be improved:

  • We're currently overly strict by not detecting inheritance in the following code:

    function Class1() {}
    Class1.prototype = new Class2();

    we only detect the inheritance when the above is followed by constructor assignment:

    Class1.prototype.constructor = Class2;
  • We detect importing util.inherits using require():

    var util = require("util");
    util.inherits(Class, SuperClass);

    but we'll fail with:

    import util from "util";
    util.inherits(Class, SuperClass);
  • Call to superclass constructor must currently be directly inside the body of the constructor, the following will not work:

    function MyClass() {
      if (someCondition) {
        SuperClass.call(this);
      }
    }
  • super() must be called before any references to this. The following code will fail:

    constructor() {
      this.age = 10; // ReferenceError
      super();
    }
  • super() must always be called from subclass constructor. The following code will fail:

    class Foo extends Bar {
      constructor() {
        this.age = 10; // super() not called
      }
    }
  • We should also convert superclass method calls inside other methods. Converting this:

    foo() {
      SuperClass.prototype.foo(this, params);
    }

    into this:

    foo() {
      super.foo(params);
    }

Attempted to assign to readonly property.

Related to #53, I tried to "fix" the issue by converting the property reference to a dynamic name instead of renaming it entirely:

function foo(b) {
    var a = 3;
    b['a'] = 42;
}

In the online converter of the home page, this fails with the following trace:

TypeError: Attempted to assign to readonly property.
d app.js:21:25701
__execute app.js:18:981
traverse app.js:18:1755
n app.js:17:26082
exports app.js:21:25824
value app.js:21:28633
value app.js:21:28786
transpile app.js:1:103
(anonymous function) app.js:21:30880

Support callee default parameters

There are several ways to define default parameters.

function (a, b, c, d) {
   a = a || 1; // 1 is a default value
   b = typeof b !== 'undefined' ? b : 2; // 2 is a default value
   c = typeof c === 'undefined' ? 3 : c; // 3 is a default value
   d = d ? d : 4; // 4 is a default value
}

And it should be converted to :

function (a = 1, b = 2, c = 3, d = 4) {

}

Transformer is not defined (webpage)

Hi

Can't test the live demo since Transformer is not defined in ine 6 main.js

Error message:
Uncaught ReferenceError: Transformer is not defined

Not sure if this was the right place to put the issue.

Problem about template string

Here's my source code:

conditionSql += "`" + p.column + "` = ?";

and this is converted one:

conditionSql += ``${p.column}` = ?`;

Invalid arrow conversions

Having played around with the online converter following xto6 being posted on hacker news, here are cases where it converts an anonymous function to an arrow function even though it should not due to a this reference in the body:

(function () { this.foo(); })();
// incorrectly converted to
(() => { this.foo(); })();
(function () { foo(this); })();
// incorrectly converted to
(() => { foo(this); })();
(function () { foo(this.bar); })();
// incorrectly converted to
(() => { foo(this.bar); })();

Source JavaScript used on xto6.js.org example contains an error

It's just a low priority issue on the homepage of http://xto6.js.org/

The source JavaScript in the example transpilation contains an error:

Person.prototype.getAge = function (birthYear) {
  var age = 2015;
  age -= birthYear;

  return result;
};

which should be

Person.prototype.getAge = function (birthYear) {
  var age = 2015;
  age -= birthYear;

  return age;
};

transformation throw _iteratorError

Precondition: Windows 7 SP2, node 0.10.29
The installation completed successfully, tested the example from xto6.js.org.
Next log obtained:

xto6 es5.js -o es6.js

\nodejs\node_modules\xto6\lib\transformation\classes.js:124
throw _iteratorError;
^
ReferenceError: Symbol is not defined
at Controller.classMaker (\nodejs\node_modules\xto6\lib\transformation\classes.js:87:40)
at Controller.__execute (\nodejs\node_modules\xto6\node_modules\estraverse\estraverse.js:399:31)
at Controller.traverse (\nodejs\node_modules\xto6\node_modules\estraverse\estraverse.js:497:28)
at Object.traverse (\nodejs\node_modules\xto6\node_modules\estraverse\estraverse.js:709:27)
at module.exports (\nodejs\node_modules\xto6\lib\transformation\classes.js:26:14)
at Transformer.applyTransformation (\nodejs\node_modules\xto6\lib\transformer.js:118:9)
at Transformer.applyTransformations (\nodejs\node_modules\xto6\lib\transformer.js:131:16)
at module.exports (\nodejs\node_modules\xto6\bin\file.js:14:15)
at Object. (\nodejs\node_modules\xto6\bin\index.js:36:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3

This error not reproduced with node v0.11.22. It's OK.

Convert var to const/let

If a variable is only assigned to once, convert its declaration to const, otherwise let in the innermost block that covers all uses of a variable within the function.

Syntax highlighting on xto6 website

On the project's webiste http://xto6.js.org "better" transpiled code looks actually uglier because of lack of syntax highlighting for ES6 on the right pane. Maybe some plugin for Ace could make it better?

PS. I know that this is not related with project itself and this is maybe not super important, but it just looks ugly ;)

Missing conversion to arrow function

The other side of #51, there are at least two cases where xto6 fails to compile literal functions to arrow functions (testing on the online converter):

  • if a function expression is directly returned:

    function foo() {
        return function () { return 42; };
    }
  • if a function expression is assigned to a local variable:

    function foo() {
        var a = function () { return 42; };
    }

Live Transpile on Front Page Fails (Doesn't Like ||?)

I recently tried to use your live transpile feature, but got the following error:

Uncaught TypeError: Cannot set property 'kind' of undefined

Here's the full stack trace (although it's probably useless because of the minification):

Uncaught TypeError: Cannot set property 'kind' of undefinedd @ app.js:22k.__execute @ app.js:19k.traverse @ app.js:19n @ app.js:18b.exports @ app.js:22e.applyTransformation.value @ app.js:22e.applyTransformations.value @ app.js:22transpile @ app.js:1(anonymous function) @ app.js:22setTimeout (async)(anonymous function) @ app.js:22d._signal @ vendor.js:3(anonymous function) @ vendor.js:11d @ vendor.js:3setTimeout (async)e @ vendor.js:3(anonymous function) @ vendor.js:11d._signal @ vendor.js:3onDocumentChange @ vendor.js:11d._signal @ vendor.js:3onChange @ vendor.js:10d._signal @ vendor.js:3removeInLine @ vendor.js:8remove @ vendor.js:8remove @ vendor.js:10insert @ vendor.js:12onPaste @ vendor.js:12K @ vendor.js:3

I tried simplifying my code until I got down to:

var NodeView = function(mode) {
    var self = this;
    self.mode = mode || 'foo';  
};

If I removed the line with || it was able to transpile, so it seems the tool has an issue with boolean logic.

Transpiling commonJS files causes exception

xto6 version: 1.1.0-alpha
node version: 0.12.2

Transpiling this file:

'use strict'

module.exports = function () {
  return 'hello, world!';
};

Results in:

C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\lib\transformation\let.js:25
    declarations[left].kind = "let";
                            ^
TypeError: Cannot set property 'kind' of undefined
  at Controller.replaceVar (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\lib\transformation\let.js:25:29)
  at Controller.__execute (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\node_modules\estraverse\estraverse.js:399:31)
  at Controller.traverse (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\node_modules\estraverse\estraverse.js:497:28)
  at Object.traverse (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\node_modules\estraverse\estraverse.js:709:27)
  at module.exports (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\lib\transformation\let.js:8:14)
  at Transformer.applyTransformation (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\lib\transformer.js:118:9)
  at Transformer.applyTransformations (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\lib\transformer.js:131:16)
  at module.exports (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\bin\file.js:14:15)
  at Object.<anonymous> (C:\Users\daniel\AppData\Roaming\npm\node_modules\xto6\bin\index.js:36:3)
  at Module._compile (module.js:460:26)
  at Object.Module._extensions..js (module.js:478:10)
  at Module.load (module.js:355:32)
  at Function.Module._load (module.js:310:12)
  at Function.Module.runMain (module.js:501:10)
  at startup (node.js:129:16)
  at node.js:814:3

This might be related to #31

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.