Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Rewrite typeof module/exports #151

Closed
Rich-Harris opened this issue Dec 19, 2016 · 0 comments · Fixed by #155
Closed

Rewrite typeof module/exports #151

Rich-Harris opened this issue Dec 19, 2016 · 0 comments · Fixed by #155

Comments

@Rich-Harris
Copy link
Contributor

Ref rollup/rollup#1061. If this plugin rewrote typeof module, typeof exports and typeof module.exports inside a createCommonjsModule wrapper as 'object', then a lot of UMD checks could be simplified:

if (typeof exports === "object" && typeof module === "object") {
  module.exports = foo;
} else if (typeof define === "function" && define.amd) {
  define([], function () { return foo; });
} else {
  window.foo = foo;
}

...becomes this...

if ('object' === "object" && 'object' === "object") {
  module.exports = foo;
} else if (typeof define === "function" && define.amd) {
  define([], function () { return foo; });
} else {
  window.foo = foo;
}

...which becomes this:

{
  module.exports = foo;
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant