-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[Suggestion]: Merge emitted getters and setters into a single Object.defineProperties call #14219
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
We would be open to accepting a PR for this. |
This will have to be limited to merging consecutive properties if we want to preserve enumeration order: class Foo {
get a() { return 1; }
normalMethod() {}
get b() { return 2; }
}
console.log(Object.getOwnPropertyNames(Foo.prototype)); // ['a', 'normalMethod', 'b'] |
Would become more worthwhile if combined with the breaking changes that are necessary to bring ES5 emit inline with the ES2015 class specification, namely making both prototype methods and getter/setter properties non-enumerable. At that point it would make sense to have the |
One thing to bear in mind for developers with this is when using UglifyJS with mangle-props afterwards. (This is informative, so anyone using UglifyJS and that option should be aware of it - and it's pretty easy to work around - the option is default-off, so not going to be relevant to most.) Using While I prefer to use descriptive names for all members, in private projects (or public ones that have private members and separate "production" build) it's potentially just wasting a lot of space to have the full text names scattered around everywhere, so merging the declarations like this (and adding all the current "normal" properties) would allow for slightly smaller output files etc. |
I need this feature. |
Declining based on low interest and increasingly-low relevance. ES5 runtimes are getting pretty rare and the only real upside of this would be a slightly smaller bundle size, which other tools will do a much better job of producing with ES6 output than we ever will with downlevel output. |
TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
Proposal
We could support better minification of class declarations involving ES5 getters and setters by collapsing the calls to
Object.defineProperty
into a single call toObject.defineProperties
, unless there is some performance reason why we currently prefer several calls toObject.defineProperty
?Code
Given the following class
Current behavior:
Suggested behavior:
The text was updated successfully, but these errors were encountered: