3238 Commits

Author SHA1 Message Date
Wenlu Wang
27075555c8 fix generate typenode from negative numerical literal (#30610) 2019-04-23 14:20:53 -07:00
Ryan Cavanaugh
885d4d63c8
Remove "generate types" code (#31075) 2019-04-23 13:51:47 -07:00
Andrew Branch
cd56398a53
Merge pull request #30743 from andrewbranch/bug/30675
Make anonymous function formatting apply to anonymous generators too
2019-04-23 09:35:35 -07:00
Nathan Shively-Sanders
c3a9429420
Handle JSDoc backticks in the parser, not scanner (#30939)
* Scan backticks in jsdoc as a single token less often

Previously, matching backticks in jsdoc would always be scanned as one
token to aid parsing incorrect jsdoc that uses backticks for parameter
names:

``js
/** @param {string} `nope`
 * @param {number} `not needed`
 */
```

However, this is wrong for code fences, which use triple backticks. This
fix parses a single backtick as a single token if it's immediately
followed by another backtick or by a newline. It retains the
questionable tokenisation of backticks-as-pairs in other cases, however.
A better fix might be to have the parser ignore backticks in jsdoc
instead.

* Add test case

* Handle jsdoc backticks in the parser, not scanner

Previously, the jsdoc scanner had ad-hoc handling of backticks that was
similar in structure to the normal scanner's handling, but much simpler.
This was a smaller code change, but is handled backwards: the special
case of backtick-quoted parameter names was handled in the scanner
instead of in the jsdoc identifier parsing code. That made it overapply
and block correct handling of asterisks across newlines, which was most
obvious in code fences inside jsdoc, as in #23517.

Fixes #23517

* More cleanup
2019-04-18 09:35:40 -07:00
Adam Postma
e951455215 Update misspelling 'identifer' to 'identifier' (#30894)
* fix typo - identifer to identifier

* fix typo - identifer to identifier
2019-04-12 13:29:00 -07:00
Nathan Shively-Sanders
ff959096df
Fix some bad jsdoc comment indent (#30838)
* First draft

Solves the initial problem but breaks commentCommentParsing. I also
found a couple more interesting cases.

* Add more tests and fix their bugs

* Another test case

* Some cleanup

I may try do a little more; `margin += tag.end - tag.pos` bothers me a
bit.

* More cleanup
2019-04-10 08:22:09 -07:00
Wesley Wigham
16450a027a
Change the default type parameter constraints and defaults to unknown from {} (#30637)
* Change the default type parameter constraint and default to unknown from {}

* Relax unknown checking outside of strictNullChecks a bit

* Increase strictness on index signatures with type `unknown` so inference doesnt change surprisingly

* Remove redundant switch
2019-04-04 12:25:15 -07:00
Andrew Branch
45ed0186a1
Make anonymous function formatting apply to anonymous generators too 2019-04-03 17:21:20 -07:00
Sheetal Nandi
17ceddaa1a
Merge pull request #29493 from Kingwl/avoid-quickfix-for-declaration-file
avoid add missing member in declaration file
2019-03-29 11:58:08 -07:00
Gabriela Araujo Britto
bb5eb025a8
Handle imports and exports in 'convert parameters to destructured object' (#30475)
* add test for imported function

* start to implement import references check

* fix imported function test

* skip alias when looking for symbol target

* recognize ES6 imports

* recognize some export syntax

* add tests for imports/exports

* add test for imported function

* start to implement import references check

* fix imported function test

* skip alias when looking for symbol target

* recognize ES6 imports

* recognize some export syntax

* add tests for imports/exports

* add test for imported function

* start to implement import references check

* fix imported function test

* recognize ES6 imports

* recognize some export syntax

* add mode import/export syntax cases

* fix entryToFunctionCall to deal with new calls through property/element access expressions

* add more tests for imports/exports

* allow function and class declarations that have no name but have a default modifier

* rename tests

* fix conflict

* fix tests

* add test for nameless class

* rename function

* minor refactor

* remove old tests

* delete old test

* refactor as suggested

* use getContainingFunctionDeclaration
2019-03-28 13:34:29 -07:00
王文璐
9050d0fdf8 update external files api 2019-03-27 19:06:21 +08:00
王文璐
6bc5ef3474 Merge branch 'master' into avoid-quickfix-for-declaration-file 2019-03-27 18:36:56 +08:00
Nathan Shively-Sanders
32054f1c31
Forbid accessing block-scoped variables on globalThis (#30510)
* Forbid accessing const & let on globalThis

It's just an error; you still get the type of the property.

* Disallow access of blockscoped vars on globalThis

Also change Array, Function, String, et al from `const` to `var` so that
they remain accessible via `globalThis.String`.

* Update baselines after lib.d.ts change

Note especially the change in redefineArray, which is now allowed as
long as you provide a type that is assignable to ArrayConstructor.

* Remove blockscoped vars from typeof globalThis

Unlike forbidding them, this removes the properties entirely.

Unfortunately, this means that accessing these properties is only an
error with noImplicitAny, and that error is quite confusing.

Let's discuss our options. I see 3:

1. Forbid access of block-scoped vars as properties (in all flag
settings), but leave them on the type. Simple to implement.
2. Remove block-scoped vars from the globalThis type. Has the bad
error/flag behaviour described above, but simple to implement.
3. Remove block-scoped vars from the globalThis type. Also, forbid
accessing them by executing another resolveName lookup for failed
property accesses on globalThisSymbol. If the second lookup returns a
blockscoped var, issue an error instead of falling back to the index
signature. This seems too complex to me.

* Update baselines

* Better error for block-scoped usage on globalThis

So that value-space references have as clear an error as type-space
references.

* Update fourslash tests

* Fix semi-colon lint

* Don't copy so much when filtering blockscoped vars
2019-03-25 14:07:48 -07:00
Gabriela Araujo Britto
0f6f3b79b5
Fix find all references of inherited constructor (#30514)
* recursively look for inherited constructor references

* add test

* remove outdated comment

* add tests

* move function

* improve tests

* minor refactor

* fix convert params refactoring to deal with inherited constructor calls

* simplify refactor test
2019-03-22 15:17:50 -07:00
Sheetal Nandi
800f7a3447
Merge pull request #30414 from Microsoft/jsSyntaxCompletions
Filter ts only keywords from js file completion
2019-03-20 10:38:11 -07:00
Gabriela Araujo Britto
84087d0e0a
Use shorthand property assignment in convert parameters to object (#30468)
* create shorthand property assignment in argument object when possible

* add shorthand property assignment test

* don't offer refactor on jsdoc comment

* add jsdoc test

* improve jsdoc test

* use crlf
2019-03-19 09:28:09 -07:00
Gabriela Britto
10b9051624
Fix convert to named parameters rest parameter tuple (#30286)
* check if rest parameter is of tuple type in isOptionalParameter

* expose isArrayType and isTupleType in checker

* don't offer refactor if rest parameter type is neither array nor tuple type

* add tests for rest parameters

* fix tests for renamed refactor

* remove unnecessary conditional operator
2019-03-18 10:31:38 -07:00
Anders Hejlsberg
d0646a629a
Merge pull request #30084 from dragomirtitian/GH-26563
Improved argument description for parameters originating from tuples
2019-03-18 06:14:52 -10:00
Nathan Shively-Sanders
658798032b
Fix globalThis completions (#30441)
* Fix, but with test not quite right

* Add missing completions to test

* Remove out-of-date comment
2019-03-15 19:10:39 -07:00
Sheetal Nandi
f829f958a2 Filter ts only keywords from js file completion
Fixes #29212
2019-03-14 15:52:50 -07:00
Gabriela Britto
1c8a359914
rename convert to named parameters (#30401) 2019-03-14 13:41:29 -07:00
Gabriela Britto
7824fbc395
Merge pull request #30383 from Microsoft/fixFindAllRefsOfDefaultExport
Fix find all refs of default export
2019-03-14 09:39:06 -07:00
Sheetal Nandi
8b04143675
Merge pull request #30380 from Microsoft/completionsWhileWritingSpread
Fix completions when writing spread expression
2019-03-14 09:38:50 -07:00
Sheetal Nandi
526eda8f18 Add extends of type parameter as type only location for completions
Fixes #28511
2019-03-13 15:22:33 -07:00
Gabriela Araujo Britto
66e2c54fe5 add tests for finding references of named and default exports 2019-03-13 15:11:33 -07:00
Sheetal Nandi
12d736f0a4 Fix completions when writing spread expression
Fixes #29234
2019-03-13 14:25:43 -07:00
Collins Abitekaniza
7b55d1846b Giving too many arguments should error on the first argument that exceeds arity (#27982)
* span on first arg that exceeds arity

* refactor baseline

* handle cases for spread arguments

* refactor + add coverage for tuple spread cases

* create diagnostic on NodeArray of exceeding args

* test function overloading
2019-03-12 15:57:12 -07:00
Titian Cernicova-Dragomir
88babf2a90 Merge remote-tracking branch 'remotes/origin/master' into GH-26563 2019-03-11 02:31:07 +02:00
Gabriela Britto
d2364f555f
Merge pull request #30089 from Microsoft/convert-to-named-parameters
Convert to named parameters
2019-03-06 09:33:01 -08:00
Gabriela Araujo Britto
8c4ab69d09 add test for non-transient symbol 2019-03-04 09:34:04 -08:00
Nathan Shively-Sanders
be2db9db12
Add globalThis (#29332)
* Restore original code from bind-toplevel-this

With one or two additional comments

* Working in JS, but the symbol is not right.

Still need to

1. Make it work in Typescript.
2. Add test (and make them work) for the other uses of GlobalThis:
window, globalThis, etc.

* Check in TS also; update some tests

Lots of tests still fail, but all but 1 change so far has been correct.

* Update baselines

A couple of tests still fail and need to be fixed.

* Handle type references to globalThis

The type reference must be `typeof globalThis`. Just `globalThis` will
be treated as a value reference in type position -- an error.

* Restore former behaviour of implicitThis errors

I left the noImplicitThis rule for captured use of global this in an
arrow function, even though technically it isn't `any` any more --
it's typeof globalThis.  However, you should still use some other method
to access globals inside an arrow, because captured-global-this is super
confusing there.

* Test values with type globalThis

I ran into a problem with intersecting `Window & typeof globalThis`:

1. This adds a new index signature to Window, which is probably not
desired. In fact, with noImplicitAny, it's not desired on globalThis
either I think.
2. Adding this type requires editing TSJS-lib-generator, not this repo.

So I added the test cases and will probably update them later, when
those two problems are fixed.

* Add esnext declaration for globalThis

* Switch to symbol-based approach

I decided I didn't like the import-type-based approach.

Update baselines to reflect the difference.

* Do not suggest globals for completions at toplevel

* Add tests of element and property access

* Look up globalThis using normal resolution

globalThis is no longer constructed lazily. Its synthetic Identifier
node is also now more realistic.

* Update fourslash tests

* Add missed fourslash test update

* Remove esnext.globalthis.d.ts too

* Add chained globalThis self-lookup test

* Attempt at making globalThis readonly

In progress, had to interrupt for other work.

* Add/update tests

* Addres PR comments:

1. Add parameter to tryGetThisTypeAt to exclude globalThis.
2. Use combined Module flag instead combining them in-place.
3. SymbolDisplay doesn't print 'module globalThis' for this expressions
anymore.
2019-02-27 14:14:34 -08:00
王文璐
4d7ec380a9 check completions with assignable rather than identity 2019-02-26 10:54:01 +08:00
Gabriela Araujo Britto
a5153a94ab add tests 2019-02-25 14:14:28 -08:00
Gabriela Araujo Britto
365967d484 Merge branch 'master' into convert-to-named-parameters 2019-02-25 10:54:58 -08:00
Gabriela Araujo Britto
f571866f47 add new tests for bad class references 2019-02-25 10:32:56 -08:00
Gabriela Araujo Britto
bc3611d1dd update failing tests 2019-02-25 10:32:28 -08:00
Titian Cernicova-Dragomir
8d66d55de1 Improved argument description for parameters originating from tuples that were extracted from functions. (ie mapped functions) 2019-02-25 18:18:00 +02:00
Joseph Wunderlich
21ab39649c remove any annotation from declare method quickfix 2019-02-22 17:24:21 -08:00
Gabriela Araujo Britto
6b53489a4a Merge branch 'master' into convert-to-named-parameters 2019-02-20 13:24:09 -08:00
xiaofa
7c8c6cf4d0 fix no space before equal operator in type parameter 2019-02-20 18:12:09 +08:00
Gabriela Araujo Britto
754f4a45b6 refactor expected test output 2019-02-19 14:23:26 -08:00
Gabriela Araujo Britto
edf0cec3dd add tests for inherited constructor and method 2019-02-19 14:22:59 -08:00
Gabriela Araujo Britto
a773046181 copy argument comments to property 2019-02-15 16:48:54 -08:00
Gabriela Araujo Britto
b93afffaf7 rename refactor tests 2019-02-15 15:36:11 -08:00
Gabriela Araujo Britto
dbd84996aa don't apply refactor when parameter has decorators 2019-02-11 14:24:05 -08:00
Gabriela Araujo Britto
4e135f13b5 add tests for comments 2019-02-11 12:03:09 -08:00
Gabriela Britto
9270e58eaf Merge branch 'master' into convert-to-named-parameters 2019-02-06 15:41:16 -08:00
Gabriela Britto
1d1c82095c add tests for rest parameters 2019-02-04 12:53:02 -08:00
Gabriela Britto
abb11550d3 add more tests 2019-02-01 16:44:22 -08:00
Ryan Cavanaugh
a856a64a5c
Merge pull request #29446 from fuafa/infer-js-doc
fix quick fix infer parameter types from usage in js file
2019-02-01 13:55:31 -08:00