1595 Commits

Author SHA1 Message Date
王文璐
0e97ce57e4 Merge branch 'master' into improve_type_arguments_parser_1 2018-09-07 11:36:02 +08:00
Ryan Cavanaugh
5d65e86756
Merge pull request #23253 from Kingwl/definite-assignment-assertion-improve
improve parser and error message if definite assignment assertions in…
2018-09-05 11:49:13 -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
Tim Schaub
20a2b0cade Ignore newline and asterisk when parsing JSDoc typedef (#26775) 2018-08-30 10:01:33 -07:00
Andy
cff04e6050
Ensure JsonSourceFile has all the non-optional properties of SourceFile (#26162)
* Ensure JsonSourceFile has all the non-optional properties of SourceFile

* Set properties in parseSourceFile
2018-08-28 16:43:14 -07:00
王文璐
78444bb724 improve test case 2018-08-27 11:47:10 +08:00
王文璐
268dbfe093 parse less than token rather than left shift in context of type arguments 2018-08-24 11:00:59 +08:00
Tim Schaub
6fd725f3ea Skip whitespace or asterisk in JSDoc param type and name (#26067) 2018-08-16 16:16:09 -07:00
Andy
08f5edbd03
Treat NoSubstitutionTemplateLiteral like StringLiteral in more places (#26330)
* Treat NoSubstitutionTemplateLiteral like StringLiteral in more places

* Move isStringOrNumericLiteral closer to its only use
2018-08-10 16:00:08 -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
Andy
a73161e9d5
Don't store @template constraint in a TypeParameterDeclaration node (#26283)
* Don't store @template constraint in a TypeParameterDeclaration node

* Code review

* Update API
2018-08-09 17:39:15 -07:00
Tim Schaub
960800d1fe Remove trailing whitespace from JSDoc comments 2018-07-28 10:36:10 -06: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
Andy
d40d54984e
Support deleting all unused type parameters in a list, and deleting @template tag (#25748)
* Support deleting all unused type parameters in a list, and deleting @template tag

* Support type parameter in 'infer'
2018-07-27 11:55:31 -07:00
Andy
5e94cf626b
Expand span of @typedef with properties to include the @typedef tag (#25950) 2018-07-26 08:56:24 -07:00
王文璐
c531065fd0 Merge branch 'master' into definite-assignment-assertion-improve 2018-07-26 18:06:47 +08:00
Matt McCutchen
f72193eedc Report a semantic error for an arrow function with a "this" parameter.
Fixes #9744.
2018-07-23 10:42:56 -04: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
6d8a5f6288
Fix invalid cast: JSDocSignature is not a SignatureDeclaration (#25734) 2018-07-17 13:35:55 -07:00
Andy
64555aa6a9
navigateTo: Collect results from all referenced projects. (#25283)
* navigateTo: Collect results from all referenced projects.

* Don't use project references, just source maps

* Move more code to session

* Test when implementation file is deleted

* Use tsserver tests instead of fourslash tests to ensure session is used

* Support find-all-references

* Restore fourslash tests

* Update emit baselines (added missing newline)

* Support rename

* @weswigham code review

* Don't open/close files

* Avoid growing `toDo` too eagerly

* @sheetalkamat code review

* Also get symlinked projects for originalLocation

* Update API (#24966)

* More @sheetalkamat code review

* Remove unnecessary test

* Update API (#24966)
2018-07-05 15:39:03 -07:00
Andy
76a4694bd4
parser: Fix testing for missing list (#25411)
* parser: Fix testing for missing list

* Fix return type
2018-07-03 12:37:20 -07:00
Andy
c5bd0405c4
JsxTagNameExpression can only be Identifier | ThisExpression, not any PrimaryExpression (#21555)
* JsxTagNameExpression can only be Identifier | ThisExpression, not any PrimaryExpression

* Use a type similar to PropertyAccessEntityNameExpression

* Fix lint errors
2018-06-29 16:50:44 -07:00
Anders Hejlsberg
70975cd08f
Merge pull request #24897 from Microsoft/restTuples
Tuples in rest parameters and spread expressions
2018-06-25 19:26:35 -07:00
Nathan Shively-Sanders
99ebcd788f
Treat link tag as comment (#25206)
* First attempt at parsing. Doesn't work

But my machine is dying, so this is an emergency commit.

* Parsing sort of works

But it's not right yet; the test I added fails. See the TODO I added.

* Parse link tag as comment
2018-06-25 15:27:49 -07:00
Andy
4c326b2b6c
Simplify addJSDocComment (#25196)
* Simplify addJSDocComment

* Add assert
2018-06-25 11:36:37 -07:00
Andy
62e5541a66
parseJSDocCommentWorker: Don't need result (#25197) 2018-06-25 11:34:20 -07:00
Anders Hejlsberg
b0d8c6551e Merge branch 'master' into restTuples
# Conflicts:
#	src/compiler/checker.ts
2018-06-22 06:10:50 -10: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
Anders Hejlsberg
4f99bc19c8 Merge branch 'master' into restTuples
# Conflicts:
#	tests/baselines/reference/APISample_Watch.errors.txt
#	tests/baselines/reference/APISample_WatchWithDefaults.errors.txt
#	tests/baselines/reference/APISample_WatchWithOwnWatchHost.errors.txt
#	tests/baselines/reference/APISample_compile.errors.txt
#	tests/baselines/reference/APISample_jsdoc.errors.txt
#	tests/baselines/reference/APISample_linter.errors.txt
#	tests/baselines/reference/APISample_parseConfig.errors.txt
#	tests/baselines/reference/APISample_transform.errors.txt
#	tests/baselines/reference/APISample_watcher.errors.txt
#	tests/baselines/reference/api/tsserverlibrary.d.ts
#	tests/baselines/reference/api/typescript.d.ts
2018-06-16 07:47:30 -07:00
Ryan Cavanaugh
1bbe6610a4 Merge branch 'master' into esau-squash 2018-06-13 15:35:18 -07:00
Ryan Cavanaugh
066b191982 Collapse core/compiler/parser into parser 2018-06-11 17:07:58 -07:00
Ryan Cavanaugh
336c37662d Projzilla phase 1 2018-06-09 16:48:08 -07:00
Nathan Shively-Sanders
8d737ca959
Simplify parseJSDocIdentifierName (#24660)
* Simplify parseJSDocIdentifierName

It now always creates a missing node. The one place that depended on it
returning undefined, parseJSDocTypeNameWithNamespace, now returns
undefined before calling parseJSDocIdentifierName.

* Remove assert

It is adequately proven at compile time.
2018-06-05 14:30:37 -07:00
Andy
735a46f838
If parsing a function type fails, parseTypeReference() to ensure something is returned (#24567)
* If parsing a function type fails, parseTypeReference() to ensure something is returned

* Avoid tryParse

* Add missing semicolon

* Don't check for undefined, check for missing type

* Don't set parameters undefined, set to missingList and return false

* Update API baselines

* Code review
2018-06-05 10:24:37 -07:00
Ron Buckton
666841264c Merge branch 'master' into libReference 2018-06-04 14:38:56 -07:00
Andy
f9530d7e8f
Add 'parseOptionalJsdoc' helper (#24650) 2018-06-04 13:28:47 -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
Sheetal Nandi
d64608dc97
Merge pull request #24615 from Microsoft/jsonSourceMaps
Disable source maps and declaration emit for the json module
2018-06-04 10:48:43 -07:00
Andy
886377f8d3
Add autoCloseTag language service (#24543)
* Add autoCloseTag language service

* Change name to getJsxClosingTagAtPosition and return an object
2018-06-04 10:08:15 -07:00
Sheetal Nandi
d246c3c2bd Disable source maps and declaration emit for the json module
Fixes #24546
2018-06-01 18:31:58 -07:00
Ron Buckton
b4e113b94e Merge branch 'master' into libReference 2018-05-31 10:02:08 -07:00
Ron Buckton
ec0af20f5a Merge branch 'master' into libReference 2018-05-29 14:13:00 -07:00
Anders Hejlsberg
03f464f433 Add 'unknown' keyword to scanner/parser/emitter 2018-05-26 08:51:09 -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
Andy
e53e56cf82
Enable '--strictNullChecks' (#22088)
* Enable '--strictNullChecks'

* Fix API baselines

* Make sys.getEnvironmentVariable non-nullable

* make properties optional instead of using `| undefined` in thier type

* reportDiagnostics should be required

* Declare firstAccessor as non-nullable

* Make `some` a type guard

* Fix `getEnvironmentVariable` definition in tests

* Pretend transformFlags are always defined

* Fix one more use of sys.getEnvironmentVariable

* `requiredResponse` accepts undefined, remove assertions

* Mark optional properties as optional instead of using `| undefined`

* Mark optional properties as optional instead of using ` | undefined`

* Remove unnecessary null assertions

* Put the bang on the declaration instead of every use

* Make `createMapFromTemplate` require a parameter

* Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional

* Plumb through undefined in emitLsit and EmitExpressionList

* `ElementAccessExpression.argumentExpression` can not be `undefined`

* Add overloads for `writeTokenText`

* Make `shouldWriteSeparatingLineTerminator` argument non-nullable

* Make `synthesizedNodeStartsOnNewLine` argument required

* `PropertyAssignment.initializer` cannot be undefined

* Use one `!` at declaration site instead of on every use site

* Capture host in a constant and avoid null assertions

* Remove few more unused assertions

* Update baselines

* Use parameter defaults

* Update baselines

* Fix lint

* Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions

* Make Node#symbol and Type#symbol non-optional to reduce assertions

* Make `flags` non-nullable to reduce assertions

* Convert some asserts to type guards

* Make `isNonLocalAlias` a type guard

* Add overload for `getSymbolOfNode` for `Declaration`

* Some more `getSymbolOfNode` changes

* Push undefined suppression into `typeToTypeNodeHelper`

* `NodeBuilderContext.tracker` is never `undefined`

* use `Debug.assertDefined`

* Remove unnecessary tag

* Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 14:46:57 -07:00
Andy
7106a587cc
Add type for diagnostics where location is defined (#23686)
* Add type for diagnostics where location is defined

* getSemanticDiagnostics may return global diagnostics

* Reduce array creation
2018-05-22 11:01:18 -07:00
Andy
982c8d0af9
Add suggestion diagnostics for unused label and unreachable code (#24261)
* Add suggestion diagnostics for unused label and unreachable code

* Always error on unused left hand side of comma
2018-05-22 07:56:29 -07:00
Wesley Wigham
d82d35c7f5
Set startPos at EOF in jsdoc token scanner so node end positions for nodes terminated at EoF are right (#24184)
* Set startPos at EOF in jsdoc token scanner to node end positions for nodes terminated at EoF are right

* More complete nonwhitespace token check, fix syntactica jsdoc classifier

* Use loop and no nested lookahead

* Do thigns unrelated to the bug in the test

* Fix typo move return

* Patch up typedef end pos

* Fix indentation, make end pos target more obvious
2018-05-17 15:16:18 -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 f41a96b24d44a6b696d39eee9e91ef7f606bea52.

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

This reverts commit 7d2233a00e5c6d794c1de32c03802e8ccce1914c.

* 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
Wesley Wigham
60df4671d0
Fix jsx element parsing within ternary (#24149) 2018-05-16 09:28:22 -07:00