Commit graph

154 commits

Author SHA1 Message Date
Gabriela Britto b3633fab52 Add more tests for qualified name param without top level object error 2019-01-10 15:04:16 -08:00
Gabriela Britto ebe193c6d7 Minor refactor in paramTagNestedWithoutTopLevelObject.ts 2019-01-10 14:05:10 -08:00
Gabriela Britto e2524e3750 Add test for qualified name param without top level object error 2019-01-10 09:55:06 -08:00
Nathan Shively-Sanders 53bb4e84a2
Better checking of assignment declarations (#28387)
Previously, type checking was turned off for all assignment
declarations. This is a problem when the declarations are annotated with
jsdoc types.

This PR checks assignment declarations, *except* for expando
initialisers. Expando initialisers are

1. Empty object types.
2. Function types.
3. Class types.
4. Non-empty object types when the assignment declaration kind is
prototype assignment or module.exports assignment.
2018-11-15 08:46:11 -08:00
Nathan Shively-Sanders bf393ae1cd
Check EOF token to get errors for JSDoc (#28000)
* Check EOF token to get errors for JSDoc

* outputFile instead of noEmit for test
2018-10-19 16:23:34 -07:00
Wesley Wigham 69b1cb5bac
Add new special assignment kinds for recognizing Object.defineProperty calls (#27208)
* Add new special assignment kinds for recognizing Object.defineProperty calls

* Add support for prototype assignments, fix nits

* Fix code review comments

* Add test documenting behavior in a few more odd scenarios
2018-10-19 14:31:55 -07:00
Nathan Shively-Sanders c184184713
Add getEffectiveConstructSignatures (#27561)
* Add helpers that understand constructor functions

* getEffectiveConstructSignatures gets construct signatures from type, and
  call signatures from constructor functions if there are no construct
  signatures.
* getEffectiveConstructSignatureReturnType gets the "JS Class type" for
  constructor functions, and the return type of signatures for all other
  declarations.

This is a first step toward making constructor functions have construct
signatures instead of call signatures, which will also contribute to
fixing instantiation of generic constructor functions, which is basically
broken right now.

Note that the baselines *improve* but, because of the previously
mentioned generic problem, are still not correct. Construct signatures
for constructor functions and generic constructor functions turns out to
be an intertwined problem.

* Correct correct originalBaseType

And, for now, return anyType for generic constructor functions used as
base types. Don't give an incorrect error based on the function's return
type, which is usually void.

* Add error examples to tests

* Add construct signatures instead of getEffective* functions

* Fix typo in baseline

* Remove pesky newline

I thought I got rid of it!

* Test of constructor tag on object literal method

It doesn't work, and shouldn't in the future, because it's a runtime
error.
2018-10-15 12:47:57 -07:00
Nathan Shively-Sanders ca840ee683 Fix name resolution of exports in JS (#27394)
The ad-hoc name resolution rule for `exports` forgets to check the
requested meaning. When `getTypeReferenceType` calls`
resolveTypeReferenceName` with `Type` only in order to give an error
when the program uses a value like a type, it is incorrectly able to
resolve `exports` instead of producing an error. Then this incorrect
symbol gets treated like an alias, which it isn't, causing the assert.

The fix, for now, is to make resolution of `exports` check the requested
meaning so that it only resolves when `Value` is requested. This makes
the above code an error ("Cannot use the namespace 'exports' as a
type."), but I think this is fine for a bug fix. We can decide later if
`exports` should behave like other expandos and be a legal type
reference.

Note that the name actually does resolve correctly, so JS users will get
the desired completions. They'll just have an error to suppress if they
have checkJs on.
2018-10-08 13:01:14 -07:00
Nathan Shively-Sanders b185784708 Only functions can be constructor functions (#27369)
`@constructor` put on anything incorrectly makes it a JS constructor. This
is a problem for actual constructors, because getJSClassType doesn't
work on actual classes. The fix is to make isJSConstructor require that
its declaration is a function.
2018-10-08 10:14:31 -07:00
Nathan Shively-Sanders a4a5b3806e Report circular JSDoc type references (#27404)
JSDoc types references can often be to values, which can often be
circular in ways that types tied to declarations cannot. I decided to
create a separate property on SymbolLinks rather than reusing
declaredType, although I'm not sure that's strictly required.
2018-10-08 08:56:29 -07:00
Nathan Shively-Sanders 6d92a2942f
Fix parent points in unreachable code (#27400) (#27406)
In the binder, unreachable code mistakenly skips the `bindJSDoc` call in
`bindChildrenWorker`, which sets parent pointers. The fix is to call
`bindJSDoc` in the case of unreachable code as well.
2018-09-28 08:31:56 -07:00
Nathan Shively-Sanders 4fac5f26dc
Fix crash in use-before-def checking of enum tag (#27350) (#27354) 2018-09-26 09:05:18 -07:00
Nathan Shively-Sanders 59e4770a51
Fix enum tag circular references (#27161)
* Fix enum tag circular references

Also, don't try to resolve enum tag types in Typescript.

* Improve comment
2018-09-17 16:06:17 -07:00
Andy f71d6005a2
Use nextToken() after parsing a tag name so we can parse type keywords (#26915)
* Use nextToken() after parsing a tag name so we can parse type keywords

* Make callback to skipWhitespaceOrAsterisk non-optional
2018-09-13 15:49:06 -07:00
Tim Schaub 262ea5b06e Skip asterisks after newline when parsing JSDoc types (#26528)
* Skip asterisks after newline when parsing JSDoc types

* Single boolean expression

* Test for parsing and printing multiline function signatures with *
2018-09-04 15:41:08 -07:00
Nathan Shively-Sanders 64ac5a53f4
Fixes for type parameter name resolution in JS (#26830)
* check for expando initializers in resolveEntityName

when resolving type parameters in a prototype property assignment
declaration. For example, this already works:

```js
/** @template T */
function f(x) { this.x = x }
/** @returns {T} */
f.protototype.m = function () { return this.x }
```

This now works too:

```js
/** @template T */
var f = function (x) { this.x = x }
/** @returns {T} */
f.prototype.m = function () { return this.x }
```

Fixes #26826

* Lookup type parameters on prototype-assignment methods

In the same way that they're looked up on prototype-property methods.

That is, this previously worked:

```js
/** @template T */
function f() { }
/** @param {T} p */
f.prototype.m = function () { }
```

And this now works too:

```js
/** @template T */
function f() { }
f.prototype = {
  /** @param {T} p */
  m() { }
}
```

Note that the baselines still have errors; I'll file a followup bug for
them.

* Look up types on property assignments too
2018-09-04 14:47:18 -07:00
Tim Schaub 20a2b0cade Ignore newline and asterisk when parsing JSDoc typedef (#26775) 2018-08-30 10:01:33 -07:00
Nathan Shively-Sanders a2e4a282e7
Get [type] parameter types from @type tag (#26694)
* Get [type] parameter types from @type tag

Previously only the return type was used in cases like this:

```js
/** @type {<T>(param?: T) => T | undefined} */
function g(param) {
  return param;
}
```

Now the type parameters from the type tag are used, and the compiler
gets the type of the parameter by using the position in the signature of
the type tag.

Fixes #25618

* Fix split ifs according to PR comments
2018-08-27 16:52:35 -07:00
Nathan Shively-Sanders b50c37de78
No assert for nameless typedefs (#26695)
The assert is over-optimistic and should be removed until we can parse
every possible thing that people might put in a JSDoc type position.

Fixes #26693
2018-08-27 14:12:14 -07:00
Tim Schaub 6fd725f3ea Skip whitespace or asterisk in JSDoc param type and name (#26067) 2018-08-16 16:16:09 -07:00
James Keane a1089893bd Fixes #26128 - signature comp for jsdoc @class. (#26160)
* Fixes #26128 - signature comp for  jsdoc @class.

Another issue caused by js functions tagged with jsdoc
`@constructor` not having construct signatures.

A jsdoc function type that constructs a type (`function(new: Ex)`),
has a construct signature and return value inferred as the
constructed type where as a jsdoc `@constructor` has no construct
signatures, and it's call signature has a void return type
(or undefined).

i.e:
```javascript
/** @constructor **/ function E() {};

// typeof E -> call signature: () => void

/** @param {function(new: E)} d */ function c(d) {}

// typeof d -> construct: () => E
```

--

This commit fixes this (in an inelegant way) by considering `@class` function signatures as construct signatures and synthesizing it's return value _only for signature comparison_.

There might be a slight performance hit, since the synthesized return value is not cached; but changing the `@class` function's return type in `getReturnTypeOfSignature` causes other issues.

* Update jsdoc function test to fix mistake.
2018-08-14 13:35:51 -07:00
Nathan Shively-Sanders a6c5d50749
Allow type predicates in JSDoc (#26343)
* Allow type predicates

1. Parse type predicates. Note that they are parsed everywhere, and get
the appropriate error when used places besides a return type.
2. When creating a type predicate, correctly find the function's parameters
starting from the jsdoc return type.

* Fix type of TypePredicateNode.parent: add JSDocTypeExpression

* Update API baselines

* Handle JSDoc signature inside @type annotations

* Fix circularity when getting type predicates

Also move createTypePredicateFromTypePredicateNode closer to its use

* More cleanup based on review comments
2018-08-10 15:31:39 -07:00
Nathan Shively-Sanders a21ac11582
In JSDoc, resolve import types as values too (#26066)
* In JSDoc, resolve import types as values too

This is something that we probably should have been doing for some time.
Fixes #26049

* Fix whitespace lint
2018-07-31 11:07:06 -07:00
Nathan Shively-Sanders 25fb5419c0
Support the JSDoc @enum tag (#26021)
* Support the JSDoc @enum tag

`@enum` is used on a variable declaration with an object literal
initializer. It does a number of things:

1. The object literal has a closed set of properties, unlike other
object literals in Javascript.
2. The variable's name is resolvable as a type, but it just has the
declared type of the enum tag.
3. Each property's type must be assignable to the enum tag's declared type,
which can be any type.

For example,

```js
/** @enum {string} */
const Target = {
  START: "START",
  END: "END",
  MISTAKE: 0, // error 'number' is not assignable to 'string' -- see (3)
}

Target.THIS_IS_AN_ERROR; // See (1)
/** @type {Target} See (2) */
var target = Target.START;
```

* Fix lint, add new test case, update API baselines
2018-07-28 07:53:08 -07:00
Nathan Shively-Sanders 1cedab18be
Fix parsing of parenthesized JSDoc parameters (#25799)
* Fix parsing of parenthesized JSDoc parameters

Parenthesis can start a jsdoc function parameter since it is just a
type, and parenthesis can start a type:

```js
/** @type {function(((string))): void} */
```

However, this is not legal in other parameter lists:

```ts
function x((((a))): string) { }
```

This change makes jsdoc function parameter lists parse differently than
normal parameter lists by allowing parenthesis as a start character of
jsdoc parameters.

* Parse nested uses of jsdoc function types

* Fix test
2018-07-19 12:50:36 -07:00
Andy f500289a44
Stricter test that JSDoc @type tag matches function signature (#25615) 2018-07-12 14:02:02 -07:00
Nathan Shively-Sanders bd7b97ce61
Get return type from @type tag (#25580)
* Get return type from `@type` tag

This only happens in the checker, where the type is easily accessible.
The syntax-based check in getEffectiveReturnTypeNode as a fast path, and
for other uses that don't want to make a call to getTypeFromTypeNode.

Fixes #25525

* Implement PR suggestions

* Error when type tag isn't callable

* Fix lint
2018-07-12 10:49:41 -07:00
Nathan Shively-Sanders c344a3ea5b
Fix bogus use before def in jsdoc (#25532)
Block scoped variables, classes and enums would issue a bogus
use-before-def error in jsdoc because name resolution always adds Value,
even when resolving a type.

Fixes #25097
2018-07-10 08:33:19 -07:00
Nathan Shively-Sanders 6589e867fe
getJSDocReturnType gets return type from @type tags (#25486)
* get return type from `@type` tags

Previously, getJSDocReturnType did not check the `@type` tag for a type
node that has a return type. Now it does.

* Improve doc comment of getJSDocReturnType

* More type predicates in type guards!

* Update API baselines with new documentation (?!)
2018-07-06 10:46:43 -07:00
Wesley Wigham 7084e6cf47
Adds related spans and error grouping for duplicate identifier errors (#25328)
* Adds related spans and error grouping for duplicate identifier errors

* Trim trailing whitespace

* Record related info in error baselines

* Make error more whimsical
2018-07-02 10:47:52 -07:00
Andy e8e80d2bbd
Don't crash on property access with type (#25170)
* Don't crash on property access with type

* Move test
2018-06-25 11:25:52 -07:00
Nathan Shively-Sanders 0bb897273f
Parse nested prop and param tags the same way (#25139)
That is, only nest them if their name matches the provided parent name.
Otherwise do not nest them.

Note that this commit changes the behaviour of an incorrect typedef that
contains both an `@type` child tag and `@property` child tags.

Previously, the `@type` would be incorrectly nested under a `@property`
tag with type `object`, just like `@property` tags would be. Now, the
`@type` tag causes the entire typedef to ignore the `@property` tags and
treat the typedef as if it were an instance of the
typedef-and-nested-type pattern:

```js
/**
 * @typedef {Object} name
 * @type {{ the, actual, type }}
 */
```
2018-06-21 16:12:55 -07:00
Nathan Shively-Sanders a7af92eb63
check return tag in getTypePredicateOfSignature (#25130) 2018-06-21 11:30:37 -07:00
Nathan Shively-Sanders 43d0794ba3
Fix crash when binding jsdoc-style inner namepaths (#25106)
* getDeclarationIdentifier handles undefined name

getNameOfDeclaration actually doesn't handle all declarations, only
those that produce names that could be reasonably used as an identifier.
Until now, getDeclarationIdentifier assumed that getNameOfDeclaration
always returned a name. This caused crashes whenever we tried to get the
name of something like a Constructor.

* Add test and baselines

* getNameOfDeclaration can return undefined

This requires all callers to handle it, which turns out now to be too
disruptive.

* Fix lint
2018-06-21 10:01:39 -07:00
Nathan Shively-Sanders 0f55566cf4
In JS, always check the extends tag of a class before its heritage clause (#25111)
* Check extends tag first in getClassExtendsHeritageClauseElement

Previously getBaseTypeNodeOfClass checked, but this is only used in a
few places.

* Fix names and add test

* Update API baseline

* Move jsdocAugments tests to conformance/jsdoc

* Better naming in checkClassLikeDeclaration
2018-06-20 16:28:30 -07:00
Nathan Shively-Sanders 4db1c132b7
No dupe jsdoc for assignment inside an initializer (#24973) 2018-06-14 15:32:10 -07:00
Nathan Shively-Sanders 57e652dd02
Js/check type tags (#24967)
* Check the type expression of `@type` tags

* Update existing tests and baselines
2018-06-14 13:11:52 -07:00
Nathan Shively-Sanders 2a8c4d1bd7
Support @this tags (#24927)
* Type check `@this` tags

No special support in fourslash yet, so quickinfo probably doesn't work.

* Do no require braces and update API baselines
2018-06-13 10:11:12 -07:00
Nathan Shively-Sanders 34e68efdae
Template tag allows specification of constraints (#24600)
* Parse (and mostly support) template tag constraints

A bunch of tests hit the asserts I added though.

* Messy version is finished. Need to add a few tests

* Refactor to be smaller

* Small refactor + Add one test

* Another test

* Minor cleanup

* Fix error reporting on type parameters on ctors

* Simplify syntax of `@template` tag

This is a breaking change, but in my sample, nobody except webpack used the
erroneous syntax. I need to improve the error message, so
jsdocTemplateTag3 currently fails to remind me of that.

* Better error message for template tag

* Fix fourslash baselines

* Another fourslash update

* Address PR comments

* Simplify getEffectiveTypeParameterDeclarations

Make checkGrammarConstructorTypeParameters do a little more work
2018-06-04 11:42:46 -07:00
Nathan Shively-Sanders e250942d6a
Disallow nested object param syntax in callback tag (#24392)
* Callback tag:Disallow nested-object-param syntax

Previously this caused a crash in parsing. If/when we want to support
this syntax, we will need to fix this crash.

* Update baselines
2018-05-24 15:11:33 -07:00
Nathan Shively-Sanders 6450490844
Fix jsdoc type resolution [merge to master] (#24204)
* Fix JSDoc type resolution

Breaks type parameter resolution that is looked up through prototype
methods, though. I need to fix that still.

* Check for prototype method assignments first

* Undo dedupe changes to getJSDocTags

* JS Type aliases can't refer to host type params

Previously, js type aliases (@typedef and @callback) could refer to
type paremeters defined in @template tags in a *different* jsdoc tag, as
long as both tags were hosted on the same signature.

* Reduce dedupe changes+update baseline

The only reason I had undone them was to merge successfully with an
older state of master.
2018-05-17 10:46:10 -07:00
Nathan Shively-Sanders aa7e2b0f07
Add callback tag, with type parameters (#23947)
* Add initial tests

* Add types

* Half of parsing (builds but does not pass tests)

* Parsing done; types are uglier; doesn't crash but doesn't pass

* Bind callback tag

Builds but tests still don't pass

* Only bind param tags inside callback tags

* Fix binding switch to only handle param tags once

* Checking is 1/3 done or so.

Now I'm going to go rename some members to be more uniform. I hate
unnnecessary conditionals.

* Rename typeExpression to type (for some jsdoc)

(maybe I'll rename more later)

* Rename the rest of typeExpressions

Turns out there is a constraint in services such that they all need to
be named the same.

* Few more checker changes

* Revert "Rename the rest of typeExpressions"

This reverts commit f41a96b24d.

* Revert "Rename typeExpression to type (for some jsdoc)"

This reverts commit 7d2233a00e.

* Finish undoing typeExpression rename

* Rename and improve getTypeParametersForAliasSymbol

Plus some other small fixes

* Core checking works, but is flabbergastingly messy

I'm serious.

* Callback return types work now

* Fix crash in services

* Make github diff smaller

* Try to make github diff even smaller

* Fix rename for callback tag

* Fix nav bar for callback tag

Also clean up some now-redundant code there to find the name of typedefs.

* Handle ooorder callback tags

Also get rid of redundant typedef name code *in the binder*. It's
everywhere!

* Add ooorder callback tag test

* Parse comments for typedef/callback+display param comments

* Always export callbacks

This requires almost no new code since it is basically the same as
typedefs

* Update baselines

* Fix support for nested namespaced callbacks

And add test

* Callbacks support type parameters

1. Haven't run it with all tests
2. Haven't tested typedef tags yet
3. Still allows shared symbols when on function or class declarations.

* Template tags are now bound correctly

* Test oorder template tags

It works.

* Parser cleanup

* Cleanup types and utilities

As much as possible, and not as much as I would like.

* Handle callback more often in services

* Cleanup of binder and checker

* More checker cleanup

* Remove TODOs and one more cleanup

* Support parameter-less callback tags

* Remove extra bind call on template type parameters

* Bind template tag containers

Doesn't quite work with typedefs, but that's because it's now stricter,
without the typedef fixes. I'm going to merge with jsdoc/callback and
see how it goes.

* Fix fourslash failures

* Stop pre-binding js type aliases

Next up, stop pre-binding js type parameters

* Further cleanup of delayed js type alias binding

* Stop prebinding template tags too

This gets rid of prebinding entirely

* Remove TODO

* Fix lint

* Finish merge with use-jsdoc-aliases

* Update callback tag baselines

* Rename getTypeParametersForAliasSymbol

The real fix is *probably* to rename Type.aliasTypeArguments to
aliasTypeParameters, but I want to make sure and then put it in a
separate PR.
2018-05-17 09:28:11 -07:00
Nathan Shively-Sanders 5ea4d3b2bb
No error for require, module.exports or exports in Javascript (#23743)
* No error for require

Still errors for module and exports, and require's type is now
incorreclty 'any'; I broke module resolution somehow. Needs
investigation.

* module/exports symbols+update isCommonJsRequire

Everything passes the tests but the code can be improved

* Update baselines

* Cleanup

* Update baselines of new tests

* Get rid of exports symbol

It wasn't doing anything anyway.
2018-04-30 15:47:59 -07:00
Nathan Shively-Sanders 7cda045d52
Always export typedefs (#23723)
* Always export typedefs

This actually just required deleting a check in declareModuleMembers
and checking for external AND commonjs modules in a couple of places.

However, while experimenting with this feature, I discovered that even
previously-exported typedefs would only be exported if they came after a
commonjs export node. So I added a commonjs check to the pass in the
parser. It will not catch nested module.exports, but it will catch
top-level assignments.

The new test tests both changes.

* Post-bind typedef instead of pre-checking for commonjs

* Duplicate identifier errors

* Fix class type reference resolution+update baselines

* Move to a type-based check for duplicate identifiers
2018-04-30 14:55:26 -07:00
Nathan Shively-Sanders 1595f7fe83
Add prettier user test and fix associated crash (#23715)
* Add prettier and fix crash bug

Name resolution would crash when resolving a type name inside a
typedef's property tag.

* Update tsconfig and thefore prettier baseline
2018-04-26 14:03:18 -07:00
Nathan Shively-Sanders b2bfccfce4
Prototype-property assignment:fix name resolution crash (#23680) 2018-04-25 13:59:40 -07:00
Nathan Shively-Sanders 905f9a02ad
module.exports = Entity is an alias, just like export = Entity (#23570)
* Make `module.export =` an alias like `export=` is

This breaks a couple of tests for previous workarounds. Fix in upcoming
commits.

* Basically fixes all the breaks, but needs cleanup

* More notes to myself

* Clean up TODOs

* Call mergeSymbolTable and delete export= afterward

instead of basically copying the code myself.

* More cleanup

* Remove unnecessary check in import type checking

* Revert to DIY code.

It is more correct and will go away in a few days.

* Exported class expressions can be used as type

In both JS and TS

* Do not require named class expressions
2018-04-23 15:24:31 -07:00
Nathan Shively-Sanders e65681a2b7
Fix assert in getjsdochost (#23575)
* Fix assert in getJSDocHost

* Update public API to add wider type

* Remove now-unnecessary type assertion
2018-04-20 10:41:58 -07:00
Nathan Shively-Sanders 8d969a23cb
In JS, class supports @template tag for declaring type parameters (#23511)
* Support @template as a class type parameter

Still need to do the following:
1. Correctly get jsdoc host in predicate.
2. Make this work for constructor functions too.
3. Scan rest of codebase for other usages of the type parameters
property that should be calls to getEffectiveTypeParameterDeclarations.
4. Rename tp to something more readable, like typar or ts'.

* Use jsdoc host declaration to find container

* Longer names for type parameters

* Fix renaming operation

* Update fourslash test

* Support @template for JS constructors

* Look for both outer and tag type parameters

* Improve naming to improve code clarity
2018-04-19 15:58:43 -07:00
Nathan Shively-Sanders 22919d57fe
JSDoc:positional matching of destructured params (#23307)
* JSDoc:positional matching of destructured params

1. When looking up tags for a parameter whose name is a binding pattern, use
the index of the parameter to get the type.
2. When reporting errors for `@param` tags with no matching parameter
name, do not report the error for tags whose index in the `@param` tag list
matches the index of a parameter whose name is a binding pattern.

* Change to an assert

* Improve comment text
2018-04-10 12:48:35 -07:00
Nathan Shively-Sanders eb3a9d05df
Fix factorial jsdoc search:chained assignments (#23115) 2018-04-04 08:57:13 -07:00
Nathan Shively-Sanders 6d9a8250bd
Improve binding and jsdoc of chained special js assignments (#23038)
* Search for jsdoc on chained assignments

* Fix binding of chained binary expression js-assignments

* Test:chained jsdoc+chained prototype assignment

* Improve naming
2018-04-02 09:47:01 -07:00
Nathan Shively-Sanders eca3d68eb4
@typedef supports nested @property names (#22967)
Previously it did not, because this capability is not documented on
usejsdoc.org. However, several people requested this feature.
2018-03-29 09:39:23 -07:00
Nathan Shively-Sanders e16bb3e418
Improve behaviour of ... inside JSDoc functions (#22809)
* No error for ... on last param of jsdoc function

* ... is a rest param w/array type in jsdoc function

* Simplify getTypeFromJSDocVariadicType
2018-03-22 16:17:16 -07:00
Nathan Shively-Sanders ab8233c5d3
Two JSdoc parsing fixes (#22705)
* Correctly parse JSDoc type *=

* Allow `markdown` quoted param names in JSDoc

* Add tests and update baselines

* Get correct span for the type '*'

* Fix whitespace lint

* Add unbracketed type test
2018-03-20 09:23:08 -07:00
Nathan Shively-Sanders b56093f3ac
Fix type when annotated with a JSDoc function type (#22692)
* Fix type when annotated with a JSDoc function type

Previously,
1. A variable annotated with a JSDoc function type would not require all
its parameters to be provided. This should only apply to functions
without a type annotation.
2. A parameter in a function with a JSDoc function type annotation would
still have the type 'any'.
3. Two `var` declarations in a Typescript and Javascript file,
respectively, would error even when they had identical function types.

* Update baselines and add constructor test

* Handle ConstructorType too

* Add test:method sig inside literal type

* Contextually type parameters by parent sig's JSDoc

Instead of a syntactic check in getJSDocTag

* Remove redundant check:isUntypedSignatureInJSFile

* Positive check for value signatures

Instead of excluding type signatures piecemeal.
2018-03-19 16:00:45 -07:00
Nathan Shively-Sanders bb23e9601f
Parse JSDoc ...T and T= only at top-level JSDoc (#22661)
* Parse JSDoc ...T and T= only at top-level JSDoc

...T and T= should only be legal at the top level of a type, and only in
JSDoc, since at least T= is ambiguous elsewhere. This PR changes parsing
to make that happen. The resulting parse tree is now simpler, allowing
me to get rid of some code I had to add in the checker.

* Extract JSDoc type parsing into its own function

* PR comments:return from parseJSDocType
2018-03-16 16:08:42 -07:00
Nathan Shively-Sanders 3b6ae8536f
JSDoc ?Type adds optionality to parameters (#22646)
* jsdoc ?Type adds optionality to parameters

Chrome devtools expects that parameters with type `?T` (or `T?`) add
null to `T` and optionality to the parameter. Previously it only added
null to the type.

Currently the PR does *not* add undefined to the type of
`T`, which is expected by chrome-devtools-frontend, but is inconsistent
with typescript's rules. The implementation achieves this inconsistency by
exploiting the fact that checking the signature adds optionality and
checking the parameter adds `undefined`.

* Update chrome-devtools-frontend baseline

* Add optionality only for jsdoc postfix=

* Skip jsdoc prefix types in isJSDocOptionalParameter

Previously isJSDocOptionalParameter was incorrect for types like
`?number=`, which are optional but have JSDocNullableType as their root
type node.
2018-03-16 13:28:24 -07:00
Nathan Shively-Sanders 677d860b44
No error on unmatchable @param tags (#22510)
* No errr on unmatchable `@param` tags

Such as when the initializer is not a function, or when the function
mentions `arguments` in its body.

* Do not require dummy param for JS uses of arguments

1. JS functions that use `arguments` do not require a dummy parameter in
order to get a type for the synthetic `args` parameter if there is an
`@param` with a `...` type.
2.JS functions that use `arguments` and have an `@param` must have a
type that is a `...` type.

* Check for array type instead of syntactic `...`

* Address PR comments

* Update baselines
2018-03-14 10:17:54 -07:00
Nathan Shively-Sanders 0fa838a3ef
Brackets and postfix= in @param add undefined (#22514)
* Brackets and postfix= in `@param` add undefined

Previously they only added optionality.
Note that, unlike Typescript, when a parameter initializer is specified
in jsdoc, it does not remove undefined in the *body* of the function.
That's because TS will generate initialisation code, but JS won't, so
the author will have to manually write code to remove undefined from the
type.

```js
/** @param {number} [a=101] */
function f(a) {
  // a: number | undefined here
  if (!a) {
    a = 101
  }
  // a: number here
}
```

Note that we don't check that
1. the initializer value is actually assigned to the parameter.
2. the initializer's type matches the declared type of the parameter.

Pretty much we just parse it and leave it alone.

* Address PR comments
2018-03-13 15:56:38 -07:00
Nathan Shively-Sanders c01f0c0b9f Test:ts-ignore works on jsdoc syntax errors 2017-11-17 10:40:16 -08:00
Nathan Shively-Sanders 8cc2af59b1 More tests for getParameterSymbolFromJSDoc 2017-10-19 16:22:05 -07:00
Nathan Shively-Sanders ecdc4b363e Test:jsdoc @param errors on vardecls/assignments 2017-10-19 09:12:49 -07:00
Nathan Shively-Sanders 2473ffcaac Add a better test for jsdoc index signatures.
The test case shows that the errorenous error no longer appears.
2017-10-18 13:06:15 -07:00
Nathan Shively-Sanders 4d8663c378 Merge pull request #18117 from Microsoft/jsdoc-dotdotdot-binds-tighter-than-postfix
Jsdoc ... binds tighter than postfix ?!
2017-10-03 08:45:26 -07:00
Nathan Shively-Sanders 34a8c8423e Merge branch 'master' into jsdoc-dotdotdot-binds-tighter-than-postfix 2017-09-08 08:37:38 -07:00
Nathan Shively-Sanders 7aac67b9b4 Test: parsing of two-line @typedef jsdoc 2017-09-07 16:22:16 -07:00
Nathan Shively-Sanders e2d2f448e4 Add postfix [] ! ? type parsing tests 2017-08-30 08:41:34 -07:00
Nathan Shively-Sanders 3e3846dba4 Test jsdoc:... binds tighter than *n* postfix tokens 2017-08-29 13:02:06 -07:00
Nathan Shively-Sanders a025192ac0 Test:allow more jsdoc types in type parameter lists 2017-08-24 08:56:20 -07:00
Nathan Shively-Sanders ca86dc4deb Test:jsdoc nullable syntax legal in type arguments
And update baselines
2017-08-23 15:00:40 -07:00
Nathan Shively-Sanders 9e59dacbfa Update baselines 2017-07-26 10:59:08 -07:00
Nathan Shively-Sanders e942bbb6f2 Test: jsdoc @param type literals 2017-07-21 14:49:07 -07:00
Nathan Shively-Sanders 1b7faf10ac Merge pull request #17254 from Microsoft/generic-Object-jsdoc-creates-index-signature
JSDoc:Object<string, T> creates index signature
2017-07-18 08:48:56 -07:00
Wesley Wigham 8a1cd33451 Use jsdoc casts (#17251)
* Allow jsdoc casts of parenthesized expressions

* Feedback from #17211
2017-07-17 23:39:20 -07:00
Nathan Shively-Sanders 10a91c5426 JSDoc:Object<string, T> creates index signature
And `Object<number, T>` creates a numeric index signature. Other uses
still create `any` as before.
2017-07-17 16:14:42 -07:00
Nathan Shively-Sanders 3f60364a64 Improve test of jsdoc literal type parsing 2017-07-17 08:29:40 -07:00
Nathan Shively-Sanders 172db13306 Parse more types in JSDoc function() syntax
Also some cleanup from PR comments
2017-07-14 14:34:32 -07:00
Nathan Shively-Sanders bdc3f1f3f7 Address more PR comments 2017-07-14 13:29:44 -07:00
Nathan Shively-Sanders da5285e979 Update baselines 2017-07-14 09:34:35 -07:00
Nathan Shively-Sanders 91633cde5f Test JSDoc parsing using TS parser 2017-07-13 11:33:12 -07:00
Kanchalai Tanglertsampan 7ae4ff3b3d Add tests and update baselines 2017-07-10 15:24:03 -07:00
Kanchalai Tanglertsampan 9df2931aa3 Add tests and update baselines 2017-06-13 15:24:05 -07:00
Kanchalai Tanglertsampan 7dae8f73dd Merge branch 'master' into master-fix13306 2017-06-13 11:41:48 -07:00
Nathan Shively-Sanders b967bbb722 Test @typedef in @typedef-only JS files
Previously there was nothing for the @typedef to attach to, so the
comment was never parsed. Now these comments attach to the EOF token.
2017-06-13 10:37:04 -07:00
Nathan Shively-Sanders da83eb967a Returned generic function is instantiated correctly 2017-06-12 13:56:17 -07:00
Ron Buckton ff1f33729b Improve contextual types and return type checking 2017-06-08 16:44:42 -07:00
Yui 66b6d69c37 Merge pull request #16110 from Microsoft/master-refactorJsDocTest
[Master] Add more JSDoc tests and move them into one folder instead of spread between salsa and jsdoc conformance
2017-06-01 14:03:58 -07:00
Nathan Shively-Sanders 928da675ac Merge pull request #16156 from Microsoft/report-jsdoc-syntax-errors
Report JSDoc syntax errors
2017-05-31 16:21:32 -07:00
Kanchalai Tanglertsampan 1daff75d46 Update tests/baselines 2017-05-31 13:13:25 -07:00
Yui T 558cb2e2fa Add tests 2017-05-31 12:15:50 -07:00
Kanchalai Tanglertsampan 7815ccff1c Merge branch 'master' into master-refactorJsDocTest 2017-05-30 13:47:53 -07:00
Nathan Shively-Sanders 41e134529a Test reporting jsdoc syntax errors 2017-05-30 13:33:13 -07:00
Kanchalai Tanglertsampan d7c33713e4 Merge branch 'master' into master-refactorJsDocTest 2017-05-30 08:38:08 -07:00
Kanchalai Tanglertsampan 27078f995e Merge branch 'master' into master-fix16092 2017-05-30 08:25:53 -07:00
Yui T 5c7c113203 Update tests and baselines 2017-05-29 21:48:34 -07:00
Yui T 227198fae1 Add tests and update baselines 2017-05-27 19:11:08 -07:00
Yui T 0cbfc79ca7 Rename test files to be more consistent and move them into jsdoc folder 2017-05-26 11:20:57 -07:00
Yui T 8ae2fbadd0 Add tests and baselines 2017-05-25 22:35:15 -07:00
Yui T 4f791040fc Add tests and baselines 2017-05-25 20:16:52 -07:00