inexorabletash / text-encoding

Polyfill for the Encoding Living Standard's API
Other
720 stars 267 forks source link

ES6/ES2015/Babel + Webpack compatibility #65

Closed therufa closed 7 years ago

therufa commented 7 years ago

The changes inside this library have been made in order to solve a transpiling issue with Babel.

We are using this lib in combination of Babel and Webpack, and we had an issue during the transpiling process. Babel sadly does not understand the meaning of this, so it was replaced with the next best it could find, which was undefined. In order to maintain compatibility with browser as well as other environments, we decided to wrap the entire scope inside a simple factory.

inexorabletash commented 7 years ago

Thanks - looks reasonable, I'll try and get to testing it in the next few days.

Only initial feedback is that it could use a comment in the code explaining why this is necessary (e.g. even something as simple as saying that it could be evaluated in strict contexts where this is undefined.)

The factory(global) line is missing a semicolon. (I try not to rely on ASI.)

We could also restructure it as IIFE at the end of the file that in place of the original }(this)); but it's probably better to have this at the top of the file to make the execution order more obvious.