google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.17k stars 581 forks source link

Unloadable via AMD #1933

Open parris opened 9 years ago

parris commented 9 years ago

I believe this is due to a recent change. If I included traceur from either the npm or bower as a plain script tag at the top of my application everything works fine. I need to reference window.traceur to then use it, but everything works. If I instead set up a traceur to load inside or after requirejs then I get the following error:

Uncaught Error: ModuleEvaluationError: regenerate is not a function in traceur@0.0.89/src/outputgeneration/regexpuRewritePattern.js I've tried a few methods to make this work, and I've almost isolated the issue.

After scouring the built source code I found this:

line 27132:

if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
      define(function() {
        return regenerate;
      });
    } else if (freeExports && !freeExports.nodeType) {
      if (freeModule) {
        freeModule.exports = regenerate;
      } else {
        freeExports.regenerate = regenerate;
      }
    } else {
      root.regenerate = regenerate;
    }
  }(this));

and then later (line 28164):

var regenerate = require('regenerate');

This series of events appears to be result in an anonymous define or at the very least a module that can't be found.

I've created an es6 requirejs loader that nearly works with the latest version of traceur. The es6 module pattern doesn't quite meet the needs of the general web yet and functionally resembles AMD, which is why we are trying to mix the 2 things. This all nearly works. In fact, I'd even be satisfied if traceur just registered globals and didn't try to be overly accommodating for AMD.

arv commented 9 years ago

This comes from regexpu.

@mathiasbynens Any plans to provide an ES6 version?

mathiasbynens commented 9 years ago

@arv Unlikely. Providing an ES6 version of regexpu would mean:

Ref. #1295.

@parris As a workaround, you could try adding regexpu as a direct dependency next to Traceur.