Skip to content

Fix serialisation of static class members in JS #37780

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 3 commits into from
Apr 4, 2020

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Apr 3, 2020

Previously static class members would be treated the same way as expando
namespace assignments to a class:

class C {
  static get x() { return 1 }
}
C.y = 12

This PR adds a syntactic check to the static/namespace filter that
treats symbols whose valueDeclaration.parent is a class as statics.

Fixes #37289

Previously static class members would be treated the same way as expando
namespace assignments to a class:

```ts
class C {
  static get x() { return 1 }
}
C.y = 12
```

This PR adds a syntactic check to the static/namespace filter that
treats symbols whose valueDeclaration.parent is a class as statics.

Fixes #37289
&& (p.flags & SymbolFlags.Optional) === (getPropertyOfType(baseType, p.escapedName)!.flags & SymbolFlags.Optional)
&& isTypeIdenticalTo(getTypeOfSymbol(p), getTypeOfPropertyOfType(baseType, p.escapedName)!))) {
if (p.flags & SymbolFlags.Prototype ||
(baseType && getPropertyOfType(baseType, p.escapedName)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a formatting change to make obvious that it's x || (y && z && ka && ki ...)

@sandersn sandersn requested a review from rbuckton April 3, 2020 20:57
getPropertiesOfType(staticType),
p => !(p.flags & SymbolFlags.Prototype) && p.escapedName !== "prototype"
p => !(p.flags & SymbolFlags.Prototype) && p.escapedName !== "prototype" && p.valueDeclaration && isClassLike(p.valueDeclaration.parent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we extract this predicate to a function, so it's obvious each place is using the same predicate (albeit inverted)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, although it reveals that this usage is not quite the same as the others, because it needs to (1) accept static members (the opposite of the others) but (2) exclude prototype (same as the others)

@sandersn sandersn merged commit eac0738 into master Apr 4, 2020
@sandersn sandersn deleted the fix-static-member-js-symbol-serialisation branch April 4, 2020 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding a JSDoc @typedef declaration breaks emitting static getter to ".d.ts" files.
3 participants