esperantojs / esperanto

DEPRECATED: An easier way to convert ES6 modules to AMD and CommonJS
http://esperantojs.org
234 stars 21 forks source link

Parse error when processing a sparse array #144

Closed rwjblue closed 9 years ago

rwjblue commented 9 years ago

Simplest reproduction:

var esperanto = require('esperanto');

esperanto.toAmd('[1,,3,4]', {
  strict: true
});

Gives the following error:

/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:159
                        if ( node.type === 'ImportDeclaration' || node.type === 'ExportSpecifier' )
                                 ^
TypeError: Cannot read property 'type' of null
    at Object.walk.enter (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:159:13)
    at visit (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:57:9)
    at visit (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:75:5)
    at visit (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:80:4)
    at visit (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:75:5)
    at walk (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:39:2)
    at annotateAst (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:157:2)
    at getStandaloneModule (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:630:3)
    at Object.toAmd (/Users/rjackson/Source/javascript/es6-testing/node_modules/esperanto/dist/esperanto.js:2449:13)
    at Object.<anonymous> (/Users/rjackson/Source/javascript/es6-testing/test.js:3:11)

Just to make this more concrete, the regenerator output from Babel translates to the following when using async/await:

var foo = {
    async save() {
      try {
        return await createThing();
      } finally { }
    }
};

We get the following output:

var foo = {
  save: function save() {
    return regeneratorRuntime.async(function save$(context$1$0) {
      while (1) switch (context$1$0.prev = context$1$0.next) {
        case 0:
          context$1$0.prev = 0;
          context$1$0.next = 3;
          return createThing();
        case 3:
          return context$1$0.abrupt("return", context$1$0.sent);
        case 4:
          context$1$0.prev = 4;
          return context$1$0.finish(4);
        case 6:
        case "end":
          return context$1$0.stop();
      }
    }, null, this, [[0,, 4, 6]]);
  }
};

Which is how this manifested itself...

rwjblue commented 9 years ago

In case it makes a difference this is with 0.6.25.

rwjblue commented 9 years ago

It also apparently only manifests with the strict: true flag set.

Rich-Harris commented 9 years ago

Thanks, this was a nice simple one-line fix. Released in 0.6.26