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

Function#name check in the runtime breaks when minified #156

Closed
fson opened this issue Dec 17, 2014 · 2 comments
Closed

Function#name check in the runtime breaks when minified #156

fson opened this issue Dec 17, 2014 · 2 comments

Comments

@fson
Copy link

fson commented Dec 17, 2014

Regenerator runtime breaks when code is minified with UglifyJS that removes the function name GeneratorFunction, because the code checks for the Function#name and throws if it does not match:

 if (GF.name !== GFName) throw new Error(GFName + " renamed?");

Similar issue (babel/babel#283) in 6to5 that uses regenerator runtime was fixed by removing the check: babel/babel@c92fd6f

@benjamn
Copy link
Collaborator

benjamn commented Dec 17, 2014

Thanks for bringing this up again (previously: #48, #55, #61, #63, #112, 49358bc).

The check exists to make sure regeneratorRuntime.isGeneratorFunction will work. I realize it's annoying that you can't just use UglifyJS without taking care to protect GeneratorFunction from being renamed, but that's the way it has to be, unless we use eval or Function to create GeneratorFunction, but that's a CSP violation.

Edit: I regret the tone of the following sentence, and would like to delete it, but it feels dishonest to hide my tracks like that. Please disregard.

I'll consider fixing this some other way if @sebmck agrees to stop storing modified Regenerator source files in his repository: babel/babel#313

@jlongster
Copy link

I definitely should have looped you in there; I don't like the idea of 6to5 maintaining its own runtime. It would be totally redundant. I was under some pressure just to get something working at that point.

The problem is that you can't use uglify at all right now, see mishoo/UglifyJS#552. It's totally Uglify's fault because it strips the names of function expressions and there's no way to turn that off, which is stupid. If you change the code to be:

  function GeneratorFunction() {};
  function GeneratorFunctionPrototype() {};
  var GF = GeneratorFunction;
  var GFp = GeneratorFunctionPrototype;

instead, then we can get it to work by adding mangle: { except: ['GeneratorFunction', 'GeneratorFunctionPrototype'] } to the uglify options.

Sometimes I hate computers.

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

No branches or pull requests

3 participants