- From: Mattias Buelens <notifications@github.com>
- Date: Wed, 07 Mar 2018 15:11:32 -0800
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/pull/899@github.com>
I'm working on an updated polyfill for streams over at [MattiasBuelens/web-streams-polyfill](https://github.com/MattiasBuelens/web-streams-polyfill). I use Rollup to convert the reference implementation from CommonJS to ES2015 modules, and then bundle it in a nice UMD wrapper.
This works great, but unfortunately the [Rollup CommonJS plugin](https://github.com/rollup/rollup-plugin-commonjs) fails to optimally transform some parts of the code. For example, it has trouble with this function in `helpers.js`:
```js
exports.createDataProperty = (o, p, v) => {
assert(exports.typeIsObject(o));
Object.defineProperty(o, p, { value: v, writable: true, enumerable: true, configurable: true });
};
```
Because `exports.typeIsObject` might be re-assigned externally, the plugin must retain the `exports` object and wrap the whole module with a `createCommonJS` call. This prevents further optimizations such as tree-shaking.
This PR changes all instances of `exports.foo = ...` with `const foo = ...; module.exports = { foo };` so that internal functions can use `foo` instead of `exports.foo`. This prevents externally re-assigned exports from changing the behavior of internal functions, and allows Rollup to transform the CommonJS module into a "proper" ES2015 module.
I realize that this is not immediately relevant for the reference implementation, but it helps to shave off a couple of bytes in the polyfill. I could keep this in my fork of the reference implementation, but I'd prefer not to need a fork. 😅
You can view, comment on, or merge this pull request online at:
https://github.com/whatwg/streams/pull/899
-- Commit Summary --
* Refactor exports
-- File Changes --
M reference-implementation/lib/helpers.js (54)
M reference-implementation/lib/queue-with-sizes.js (15)
M reference-implementation/lib/utils.js (4)
-- Patch Links --
https://github.com/whatwg/streams/pull/899.patch
https://github.com/whatwg/streams/pull/899.diff
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/899
Received on Wednesday, 7 March 2018 23:18:56 UTC