Commit graph

23602 commits

Author SHA1 Message Date
Wesley Wigham
d1b43429c2
Allow nested reverse mapped type printback (#42485)
* Optimize interning of reverse mapped types

* Style feedback

* Whitespace

* Update baseline
2021-04-05 11:37:51 -07:00
Wesley Wigham
1f1dcd60b5
When reusing input type nodes, only instantiate the type for comparison if it is a this type (#42584) 2021-04-05 11:10:47 -07:00
Oleksandr T
5268264e64
fix(43316): omit to suggest converting to async function if a void is explicitly returned (#43358) 2021-04-05 11:09:33 -07:00
Wesley Wigham
f03e59ecc9
Do not covariantly mix in constraints from contravarrying positions (#43439)
* Do not covariantly mix in constraints from contravarrying positions

* Exclude keyof from constraint variance tracking

* Extra test case

* Always subtitute on type parameter types
2021-04-05 11:05:33 -07:00
Josh Goldberg
38da7c600c
Disabled 'used before initialization' error for optional properties (#43100)
* Disabled 'used before initialization' error for optional properties

* Expanded tests to include code snippet from issue
2021-04-02 10:08:10 -07:00
Sang
f9b35cd302
Add @link jsdoc auto-complete (#43475)
* feat(services): jsdoc add link tag name

* test: add jsdoc inline test
2021-04-01 17:02:50 -07:00
Nathan Shively-Sanders
c6a2e45768
Add @deprecated to tree walk (#43473)
So various things don't crash. Fixes #43472
2021-04-01 08:42:00 -07:00
Armando Aguirre
8f8a579eee
Added BindingElement to isSomeImportDeclaration (#43387)
* Added BindingElement to isSomeImportDeclaration

* Added tests

* Refactores to use getDeclarationOfAlias
2021-03-31 18:18:16 -07:00
Wenlu Wang
62f3ccd9c0
Error if assignment after block (#41115)
* Error if assignment after block

* Update src/compiler/diagnosticMessages.json

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Fix diags

* Error after block

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-31 15:57:25 -07:00
Nathan Shively-Sanders
76a2ae3d69
Only issue matching token errors on non-dupe locations (#43460)
* Only issue matching token errors on non-dupe locations

Intead of unconditionally retrieving the last error and attaching a
related span, `parseErrorAt` and friends now return the last error and
return `false` when there is none.

Also make one more place use parseExpectedMatchingBrackets that I missed
last time.

* Inline parseTokenForError, return undefined not false

* skip redundant undefined assignment

* address PR comments
2021-03-31 13:54:53 -07:00
Sheetal Nandi
d51b8cff6a
Do not delete output file names that are same as input file name (#43448)
* Add failing test case

* Do not delete output file names that are same as input file name
Fixes #43116
2021-03-30 16:04:25 -07:00
Anders Hejlsberg
3dd68b878a
Fix template literal type relations (#43440)
* Fix template literal relationships

* Accept new baselines

* Add regression test
2021-03-30 12:53:15 -10:00
Oleksandr T
819651eb5f
fix(43313): add parentheses to a type assertions (#43315) 2021-03-30 15:29:02 -07:00
Sang
a8ee22f73d
"fix(services): convert to es6 module generate invalid code with .default" (#43309) 2021-03-30 15:24:31 -07:00
Andrew Branch
b549467368
Consider base types in isArrayLikeType (#43435)
* Types that extend Array or ReadonlyArray are automatically array-like

* Add React repro to test
2021-03-30 13:18:38 -07:00
keerthana1212
555ef73da8
Adding Diagnostic message for missing ']' and ')' in Array literal and conditional statements (#40884)
* Adding Diagnostic message for missing ']' in Array literal

* revert change on parseArrayBindingPattern

* Adding diagnostic message for if, while, do and with statements

* Extract parseExpectMatchingBrackets

Co-authored-by: Keerthana Kanakaraju <kekanaka@microsoft.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-30 13:13:57 -07:00
Ryan Cavanaugh
294a5a7d78
Remote duplicated assignment (#43399) 2021-03-29 21:30:45 -07:00
Oleksandr T
6fd676b8ef
fix(43215): disallow using never as an interface name (#43217) 2021-03-29 17:22:41 -07:00
Josh Goldberg
57775ed405
Consider class field properties to redeclare parent definitions (#43194) 2021-03-29 17:20:25 -07:00
Eli Barzilay
c34b252e1e Fix length of JSDocTypedefTag
(Accidentally broken in dcc27eb.)

Fixes #43394 and microsoft/tsserverfuzzer#309.
2021-03-29 16:06:53 -04:00
Daniel Rosenwasser
a3d207a905
Improve (and actually use) "always truthy promise" error (#43023)
* Modify error message and actually use the error message.

* Accepted baselines.
2021-03-29 12:44:05 -07:00
Greg Finley
11097c622c
Fix typo (#43404)
* Fix typo

* Fix off baseline

Co-authored-by: Orta <git@orta.io>
2021-03-29 12:14:44 +01:00
Anders Hejlsberg
4774666f23
Support relations and inference between template literal types (#43361)
* Support assignment and inference between template literal types

* Add tests

* Accept new baselines

* Add comments
2021-03-28 13:11:56 -07:00
Ryan Cavanaugh
451089e8ef
Rename isWrite -> writing (#43405) 2021-03-27 21:56:50 -07:00
Ryan Cavanaugh
ff233a9ac2
Variant accessors (#42425)
Allows accessors to have different access modifiers and types

Fixes #2845, #2521
2021-03-26 20:11:02 -07:00
Wenlu Wang
2f0c8b2bea
--noImplicitOverride (#39669)
* wip: add types

* wip

* Add cases

* Add some case

* Add more check

* accept baseline

* add abstract abd declare method

* add override in declaration

* accept baseline

* add property override

* Fix decalre modifier

* update baseline

* Add more cases

* make lint happy

* make lint happy

* Update description

* Add codefix

* simplify code

* accept baseline

* Update desc

* Accept baseline

* Add override completions

* filter out implements field in override context

* fix tests

* Add parameter property check

* Accept baseline

* acept baseline

* Add parameter property to declaration code action

* Add quickfix for override parameter property

* fix code style

* Add override with interface tests

* Add more cases about modifier position

* rename flag

* rename flags

* Added tests.

* Accepted baselines.

* Always issue errors for unnecessary 'override' modifiers.

* Accepted baselines.

* Override perf (#4)

* try cache check result

* pre check for override

* Do not issue error if implement abstract

* Add abstract-spec check

* Avoid override dead lock

* Add more case

* Add codefix for new error

* Fix error message

* Add jsdoc override tag (#6)

* Override jsdoc tag (#7)

* accept baseline

* Disallow codefix in js

* update baseline

* Omit override in d.ts

* Add more case in js

* Accept baseline

* fix override js test

* fix crlf

* Revert merge conflict changes

* Accept baseline

* Avoid space

* Fix CR issues

* Accept baseline

* Fix typo and add more check

* Fix error name

Co-authored-by: Daniel Rosenwasser <Daniel.Rosenwasser@microsoft.com>
2021-03-26 16:29:22 -07:00
Wenlu Wang
41dc625b0a
Add static index signature (#37797)
* Add static index

* fix lint

* make lint happy

* adjust test cases

* add more cases

* fix changes

* Add more case

* accept baseline

* fix error if extends others

* Update vfsUtil.ts

* use equal to empty array

* static signature of interface is an error

* Accept baseline

* Check index constraints for static signature

* Accpet baseline

* Fix crash

* fix crash

* Accept baseline

* Fix regression

* Fix crash

* always return new array
2021-03-26 15:30:09 -07:00
Andrew Branch
2d6a490363
Import statement completions (#43149)
* WIP

* WIP

* Get completion details working

* Start unifying eager and lazy auto imports

* Fix export=

* Fix completion details for totally misspelled names

* Almost fixed duplication...

* Fix remaining completion tests

* Refactor to support multiple origins for same symbol

* Make import fixes make slightly more sense

* Add cache back in

* Set insertText based on import kind

* Update API baselines

* Add semicolons, snippet support, and sourceDisplay

* Add some tests

* Update baselines

* Fix pattern ambient modules appearing in auto imports

* Fix tests

* Remove commented code

* Switch to valueDeclaration for getting module source file

* Small optimizations

* Cache module specifiers / importableness and export map separately

* Fix and test cache invalidation logic

* Update API baselines

* Add separate user preference for snippet-formatted completions

* Require first character to match when resolving module specifiers

* Fix AutoImportProvider export map cache invalidation

* Really fix auto import provider export map invalidation

* Update test added in master

* Use logical or assignment

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Simply conditional by reversing

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* When file is deleted need to marked correctly in the project as removed file

* Simplify hasAddedOrRemovedSymlinks with cherry-picked fix

* Ensure replacement range is on one line

* Update baselines

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 14:47:07 -07:00
Sheetal Nandi
a545ab1ac2
Cache resolved project references and watch wild card directories from them to update them (#42929)
* Test for not watchiong referenced projects fileNames and invalidating it

* Add watching wild card directories and caching parsed command line for projects so that its shared

* Handle config file watching and commandline cache together

* Watch extended files for commndline cache instead of project

* Use extended config cache now that we are watching extended config files

* Structure for getParsedCommandLine from the LS

* Adding some more skeleton with todos

* getParsedCommandLine on WatchCompilerHost

* Tests for Watch, LS scenarios

* Handle getParsedCommandLine so we are looking at all things for referenced

* Cleanup and commenting

* Test for transitive references with tsc-watch

* Cache parsed command line even if host implements getParsedCommandLine

* Cleanup

* Cleanup

* Some tests to verify exclude from referenced project doesnt trigger the update

* Baseline when program is same

* Test for incremental scenario

* Tests for output from referenced project

* Comments
2021-03-26 13:23:03 -07:00
Anders Hejlsberg
a26acf4540
Template literal types for contextually typed template literal expressions (#43376)
* Template literal types for contextually typed template literal expressions

* Accept new baselines

* Add regression test

* Add a few more tests
2021-03-26 10:32:05 -07:00
Andrew Casey
6066eaec09
Port realpath workaround from release-4.2 (#43384)
* Don't use _fs.realpathSync.native on windows, a semi-revert of #41292 (#43348)

We're planning a real fix for TS 4.3, but port the workaround from 4.2
so the beta doesn't have this bug.

(cherry picked from commit e462dfa347)

* Un-reverse condition

Co-authored-by: Orta Therox <ortam@microsoft.com>
2021-03-25 17:12:13 -07:00
Andrew Casey
3db6d803d5
Don't build type catalog during server tracing (#43354)
Bonus: this also drops the redundant type catalog from the
non-diagnostics-producing checker.
2021-03-25 15:52:04 -07:00
Ron Buckton
e10a32591c
Use 'abstract new' in InstanceType and ConstructorParameters (#43380) 2021-03-25 15:27:06 -07:00
Ron Buckton
fbd7f7db20
Update typescript-eslint to latest (#43381) 2021-03-25 14:46:16 -07:00
Eli Barzilay
eb804a9706 getSemanticDocumentHighlights: don't fail...
...when missing `program.redirectTargetsMap` info.  This assertion fails
in the added test case -- looks like there is no entry in
`program.redirectTargetsMap` when it comes from a file that is no in the
project.  So in this case don't follow the (missing) info, and instead
drop the highlight.

Fixes #33722.
2021-03-25 15:48:34 -04:00
Titian Cernicova-Dragomir
e638af7560
ES private class elements (#42458)
* Added support for private identifier methods.

* Added tests for private methods.

* Added check to only not allow private name method signatures in anything except classes.
Changes objects literal checking to not bail on first private name found in object literal.

* Added private accessors tests

* Transform private methods

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Rename shouldTransformPrivateFields

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Use a single WeakSet for brand-check

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add a test for using private methods in static field initializers

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add breaking checker test

Private methods inside class expressions should not error.

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add to instances once per-instance

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: evaluate receiver and rhs expressions before throwing on readonly assignment

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add a test for evaluating rhs before readonly assignment

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Transpile private accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: handle readonly/writeonly accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for private setter without a getter

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: getAllUnscopedEmitHelpers

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: better handling of duplicate names

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Fixed wrong error message for private methods in class expressions.

* change error message

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for async private methods with a higher target

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: setter assignment returns rhs value

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for setter assignment return value

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: handle duplicate accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add tests for duplicate accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* docs: add missing parameter docs

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Fixed failing test.

* baseline-accept: ordering changes

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: attach weakSetName to property declaration

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for nested private methods

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test with any

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Added support for static private fields accessors and methods.

* Added error message for private identifiers used with static decorators. There is no spec to go with this behavior as of yet.

* Fixed emit static bug that used private names outside of classes for initialization in esnext. Fixed issue where nested privates produce incorrect brand check.

* Added tests for private static fields methods and accessors.

* Fixed error messages and tests after merge.

* Accept new baseline.

* Improved duplicate identifier checks for static private class elements.

* Added error when using initializers with private static fields when useDefineForClassFields is not specified and target is esnext.

* Fixed code review issues.

* Removed semantically wrong emit on `useDefineForClassFields:true` with `target:esnext`

* Changed emit for uninitialized private static fields.

* Added runtime error in helper if a static private field is accessed before it was declared.

* Fixed code review comments for private identifier static class elements.

* add debug.assertNever for unknown node type (#53)

* Fixed code review issues.

* Fixed code review issues for private class elements.

* Fixes class shadowing when checking access to a private static class element.

* fix private methods/accessors in class expr inside a loop

* collapse switch case

* fix class name

* simplify getPrivateMethodsAndAccessors

* remove findPreviousAccessorInfo

* lazily create weakSetName identifier

* do not allocate a node if not needed in visitMehodDeclaration (#55)

* Removed all the emit helpers for private identifier methods accessors and modified the existing helpers for get and set fields to do the same job.

* Simplified emit for private identifier class elements.

* do not clone the receiver (#57)

* leave bad code in for #constructor and duplicate private names (#58)

* Added check for WeakSet collision.

* Added error for using a set only accessor.

* update keyof tests and ?? (#62)

* replace ?? with ||

* update keyof tests

* fix emit helpers comments

* produce an error if private field helpers are not up to date

* add tests

* fix setter-only compound assignment

* fix tests

* fix duplicated trailing comments (#64)

* clear receiver pos and setTextRange on helper calls

Co-authored-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
2021-03-24 18:15:50 -07:00
Eli Barzilay
6ce82ab02e deleteDeclaration: don't crash on the top node.
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

Do three things to improve this:

1. `textChanges.ts`: if we get here with the root node, delete it
   instead of failing.

2. `fixUnusedIdentifier.ts`: check that we don't `delete` a node that is
   the whole source file, so the error is more focused (should have more
   similar failure stacks).

3. `session.ts`: when there was any failure in `getCodeFixes`, check if
   the input had a diag code that does not appear in the requested text
   range, and throw an error saying that the failure is probably a
   result of a bad request.

Closes #33726 (probably not fixing it, but making it easier to find the
cause)
2021-03-24 19:25:06 -04:00
Wesley Wigham
fb60c9f46e
Use last detected JSX import source pragma as canonical source, rather than first (#43351) 2021-03-23 18:02:37 -07:00
Sheetal Nandi
04205ca32c
Do not calculate signatures if old state is not used (#43314)
* Extra tests in preparation for lazy signature making sure the original intent of test is maintained

* Whenver we cant use state delay signature calculation and use source file version as signature

* Incremental correctness checks

* Retain old behavior in compile on save by disabling use of file version as signature in when state is not reused
2021-03-23 13:43:43 -07:00
Nathan Shively-Sanders
dcc27ebaf2
@link support, second try (#43312)
* Revert "Revert "Editor support for link tag (#41877)" (#43302)"

This reverts commit 451d4354b9.

* Fix parsing @link at end of comment

* Parse comments as string when no @link occurs

* fix lint
2021-03-22 16:39:35 -07:00
Simar Bassi
462271854d
Fix Issue #39155 (importModuleSpecifierEnding does not apply for module specifier completions) (#42467)
* Pass preferences down to getCompletionEntriesForRelativeModules

* Add preferences to getExtensionsOptions call

* Add test case

* Fix test case typos
2021-03-22 14:10:41 -07:00
Wesley Wigham
9a256a1935
Adjust scanning of keywordy jsx namespace names, add grammar error for jsx dotted names containing namespace names (#43104) 2021-03-22 10:28:43 -07:00
Ron Buckton
9af313db77
Use shared binary trampoline in checker (#43035) 2021-03-19 18:54:51 -07:00
Anders Hejlsberg
15fae38b39
Improve narrowing of generic types in control flow analysis (#43183)
* Narrow type variables with union constraints when merited by contextual type

* Narrow generics with union type constraints as indicated by contextual type

* Accept new baselines

* Add tests

* Fix circularity for JSX elements

* Remove unnecessary isConstraintPosition information from flow cache key

* Update comment

* Add additional tests

* Rename to getNarrowableTypeForReference, remove getConstraintForLocation

* Add comment

* Fix removal of undefined in destructurings with initializers

* Use getContextFreeTypeOfExpression in discriminateContextualTypeByObjectMembers

* In obj[x], use constraint of obj's type only when x's type is non-generic

* Add comment
2021-03-19 17:12:57 -07:00
Tobias Koppers
8a5939fdae
fix CommonJs modules no longer affecting the global scope (#43090) 2021-03-19 16:24:17 -07:00
Josh Goldberg
5813907abf
Made TS6059 rootDir validation consistent for programmatic usage (#43145)
* Made TS6059 rootDir validation consistent for programmatic usage

* Corrected other baselines
2021-03-19 15:52:04 -07:00
Hossein
6a83ae19e2
[GH-43213] Fix duplicate comments printed in quick info section (#43240)
* Concat on unique values

* more changes

* only push values to array if unique

* address review comments

* Fix lint

* removw foeachunique
2021-03-19 14:14:32 -07:00
Andrew Casey
b925c165c4
Only catalog types when tracing (#43304) 2021-03-19 09:59:04 -07:00
Anders Hejlsberg
fbc9c942b2
Normalize target type after null-stripping unions in relationship checks (#43202)
* Normalize target type after null-stripping

* Add regression tests
2021-03-19 09:19:25 -07:00
Nathan Shively-Sanders
451d4354b9
Revert "Editor support for link tag (#41877)" (#43302)
This reverts commit ec77bff332.
2021-03-18 14:42:25 -07:00
Anders Hejlsberg
a21f61f746
Fix narrowing of intersections of type variables and primitive types (#43131)
* Fix narrowing of intersections of type variables and primitive types

* Add tests
2021-03-18 08:55:50 -07:00
Nathan Shively-Sanders
ec77bff332
Editor support for link tag (#41877)
* Initial scribbles

* Compiles but provides spans instead of location pairs

Probably need to fork the services/server types and provide a conversion
with Session.toFileSpan. Not sure where to put the conversion.

* Switch to DocumentSpan

In theory this is already better supported, but not sure practise bears
that out.

* Builds w/protocol types + conversions

* cleanup:better names and scrub TODOs

* fix test harness too

* Misc

1. Simplify protocol after talking to @mjbvz.
2. Add more tests.
3. Initial notes about where to add parsing.

* Parse and store links in the compiler

The text of the link is still stored in the comment text, but that's now
kept in an object instead of just a string. Each link has the parse for
the entity reference, if there is one.

Needs lots more tests -- this just makes all the existing jsdoc tests
pass.

* more tests and some fixes

* Fix other failing tests

* fix bad merge

* polish parser

* improve names and array types

* slight tweaks

* remove some done TODOs

* more tests + resulting fixes

* add+fix cross-module tests

* Support `@see {@link`

Plus find-all-refs support equivalent to @see's.

* add server test

* Make comments actually part of the AST

* Add span for link.name in language service/protocol

* Make checker optional in getJSDocTags

Also change to JSDocCommentText from JSDocCommentComment

* Use getTokenValue instead of getTokenText

Measure twice, slice once

* Add missing support for top-level links

The language service and protocol were missing support for top-level
links. This commit adds that plumbing.

* add string back to comment type in node constructors

* Full parse of link tags and jsdoc comment text

- Doesn't pass fourslash yet, I'm going to switch to baselines for
  failures there.
- Still needs some work on the protocol to convert file+offset to
  file+line+offset.

* fix lint

* Fix missing newlines in inferFromUsage codefix

* Parse jsdoc comments as text node/link array

And switch to line+character offsets in the protocol

* Fix fourslash tests

Mostly ones that can't be baselined, but I switched a couple more over
to baselines

* Improve types and documentation

* Test+fix @link emit, scrub other TODOs

* update API baselines

* test that goto-def works with @link

* Split link displaypart into 3

One for link prefix and suffix, one for link name, and one for link
text.

* update baselines

* Provide JSDocTagInfo.text: string to full clients by default

Instead of upgrading them to displayparts.

* Real server tests

* Disambiguate {@link} and @param x {type}

They are ambiguous; previously the parser preferred the type
interpretation, but will now look ahead and parse links instead when the
prefix is `{@link`.

* Add explanatory comment in test

* fix location in richResponse in protocol

* update API baseline

* Address PR comments

1. Add a cross-file goto-def test.
2. Switch from per-message args to UserPreference.

* use arraysEqual from core
2021-03-16 16:26:01 -07:00
Oleksandr T
3da5982c9a
fix(43254): show named tuple member type (#43273) 2021-03-16 12:56:12 -07:00
Andrew Casey
ae884b1a38
Fix dump of tracing legend (#43263) 2021-03-16 10:57:10 -07:00
Sheetal Nandi
53cbc046d2
Refactor the test for easy maintainability (#43262) 2021-03-15 18:04:30 -07:00
Armando Aguirre
322c70fd82
Fixed reporting error for type arity (#43111) 2021-03-13 01:01:04 -08:00
Armando Aguirre
36f7623225
Fix jsx formatting (#42671)
* Refactored scanJsxToken when is formatting

* Added bug regression test

* Simplify JsxText formatting

* Renamed isFormatting to allowMultilineJsxText

* Updated baselines
2021-03-13 01:00:42 -08:00
Sheetal Nandi
d2cb05a6b5
Emit readable BuilderFileEmit kind (#43221) 2021-03-12 14:32:50 -08:00
Sheetal Nandi
82bfe5ad93
Fix issue with some baselines for tsbuildinfo not getting generated (#43218) 2021-03-12 12:28:20 -08:00
Sheetal Nandi
496a1d3caa
Improvements to dts emit for tsbuildinfo (#43205)
* Test update

* Use source file version as default signature for the file whenever there is no dts emit for the file

* json source files from project reference should be able to calculate the signature

* Dont emit declaration map when emitting dts files for force emit for signature
2021-03-12 09:44:22 -08:00
Nathan Shively-Sanders
2ea2f4f9a0
Bigint constructor forbids object null undefined (#43204)
* Update es2020.bigint.d.ts

* Update es2020.bigint.d.ts

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* add a test

Co-authored-by: 龙腾道 <LongTengDao@LongTengDao.com>
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-03-11 16:51:03 -08:00
Hai Lin Zhang
e44d39d4eb
Updated error message for TS2539 (#39827)
* Updated error message for TS2539

* Switch to multiple error messages

* inline variable

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-11 15:51:15 -08:00
Sheetal Nandi
9933c8ac7d
Build info baseline improvements (#43200)
* Use ids as 1 based so we can specialize `0` to be some special meaning

* Baseline tsbuildinfo size in the readable baseline

* Baseline fileName and fileNames list as well in readable tsbuildinfo so that new additions are easy to recognize
2021-03-11 13:30:06 -08:00
Wesley Wigham
2643e65da4
Add missing relationship allowing a type to be assignable to a conditional when assignable to both branches (#30639)
* Finally add that missing relationship allowing a type to be assignable to both branches of a conditional

* Explicitly write out Ternary.Maybe

* Add slightly modified example from #25413

* fix sick sentence

* Loosen check to skip false branch constraint check to consider `infer` parameters as always satisfied in the extends clause

* Simplify things a bit, only instantiate once

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-11 11:56:55 -08:00
Nathan Shively-Sanders
b2d1f537f1
Bloomberg computed property name fix (#43197)
* Fix property name bindings for class expr in loops

* Fix block-scope capturing with prop initializers

Co-authored-by: Joey Watts <joey.watts.96@gmail.com>
2021-03-11 10:32:42 -08:00
Matthew Pietz
dcaefe732e
Accept generics for defineProperty (#42424)
* Accept generics for defineProperty

Both `Object.defineProperty()` and `Object.defineProperties()` return their
first argument. Use a generic so that typings can be passed through.

* Update baselines

* update missed baseline

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-11 07:57:42 -08:00
Titian Cernicova-Dragomir
71661b932a
Fixed issue where non null assertion caused getFlowTypeOfReference to return the declared type if the type was already narrowed to never. (#35863)
This was caused by the fact that getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull) will return never both if resultType was already never and if resultType does not contain undefined or null. In the latter case returning the declaring type is correct, in the former case this causes something narrowed to never to still be typed as the original declared type.
2021-03-11 07:33:33 -08:00
Jack Williams
3d6650eb4f
Fix #38608 (#38610)
* Fix #38608

* Work for narrowed non-unions

* Add comment
2021-03-11 07:32:49 -08:00
Ryan Cavanaugh
79d3058b83
Don't crash when renaming a JS property declared via module.exports (#40297)
Fixes #38070

When the originating definition was of the form
```js
module.exports.foo = expr
```
we were incorrectly trying to call `resolveName` on just the `foo` portion to get the "local" symbol, which simply failed to resolve (or would have resolved to the wrong thing), but for this form, the local symbol is just the containing property access expression
2021-03-11 07:23:19 -08:00
Oleksandr T
3c576f108c
fix(41027): handle unused static members (#41103) 2021-03-11 06:39:20 -08:00
Kagami Sascha Rosylight
f4d0ea6539
Add target: ES2021 (#41239)
* Support `target: es2020`

* use CRLF

* update symbols

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-10 13:31:25 -08:00
Wenlu Wang
b20331a4db
Fix missing func modifier (#40379)
* Fix missing function modifier

* Update src/services/refactors/convertArrowFunctionOrFunctionExpression.ts

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-03-10 09:34:31 -08:00
Oleksandr T
b1f86eca3e
fix(42265): Error accessing abstract property in constructor via destructuring (#42276) 2021-03-10 07:26:50 -08:00
Sheetal Nandi
acc8f2fb05
Ensure that when new file affecting global scope is added, the signatures are updated (#43084)
* Ensure that when new file affecting global scope is added, the signatures are updated

* Update src/compiler/builder.ts

* Better comment
2021-03-09 17:40:02 -08:00
Sheetal Nandi
6e4456b3b4
Optimize the size for tsbuildinfo (#43155)
* Baseline readable buildinfo

* Use file names as index in file name list
This is extension of the idea given by @sokra to optimize size of tsbuildinfo

* Deduplicate reference map lists and use file name index to sort them
Different implementation of #43079 based on idea suggested by @sokra

* Minimal json.stringify for the tsbuildinfo
Again implementaion of suggestion by @sokra

* Update src/testRunner/unittests/tsbuild/helpers.ts

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>

* Readable version of buildinfo all the time

* Some renames for readability as per feedback

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2021-03-09 16:15:26 -08:00
Tarik Eshaq
626e78c959
Clearifies protected error message (#42599) 2021-03-09 15:58:31 -08:00
Nathan Shively-Sanders
3d53661605
Don't inherit jsdoc tags from overloaded signatures (#43165)
Previously, when getting jsdoc for signatures, the services layer would
get the jsdoc tags for the base symbol of a signature if it was
present. This is fine except when the base was overloaded. In that case,
the multiple signatures of the overload would all contribute jsdoc,
which is not correct.

A more correct fix would be to resolve overloads to the base, but
the compiler doesn't have this capability and adding it or jury-rigging
it seems like it would be complex, inappropriate for a fix to ship in a
patch version.

Co-authored-by: Orta Therox <git@orta.io>

Co-authored-by: Orta Therox <git@orta.io>
2021-03-09 12:28:36 -08:00
Ron Buckton
ec4863cc0e
Fix37991 (#43166)
* Add failing test

* Fix tslib check errors for commonjs imports
2021-03-09 11:43:19 -08:00
Oleksandr T
9610c16cc8
fix(42380): include JSDoc comments in declarations for static/prototype methods (#42454) 2021-03-09 11:37:40 -08:00
Anders Hejlsberg
f918bd9c76
Exclude enum/number compatibility rule from comparable relation (#42472)
* Exclude old number/enum literal compatibility rule from comparable relation

* Add tests

* Accept new baselines
2021-03-06 06:52:00 -08:00
Anders Hejlsberg
ba56fca0bf
Remove undefined from optional properties when inferring to index signatures (#43086)
* Remove undefined from optional properties when inferring to index signatures

* Add tests
2021-03-06 06:51:02 -08:00
Sang
612a96e161
Update parseInt parameter name and jsdoc (#42756)
* feat(lib): improve parseInt type definition and docstring

* Accepted baselines

* update tests
2021-03-05 11:23:08 -08:00
Jonas Hübotter
25375a2213
Unnecessary elaboration about not being assignable to type parameters (#42952) 2021-03-05 11:15:05 -08:00
Anders Hejlsberg
408c804103
Properly instantiate inferred constraints in conditional types (#42747)
* fix combined type mapper in getConditionalType

* Add regression tests
2021-03-05 07:26:27 -08:00
Daniel Rosenwasser
9862b031b0
Relax requirements on index signatures to 'any' when a type also contains a string index signature to 'any' (#43065)
* Added test.

* Accepted baselines.

* Allow other index signatures to 'any' if there is a string index signature to 'any'.

* Accepted baselines.
2021-03-04 17:42:00 -08:00
Oleksandr T
ca8d9e4402
fix(39836): allow type declaration/unknown type in catch arguments in JavaScript files (#42392) 2021-03-04 17:19:35 -08:00
Ron Buckton
38fdce9440
Expose 'reservedInNestedScopes' option when creating temp and loop variables (#43083) 2021-03-04 15:37:45 -08:00
Nathan Shively-Sanders
e234f0c094
Update the DOM: March 03, 2021 (#43070)
* Update the DOM: March 03, 2021

Mostly Typescript-DOM-lib-generator#915

* update baselines
2021-03-04 06:28:00 -08:00
Klaus Meinhardt
15e69acc20
capture thisArg of optionalChaining in parens (#35494)
Fixes: #35476
2021-03-03 19:35:17 -08:00
Klaus Meinhardt
7751ecb544
fix receiver on calls of imported and exported functions (#35877)
* fix receiver of imported and exported functions

fixes: #35420

* Rebase against master and clean up substitution flow

* Add evaluator tests

* Fix evaluator tests

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-03-03 10:38:32 -08:00
Sheetal Nandi
0cf834ceec
Move fixed chunk size polling as a watch option and move it out of server (#42542)
* Move fixed chunk size polling as a watch option and move it out of server
Fixes #41549

* Feedback
2021-03-02 16:45:53 -08:00
Nathan Shively-Sanders
5dbb110497
Baseline completions and signature help (#43049)
* Initial implementation+first big transitions

* about 10 more

* Change baseline filename + more baselines

1. Use containing file name instead of first @Filename.
2. Switch the rest of the tests I need for @link over to baselines.

* fix lint

* Remove unused/incorrectly named fourslash baselines

* fix incorrectly updated baselines

* dedupe non-unique filenames

* Add names to marker baselines

Also rename another duped test filename.

* Fix semicolon lint
2021-03-02 16:33:32 -08:00
Oleksandr T
f1c911b6c6
fix(43006): skip trivia in a function name (#43021) 2021-03-02 16:32:28 -08:00
Nathan Shively-Sanders
c497b487a7
Add undefined to Symbol.valueDeclaration (#43033)
* About halfway through the checker

I'm going to merge with master to avoid clashing with the declaration
fix.

* Add undefined to Symbol.valueDeclaration

Also add undefined to a number of utility functions that have always
accepted it, but never added it to their type.

* Fix lint from code review

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* remove obsoleted fix from inferFromUsage

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-03-02 12:36:26 -08:00
Zen
3d1c6e8f2f
fix(42765): require should not work in ts files (#42792)
* add failing test

* fix(42765): require should not work in ts files
2021-03-02 06:54:31 -08:00
pushkine
0b337f12b5
Update project.ts (#42900) 2021-03-02 06:37:22 -08:00
pushkine
2834737bc1
typo (#42899)
* Update editorServices.ts

* Fix baselines

Co-authored-by: Orta <git@orta.io>
2021-03-02 06:35:11 -08:00
Andrew Branch
56f95d2a3f
Only filter ignored paths from module specifier generation if there exists a better option (#43024)
* Only filter ignored paths from module specifier generation if there exists a better option

* Nit
2021-03-01 16:12:03 -08:00
Andrew Branch
4b67b4a7bc
Support go-to-definition for imports of arbitrary files (#42539)
* Support go-to-definition for imports of scripts and arbitrary files

* Support go-to-definition for non-existent files

* Add missing file property

* Use `isExternalModuleNameRelative` instead of `!pathIsBareSpecifier`

* Add partial semantic test

* Combine with symbol search for non-source-file file references

* Fix and accept API baselines

* Fix useless or

* A definition is unverified if the file path was a guess, even if a source file has that path
2021-03-01 15:15:09 -08:00
Nathan Shively-Sanders
aa67b16e99
Add undefined to Symbol.declarations' type (#42975)
* Add undefined to Symbol.declarations' type

Symbol.declarations now has type `Declaration[] | undefined`.

I made a mistake somewhere in the checker related to JS checking, so
there are quite a few test failures right now.

* undo clever change to getDeclaringConstructor

* Address PR comments

1. More early-returns.
2. More line breaks.
2021-03-01 14:32:28 -08:00
Andrew Branch
993c503c84
Add 'data' property to completion entry for better coordination between completions and completion details (#42890)
* Add 'data' property to completion entry for better cooperation between completions and completion details

* Add doc comment

* Update API baselines

* Add server test

* Test session’s Full result

* Fix tests

* stableSort to fix server fourslash test

* Explicit verification of data parameter
2021-03-01 12:09:45 -08:00
Andrew Casey
41b5abf342
Tracing: dump more information about types (#42962)
* Tracing: dump more info about substitution types

* Tracing: dump more info about reverse-mapped types

* Tracing: dump more info about destructuring types

* Tracing: dump more info about evolving-array types

* Tracing: dump more info about tuple types

* Tracing: dump more info about type references

* Fix lint errors

* Tracing: extract getLocation helper
2021-03-01 09:22:15 -08:00
Anders Hejlsberg
ef2c98fc35
Optimize checking involving large discriminated union types (#42556)
* No array literal subtype reduction when contextual type is present

* Accept new baselines

* Fast path in relations and filtering of pure discriminated union types

* Create maps for mixed unions, but not for small or primitive only unions

* Create many-to-many mapping with certain limits, also use in CFA

* Use constituent maps in CFA for switch statements, cleanup, add comments

* Revert change to apparent contextual type / better criteria for map eligibility

* Deduplicate array literal element types

* Accept new baselines

* Filter in false case only when discriminant property has unit type

* Only subtype reduce unions with less than 100 distinct types

* Accept new baselines

* Caching and quick discriminant checks in subtype reduction

* Accept new baselines

* Remove deduplication logic now that subtype reduction was optimized
2021-02-28 16:38:20 -08:00
Andrew Branch
3c32f6e154
Fix preserveSourceNewlines sibling node comparison (fixes extra newlines in organize imports) (#42630)
* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* More sophisticated check for source position comparability

* Fix organize imports by looking at the nodes positions

* Rollback formatting changes

* Added tests, fixed organizeImports algorithm

* Fix autoformatting again

* Make sibling node comparison work for all lists

* Don’t run siblingNodePositionsAreComparable at all unless `preserveSourceNewlines` is true

* Move getNodeAtPosition back

* Optimize

* Use node array index check instead of tree walk

* Revert unneeded change

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
Co-authored-by: Armando Aguirre <armanio123@outlook.com>
2021-02-26 10:37:51 -08:00
Ron Buckton
68b0323b72
Refactor emit substitution into transform (#42676)
* Refactor emit substitution into transform

* Add reusable state machine for binary expressions

* Allow emitBinary to use state machine for comments/sourcemaps

* Switch core trampoline state back to arrays

* Switch binder to parallel stacks, temporarily partially revert emitBinary

* Add link to benchmark when posting perf results

* Ensure work stacks are per-execution

* Reenable comments and sourcemaps
2021-02-25 23:01:41 -08:00
Daniel Rosenwasser
df5ffc0ea1
Remove special any assignability for numeric index signatures (#41660)
* Only enable special assignability rule on string index signatures to 'any'.

* Accepted baselines.

* Added test.

* Accepted baselines.

* Renamed test files.

* Add non-erroring version of bclas'subClassThisTypeAssignable01.ts'

* Accepted baselines.

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-02-25 17:36:09 -08:00
Nathan Shively-Sanders
2c5cee59f0
Fix: checkAliasSymbol crash when checking for @deprecated (#42971)
* Fix: checkAliasSymbol crash when checking for @deprecated

It's possible that we shouldn't be creating symbol with no declarations
from non-homomorphic mapped types, but for 4.2, the right fix is to make
the @deprecated-check in checkAliasSymbol ensure that
target.declarations is defined.

* Add bug number and accept baselines
2021-02-25 16:26:16 -08:00
Anders Hejlsberg
ccdd688e4f
Properly handle duplicate enum types in type inference (#42943)
* Ensure no duplicates in named union list

* Add regression test
2021-02-25 13:54:14 -08:00
Orta Therox
a2f09ed4fc
Expose EncodedSemanticClassificationsRequest in protocol.d.ts (#42640)
* Expose EncodedSemanticClassificationsRequest in protocol.d.ts

* Adds the response for encoded semantic highlights too

* Update types:

* Also include classificationtype anyway

* Fix feedback
2021-02-25 21:40:52 +00:00
pushkine
fc64b77b52
Update editorServices.ts (#42951) 2021-02-25 09:00:08 -08:00
Wesley Wigham
3b35522fd0
Type lookup in getIntrinsicAttributestypeFromJsxOpeningLikeElement should match getIntrinsicTagSymbol (#42819) 2021-02-24 22:36:04 -08:00
Armando Aguirre
5c5d374b8d
Merge pull request #42904 from a-tarasyuk/fix/42339
fix(42339): "import" missing in transpiled code when variable typed as `unknown`
2021-02-24 18:25:53 -08:00
Armando Aguirre
0791bb0f84
Merge pull request #42332 from a-tarasyuk/fix/42259
fix(42259): Outline and breadcrumb show wrong namespace name
2021-02-24 17:35:36 -08:00
Oleksandr T
896a2b49ac
fix(42923): add go-to-definition on unresolved shorthand properties (#42924) 2021-02-24 10:53:27 -08:00
Sheetal Nandi
5f5437af66
Do not cache directory structure for symlinked directories (#42868)
Fixes #42839
2021-02-24 09:51:19 -08:00
Andrew Branch
56cf2e68e8
Never-reducing intersections are not untyped function call targets (#42917)
* Never-reducing intersections are not untyped function call targets

* Don’t attempt to reduce union types
2021-02-23 17:22:41 -08:00
Wesley Wigham
8d58c8d90b
Base signatures resolve only the type parameters local to the signature, not all type parameters (#42703) 2021-02-23 16:17:57 -08:00
Wesley Wigham
6da262591c
Bail when comparing a specialized form of an already ongoing comparison (#42727)
* When structurally comparing similar types, check if we are already in the middle of a more general comparison of those same types

* Do the same, but with only string manipulations
2021-02-23 16:13:59 -08:00
Sheetal Nandi
c117c266e0
Refactor to simplify project references tsc-watch and tsserver tests (#42926) 2021-02-23 11:27:16 -08:00
Andrew Branch
2a01f923ca
Improve JSON parser error recovery (#42657)
* Improve JSON parser error recovery

* Add error baselines

* Move tsconfig root checking out of common JSON checking function

* Use new function in parseConfigFileTextToJson

* Fix test

* Replace non-null assertion with explicit debug assertion
2021-02-23 09:31:09 -08:00
Oleksandr T
9de8dbbfb8
fix(42833): add return type to methods with overloads (#42881) 2021-02-23 14:24:47 +00:00
Eli Barzilay
67f55aabd7 Extend the MetaProperty check to work for new.target too 2021-02-22 19:33:01 -05:00
Eli Barzilay
d495957065 Add missing MetaProperty stuffs
Add missing parts in the binder and the checker to enable CFA +
narrowing of `import.meta` values.

Fixes #41468
2021-02-22 19:33:01 -05:00
Wesley Wigham
87d10eb055
Eliminate well known symbols as a concept in the checker and rely on unique symbols (#42543)
* Eliminate well-known symbols in the checker: 2021 edition

* Actually update the lib text to say unique symbol, too (this is unneeded with compat code in place, but this makes goto-def make more sense)

* Add test showing mismatched symbol constructor type interop

* Add more test cases for some other related issues this fixes

* Revert computed name change

* Style comments
2021-02-22 14:43:28 -08:00
Wesley Wigham
5a1d30815b
Combine multiple overloads into a single contextual signature (#42620)
* When noImplicitAny is set, combine multiple contextual overloads into a single signature, rather than producing `any` and an error

* Amalgamate intersection composite signature return types as intersections, rather than the prior exclusively union behavior

* Add another example from an issue, albeit slightly modified

* Fix newlines, add test from DT

* Interior remodelling
2021-02-22 13:34:47 -08:00
Oleksandr T
74e3ad9735 fix(42339): skip return if spread type is wrong 2021-02-21 12:27:46 +02:00
Daniel Rosenwasser
f633446969
Make 'calendar' and 'numberingSystem' open strings in es2020.intl. (#42886) 2021-02-19 12:57:56 -08:00
Nathan Shively-Sanders
0ce5c4a7ee
improve isRequireVariableDeclaration parameters (#42865)
One parameter is always called with `true`, so drop it.
2021-02-19 09:34:05 -08:00
Oleksandr T
e961916217
fix(42368): omit converting jsx spread attributes to Object.assign for ES2018 and up (#42554) 2021-02-18 17:06:08 -08:00
ExE Boss
0723904bfb
feat(lib/es2021): Add type parameter to FinalizationRegistry (#42274)
* feat(lib/es2021): Add type parameter to `FinalizationRegistry`

* test(lib/es2021): Add test for generic `FinalizationRegistry`
2021-02-18 16:43:36 -08:00
ZYSzys
9950b6e596
Improve error messages for computed class property names (#42675) 2021-02-18 15:58:18 -08:00
Titian Cernicova-Dragomir
a2ed469022
Fix for crash when using ca call expression on private identifier coming from an any typed variable. (GH #42860) (#42861) 2021-02-18 13:54:10 -08:00
pushkine
d2737ecd17
Update scriptInfo.ts (#42855) 2021-02-18 10:52:58 -08:00
Andrew Branch
1fd71478f9
Fix duplicate auto-import completions (#42850)
* Fix duplicate auto-import completions

* Update src/services/completions.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-02-18 10:06:37 -08:00
Nathan Shively-Sanders
3d7ec8aab2
Improve @template lookup and resilience (#42851)
* Improve @template lookup and resilience

1. @template parsing may produce a template tag with a type parameter
whose name is the missing identifier. These tags should be skipped
in the checker because they receive an error in the parser.
2. The fix in #37819 was incorrect; there's no such thing as a type
parameter declared on a variable declaration. Instead, there needs to be a type
parameter declared on a jsdoc comment, because that's the scope for tags
like `@return` and `@typedef`.

There are 3 tests because either fix (1) and (2) fix the first test's
failure, but both are required to fix the last two tests' failures.

* remove containsParseError call
2021-02-17 17:21:17 -08:00
Josh Goldberg
c3d7a56e90
Specified diagnostic for iterating known array type without --downlevelIteration (#40070)
* Specified error message for iterating known array types without --downlevelIteration

* Added extra target info to diagnostic

* NodeList too, a classic

* PR feedback: invert to allowsStrings; required param

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-02-17 17:12:32 -08:00
Oleksandr T
7fca9267e6
fix(41740): disallow renaming/exclude from references default keyword (#41947) 2021-02-17 17:07:31 -08:00
Amin Pakseresht
20ce292484
Provide completion for partial expression on closing jsx tags (#42029)
* Provide completion for partial expression on closing jsx tags

* Add more cases and cover opening tag is parent parent of location

* Fix code style indentation

* Add some more notes

* Guarding null pointer

* Guarding null pointer 2

* PR reviews & adjustments 1

* Fix typos

* Better namings

* Remove failing test-case

* PR reviews & adjustments 2 - new approach

* More comments

* More comments 2

* PR reviews & adjustments 3

* Revert previous test-case file changes

* Write explicit completions from ranges

* PR reviews & adjustments 4 - adding exact entry

* Add another missing test-case

* Find jsx closing element by findAncestor

* Walk up till find jsx closing element

* Add one more test-case

* PR reviews & adjustments 4 - Pattern matching to get jsx closing element

* Minor change

* Linting fixes
2021-02-17 17:06:13 -08:00
Ryan Cavanaugh
f5618562ab
Check for missing type parameter names in JSDoc template tags (#42017)
* Check for missing type parameter names in JSDoc template tags

Fixes #36692

* Update baselines
2021-02-17 16:54:56 -08:00
Anders Hejlsberg
412ecbc291
Reduce void | undefined only in conjunction with subtype reduction (#42846)
* Reduce void | undefined only in conjunction with subtype reduction

* Accept new baselines

* Add regression test
2021-02-17 14:48:07 -10:00
Jesse Trinity
d640313ff2
Expand extractSymbol ranges (#42770)
* allow partial selections of node ranges

* separate tests for better failure investigation

* gate span expansion behind invoked command

* add invoked test

* comment wording

* for test
2021-02-17 12:55:12 -08:00
Chakib Ljazouli
3fe05c8c81
fix(37578): Deprecate variable name AllowQualifedNameInPlaceOfIdentifier (#38726)
* Change variable name AllowQualifedNameInPlaceOfIdentifier to AllowQualifiedNameInPlaceOfIdentifier

* Change deleting AllowQualifedNameInPlaceOfIdentifier to deprecating it instead.

* Fix failing tests

* Replace old value
2021-02-16 16:07:44 -08:00
Long Ho
3910d9ede2
fix: fix RelativeTimeFormat type definition (#39661)
* fix: fix RelativeTimeFormat type definition
Changes:
1. Change BCP47LanguageTag to UnicodeBCP47LocaleIdentifier: Those mean 2
different things. BCP47LangTag allows _ as separator while UTS35
doesn't. It also allows grandfathered locales and UTS35 doesn't.

2. Combine RelativeTimeFormat interface and const declaration into a
single class. The old way of declaring as `interface` & `const` permits
calling `Intl.RelativeTimeFormat` without `new` which is no longer
possible after `Intl.DateTimeFormat` & `Intl.NumberFormat`. The spec
explicitly forbids it in
http://ecma-international.org/ecma-402/7.0/index.html#relativetimeformat-objects
where:

> If NewTarget is undefined, throw a TypeError exception.

Intl.RelativeTimeFormat is also extensible per spec. This is closer to a
`class` than the current declaration.

* address feedbacks
2021-02-16 15:56:56 -08:00
Wenlu Wang
d6a32e31ae
Fix import fix on react or react dev (#41950) 2021-02-16 10:28:48 -08:00
Jack Works
bb8b9db9f7 Add error for missing await in conditionals 2021-02-16 12:00:41 -05:00
Oleksandr T
e5294b4d3c
fix(42519): fix infer function return type quick fix with arrow functions without parens (#42532) 2021-02-12 14:38:29 -08:00
Sheetal Nandi
e98f6b07ab
Refactor project references and source map tsserver tests so they are inline for easy editing (#42782) 2021-02-12 14:32:23 -08:00
Nathan Shively-Sanders
5deb676b3a
No did-you-mean-to-call error on casts Part 2 (#42779)
* No did-you-mean-to-call error on casts

I chose to do the ad-hoc check rather than yet another tree walk.

1. It's faster to run and easier to read.
2. This error came from looking at real code. It happened twice, so I
think the best estimate for other uses that happened zero times is in
fact zero.
3. I couldn't think of other places to put the cast, given the
restrictions on `testedNode` just before the new code.

* Skip parentheses
2021-02-12 10:07:59 -08:00
Nathan Shively-Sanders
f2bcb2101b
No did-you-mean-to-call error on casts (#42626)
I chose to do the ad-hoc check rather than yet another tree walk.

1. It's faster to run and easier to read.
2. This error came from looking at real code. It happened twice, so I
think the best estimate for other uses that happened zero times is in
fact zero.
3. I couldn't think of other places to put the cast, given the
restrictions on `testedNode` just before the new code.
2021-02-12 09:36:55 -08:00
Oleksandr T
ff5ae3561f
feat(42735): add single line comments to selection ranges (#42763) 2021-02-11 17:14:55 -08:00
Oleksandr T
475036950e
fix(42133): fix instantiated undefined type from JS initializer (#42662) 2021-02-11 17:07:14 -08:00
Eli Barzilay
c7bac6f2e6 Avoid getting undefined callSignatures/constructSignatures in getPropertyOfType
e350c357 (#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`.  So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.

Fixes #42350
2021-02-11 18:56:47 -05:00
Masato Urai
a3ead92046 Improve error message for overload that takes spread arguments
The original error message on the last line I have added to in
functionParameterArityMismatch.ts was

    No overload expects 5 arguments, but overloads do exist that expect
    either 4 or Infinity arguments.

even if we do not define a function that takes Infinity arguments.

This PR changes it to this:

    Expected 0-6 arguments, but got 5 or more.

I feel it is still a bit strange but much more understandable.

Fixes #42418
2021-02-11 16:49:21 -05:00
Eli Barzilay
4fc9c8446d Refactor the tracing namespace organization
Also changes the `tracingEnabled.Mode.*` enum to a string union.
2021-02-11 16:08:35 -05:00
Oleksandr T
b7922147d3
fix(42714): do not show inferFunctionReturnType QF on function body (#42737) 2021-02-11 10:46:48 -08:00
Daniel Rosenwasser
94747aa4e1
Bump version to 4.3. (#42728) 2021-02-09 17:07:28 -08:00
Sheetal Nandi
5280ba400c
Handle if plugin doesnt specify name (#42717)
Fixes microsoft/vscode#116219
2021-02-09 15:23:29 -08:00
Orta Therox
8c5fa5cc91
Revert assignability cases in getNarrowedType (#42231)
* Revert subtype narrowing changes from readonly array PRs

* Adds a test for the change

* More baselines
2021-02-09 15:03:11 -08:00
Jesse Trinity
1b19af0f14
Refactor params for interface (#42652)
* apply refactor to interface methods

* handle calls

* no available refactors for union type

* add tests

* Update src/services/refactors/convertParamsToDestructuredObject.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* address comments

* Update src/services/refactors/convertParamsToDestructuredObject.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Update src/services/refactors/convertParamsToDestructuredObject.ts

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-02-09 13:30:31 -08:00
Daniel Rosenwasser
664ed17ebd
Allow only package names as plugin names (#42713)
* Allow only package names as plugin names

* Remove extra argument following merge from master branch.

* kipped -> Skipped

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-02-09 11:30:09 -08:00
Eli Barzilay
fe2899c2ac Use a 10ms sampling frequency to filter tracing dumps
Currently hard-wired to 10ms, can be made configurable if needed later.
2021-02-08 17:01:45 -05:00
Eli Barzilay
f462576ac2 Re-do tracing initialization and tests around calls
Make `tracing` either `undefined` or the same namespace as before.
Switching all calls to `tracing?.___` means that there is no cost for
a call or the arguments when tracing is not used.  Comparing two runs
without tracing (27 runs, drop 5+5, avg rest) I get:

    master:
      42.59s user 1.00s system 165% cpu 26.372 total
    changed:
      42.01s user 0.982 system 165% cpu 26.039 total

(Makes it all private, so no api changes.)
2021-02-08 15:41:35 -05:00
Oleksandr T
60a6240210
feat(42637): add generateReturn option to UserPreferences (#42642) 2021-02-05 15:24:48 -08:00
Wesley Wigham
4c43e09c9e
Add fallback error locations for nameless declarations, better class error locations (#42585) 2021-02-05 12:07:14 -08:00
Nathan Shively-Sanders
aba932aefa
Create synthetic exports symbol for commonjs module (#42655)
* Commonjs module:create synthetic exports symbol

Previously, the `module` identifier in commonjs modules got a synthetic
type with a single property `exports`. The exports property reused the
file's symbol, which, for a module file, gives the correct exported
properties.

However, the name of this symbol was still the filename of the file, not
`exports`. This PR creates a synthetic symbol for `exports` by copying
in a similar way to esModuleInterop's `default` symbol in
`resolveESModuleSymbol` (although the intent there is to strip off
signatures from the symbol).

* correct parent of synthetic symbol
2021-02-05 10:56:03 -08:00
Andrew Branch
79ed041b6a
Fix Format Selection on JSDoc comments (#42411) 2021-02-05 10:37:47 -08:00
Nathan Shively-Sanders
f1583f08a0
Signature help turns off current-parameter display for non-trailing rest parameters (#42592)
* Signature help: support non-trailing rest parameters

In signature help, the first rest parameter will always be the *last*
'current' parameter (disregarding types). Previously, the signature help
current-parameter highlight was only correct for trailing rest
parameters. However, with tuple types, you can now create non-trailing
rest parameters. This PR now correctly highlights non-trailing rest
parameters as the last 'current' parameter.

For example, `names` should be the current parameter in all the calls
below:

```ts
declare function loading(...args: [...names: string[], allCaps: boolean, extra: boolean]): void;

leading(/**/
leading('one', /**/
leading('one', 'two', /**/
```

And, because signature help doesn't do real overload resolution, `names`
is also the current parameter for other calls:

```ts
leading(1, 2, 3, 'ill-typed', /**/
leading('fine', true, /**/
```

* Change 'variadic' to 'rest'

* fix missed rename

* use single, original tuple instead

* Revert "use single, original tuple instead"

This reverts commit f0896f32ea.

* Improve sig help of trailing rest too

1. Trailing rest keeps highlight at end instead of going off the end.
2. Non-trailing rest disable highlight entirely (by putting the index
one past the end).

* update API baselines
2021-02-05 09:37:28 -08:00
Wesley Wigham
19db9ad675
Swapping the quote style of a string for completions should swap _all_ quotes in the string (#42650) 2021-02-04 13:56:34 -08:00
Wesley Wigham
f569aa3832
Use a (hopefully) more efficient regex for matching jquery in the safelist (#42653) 2021-02-04 13:53:05 -08:00
Wesley Wigham
62bc8bec4e
Replace _all_ tabs in pretty output, not just the first on each line (#42649) 2021-02-04 13:25:53 -08:00
Wesley Wigham
be18057792
Add check for no match into fs watch rename event handler (#42651) 2021-02-04 13:20:38 -08:00
Anders Hejlsberg
ab2729a99b
Smarter subtype reduction in union types (#42353)
* Exclude primitive types from union subtype reduction in most cases

* Accept new baselines

* Minor fixes

* Less aggressive checking of assertion function calls that don't affect control flow

* Accept new baselines
2021-02-04 11:18:30 -10:00
Andrew Branch
258be217a6
Fix completions crash on transient exported property named 'default' (#42583)
* Fix completions crash on transient exported property named default

* Revert simplification, both conditions were needed
2021-02-04 10:22:15 -08:00
Oleksandr T
4c118ae67b
fix(39022): wrap export references UnaryExpression to ParenthesizedExpression (#41156) 2021-02-03 18:26:33 -08:00
Anders Hejlsberg
e2318217fb
Strip nullable types from 'this' type in inference with optional chain calls (#42536)
* Properly strip nullable types from this type in optional chain calls

* Add regression test
2021-02-03 13:50:23 -10:00
Daniel Rosenwasser
cce4bfbc7c
Revert changes for template literal types, keeping tests. (#42588)
* Revert changes for template literal types, keeping tests.

* Update Baselines and/or Applied Lint Fixes

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-02-03 14:49:03 -08:00
Daniel Rosenwasser
654975481f
Use spaces instead of non-breaking spaces, narrow non-breaking spaces. (#42500) 2021-02-03 14:29:42 -08:00
Sheetal Nandi
c3e132da59
Keep extended config's raw file, include, exclude relative to itself and correct it when setting extending options (#42544)
* Test when config file extends is incorrectly computed
Test for #40720

* Keep extended config's raw file, include, exclude relative to itself and correct it when setting extending options
Fixes #40720
2021-02-03 11:09:06 -08:00
Andrew Branch
1c25b009f2
Sort import fixes by number of directory separators (#42614)
* Add failing test

* Sort all import fixes by number of directory separators
2021-02-03 10:42:13 -08:00
Andrew Branch
96cc9b96fe
Make object literal properties new identifier locations when not contextually typed (#42612)
* Make object literal properties new identifier locations when not contextually typed

* Fix completions after comma in object literal

* Update other test
2021-02-02 16:17:55 -08:00
Andrew Branch
71de94a543
Limit tuple size resulting from spread (#42448)
* Limit tuple size resulting from spread

* Update limit to 10k

* Update baseline after merge conflict
2021-02-02 14:02:35 -08:00
Song Gao
3e28e29c51
fix 38503. (#39716)
* fix 38503.

* trigger test.

* trigger test.

* Move isCallChain

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-02-01 18:34:46 -08:00
Ron Buckton
c953969698
Switched 'ts.performance' to a mixed mode only uses native performance APIs when necessary (#42586)
* Partially revert native performance

* Fix bug in measure

* Conditionally enable native perf events
2021-02-01 15:33:34 -08:00
Andrew Branch
8523ca4fa3
Don’t create missing nodes for identifiers that would be valid in a newer script target (#42520)
* Add test

* Don’t create missing nodes for identifiers that would be valid in a newer script target

* Add to test

* Remove unnecessary assignment
2021-01-29 14:10:29 -08:00
Andrew Branch
d7d7b888b6
Remove Travis CI (#42507)
* Remove Travis CI

* Revert deletion of cron stuff

* Fix formatting
2021-01-29 12:38:26 -08:00
Andrew Branch
9d21a5b56c
Fix indentation of multiline conditional expressions (#42484)
* Fix indentation of multiline conditional expressions

* Add more comment

* Fix comment typo

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* Fix suggestion formatting

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-01-29 12:07:57 -08:00
Andrew Branch
c15f40abfa
Fix discriminant property narrowing through optional chain with null (#42503)
* Fix discriminant property narrowing through optional chain with null

* Accept baselines

* Add tests from Anders
2021-01-29 12:03:42 -08:00
Andrew Branch
65e4d60d81
Fix formatter determination of initial indentation of list items after the first (#42352)
* Add failing test

* Fix determination of initial indentation of list items after the first
2021-01-29 09:49:47 -08:00
Wesley Wigham
2730cb24f5
Only skip any checks for unwrapped tuples in conditionals, rather than all nondistributive conditionals for backcompat (#42447) 2021-01-28 23:36:43 -08:00
Nathan Shively-Sanders
9dbfaeef2d
Narrow QualifiedName inside typeof (#42540)
Previously this wasn't narrowed at all. Now there is control flow and
code in isMatchingReference.
2021-01-28 15:19:01 -08:00
Wesley Wigham
5a21291b7c
Propegate contextual types through nonnull assertion operators (#42526) 2021-01-28 09:24:54 -08:00
Nathan Shively-Sanders
d2443a5df1
@typedef: Improve error spans from declaration emit (#42501)
* @typedef: Improve error spans from declaration emit

This is a proof-of-concept fix. I think it could be expanded for all of
jsdoc, but I only set it up for jsdoc type aliases. It could use a lot
of polish too.

* track error node in isSymbolAccessible instead

* Switch to using enclosingDeclaration

Remove trueErrorNode

* add test of @callback and @enum

* Better error + fix @enum error

Since enums don't have a name property, you *have* to call
`getNameOfDeclaration` to go looking through the AST for one.
2021-01-28 08:35:05 -08:00
Wesley Wigham
203a5ce78f
Include all properties from the mapped modifier type when calculating index types for mapped types with name types (#41976) 2021-01-27 13:32:46 -08:00
Sheetal Nandi
b8faaea90c
Only look for file exists and read file on supported locale directories that we build (#42505)
Fixes #42263
2021-01-26 17:43:37 -08:00
Armando Aguirre
871096b3a1
Merge pull request #42356 from armanio123/FixJSDocFormatting
Fix double asterisk formatting in JSDoc
2021-01-25 15:05:44 -08:00
M.Yoshimura
701493fb80
Support top level "for await of" (#37424)
* Support Top Level "for await of".

* Add test cases for top level "for await of".

* Apply suggestions from code review

* add test cases

* remove redundant variables

* fix test baselines

* Update diagnostic message and tests

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-01-25 13:40:45 -08:00
AnyhowStep
f529115b41
fixes microsoft/TypeScript#41286 (#41294)
* fixes microsoft/TypeScript#41286

* Added period to end of deprecation message

* Search Symbol.declarations for deprecated tag instead of Symbol.valueDeclaration

* renamed arg0 to deprecatedEntity, narrowed param type

* Added different deprecation message if signature is available

* address PR comments

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-01-25 13:33:28 -08:00
Wesley Wigham
d7d8f33def
In bundle declaration emit, refuse to rewrite nonrelative references to files outside the common source directory (#42306) 2021-01-25 11:16:59 -08:00
Sheetal Nandi
1b57a0395e
Fix incorrectly logging ts files instead of .js files as top files (#42463)
Fixes #41071
2021-01-25 10:04:39 -08:00
Nathan Shively-Sanders
ca380af99b
At starts jsdoc tag only after whitespace (#42364)
* Update tests

* @ begins JSDoc tag only after whitespace

Previously, inside a JSDoc tag's comment, @ would start a tag unless it
was surrounded by backticks. However, looking at real code showed that
only whitespace-preceded uses of @ were intended to start tags.
2021-01-25 09:42:24 -08:00
Andrew Branch
89c173fddc
Narrow via discriminant property through optional chain (#42450)
* Naive attempt at narrowing via discriminant property through optional chain

* Clean up test
2021-01-25 09:29:51 -08:00
Amin Pakseresht
290af69b73
Filter out global keywords of UMD module export declarations in completion providing auto import suggestions (#42141)
* Add AutoImportSuggestions for UMD module export declarations instead of global keywords

* Add test for scripts

* Add more comments

* Provide auto import suggestion only for modules and not scripts

* PR review #1

* PR review #1
2021-01-25 09:29:13 -08:00
Orta Therox
154f2094fc
WIP-semantic in session based TS (#42438) 2021-01-23 13:13:56 +00:00
Ron Buckton
ee3fe472d7
Fix broken user and docker tests (#42431)
* Add --force to npm install script for user tests

* Migrate prettier to docker

* Fix vscode Dockerfile

* Fix stack space issue in isJSLiteralType

* Use --legacy-peer-deps based on npm version

* Fix xterm.js Dockerfile
2021-01-22 13:23:41 -08:00
Sheetal Nandi
80dfc6a45b
Only when typings file change for the project, schedule the update for the project (#42428)
* Update and add test when typings dont change because of import name

* Update project scheduling only when typings are set

* Schedule update graph only if typings change
Fixes #39326
2021-01-22 11:16:07 -08:00
Wesley Wigham
71d4ee5d60
Preserve alias information where possible when looking up union and intersection base constraints (#42430) 2021-01-21 13:06:56 -08:00
Matt Kantor
424b805d61
Fix "Cannot find name 'global'. Did you mean 'global'?" (#42262)
* Add tests for "Cannot find name 'global'. Did you mean 'global'?"

* Fix "Cannot find name 'global'. Did you mean 'global'?"

* Add an additional test case for spelling suggestions of "global".

* Name the boolean for suggestions being global scope augmentations.
2021-01-20 15:23:34 -08:00
Andrew Branch
0383b5cb4c
Optimize import fixes for projects with many symlinks (#42150)
* Create symlink cache when a pnpm module is found

* Keep pnpm-internal symlinks out of the symlink cache

* Filter out  pnpm path from realpath module specifier too

* Optimize symlink module specifier generation

* Add trailing directory separators

* Remove unneeded change

* Fix paths losing case in cache

* Fix missing absolutification
2021-01-20 12:15:36 -08:00
Anders Hejlsberg
028f14c507
Filter origin types when filtering union types (#42378)
* When filtering a union type, also filter its origin type, if any

* Accept new baselines
2021-01-20 06:37:02 -10:00
Armando Aguirre
a231b23772 Fix start position on JSDoc parsin 2021-01-19 23:02:56 -08:00
Wesley Wigham
0d494abc77
Add missing unwrap call for the inferredExtendsType (#42409) 2021-01-19 18:02:35 -08:00
Armando Aguirre
98e9e77255 Fixed JSDoc with only one asterisk in comment 2021-01-19 15:55:01 -08:00
Zuckjet
147384c932
Fix typos in comments (#42396) 2021-01-19 09:13:26 -08:00
Anders Hejlsberg
70c82cab75
Include alias type arguments in keys for aliased types (#42365) 2021-01-15 16:00:55 -10:00
Wesley Wigham
ab32fcadbd
Fix type parameter lookup for TypeAlias LibraryManagedAttributes (#42245) 2021-01-15 17:23:01 -08:00
chenjigeng
d1e1e9dccc
Feat/exclude completions of variable initializers (#42087)
* feat: exclude declared variable when Object literal completions

* feat: check undeclareVariable when completion

* feat: add completion test case

* feat: code optimization

* feat: support shorthand property assignment

* feat: add shorthand property assignment test case

* feat: update completionPropertyShorthandForObjectLiteral test cases

* feat: exclude completions of variable initializers

* feat: update test cases

* feat: add completionListWithoutVariableinitializer test case

* feat: perfect the completionListWithoutVariableinitializer test case

* feat: remove isIdentifier limit

* feat: update test cases

* feat: code optimization and filter out some binding cases

* feat: update test case

* feat: handle arrow function expressions without braces

* feat: add arrow function expressions without braces test case

* feat: check node.parent exist first

* feat: optimization name

* feat: optimize test cases

* chore: code formatting

* feat: perfect type
2021-01-15 15:57:18 -08:00
Oleksandr T
8324dec9e9
feat(33715): include methods of class defined in a property (#42164) 2021-01-15 09:52:46 -08:00
Armando Aguirre
995023c2a7 Fix double asterisk formatting in JSDoc 2021-01-14 21:50:22 -08:00
Oleksandr T
c83f769850
fix(41405): allow using property access as reference to function (#41429) 2021-01-14 17:02:48 -08:00
Andrew Branch
33ea6c581a
Fix indentation for closing > of ExpressionWithTypeArguments (#42341) 2021-01-14 14:48:40 -08:00
Oleksandr T
8eaf58fd13 fix(42259): omit merging modules with different names 2021-01-14 15:27:28 +02:00
Chris West
368cdfd29a
fix: const enums + isolatedModules emit invalid code (#41933)
* chore: failing test for const enums and isolatedModules

* fix: const enums + isolatedModules emit invalid code

In `isolatedModules` mode, the compiler does not inline const enums,
but also decides not to `import` them, leaving invalid code that
throws a `ReferenceError` at runtime.

This code:

```
import { SomeEnum } from './bar';
sink(SomeEnum.VALUE);
```

..should compile to either:

```
var { SomeEnum } = require('./bar');
sink(SomeEnum.VALUE);
```

..or (with const enum inlining):

```
sink(1 /* VALUE */);
```

..but actually compiles to:
```
sink(SomeEnum.VALUE);
```

..with no imports, which throws a ReferenceError at runtime.

---

The compiler has already realised that the symbol is a referenced const
enum, it just doesn't use this information when it comes to deciding
whether to emit an import. This commit additionally checks that
information, if we are compiling in isolatedModules mode.

---

In my opinion, this is not the correct fix, but it is the simplest. In
`isolatedModules` mode, `const enum` should probably be a compile error
(because there are no benefits and the complexity is high, and,
apparently, buggy). If not, the compiler should not be checking whether
something is a const enum, and should just be treating it as a regular
enum, and checking as if it was?

Fixes #40499.

* chore: extra test for type-only

* feat: explicitly ban --isolatedModules --preserveConstEnums false

* feat: isolatedModules implies preserveConstEnum

* Update src/compiler/diagnosticMessages.json

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>

* chore: compiler test for argument incompatibility

* Add and fix test for namespace import of const enum

* Fix additional bug with reexport of const-enum-only module

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
Co-authored-by: Andrew Branch <andrew@wheream.io>
2021-01-13 15:51:08 -08:00
Klaus Meinhardt
9171aa5a1b
fix forEachChildRecursively (#42300) 2021-01-13 03:20:46 -08:00
Andrew Branch
33046e389a
Do not suggest paths inside node_modules/.pnpm as module specifiers (#42095)
* Create symlink cache when a pnpm module is found

* Keep pnpm-internal symlinks out of the symlink cache

* Filter out  pnpm path from realpath module specifier too

* Use ignoredPaths instead of pnpm-specific path
2021-01-12 14:04:03 -08:00
Nathan Shively-Sanders
2f5863754f
Improve naming of hasNonBindableDynamicName (#42297)
hasNonBindableDynamicName

1. Has 'non' in the name, and is only ever used negated.
2. Is true for a case that's not reflected correctly in the name -- it's
true for non-dynamic names as well.

I considered hasEarlyOrLateBindableName, but decided to use
hasBindableName for now.
2021-01-12 13:15:54 -08:00
Wesley Wigham
c3dd845923
Better detect when typical nondistributive conditionals need to be defered by unwrapping their check and extends types (#42248) 2021-01-12 12:59:52 -08:00
Oleksandr T
a276a6dce7
feat(31388): allow binding elements starting with an underscore (#41378) 2021-01-12 10:59:08 -08:00
Andrew Branch
b0f5e35777
'in' should not operate on primitive types (#41928 + @andrewbranch) (#42288)
* 'in' should not operate on primitive types

* accept baselines of failing tests

* review

* update error message

* check if constraint of right type is assignable to a non primitive or instantiable non primitive

* do not throw errors where narrowing is impossible

* accept baselines

* fix test case failures

* Add more accurate comment discussion and document failing edge case in test

* Update baselines

Co-authored-by: Jonas Hübotter <jonas.huebotter@gmail.com>
2021-01-11 16:46:08 -08:00
Anders Hejlsberg
c456bbd466
Support re-aliasing of type alias instantiations (#42284)
* New aliases for type alias instantiations

* New aliases for conditional, mapped, and anonymous object type instantiations

* Accept new baselines

* Fix issues with re-aliasing

* Accept new baselines
2021-01-11 13:29:46 -10:00
Oleksandr T
1ecf22884f
fix(42166): allow assertion signature for private identifiers (#42176) 2021-01-11 09:25:51 -08:00
Oleksandr T
1cd8ee4b8d
fix(42088): fix crash on unreachability condition in for statement (#42110) 2021-01-10 15:42:39 -08:00
Anders Hejlsberg
6aeb8c12cc
Preserve type aliases for union and intersection types (#42149)
* Create separate types for equivalent aliased unions

* Accept new baselines

* Preserve original types for union types

* Accept new baselines

* Preserve intersection origin for union types

* Accept new baselines

* Accept new baselines

* Preserve aliases during relationship checks

* Accept new baselines

* Preserve aliases for intersection and indexed access types

* Accept new baselines

* Compute intersection-of-unions cross product without recursion

* Accept new baselines

* Use denormalized type objects for origin / support 'keyof' origins

* Accept new baselines

* Fix fourslash test

* Recursively extract named union types

* Accept new baselines

* Map on union origin in mapType to better preserve aliases and origins

* Remove redundant call

* Accept new baselines

* Revert back to declared type when branches produce equivalent union

* Accept new baselines

* Don't include denormal origin types in regular type statistics

* Fix issue with unions not being marked primitive-only

* Allow new alias to be associated with type alias instantiation

* Accept new baselines

* Revert "Accept new baselines"

This reverts commit 4507270cc1.

* Revert "Allow new alias to be associated with type alias instantiation"

This reverts commit 2c2d06dfe1.
2021-01-08 15:19:58 -10:00
Oleksandr T
0c58edeb29
feat(26217): Add missing member fix should work for missing function (#41215)
* feat(26217): Add missing function declaration QF

* use codeFixAvailable instead of codeFix

* add diagnostics messages 'Method not implemented.' and 'Function not implemented.'

* use codeFixAvailable instead of codeFix

* fix signature types
2021-01-08 16:10:50 -08:00
Sheetal Nandi
66ba15a3fd
If import is used in the file, prefer that import specifier over calculating new one (#42224)
* Test case where the wrong path is emitted

* If import is used in the file, prefer that import specifier over calculating new one
Fixes #39117

* Update Baselines and/or Applied Lint Fixes

* When non-relative path is used as user preference, ignore relative paths even if they are from the existing file

* Fix test

* Add comment

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-01-08 15:20:29 -08:00
Sheetal Nandi
d36df0dda5
Try file if matched pattern specifies the extension instead of all the time (#42246)
* Test case for path mapping with extension

* Try file if matched pattern specifies the extension instead of all the time
Fixes #39743
2021-01-08 12:03:29 -08:00
Orta Therox
055f363fba
Reverts #39277 removing bundledPackageName (#41499)
* Reverts #39277

* Bring back modeyule resolution for the test runner
2021-01-08 10:55:34 +00:00
Oleksandr T
042bf4eb15
feat(14248): add returns tag to JSDoc template (#42068) 2021-01-07 17:57:23 -08:00
Ron Buckton
0d284e6c26
Add support for abstract constructor types (#36392)
* Add support for abstract constructor types

* Add backwards-compatible overloads for creating/updating constructor types

* Reverting use of 'abstract' in lib/es5.d.ts due to eslint issues

* Update baseline due to reverting lib

* Add error for failing to mark an mixin class as abstract

* Fix declaration/quick info for abstract construct signatures
2021-01-07 17:11:14 -08:00
Nathan Shively-Sanders
3273dbc188
Finish #42230 by reverting webworker too (#42250) 2021-01-07 17:10:33 -08:00
Wesley Wigham
11606e4de4
Do for unions of many empty-object-spreadables what we did for unions of 2 (#42233)
* Do for unions of many empty-object-spreadables what we did for unions of 2

* Accept baseline
2021-01-07 12:05:40 -08:00
Andrew Branch
dbba8b358f
Make optional properties assignable to string index signatures (#41921) 2021-01-07 10:46:55 -08:00
Orta Therox
35c8df04ad
Revert the DOM query changes (#42230)
* Revert the DOM query changes

* Adds baselines

* Hotfix for the removeal of the url nullabulity for testing
2021-01-06 22:21:16 +00:00
Ron Buckton
44ec8ddaee
Fix array spread with sideeffects (#41523)
* Fix array spread with sideeffects

* Minor cleanup, ensure multiple emit helpers for outfile tests
2021-01-05 17:24:21 -08:00
Christian
7a5aadca69
Adjust TS2691 message for .ts import sources (#42184)
* Adjust TS2691 message for .ts import sources

* Only ModuleKind is needed for TS2691 logic

* Added tests for TS2691
2021-01-05 11:10:04 -08:00
Anders Hejlsberg
e1fda834f3
Cache complex union and intersection relations (#37910)
* Cache complex union/intersection relations

* Accept new baselines

* Accept new baselines
2021-01-04 15:15:01 -10:00
Anders Hejlsberg
9b1718677a
Leading and middle rest elements in tuple types (#41544)
* Support starting and middle rest elements in tuples

* Accept new baselines

* Include all rest arguments in error span

* Accept new baselines

* Fix tests

* Add new tests

* Fix lint errors
2021-01-04 15:12:51 -10:00
Wesley Wigham
72dfc589a1
Retain CheckFlags.Late on symbols manufactured based on Late-bound symbols (#42205) 2021-01-04 15:49:52 -08:00
Oleksandr T
b405fdd2ab
fix(41420): forbid optional chain in extends/implements (#41481) 2021-01-04 15:38:54 -08:00
Ron Buckton
6fac3ddfd4
Fix module resolution for import call emit (#41390) 2021-01-04 15:08:57 -08:00
Song Gao
b9ac2f50b8
remove duplicated type -- remove TriviaKind, keep TriviaSyntaxKind. (#42108) 2021-01-04 14:34:53 -08:00