Skip to content

Commit

Permalink
Remove babel polyfill
Browse files Browse the repository at this point in the history
Basically, here’s what’s going on. Babel has a transformer, called
runtime, that can turn ES6 code like `new Promise()` into `new
core.Promise()`, where `core.Promise` is a polypill. But, that runtime
transformer (which I was already using), can’t polyfill some ES6 code
(e.g. `var it = "test"; it.startsWith("t");`) because it doesn't know,
e.g., that the `it` in `it.startsWith` is a string, so it doesn't know
that you're looking for `String.prototype.startsWith`. The solution to
this is to require the babel polypill, which modifies the global
`String.prototype` directly. That's what I was doing before this
commit, except that it also causes a problem: any dependents of this
library also get their globals changed.

Now, maybe that should usually be ok in practice—since most of the
polyfills match the ES6+ specs—but, of course, there's a possibility of
a polyfill having a bug, or two polyfills doing something different in
an unpolyfillable case. So, clobbering the dependent's globals is still
a bad idea. And, with this in mind, Babel actually throws an error if
the dependent tries to load babel/polyfill for a second time…so just
transparently modifying the globals and bearing the risk isn't possible
even if it's what we wanted to do.

So, this commit removes the polyfill's require, which then allows me to
move babel to a devDependency (without reopening #11, which was based
on the polyfill line). This means no using the ES6/7 `Array.prototype`
and `String.prototype` methods, but, oh well. It looks like I’d removed
all uses of them earlier anyway in preparation for this change.

Should close #47
  • Loading branch information
ethanresnick committed Aug 7, 2015
1 parent 34186ce commit e4986e1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require('babel/polyfill');

module.exports = {
dbAdapters: {
Mongoose: require('./build/src/db-adapters/Mongoose/MongooseAdapter')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"main": "index.js",
"dependencies": {
"babel": "5.6.14",
"babel-runtime": "5.6.17",
"co": "4.5.x",
"content-type": "1.x.x",
Expand All @@ -28,6 +27,7 @@
"vary": "^1.0.0"
},
"devDependencies": {
"babel": "5.6.14",
"babel-eslint": "3.x.x",
"chai": "^1.9.2",
"eslint": "0.x.x",
Expand Down

0 comments on commit e4986e1

Please sign in to comment.