Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime defaults to creating a global variable #166

Closed
appden opened this issue Jan 13, 2015 · 8 comments · Fixed by #167
Closed

Runtime defaults to creating a global variable #166

appden opened this issue Jan 13, 2015 · 8 comments · Fixed by #167

Comments

@appden
Copy link

appden commented Jan 13, 2015

It's quite unfortunate that the runtime is not easy to package up as self-contained module. It seems to me that if the exports variable is available, then there should be no need to create the global variable.

I'm creating a self-contained library with generators, and it would be great to not have to manually delete this variable.

@sebmck
Copy link
Contributor

sebmck commented Jan 13, 2015

This would also be a good supplement to the core aliasing (and babel/babel#446) behaviour of 6to5. It'd allow library authors to use generators with 6to5 and have the regenerator runtime imported into the local variable scope so it wouldn't leak.

@benjamn
Copy link
Collaborator

benjamn commented Jan 13, 2015

I think this might be a potential answer to my recent question: #165 (comment)

@benjamn
Copy link
Collaborator

benjamn commented Jan 13, 2015

Are you defining a local variable called regeneratorRuntime? Or do we need to generate a different expression for referring to the runtime? It shouldn't be too hard to make that configurable, if need be.

@sebmck
Copy link
Contributor

sebmck commented Jan 13, 2015

@benjamn Ideally it'd be great to be able to go var regeneratorRuntime = require("regenerator/foobar");.

@appden
Copy link
Author

appden commented Jan 14, 2015

@benjamn for my case, I wouldn't need that be configurable, so that could be a separate issue.

I'm using this configuration with browserify to accomplish what I need:

insertGlobalVars: {
  regeneratorRuntime: function() {
    return "require('regenerator/runtime')";
  }
}

benjamn added a commit that referenced this issue Jan 14, 2015
benjamn added a commit that referenced this issue Jan 14, 2015
benjamn added a commit that referenced this issue Jan 14, 2015
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.
benjamn added a commit that referenced this issue Jan 14, 2015
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.
benjamn added a commit that referenced this issue Jan 14, 2015
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.
@fkling
Copy link
Contributor

fkling commented Jan 14, 2015

I think it should be made clear somewhere that the module still has to be assigned to the variable regeneratorRuntime (that's the case, right?).

@benjamn
Copy link
Collaborator

benjamn commented Jan 14, 2015

That's true, but the failure mode is that generated code will make undefined reference to regeneratorRuntime, which is a pretty easy problem to diagnose? Is that wishful thinking on my part?

@fkling
Copy link
Contributor

fkling commented Jan 14, 2015

That is true. But having to run into the issue in the first place to find out the name to use (which requires inspecting the generated code) can be discouraging. Personally I would be annoyed if I had to find out that way.

Either way, I think it would be worth extending the readme with an example that shows how to include the runtime "manually" (not via --include-runtime).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants