Skip to content

Comments

Fix expando handling in getTypeReferenceType#34712

Merged
sandersn merged 2 commits intomasterfrom
fix-expando-symbol-handling-in-getTypeReferenceType
Oct 24, 2019
Merged

Fix expando handling in getTypeReferenceType#34712
sandersn merged 2 commits intomasterfrom
fix-expando-symbol-handling-in-getTypeReferenceType

Conversation

@sandersn
Copy link
Member

getExpandoSymbol looks for the initialiser of a symbol when it is an expando value (IIFEs, function exprs, class exprs and empty object literals) and returns the symbol.

Previously, however, it returned the symbol of the initialiser without merging with the declaration symbol itself. This missed, in particular, the prototype assignment in the following pattern:

var x = function x() {
  this.y = 1
}
x.prototype = {
  z() { }
}

/** @type {x} */
var xx;
xx.z // missed!

getJSDocValueReference had weird try-again code that relied on calling getTypeOfSymbol, which does correctly merge the symbols. This PR re-removes that code and instead makes getExpandoSymbol call mergeJSSymbols itself.

Fixes #34707

getExpandoSymbol looks for the initialiser of a symbol when it is an
expando value (IIFEs, function exprs, class exprs and empty object
literals) and returns the symbol.

Previously, however, it returned the symbol of the initialiser without
merging with the declaration symbol itself. This missed, in particular,
the prototype assignment in the following pattern:

```js
var x = function x() {
  this.y = 1
}
x.prototype = {
  z() { }
}

/** @type {x} */
var xx;
xx.z // missed!
```

getJSDocValueReference had weird try-again code that relied on calling
getTypeOfSymbol, which *does* correctly merge the symbols. This PR
re-removes that code and instead makes getExpandoSymbol call
mergeJSSymbols itself.
@sandersn sandersn requested a review from weswigham October 24, 2019 17:53
}

function mergeJSSymbols(target: Symbol, source: Symbol | undefined) {
if (source && (hasEntries(source.exports) || hasEntries(source.members))) {
Copy link
Member Author

Choose a reason for hiding this comment

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

turns out we need to merge just for the flags sometimes.

// @allowJs: true
// @checkJs: true

// @Filename: test.js
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 now a single-file repro. It is still written in such a way that function wp is checked after p.isServiceProject.

@sandersn sandersn merged commit d892fd4 into master Oct 24, 2019
@sandersn sandersn deleted the fix-expando-symbol-handling-in-getTypeReferenceType branch October 24, 2019 20:12
@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.

JSDoc type reference resolves incorrectly if checked before the constructor function it refers to

2 participants