-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Make exported consts better minifiable #7565
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
Comments
now every other reference to I expect what you want is constant folding and propagation, see #3964 |
This is different from what I understand. I specifically want to avoid const values being inlined because that that makes the resulting code larger. The goal is to have code that can be shrunk better by a minifier for JavaScript. To compare a few examples: module Some {
export const thing = "";
export function getThing() {
return thing;
}
getThing();
export class Thing {}
var t = new Thing();
} This compiles to: var Some;
(function (Some) {
Some.thing = "";
function getThing() {
return Some.thing;
}
Some.getThing = getThing;
getThing();
var Thing = (function () {
function Thing() {
}
return Thing;
}());
Some.Thing = Thing;
var t = new Thing();
})(Some || (Some = {})); A JavaScript minfier will rename function getThing and the two direct references to some short name. Likewise with the class Thing and its two direct references. With the exported const though, it cannot do that, because that is not assigned to a local variable. The request here is to have a local variable for the exported const to which the value is assigned and which is then referenced everywhere from within the local scope. |
Approved but please wait for the new transforms-based emitter to merge before sending a PR |
most people use uglify.js for minification. Doing something like that would make the code better minifiable in all cases. |
No one seemed interested in sending a PR for this and very few people are using value-based |
TypeScript Version:
1.8.2 (Playground on 20160317)
Code
Expected behavior:
Should compile to:
So internal references can use the local variable which will minify well. Exported functions and classes already compile minifier-friendly.
Actual behavior:
But compiles to:
So internal references use the nested reference which does not minify.
The text was updated successfully, but these errors were encountered: