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

Leading underscores in __extends etc prevent Closure minification #7345

Closed
evmar opened this issue Mar 2, 2016 · 3 comments
Closed

Leading underscores in __extends etc prevent Closure minification #7345

evmar opened this issue Mar 2, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@evmar
Copy link
Contributor

evmar commented Mar 2, 2016

TypeScript helpers (__extends, __decorate, __param, etc.) currently all have leading underscores in their names in the generated code. Unfortunately the Closure compiler treats names with a preceding underscore as special names that shouldn't be dead-code eliminated or renamed.

It would be nice if these builtins had some other name, e.g. TypeScript__extends or some such. It's not really TypeScript's problem but Closure is currently the best minifier so working together is nice.

This would be fixed by issue #3364 as well, but I thought I'd capture the Closure-specific issue separately because it's not the same problem.

Example code to make it clearer: this input code

function _foo() {
  return 3;
}
function bar() {
  return 3;
}
function baz() {
  return 3;
}
console.log(_foo(), bar());

in Closure produces

function _foo() {
  return 3;
}
console.log(_foo(), function a() {
  return 3;
}());

where baz was eliminated and bar was renamed and inlined, but _foo was kept due to the underscore.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 2, 2016

Please note that --noEmitHelpers will not emit any of these helpers and you can specify them once in your project.

@evmar
Copy link
Contributor Author

evmar commented Mar 3, 2016

@mhegazy yes, I believe we use that. But that one specification is redundant for helpers that are unused, and it'd be nice to be able to minify the function names (__extends => a) as well.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 3, 2016

#3364 is on the road map. so we should have that working soon.

@mhegazy mhegazy closed this as completed Mar 28, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Mar 28, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants