Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Error when running through babel compiler #49

Closed
alexreardon opened this issue Aug 4, 2015 · 5 comments
Closed

Error when running through babel compiler #49

alexreardon opened this issue Aug 4, 2015 · 5 comments

Comments

@alexreardon
Copy link

When npo.src.js or npo.js is run through babel the following line:

})("Promise", typeof global != "undefined" ? global : this, function DEF() {

becomes

})("Promise", typeof global != "undefined" ? global : undefined, function DEF() {

This causes this line to die, as context is undefined

 // special form of UMD for polyfilling across evironments
      context[name] = context[name] || definition();

Script to replicate issue:

var fs = require('fs'),
    babel = require('babel-core');
babel.transformFile('./node_modules/native-promise-only/lib/npo.src.js', function (err, result) {
    if(err) {
        return console.log(err);
    }
    fs.writeFileSync('.temp.txt', result.code, {
        encoding: 'utf8'
    });
});
@getify
Copy link
Owner

getify commented Aug 4, 2015

  1. Polyfills shouldn't be run through a transpiler. That doesn't make sense. In fact, you shouldn't run any third-party code through a transpiler, IMO. Exclude such file(s) from transpilation runs.
  2. I disagree with babel that such assumptions about this are either spec compliant or appropriate for polyfills.

Sounds like you should either not run NPO through babel, or you should blacklist the strict transformer, as @zloirock suggests.


use correct way detection global object.

I disagree that the much more convoluted code linked to is "correct". It may work, but it's far from what we ought to be doing. See points above.

@zloirock
Copy link

zloirock commented Aug 4, 2015

@getify see this table. It not contains this because of strict mode, but w/o strict mode in many case it shouldn't work too. It's simples correct for most case way, "convoluted", for example, in LoDash.

@alexreardon
Copy link
Author

I agree with your first point @getify. I makes little sense to run a library through babel. I now exclude it. Thanks!

@getify
Copy link
Owner

getify commented Aug 4, 2015

Cheers!

@getify getify closed this as completed Aug 4, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants