Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel is not processing Array.from or 'for ... of' loops

Tags:

babeljs

I'm using babel with gulp (.pipe($.babel())), and it seems to work for most things but is not working for Array.from.

It works fine when running babel-node:

$ ./node_modules/babel/bin/babel-node.js
> Array.from
[Function: from]

But when the following code is processed with gulp:

var foo = () => { console.log(Array.from) }

The transpiled source is:

var foo = function foo() {
    console.log(Array.from);
};

And the console output when I execute foo is:

undefined

like image 458
Zach Lysobey Avatar asked Aug 20 '15 14:08

Zach Lysobey


1 Answers

Ended up solving this myself while writing my question, but figured I'd finish and answer myself to help future searchers:

There are certain features of babel that require a polyfill loaded in the browser due to limitations of ES5. This is loaded automatically in babel-node or you can include with with babel-polyfill.

Some of the features requiring the polyfill:

  • Abstract References
  • Array destructuring
  • Async functions
  • Comprehensions
  • For of
  • Array.from
  • spread
like image 92
Zach Lysobey Avatar answered Nov 03 '22 01:11

Zach Lysobey