Skip to content

Fix class/constructor-function merge#27366

Merged
sandersn merged 1 commit intorelease-3.1from
fix-class/constructorFunction-merge
Oct 8, 2018
Merged

Fix class/constructor-function merge#27366
sandersn merged 1 commit intorelease-3.1from
fix-class/constructorFunction-merge

Conversation

@sandersn
Copy link
Copy Markdown
Member

The check for prototype assignment on constructor functions assumes that the prototype property, if present, comes from an assignment declaration, such as:

SomeClass.prototype = { /* methods go here */ }

In this case, however, when class SomeClass and var SomeClass merge (because this is allowed), prototype is the synthetic property from class SomeClass, which has no valueDeclaration.

The fix is to check that prototype has a valueDeclaration before checking whether the valueDeclaration is in fact a prototype-assignment declaration.

Fixes #27344

The check for prototype assignment on constructor functions assumes
that the prototype property, if present, comes from an assignment
declaration, such as:

```js
SomeClass.prototype = { /* methods go here */ }
```

In this case, however, when class SomeClass and var SomeClass merge
(because this is allowed), prototype is the synthetic property from
class SomeClass, which has no valueDeclaration.

The fix is to check that prototype has a valueDeclaration before
checking whether the valueDeclaration is in fact a prototype-assignment
declaration.
@sandersn sandersn added this to the TypeScript 3.1 milestone Sep 26, 2018
@sandersn
Copy link
Copy Markdown
Member Author

sandersn commented Oct 8, 2018

Ping @RyanCavanaugh

@sandersn sandersn merged commit 1d773a1 into release-3.1 Oct 8, 2018
@sandersn sandersn deleted the fix-class/constructorFunction-merge branch October 8, 2018 19:56
@sandersn
Copy link
Copy Markdown
Member Author

sandersn commented Oct 8, 2018

This is now in master as well.

sandersn added a commit that referenced this pull request Oct 8, 2018
The check for prototype assignment on constructor functions assumes
that the prototype property, if present, comes from an assignment
declaration, such as:

```js
SomeClass.prototype = { /* methods go here */ }
```

In this case, however, when class SomeClass and var SomeClass merge
(because this is allowed), prototype is the synthetic property from
class SomeClass, which has no valueDeclaration.

The fix is to check that prototype has a valueDeclaration before
checking whether the valueDeclaration is in fact a prototype-assignment
declaration.
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants