Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the runtime to be required as a module.
Specifically, you can now require("regenerator/runtime-module") if you want to access the runtime without relying on the global namespace. Note that runtime.js is now fully strict-mode-compliant. Fixes #165. Fixes #166.
- Loading branch information
Showing
2 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This method of obtaining a reference to the global object needs to be | ||
// kept identical to the way it is obtained in runtime.js | ||
var g = | ||
typeof global === "object" ? global : | ||
typeof window === "object" ? window : this; | ||
|
||
var hasOwn = Object.prototype.hasOwnProperty; | ||
var hadRuntime = hasOwn.call(g, "regeneratorRuntime"); | ||
var oldRuntime = hadRuntime && g.regeneratorRuntime; | ||
delete g.regeneratorRuntime; // Force reevalutation of runtime.js. | ||
|
||
module.exports = require("./runtime"); | ||
|
||
if (hadRuntime) { | ||
// Restore the original runtime. | ||
g.regeneratorRuntime = oldRuntime; | ||
} else { | ||
// Remove the global property added by runtime.js. | ||
delete g.regeneratorRuntime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters