Does babel need es6-shim?
Asked Answered
O

2

8

I mentioned on Twitter that I was moving from es6-shim to babel. Someone else mentioned:

the shims are still needed even with babel. they fix broken builtins, ones babel's output uses.

So:

  1. Does babel need es6-shim or similar?

  2. If it does, why doesn't babel require these things as a dependency?

Answers with references preferred over 'yes / no' with no supporting arguments!

Oscillatory answered 12/10, 2015 at 11:37 Comment(0)
C
13

Babel, at its core, does a single thing: convert syntax from one form to another.

Some of Babel's syntax transformations introduce dependencies on ES6 library functionality. It doesn't concern itself with how that functionality got there because:

  • The system might already provide it
  • The user might only want to load specific pieces of a library
  • There are many polyfills and the user might have a specific one it wants to use.

It is the developers job to ensure that the transpiled code is running in an environment where all the functions it needs actually exist.

  • Babel should work fine with es6-shim if you'd like to keep using it.
  • Babel also exposes babel/polyfill as a dead simple way to load a polyfill, which loads core-js, another polyfill like es6-shim. Just:

    require('babel/polyfill');

Craps answered 12/10, 2015 at 16:28 Comment(0)
S
4

Some Babel transformations rely on objects or methods that may not be available in your runtime environment and which you therefore would want to polyfill for those environments. Those dependencies are documented at https://babeljs.io/docs/usage/caveats/.

Babel ships with a polyfill that satisfies all of those requirements that you can opt-in to if you want, and doesn't attempt to automatically insert polyfills for the reasons that @loganfsmyth explained.

Sporangium answered 13/10, 2015 at 20:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.