Commit Graph

556 Commits

Author SHA1 Message Date
Nathan Shively-Sanders
60efb65931 infer-from-usage suggestions can't be ignored, and always do something when invoked. (#28206)
* Do not ts-ignore noImplicitAny suggestions

Still need to write tests.

* Add tests

* More tests

* Update baselines
2018-10-29 13:23:33 -07:00
Andy
672b0e3e16 Have flatMap return a ReadonlyArray by default (#28205) 2018-10-29 11:12:51 -07:00
Andy
77d8e15905 Remove unused property ParameterInference#typeNode (#28115) 2018-10-26 14:44:49 -07:00
Nathan Shively-Sanders
372c7d9b0c infer from usage JSDoc:Don't emit nested comments (#28161)
* 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.
2018-10-26 14:09:42 -07:00
Andy
42740d66c2 Improve performance of suggestionDiagnostics for convertToAsyncFunction (#28089) 2018-10-24 21:23:47 -07:00
Nathan Shively-Sanders
fe2a33fcbc Merge existing JSDoc comments (#27978)
* 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
2018-10-24 16:14:52 -07:00
Andy
eadf44d073 Add generateTypesForModule to public API (#28069)
* Add generateTypesForModule to public API

* Avoid parameter initializer and update baselines
2018-10-23 16:10:26 -07:00
Andy
dd764b318f importFixes: Skip alias when testing isTypeOnlySymbol (#27674) 2018-10-10 13:45:52 -07:00
Nathan Shively-Sanders
88d3c6fd5f inferFromUsage codefix now emits JSDoc in JS files (#27610)
* Now adding @type to variable declarations, at least

Probably everything else, but not as well.

* Improve @param output and add test

It's still bad, but at least it's not wrong.

* Add some js/inferFromUsage tests and fixes

Also, remove redundant is(Set|Get)Accessor functions.

* Fix @typedef refactor

* Emit JSDoc optional parameters

By surrounding the parameter name with brackets. It is super, super ugly
right now.

* Get rest of existing tests working

* Correct location of comments

* Handle @param blocks

1. Format multiple params nicely in a single-multiline block.
2. Generate only params that haven't already been documented. Existing
documentation is not touched.

* Re-add isGet/SetAccessor -- it is part of the API

* Move isSet/GetAccessor back to the original location

* Oh no I missed a newline and a space

* Switch to an object type

* A lot of cleanup

More to come, though. annotate is only called in
annotateVariableDeclaration where we don't know whether we're in JS or
not.

* Move and delegate to annotateJSDocParameters

* Address PR comments

* Lint: newline problems!!!!

* Switch another call to getNonformattedText

* Update baseline missed after merge
2018-10-09 10:38:46 -07:00
Nathan Shively-Sanders
ca94d8efd9 Infer from usage better import types (#27626)
* Use host to improve SymbolTracker implementation

* inferFromUsage: Provide a better moduleResolverHost

This produces better paths on import types.
2018-10-09 07:12:09 -07:00
Benjamin Lichtman
2ebd986d99 Always await expression of promise type in return position 2018-10-05 09:59:22 -07:00
Alessandro Vergani
bbf77538c4 Remove unneeded check from getTransformationBody
Remove unneeded `argName` check, because it always evaluates to `true` (the `false` case is handled just before the modified line)
2018-10-02 16:02:04 +02:00
Benjamin Lichtman
f356cd6c89 Insert async keyword as last modifier (#27491) 2018-10-01 17:43:17 -07:00
Dhruv Rajvanshi
bde81deed2 Issue #27301: Fixed crash when converting function to async (#27396) 2018-09-27 18:56:37 -07:00
Andy
0a97663843 Add 'prefixText' and 'suffixText' when renaming shorthand properties (#27356)
* Add 'prefixText' and 'suffixText' when renaming shorthand properties

* Make prefixText and suffixText missing instead of undefined

* Fix test
2018-09-26 16:58:01 -07:00
Andy
5f563c99f6 convertToAsyncFunction: Use ReadonlyArray / ReadonlyMap where possible (#27190) 2018-09-20 16:45:28 -07:00
Andy
c57ff087d6 Add codefix to generate types for untyped module (#26588) 2018-09-18 11:47:29 -07:00
Benjamin Lichtman
b484370dcc Clean up for type precision and clarity 2018-09-18 09:34:08 -07:00
Benjamin Lichtman
0cb9fd62ba Merge branch 'master' into promisesAndUnderscores 2018-09-17 16:43:08 -07:00
Benjamin Lichtman
b2378ca40c Stop adding name of function being fixed and update baseline 2018-09-17 16:33:32 -07:00
Benjamin Lichtman
a73b561dd3 Ensure name for callback is generated even when it has no args 2018-09-17 16:23:47 -07:00
Benjamin Lichtman
0995869377 Stop creating empty identifier name 2018-09-17 15:53:15 -07:00
Benjamin Lichtman
1a3ff452c1 Respond to CR 2018-09-17 15:44:08 -07:00
Andy
4e3e8f5ea7 convertToAsyncFunction: Reduce casts in getTransformationBody (#27158) 2018-09-17 15:23:44 -07:00
Benjamin Lichtman
830b387765 No longer specially recognize underscore and update baselines 2018-09-17 14:34:31 -07:00
Benjamin Lichtman
1b9507ad06 Wrap expressions returned from promises in awaits when appropriate 2018-09-17 11:33:28 -07:00
Benjamin Lichtman
f9072621a9 Run callback as expression statement when no arg to assign to exists 2018-09-17 09:48:19 -07:00
Wesley Wigham
20eafb5b74 Introduce boolean literal freshness (#27042) 2018-09-14 15:00:09 -07:00
Benjamin Lichtman
0e985eb342 Merge branch 'master' into asyncCatchUniqueNames 2018-09-14 09:50:27 -07:00
Benjamin Lichtman
98055ad540 Use separate map with smaller scope to track renames 2018-09-14 09:46:58 -07:00
Benjamin Lichtman
13deedf841 Merge pull request #26930 from uniqueiniquity/onlyReportExpectedPromiseArgs
Only perform async code fix if it can successfully refactor all parts
2018-09-14 09:41:34 -07:00
Benjamin Lichtman
57a6dbd6fa Add clarifying comments 2018-09-14 08:50:18 -07:00
Benjamin Lichtman
e700022cef Remove unnecessary case 2018-09-13 09:46:40 -07:00
Benjamin Lichtman
d12110d3e5 Respond to CR 2018-09-13 09:32:38 -07:00
Benjamin Lichtman
905578cf37 Use existing identifier when possible for renaming functions 2018-09-13 09:02:02 -07:00
Benjamin Lichtman
906fbae37b Handle promise handler block bodies with no return and other cleanup 2018-09-12 14:47:06 -07:00
Nathan Shively-Sanders
6bd1da20c9 Rename JS-specific concepts (#26795)
* Rename JS concepts

1. Assignment declaration -- an assignment that is treated like a
declaration. Previously called [JS] special (assignment|declaration),
among other things.
2. Expando -- a value that can be used as a target in assignment
declarations. Currently, a class, function or empty object literal.
Functions are allowed in Typescript, too. Previously called a JS
container, JS initializer or expando object.
3. JavaScript -> Javascript. This is annoying to type, and looks like
'Java Script' in a camelCase world.

Everything is a pure rename as far as I know. The only test change is
the API baselines, which reflect the rename from SymbolFlags.JSContainer
to SymbolFlags.Assignment.

* Remove TODO

* Rename Javascript->JS

Note that this introduces a variable name collision in a couple of
places, which I resolved like this:

```ts
const isInJavascript = isInJSFile(node);
```
2018-09-12 10:44:46 -07:00
Benjamin Lichtman
92edc2db56 [WIP] Record original name of renamed variable 2018-09-11 11:12:11 -07:00
Benjamin Lichtman
a4c87df821 [WIP] Use original identifier name to count up from when renaming collisions 2018-09-11 11:12:11 -07:00
Benjamin Lichtman
8c9e8666ed Miscellaneous cleanup 2018-09-11 11:12:10 -07:00
Benjamin Lichtman
95d57885c5 Ensure diagnostic reporting matches code fix ability 2018-09-07 14:14:01 -07:00
Ron Buckton
a255d9a163 Merge branch 'master' into typesVersions 2018-09-07 13:52:12 -07:00
Benjamin Lichtman
f7f5b1ac87 Don't case on type node 2018-09-05 16:28:53 -07:00
Benjamin Lichtman
5a72da76c2 Only perform async refactor if it won't delete code 2018-09-05 16:27:14 -07:00
Andy
bcb815b3ac Remove duplicate function createTextRange (#23346)
* Remove duplicate function createTextRange

* Always allow end=-1

* Put noAssert back, pending #23370

* Use getRangeUnion helper

* Update API (#24966)
2018-09-05 11:19:56 -07:00
Benjamin Lichtman
6ddf75209a Merge pull request #26749 from uniqueiniquity/getWholeType
Use correct type for async refactoring diagnostics
2018-08-31 09:09:25 -07:00
Benjamin Lichtman
64bbf8925c Allow for undefined in type 2018-08-30 16:53:46 -07:00
Andy
f78dc2ad11 importFixes: Only provide a fix using the best module specifier for a given module (#26738) 2018-08-29 16:18:56 -07:00
Benjamin Lichtman
97e539339d Add comment explaining special casing 2018-08-29 15:53:34 -07:00
Benjamin Lichtman
158f0b0c0b Allow codefix to apply to function expression in variable declaration 2018-08-29 15:52:35 -07:00