-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Use redefining helper pattern for better tree-shakeability #24244
Conversation
Your change is not valid. Running your |
7b40512
to
fae0a0a
Compare
You are right, I've reassigned wrong identifier - it should be fixed now. |
@rbuckton thoughts? |
7c30d86
to
6a45805
Compare
Not sure, but I was reassigning wrong identifier at first - I've fixed it and the problem is gone. However still the received error seemed to be wrong as my code error was causing runtime recursion error and not I've updated baseline tests, from my perspective it is ready to merge if you decide the change is worth it 😉 |
I think that the @rbuckton comment is because your current var __extends = (this && this.__extends) || (function () {
function extendStatics(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})(); Seems it is valid to reassign a function in javascript but typescript don't allow it. I don't know if is by design. How to change it to this? var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})(); |
Sure, I can change |
@rbuckton friendly 🏓 is there anything left to do here? is this something that you would like to incorporate? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor change, per the earlier discussion.
Also, would you be interested in making this change in https://github.com/Microsoft/tslib as well?
src/compiler/transformers/es2015.ts
Outdated
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
function extendStatics(d, b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this a var
per #24244 (comment)?
6a45805
to
26f347f
Compare
Done.
That was my original intention/reason why I've started this discussion here 😉 Is |
26f347f
to
30fe9b8
Compare
30fe9b8
to
756910d
Compare
756910d
to
3af425b
Compare
@rbuckton can u take one more look? |
@rbuckton friendly 🏓 😉 |
Sorry for the delay.
tslib is manually updated currently. |
Ok, thanks for the info - gonna prepare a followup PR there. |
master
branchjake runtests
locallyI'm not yet sure if I've made this change correctly, need to fix tests first - but this presents the idea, so let me know if you'd like to proceed with this or not. By changing
extendStatics
&assign
to declarations they become effectively more static and thus it makes the whole thing more recognizable as side-effect free, so other tooling has easier job at tree-shaking them.We use this pattern currently in babel. You can check here.
This PR fails at:I suspect that those helpers are transformed toconst
somewhere, but I don't know where yet. I'd appreciate some hint about this one