For parameters, the infer-from-usage codefix uses a substantially
different codepath that previously only looked at call site uses. When
this resulted in no inferences, or bad inferences, for a single
parameter, the codefix would just use any. Only if no usages of a
function were found would the codefix use the body-inference
code.
This commit makes parameter inference fall back to body-inference code
for individual parameters when there is no inference or inference to
any.
* Set-only accessors spread to undefined
Previously they were skipped. The runtime behaviour is to create a
property of type undefined, unlike (for example) spreading numbers or
other primitives. So now spreading a set-only accessor creates a
property of type undefined:
```ts
const o: { foo: undefined } = { ...{ set foo(v: number) { } } }
```
Notably, `o.foo: undefined` not `number`.
Fixes#26337
* Fix isSpreadableProperty oversimplification
* Measure variance of aliased conditional types using variance markers
* Just do variance probing for all type aliases
* Small limiter for predictability
* Inline property set, remove unused functions
* infer from usage JSDoc:Don't emit nested comments
Previously, the trivia on a parameter name would show up inside the
emitted JSDoc comment. If the trivia contained a C-style comment, the
emitted JSDoc comment would be invalid. For example:
```js
function call(callback /*oh no*/) {
return callback(this)
}
```
Emitted this comment:
```js
/**
* @param {(arg0: any) => void} callback /*oh no*/
*/
```
* Remove misleading comment used for debugging.
* Do not merge commonsjs exports onto an alias
getCommonJSExportEquals merges export assignments and export property
assignments. Something like this, which has no equivalent structure in
TS:
```js
module.exports = function() { }
module.exports.expando = 1
```
However, it is sometimes called with an alias, when its
parent, resolveExternalModuleSymbol, is called with dontResolveAlias:
true, and when the initialiser of the export assignment is an alias:
```js
function alias() { }
module.exports = alias
module.exports.expando = 1
```
In this case, (1) the actual value `alias` will have already merged in a
previous call to getCommonJSExportEquals and
(2) getTypeOfSymbol will follow the alias symbol to get the right type.
So getCommonJSExportEquals should do nothing in this case.
This bug manifests in the code for dynamic imports, which calls
getTypeOfSymbol on the incorrectly merged alias, which now has enough
value flags--Function, for example--to take the wrong branch and
subsequently crash.
* Update baselines
* Correct indentation, using correct (I hope) indentation code
Note that part of the code, in formatting.ts, is cloned but should be
extracted to a function instead.
* Remove some possibly-superfluous code
But I see 4 failures with whitespace, so perhaps not.
* Restrict indentation change to avoid breaking baselines
The indentation code is very complex so I'm just going to avoid breaking
our single-line tests for now, plus add a simple jsdoc test to show that
multiline jsdoc indentation isn't destroyed in the common case.
* Switched over to construction for @return/@type
Still doesn't merge correctly though
* Add @return tags to emitter
* Merge multiple jsdocs
(not for @param yet)
* Merge multiple jsdoc for parameters too
* Emit more jsdoc tags
Not all of them; I got cold feet since I'll have to write tests for
them. I'll do that tomorrow.
* Many fixes to JSDoc emit
And single tests (at least) for all tags
* Cleanup in textChanges.ts
* Cleanup in formatting.ts
(Plus a little more in textChanges.ts)
* Cleanup in inferFromUsage.ts
* Fix minor omissions
* Separate merged top-level JSDoc comments with \n
instead of space.
* Don't delete intrusive non-jsdoc comments
* Cleanup from PR comments
1. Refactor emit code into smaller functions.
2. Preceding-whitespace utility is slightly easier to use.
3. Better casts and types in inferFromUsage make it easier to read.
* Fix bogus newline
* Use @andy-ms' cleanup annotateJSDocParameters
1. Sort is now stable in node 11, which exposed a lack in the sorting of
nested ranges. Ranges now sort based on last ending if the start
positions are the same. This means nested ranges sort the
containing range first, even if a range contains another range that
starts at the same position.
2. Symbol has a new member description which can't be accessed through
the prototype. In addition, Array now has flat and flatMap, which I
excluded to keep baselines the same between Node 6-11.