You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
most people use uglify.js for minification.
If i read the documentations of uglify.js I can define a const with the const keyword in a javascript file and make uglify.js remove dead code/optimize the constant. However uglify.js will only output const keyword in ES6 code, which uglify.js can't parse. If I output it to ES5 code it becomes a regular var variable and uglify.js can't optimize it better. Would be nice to have an option to force the use of the const keyword in ES5 output, or prefix the var statement with the comment /** @const */
Doing something like that would make the code better minifiable in all cases.
Activity
mhegazy commentedon Mar 17, 2016
now every other reference to
thingneeds to beSome.thing. this not only impacts minification, it also impacts performance.I expect what you want is constant folding and propagation, see #3964
chrmarti commentedon Mar 17, 2016
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:
This compiles to:
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.
RyanCavanaugh commentedon Jun 9, 2016
Approved but please wait for the new transforms-based emitter to merge before sending a PR
pjordaan commentedon Jan 6, 2017
most people use uglify.js for minification.
If i read the documentations of uglify.js I can define a const with the const keyword in a javascript file and make uglify.js remove dead code/optimize the constant. However uglify.js will only output const keyword in ES6 code, which uglify.js can't parse. If I output it to ES5 code it becomes a regular var variable and uglify.js can't optimize it better. Would be nice to have an option to force the use of the const keyword in ES5 output, or prefix the var statement with the comment
/** @const */Doing something like that would make the code better minifiable in all cases.
RyanCavanaugh commentedon Mar 4, 2024
No one seemed interested in sending a PR for this and very few people are using value-based
namespaceanymore