Skip to content

Refactor static properties / use correct this arguments #1259

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

Merged
merged 2 commits into from
May 13, 2020
Merged

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented May 10, 2020

This PR fixes #1252 by refactoring static property prototypes to have a singleton instance. Previously, the compiler would instead resolve the respective getter/setter, skipping over the static prototype, while it now behaves more like with functions. Note that this still does not apply to instance properties, since properties can never be generic anyway so these are resolved together with the class, which then doesn't contain property prototypes anymore.

While on it, I also made compilation of this arguments use the correct type, which is either the implicit or explicit this type of a function or getter/setter, or the class type for fields. Noticed that this was still TODO for properties, but then also implemented it for everything else. Has a couple implications on null checking, where some property accesses would not have complained previously, but now do (see the related compiler source changes, like namespace.members ? namespace.members.x : y, necessary to fix bootstrapping).

@dcodeIO
Copy link
Member Author

dcodeIO commented May 11, 2020

Thinking about this more, it might be even better to make properties behave exactly like functions, always using an intermediary prototype, since currently it's still somewhat inconsistent. For example, if a method is not used, it won't ever be resolved, hence essentially ignored, while properties will always be resolved along the class. I don't expect a large compile-time win from this, but extending tree-shaking to everything appears to be worth.

@dcodeIO dcodeIO merged commit e68fbb4 into master May 13, 2020
@dcodeIO dcodeIO deleted the issue-1252 branch May 14, 2020 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static properties' types fail to be inferred
1 participant