TypeScript/tests/cases/fourslash/codeFixInferFromUsage_allJS.ts
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

49 lines
712 B
TypeScript

/// <reference path='fourslash.ts' />
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @strictNullChecks: true
// @Filename: important.js
////function f(x, y) {
//// x += 0;
//// y += "";
////}
////
////function g(z) {
//// return z * 2;
////}
////
////let x = null;
////function h() {
//// if (!x) x = 2;
////}
verify.codeFixAll({
fixId: "inferFromUsage",
fixAllDescription: "Infer all types from usage",
newFileContent:
`/**
* @param {number} x
* @param {string} y
*/
function f(x, y) {
x += 0;
y += "";
}
/**
* @param {number} z
*/
function g(z) {
return z * 2;
}
/** @type {number | null} */
let x = null;
function h() {
if (!x) x = 2;
}`,
});