Commit graph

15992 commits

Author SHA1 Message Date
Andrew Branch 48aecfa5a5
Consider module augmentations in files referenced by imports in watch/incremental (#45156)
* Consider module augmentations in files referenced by importsin watch/incremental

* Accept baselines

* Accept other baseline

* Hooray optional chaining

* Delete outdated and unuseful comment
2021-07-23 16:32:52 -07:00
Oleksandr T e064817371
feat(42639): allow narrowing type in 'in' operator with the identifier on the left side (#44893) 2021-07-21 09:10:32 -07:00
Ron Buckton 365b25693c
Fix and validate post-increment/decrement in module emit (#44968) 2021-07-19 13:34:42 -07:00
Andrew Branch 36225c3260
Detect preference for Unode:-prefixed node core modules (#45080) 2021-07-19 09:56:24 -07:00
Oleksandr T 1aac3555f7
fix(45049): fix diagnostic for missing property initializer (#45052) 2021-07-16 15:10:42 -07:00
Anders Hejlsberg 193b7494d0
Properly propagate silentNeverType in intersections (#45073)
* Properly propagate silentNeverType in intersections

* Add regression test
2021-07-16 11:20:04 -07:00
Wesley Wigham d0efe9065e
Dont swallow declaration emit errors when issued on nodes without names (#44995) 2021-07-16 10:30:22 -07:00
Oleksandr T 23ebe04563
fix(44902): resolve members in Union or Intersection types (#44904) 2021-07-16 09:07:52 -07:00
Wesley Wigham 8268f2adec
Avoid bogus circularity error on context sensitive constructor property assignments (#44601)
* Avoid bogus circularity error on context sensitive constructor property assignments

* Add JS case and ensure its fixed
2021-07-15 17:06:56 -07:00
Josh Goldberg 541e553163
Specific diagnostic suggestions for unexpected keyword or identifier (#43005)
Error message improvement for unexpected tokens in the following situations:

* A word was parsed that seems to have a low edit distance from a known common keyword
* A word was parsed that seems to be a known common keyword and a name _without_ a space in-between
* Parsing in a particular type of node (mostly a class property declaration) got a different word or token than expected

___

* Specific diagnostic suggestions for unexpected keywords or identifier

* Don't reach into there, that's not allowed

* Improved error when there is already an initializer

* Specific module error message for invalid template literal strings

* Skip 'unexpected keyword or identifier' diagnostics for declare nodes

* Improve error for function calls in type positions

* Switch class properties to old diagnostic

* Corrected errors in class members and reused existing textToKeywordObj map

* Corrected more baselines from the merge

* Update src/compiler/parser.ts

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

* Mostly addressed feedback

* Clarified function call type message

* Split up and clarified parsing vs error functions

* Swap interface name complaints back, and skip new errors on unknown (invalid) tokens

* Used tokenToString, not a raw semicolon

* Inline getExpressionText helper

* Remove remarks in src/compiler/parser.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-07-14 13:50:55 -07:00
jjangga0214 2b8296b7ad
chore(typo): fix comment (#45016) 2021-07-14 09:28:48 -07:00
Jean Pierre 40ec8392a1
Fixes JSDoc @type function with variable args is interpreted incorrectly (#44864)
* Fixes #44386

* Add test

* Move test from fourslash to conformance
2021-07-13 17:17:24 -07:00
caojoshua acdf62fa1e
Fix "Union types are not being narrowed down correctly in 4.3 #44401" (#44771)
* Fix "Union types are not being narrowed down correctly in 4.3 #44401"

* On undefined constraint, add the original type to constraints.
2021-07-13 11:02:18 -07:00
Wesley Wigham 8e855d140b
Watch mode watches for changes in package.json files used in resolution (#44935)
* watch mode watches for changes in package.json files used in resolution

* Pathify result of realpath

* Actually accept pathified baselines
2021-07-12 17:23:08 -07:00
Ron Buckton 66c3063b06
Add collision check for 'Reflect' when using super in static initializers (#44876)
* Add collision check for 'Reflect' when using super in static initializers

* PR feedback

* Accept baseline for new failing test
2021-07-10 12:48:54 -07:00
Oleksandr T a15030ff6f
fix(35050): Decorator emit incorrect within try block (#41951)
* fix(35050): fix decorated block-scoped class emit

* Only use internal name when targeting ES5/3

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-07-08 10:48:02 -07:00
Andrew Branch e881a69939
Detect circularities printing recursive conditional types (#43733) 2021-07-08 09:19:58 -07:00
Ron Buckton 8590f0db40
Fix decorator emit regression for static fields (#44933) 2021-07-07 16:58:36 -07:00
Oleksandr T c0821aeacd
fix(44926): change noImplicitOverride description (#44929) 2021-07-07 18:43:44 +01:00
Anders Hejlsberg 8e01a86c01
Consistently ignore attributes with hyphenated names in JSX (#44873)
* Consistently skip attributes with hyphenated names in JSX

* Add regression test

* Accept new baselines

* Fix tests

* Accept new baselines
2021-07-06 10:29:51 -10:00
Oleksandr T fc5c765f81
fix(44868): handle import type in shorthand assignment (#44881) 2021-07-06 09:29:09 -06:00
Ron Buckton 069650f602
Change PerformanceObserver to be compatible with new Node types (#44884) 2021-07-03 21:26:56 -07:00
Ron Buckton 8b496ed34c
Fix class name reference in class expr (#44877) 2021-07-02 18:37:23 -07:00
Daniel Rosenwasser 248b2c3fc1
Further optional delete corrections (#44862)
* Add more tests.

* Accepted baselines.

* Switch to testing the symbol's flags.

* Accepted baselines.
2021-07-01 18:44:22 -07:00
Daniel Rosenwasser e3d6189e3a
Correctly check for 'delete' on optional properties in 'exactOptionalPropertyTypes'. (#44854)
* Check for optionality in 'delete'.

* Accepted baselines.
2021-07-01 15:19:11 -07:00
Daniel Rosenwasser 9d443b76aa
Update LKG to enable improved narrowing in 4.4. (#44842)
* Update LKG.

* Remove unnecessary assertions.
2021-07-01 12:21:27 -07:00
Zzzen 813ddf7909
ensure export modifier is used before default modifier (#44570)
* ensure export modifier is used before default modifier

* gracefully handle `default function`

* Revert "gracefully handle `default function`"

This reverts commit 1d8e288754.

* give better error message on default without leading export
2021-06-30 09:43:14 -07:00
Oleksandr T 5c8d76347c
fix(44448): disallow 'delete' operator for optional properties (#44612) 2021-06-29 16:56:45 -07:00
Anders Hejlsberg 4c19873b64
Validate symbol-named properties against symbol index signatures (#44815)
* Validate symbols against both symbol and string index signatures

* Add tests

* Accept new baselines
2021-06-29 11:53:07 -10:00
Oleksandr T 114f68cd3d
fix(44725): handle this parameter in tagged template call (#44734) 2021-06-29 14:11:35 -07:00
Anders Hejlsberg 5f8a9e5181
Fix constant reference check in CFA (#44762)
* Check entire access path is constant when narrowing by inlining

* Add tests

* Accept new baselines

* Added test cases for parameter properties.

* Accepted baselines.

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-06-28 16:41:17 -07:00
Andrew Casey c0d5c29080
Reduce exceptions (#44710)
* Don't visit non-existent basePaths

* Stop trying to add file watchers after hitting the system limit

* Update tests
2021-06-28 15:45:35 -07:00
Andrew Branch 54b913cf31
Issue unawaited promise error on symbol-less expressions (#44491)
* Issue unawaited promise error on symbol-less expressions

* Use same behavior for call expressions

* Revert "Use same behavior for call expressions"

This reverts commit 60d58132e4.
2021-06-28 12:35:58 -05:00
Wenlu Wang dc237b317e
Change static fields emits (#43114)
* use emit into iife

* Update emit

* Revert un-related changes

* Allow super in static context

* Allow this and super in static property declaration

* Add more tests

* Avoid errors

* Accept baseline

* Accept baseline

* Add decorated classes test

* Add errors

* Avoid this in emitter

* make lint happy

* Add class expression tests

* Add computed name test

* Avoid super if target below es6

* Adjust function boundary

* Add internal

* Fix minor CR issues

* accept baseline

* Update behavior

* Avoid spaces

* Make lint happy

* Avoid function boundary utils

* Update baseline

* Avoid errors

* Accept baseline

* Accept baseline

* Accept baseline

* Accept baseline

* Use substitutions

* Full coverage for super, this, merge static and private context

* Fix use-before-def in static fields

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-06-25 15:49:27 -07:00
Andrew Branch 328e888a9d
Resolve module specifiers for auto imports in completion list (in incomplete chunks) (#44713)
* Enable module specifiers for all auto imports

* Use isIncomplete

* isIncomplete continuation

* Lots of fixes

* Merged/transient symbol fixes, resolve all ambient module specifiers up front, pull as many as we want from cache

* Fix existing tests

* Start testing

* Add more tests

* Set cache attempt limit, update API baseline

* Fix a few tests

* Fix contextToken

* Split getModuleSpecifiers

* Unexport function

* Clean up importFixes

* Clean up completions

* Delete transient symbol assertion - fixing later
2021-06-25 17:26:53 -05:00
Anders Hejlsberg 8058619aed
Control flow analysis of aliased conditional expressions and discriminants (#44730)
* CFA inlining of conditional expressions referenced by const variables

* Accept new baselines

* Add tests

* Accept new baselines

* Increase inlining limit to 5 levels per design meeting discussion
2021-06-25 13:59:58 -07:00
Wenlu Wang 906cbd2715
Proposal class static block support (#43370)
* Class static block (#9)

* Add types factory and parser

* Add some case

* Make class static block as a container

* Update cases

* Add visitor

* Add emitter and more compile target

* Check boundary of break and continue

* Add basic transformer

* Fix emit behavior

* Add more tests

* Add friend tests

* Update baseline

* Fix cr issues

* Accept baseline

* Add decorator and modifier check

* Add functional boundary check

* Fix conflict

* Fix computed prop name within context

* Add more tests

* Update baseline

* Avoid invalid test baseline

* Support use before initialize check

* wip

* Fix class static block context

* Fix checks

* Fix missing case

* Improve assert message

* Accept baseline

* Avoid new context

* Update diagnostic message

* Fix name collision

* Fix targets

* Avoid unnecessary files

* Add more case

* Add more test cases

* Fix strict mode function declaration

* Avoid private fields initializer if no private identifier references

* Avoid private fields and add more test case

* Add more case

* Add tests and support for related services functionality

* Fix this reference in static block

* Split parser diagnostic and binder diagnostic

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-06-25 09:24:05 -07:00
Wenlu Wang 66b4ba4b35
Add inlay hints support (#42089)
* Add signature arguments label support

* Support rest parameters and destruction

* make lint

* Fix tuple rest parameters

* Adjust name styles

* Rename to inline hints

* Partition inline hints

* Adjust range pred

* Add function expression like hints

* Support configure inline hints

* Display hints in single line

* Add test suits and tests

* Add range tests

* Support more hints

* Add more options

* Fix logical

* Add more cases

* Support call chains

* Rename options

* Match lastest protocol

* Update protocol changes

* Support context value and hover message

* Revert "Support context value and hover message"

This reverts commit 37a7089633.

* Revert "Update protocol changes"

This reverts commit e5ca31bc30.

* Add hover message

* Accept baseline

* Update src/services/inlineHints.ts

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

* Update src/services/inlineHints.ts

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

* Cache across the program

* Fix possible undefined

* Update protocol changes

* Fix missing property

* Make lint happy

* Avoid call chain hints

* I'm bad

* Add whitespace before type

* Add more tests

* Should care about jsdoc

* Support complex rest parameter

* Avoid module symbol  hints

* Care about leading comments

* Fix CR issues

* Avoid changes

* Simplify comments contains

* Fix CR issues

* Accept baseline

* Check parameter name before create regex

* Rename option

* Avoid makers

* Skip parens for argument

* Fix CR issues

* Fix enums

* Accept baseline

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-06-24 23:06:34 -07:00
Zzzen ce8e873bf8
regard TemplateLiteral as discriminant property (#44569) 2021-06-23 15:48:39 -07:00
Tobias Koppers fd49b26025
json modules should not treated as affecting global scope (#44690) 2021-06-23 10:04:25 -07:00
Anders Hejlsberg 61ccc49a7b
Fix check for overwritten properties in object spreads (#44696)
* Fix check for overwritten properties in object spreads

* Accept new baselines

* Add tests

* Accept new baselines
2021-06-22 14:39:33 -07:00
Tobias Koppers 22637a232b
avoid computing a full shape for indirectly invalidated files (#44090)
* add shape updates to baselines

* avoid computing a full shape for indirectly invalidated files

using file version as shape is enough to keep build info valid
and it's much cheaper
2021-06-22 10:33:54 -07:00
Ron Buckton 711b4e778b
Indirect calls for imported functions (#44624)
* Indirect calls for imported functions

* Fix unit tests
2021-06-21 19:51:13 -07:00
Wenlu Wang fafe3ff0b4
Improve parsing in await and yield context (#44680)
* Improve parsing in await and yield context

* Avoid yield and await check in identifier

* Revert "Avoid yield and awaitt check in identifier"

This reverts commit 9644859f29.

* Add some comments
2021-06-21 17:30:55 -07:00
exoticknight 9708022537
Fix 'arguments' check in class field initializer or static initialization block (#44393)
* Fix 'arguments' check in class field initializer or static initialization block

* return errorType

* Merge branch 'master' of https://github.com/exoticknight/TypeScript

* use isInPropertyInitializer

fix Diagnostics message
2021-06-21 16:57:48 -07:00
Jesse Trinity 753feb8707
importModuleSpecifierEnding changes .ts string completions to .js (#44602)
* don't add .ts extensions to imports

* Update src/services/stringCompletions.ts

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

* add other supported extension types

* add final newlines

* adress PR comment

* add unsupported extension test

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2021-06-21 14:43:33 -07:00
Josh Goldberg 0a9b218b11
Report exact position of invalid characters in scanner (#44671) 2021-06-21 14:23:14 -07:00
Anders Hejlsberg 0e905be42b
Index signatures for symbols and template literal strings (#44512)
* Switch index signature storage to 'indexInfos: IndexInfo[]' property

* Accept new baselines

* Remove another usage of IndexKind enum

* Update getIndexedAccessType and resolveMappedTypeMembers

* Accept new baselines

* Update grammar checking for index signatures

* Accept new baselines

* Consider all index signatures in mapped types and union types

* Accept new baselines

* Update getIndexType

* Accept new baselines

* Intersect multiple applicable index signatures

* Use getApplicableIndexInfo instead of hardwired string/number handling

* Update index signature relationship checking

* Report type for which index signature is missing

* Report type for which index signature is missing

* Accept new baselines

* Make 'number' index signatures consistently apply to numeric strings

* Accept new baselines

* Update fourslash test

* Revise index constraint checking

* Accept new baselines

* Update error messages

* Accept new baselines

* Update type inference from index signatures

* Update isKnownProperty

* Update contextual typing based on index signatures

* Accept new baselines

* Support union types in index signature declarations

* Accept new baselines

* Check duplicate index signatures / remove redundant template literals from unions with string

* Accept new baselines

* Include key type in diagnostic / check symbol-named properties

* Accept new baselines

* Minor fix

* Add tests

* Accept new baselines

* Add optimized findApplicableIndexInfoForName

* Accept new baselines

* Another place we don't need to obtain literal type for property name

* Accept new baselines

* Don't create literal types that are going to be discarded

* Individual maps for string, number, bigint, and enum literal types

* Remove ineffective optimizations

* Accept new baselines

* Permit intersections as key types in index signatures

* Index expression in element access is template literal context

* Add tests

* Accept new baselines

* Symbol index signatures from object literals with computed symbol properties

* Accept new baselines

* Add more tests

* Accept new baselines

* Implement Go To Definition for all applicable index signatures

* Add fourslash test

* Accept new API baselines
2021-06-21 11:25:42 -07:00
Oleksandr T f850470d18
fix(44377): omit type alias declarations from JavaScript (#44378) 2021-06-18 14:59:31 -07:00
Ryan Cavanaugh 5afe42e14e
Rename strictOptionalProperties -> exactOptionalPropertyTypes and remove from strict family (#44626) 2021-06-17 15:12:19 -07:00
Oleksandr T eee34d539c
feat(28491): add QF to declare missing properties (#44576) 2021-06-17 11:12:29 -07:00
Andrew Casey 9549928ce9
Make export-module and reference maps invertible (#44402)
* Make export-module and reference maps invertible

Right now, we're enumerating all the entries to find out which keys map
to a corresponding value.  By maintaining a two-way map, we can convert
this linear search into a map lookup and skip allocation of many, many
iterator results.

* Fix lint error

* Add some explanatory comments

* Rename, drop type parameters, and add readonly variant

* Simplify member list

* Fold non-exporting behavior into custom map type
2021-06-17 11:06:42 -07:00
Zzzen 8dbb2cd5fb
allow this in typeQuery (#43898)
* allow `this` in typeQuery

* add tests

* get this type as expression

* handle nested nodes

* update baselines
2021-06-17 07:52:20 -07:00
Anders Hejlsberg d46d82c9bd
Slightly more conservative check in isConstraintPosition function (#44621)
* Slightly more conservative check in isConstraintPosition function

* Update comment

* Add tests
2021-06-16 17:16:32 -07:00
Anders Hejlsberg 97b4063d73
Don't attach declarations to symbols in mapped types with 'as XXX' clauses (#44609)
* Don't attach declarations to symbols in mapped types with 'as XXX' clauses

* Add test (and tweak comment)

Co-authored-by: Eli Barzilay <eli@barzilay.org>
2021-06-16 16:07:33 -07:00
Anders Hejlsberg a3eadfe905
Skip base type checks that can cause circularities (#44615)
* Don't do base type checks that can cause circularities

* Add regression tests
2021-06-16 13:36:43 -07:00
Armando Aguirre d0159a8891
Fix late bound method name assignment, added tests (#43344)
* Fix late bound method name assignment, added tests

* Refactor bindDynamicallyNamedthisPropertyAssignment

* PR comments

* Rollback allowJscheck fix
2021-06-16 12:46:00 -07:00
Song Gao 971133d5d0
New command line help developer experience. (#44157)
* refactor help CLI output.

* fix typo and omit false condition boolean output.

* fix typo

* add line break

* add --plugins option to basic option category.

* add ts icon and remove old print help function.

* better command description for --jsx.

* Fix test

* fix lint

* Improvements to the UX

* Fix tests

* fix test.

* add missing help out.

* use environemnt variable to control test case.

* fix merge issues.

* No `No Category`

* make getWidthOfTerminal optional.

* fix test

* fix review.

* fix review.

* Update baselines

Co-authored-by: Orta <git@orta.io>
2021-06-16 14:18:00 +01:00
Anders Hejlsberg 6bb1f0792b
Fixes to inference and mapped types in --strictOptionalProperties mode (#44595)
* Fix Required<T> and inference to index signatures in --strictOptionalProperties mode

* Add tests

* Accept new baselines
2021-06-15 14:16:38 -07:00
Orta Therox b74b8977d5
Update descriptions for all compiler options (#44409)
* Add new descriptions to compiler options

* Update baselines
2021-06-15 21:20:14 +01:00
Nathan Shively-Sanders e53f19f8f2
Issue "Cannot find name did-you-mean" errors as suggestions in plain JS (#44271)
* Always issue cannot find name did-you-mean error

This PR issues "cannot find ${name}, did you mean ${name}" errors for
identifiers and propery access expressions in JS files *without*
`// @ts-check` and without `// @ts-nocheck`. This brings some benefits of
Typescript's binder to all Javascript users, even those who haven't
opted into Typescript checking.

```js
export var inModule = 1
inmodule.toFixed() // errors on exports

function f() {
    var locals = 2
    locale.toFixed() // errors on locals
}
var object = {
    spaaace: 3
}
object.spaaaace // error on read
object.spaace = 2 // error on write
object.fresh = 12 // OK, no spelling correction to offer
```

To disable the errors, add `// @ts-nocheck` to the file. To get the
normal checkJs experience, add `// @ts-check`.

== Why This Works ==

In a word: precision. This change has low recall &mdash; it misses lots
of correct errors that would be nice to show &mdash; but it has high
precision: almost all the errors it shows are correct. And they come
with a suggested correction.

Here are the ingredients:

1. For unchecked JS files, the compiler suppresses all errors except
two did-you-mean name resolution errors.
2. Did-you-mean spelling correction is already tuned for high
precision/low recall, and doesn't show many bogus errors even in JS.
3. For identifiers, the error is suppressed for suggestions from global files.
These are often DOM feature detection, for example.
4. For property accesses, the error is suppressed for suggestions from
other files, for the same reason.
5. For property accesses, the error is suppressed for `this` property
accesses because the compiler doesn't understand JS constructor
functions well enough.
In particular, it doesn't understand any inheritance patterns.

== Work Remaining ==

1. Code cleanup.
2. Fix a couple of failures in existing tests.
3. Suppress errors on property access suggestions from large objects.
4. Combine (3) and (4) above to suppress errors on suggestions from other, global files.
5. A little more testing on random files to make sure that precision
is good there too.
6. Have people from the regular Code editor meeting test the code and
suggest ideas.

* all (most?) tests pass

* NOW they all pass

* add tonnes of semi-colons

* restore this.x check+add a test case

* make ts-ignore/no-check codefix work in unchecked js

* Issues errors only in the language service

* add a few more tests

* fix incorrect parentheses

* More cleanup in program.ts

* Improve readability of isExcludedJSError

* make diff in program.ts smaller via closure

* Switch unchecked JS did-you-mean to suggestion

Instead of selectively letting errors through.

* undo more missed changes

* disallow ignoring suggestions

* Issue different messages for plain JS than others

Straw text for the messages, I just changed the modals to avoid name
collisions.
2021-06-15 08:54:08 -07:00
Anders Hejlsberg 5540364c12
Correct tuple relations in --strictOptionalProperties mode (#44568)
* Fix relations for optional elements in tuples with --strictOptionalProperties

* Accept new baselines

* Add regression test

* Address CR feedback
2021-06-13 12:53:13 -07:00
Anders Hejlsberg 6a1623d413
Ensure singleton types always compare identical (#44565)
* Singleton types should compare identical + fix boolean types

* Add tests

* Accept new baselines
2021-06-13 12:51:36 -07:00
Ron Buckton a0c44b26b7
Improve __spreadArray perf, and other fixes related to SpreadElement (#44527)
* Improve __spreadArray perf, fix array packing and trailing omitted expressions

* Ensure __spreadArray is backwards-compatible

* Add signature restriction for __spreadArray

* Added reusable true/false literals
2021-06-11 16:21:55 -07:00
Andrew Casey cdd7ffdc56
Make handleDtsMayChangeOf void-returning (#44322)
* Make handleDtsMayChangeOf void-returning

Right now, it always returns false.  This seems important, since
otherwise it would stop graph traversals prematurely.  It took me a
while to figure that out though and I thought it might be clearer if it
were simply void-returning.

I've kept the behavior the same, except in
`forEachReferencingModulesOfExportOfAffectedFile`, where it seemed like
never enqueueing new references was a mistake.

* Make forEachFileAndExportsOfFile void-returning

As far as I can tell, it could only return `false`.
2021-06-11 14:52:52 -07:00
Andrew Branch 7c293c8d46
Include actual generated module specifiers in module specifier cache (#44176)
* Add cache invalidation for node_modules, config, and preferences changes

* Share watches with closed script info

* Update API baseline

* Small adjustments for fewer object allocations

* Document overloaded return value

* Update baselines

* Store isAutoImportable separately from modulePaths

* Add back missing return

* Return wrapped watcher instead of underlying one

* Make user preferences part of the cache key instead of implicitly clearing in editor services

* Fix missed merge conflict
2021-06-10 12:26:32 -05:00
Oleksandr T 591be7bece
feat(44263): add quick fix for misspelled override error (#44266) 2021-06-08 15:17:56 -07:00
Andrew Branch 703c1bc69d
Include type reference directives in symlink cache, wait until program is present to create it (#44259)
* Fix discovery of more pnpm symlinks

* Add some tests

* Never show pnpm paths in auto imports, even if there’s no other path

* Import statement completions can return none

* Fix tests

* Add failing test showing poor symlink cache reuse

* Fix test, fails for right reasons now

* Preserve cache built up during program creation, then fill in with program resolutions

* Remove obsolete comment

* Remove obsolete type assertion

* Revert fully filtering out ignored paths
2021-06-08 12:06:55 -05:00
Sheetal Nandi dab2ffc45a
Add SolutionBuilderHostBase.getCustomTransformers to be used when emitting. (#44489)
This allows not having to specify the transformers during normal watch scneario
Builds on top of #43984
2021-06-07 15:32:39 -07:00
Nathan Shively-Sanders 8e1bf08fa9
Fix duplicate visit of param tag comments (#44443)
Fixes #44422
2021-06-04 12:54:36 -07:00
Paul Gschwendtner b26f77a703
Do not incorrectly add line separators for non-synthetic nodes when emitting node list (#44070)
As of 3c32f6e154, a line separator is
added between nodes if the nodes are not synthetic and on separate
lines. This it push s wrong and previously only happened if the non-synthetic
nodes were on different lines but had the same parent.

Fixes #44068.
2021-06-04 09:46:23 -05:00
Kitson Kelly 4b235eca17
fix: check if sysFormatDiagnosticsHost is defined (#44344)
* fix: check if sysFormatDiagnosticsHost is defined

* improve types
2021-06-03 17:05:48 -07:00
Sheetal Nandi 9df7ecb38b
Handle strict flag when writing tsbuildinfo (#44394)
* Add test showing how setting strict is not preserved in tsbuildinfo
Test for #44305

* Handle strict flag when writing tsbuildinfo
Fixes #44305

* Apply suggestions from code review

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

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-06-03 16:14:58 -07:00
Oleksandr T 31f03f46f2
fix(44273): preserves 'override' modifier in JavaScript output (#44290) 2021-06-03 15:42:19 -07:00
Daniel Rosenwasser 9906092db2
Add flag to change catch variables' default types to unknown (#41013)
* Add test case for 'useUnknownInCatchVariables'.

* Add new 'useUnknownInCatchVariables' flag.

* Accepted baselines.

* Add test for catch variable explicitly typed as 'any'.

* Accepted baselines.

* Move option under 'strict'.

* Accepted baselines.

* 'useUnknownInCatchVariables' is strict in command line help.
2021-06-03 13:12:56 -07:00
Orta Therox 6baa1bec64
Improve non-ambient class and function merge error (#44352)
* Improve non-ambient class and function merge error

* Update baselines

* Update tests

Co-authored-by: Austin Cummings <austin@austincummings.com>
2021-06-03 14:08:04 +01:00
Orta Therox 9d345e7734
Rename TSConfig option categories (#42514)
* Update the category descriptions for the tsconfig options

* Gets tests green

* Whitespace change

* Drop command line options from --init

* Go back to the old re-build baseline

* Fix numbers

* Remove formatting options from --showconfig

* Dpon't show output formatting changes in showConfig

* Update baselines

* Update baselines
2021-06-03 12:21:04 +01:00
Isabel Duan 9c50cb925e
Fixes subset of bugs (three tests fixed) listed in issue #41974 (#44367)
* some fixes for 41974

* linted

* fixed todo messages for readability
2021-06-02 09:32:19 -07:00
Anders Hejlsberg 391f9ffb85
Strict optional properties (#43947)
* Introduce --strictOptionalProperties compiler switch

* Accept new baselines

* Removing missingType when printing back optional properties

* Accept new baselines

* Fix linting issue

* Use getNonMissingTypeOfSymbol in getTypeOfSymbolAtLocation

* Properly elaborate errors involving optional properties

* Accept new baselines

* Properly check optional properties in tuple types

* Accept new baselines

* Add missing tuple type check

* More permissive check of strict optional properties and index signatures

* Add tests

* Fix lint issues

* Accept new baselines
2021-06-01 14:52:16 -07:00
Wesley Wigham 09a21ce7c6
Consider inferences between mapped type templates lower priority (#44126) 2021-05-28 21:07:39 -07:00
Anders Hejlsberg 9aa50d6475
Fix unintended 'as const' name lookup error (#44311)
* Fix logic for methods in isTypeParameterPossiblyReferenced

* Add regression tests
2021-05-27 17:23:28 -07:00
Sheetal Nandi 817e45d1c1
Dont update timestamps of output files if noEmit was specified (#44306)
* Add failing test for #44303

* Dont update timestamps of output files if noEmit was specified.
Fixes #44303
2021-05-27 17:09:30 -07:00
Wesley Wigham 7c31d97cbf
Move string trim methods from utilities to core (#44308) 2021-05-27 14:20:23 -07:00
Sheetal Nandi 8721dd06f1
Add type brands for fileId and fileIdListId (#44280) 2021-05-27 11:15:13 -07:00
Sheetal Nandi 6329a0df90
Add traces for module resolution reuse (#44282) 2021-05-27 11:14:12 -07:00
Sheetal Nandi 32323ce7fb
redirectsTarget is keyed with Path (#44278)
* redirectsTarget is keyed with Path

* sourceFileToPackageName to keyed with Path

* feedback
2021-05-26 16:50:14 -07:00
Sheetal Nandi 2ffd35de4d
More updates to program reuse with different option changes (#44276) 2021-05-26 15:57:43 -07:00
Sheetal Nandi 3442d311cf
Fix outFile check (#44277) 2021-05-26 15:57:30 -07:00
Sheetal Nandi 54fbeb511d
Use correct state when getting it from redirected program (#44275)
Eg. program can backup and restore state changing the state object and we want to release program on the correct one
This ensure program is released correctly when there are declaration emit errors during tsc --build
2021-05-26 15:31:26 -07:00
Nathan Shively-Sanders 459bd19941
Add unqualified JSDoc member references (#44202)
* Add unqualified JSDoc member references

This allows unqualified references like:

```ts
class Zero {
 /** @param buddy Must be {@link D_HORSE} or {@link D_DOG}. */
 deploy(buddy: number) { }
 static D_HORSE = 1
 static D_DOG = 2
}
```

I surveyed @see and @link again to estimate how common this is. I found
a little over 200 uses, which is around 2%. Sorted by frequency, this
*is* the next feature on the list, along with the `module:` prefix.
So I think this is about the right point to stop adding code.

In this case, however, I liked most of the uses -- there were a lot
of deprecated functions that referenced a function just below, where it
would be wordy to qualify the name, but the reader would benefit from a
link.

Note that unqualified references do *not* work inside type or object
literals. The code I ended up with is quite complicated and I didn't
observe any uses in the wild.

Fixes #43595

* Remove type/object literal container check

Since they don't work anyway
2021-05-26 09:54:05 -07:00
Andrew Casey 3ffa245f07
Cache parsed path mapping patterns (#44078)
* Cache parsed path mapping patterns

If a project has many of them (e.g. 1800), parsing the patterns
repeatedly can take up a lot of time.

* Move cache to ConfigFileSpecs

* Inline constants

* Simplify cache access
2021-05-26 09:40:42 -07:00
Oleksandr T 4559855c64
feat(44190): check misspelled base members in override checks (#44213) 2021-05-25 21:24:28 -07:00
Anders Hejlsberg 3938958d36
Properly remove generic types that are constrained to 'null | undefined' in getNonNullableType (#44219)
* Improve getNonNullableType function

* Add tests

* More closely match previous behavior

* Add non-strict mode test
2021-05-25 11:40:28 -07:00
Zzzen 0e1df66a7c
don't duplicate function properties when emiting definitions of overload signatures (#44235) 2021-05-24 15:52:40 -07:00
Wesley Wigham fcabb5c0cc
Simplify or optimize regexes with polynomial time worst cases (#44197)
* Simplify or optimize regexes with polynomial time worst cases

* PR feedback & cleanup

Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com>

* Use builtin scanner function for checking whitespace in fallback method (its faster)

Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com>
2021-05-24 15:28:52 -07:00
Wesley Wigham 2203228b62
Ensure static index signatures have an errorNode available (#44129)
* Ensure static index signatures have an errorNode available

* Lookup static index signature declarations in the right symbol table, stop checking prototype props
2021-05-24 14:30:59 -07:00
Nathan Shively-Sanders c4c6a83922
Add @linkcode and @linkplain tags (#44208)
* Add @linkcode and @linkplain tags

They are just like @link tags but request fixed-width and normal
presentation, respectively.

Fixes #43935

* revert JSDocComment -> JSDoc SyntaxKind rename

* update API baselines

* fix lint
2021-05-24 13:01:58 -07:00
Eli Barzilay fb5f855108 Avoid convertExport when there's a non-identifier or a bogus one
Fixes #44105
2021-05-24 14:24:36 -04:00
Andrew Casey 7954f0c947
Kick out of normalizePath if there's nothing to do (#44173)
* Kick out of normalizePath if there's nothing to do

...using `relativePathSegmentRegExp`.

Bonus: use a regex to handle "/./" to avoid splitting and joining in a
common case.

When building the compiler, for example, it looks like ~95% of arguments
to `normalizePath` do not require any normalization.

* Check normalization before and after . cleanup

* Also cleanup leading ./
2021-05-24 09:38:44 -07:00
ZYSzys eb7c1ada6f
fix: internal createSignature support undefined declaration (#44109) 2021-05-24 06:50:20 -07:00
Zzzen 756392c1f5
support QualifiedName when narrowing inside loops (#43592)
* support QualifiedName when narrowing inside loops

* add test

* narrow more qualified names

* handle `undefined` of `getFlowCacheKey `

* update comments in test
2021-05-21 10:36:54 -07:00
Andrew Casey 14343bead8
Avoid calling replace in normalizeSlashes when it would do nothing (#44100)
* Make normalizeSlashes a no-op there are no bad slashes

On Windows, there will probably be a negligible slowdown, iterating over
the pre-slash prefix of each unnormalized path (though we might come out
ahead if paths are normalized more than once).

On *nix, this saves work - 1.8s -> 0.4s in the project I'm
investigating.

* Reuse already-computed index
2021-05-21 10:28:22 -07:00
Nathan Shively-Sanders 086423729a
Add jsdoc member names: Class#method (#44150)
* Everything mostly works

A couple of mixed, nested references don't work yet.
The scanner+parser interaction is wrong, the parser consumes one too
many spaces, and the checker+services code needs a little cleanup.

* Cleanup

1. I decided that correctly parsing a#b.c, an entity name containing an
instance reference, is not worth the work.
2. I made the scanner, at least the jsdoc part, emit a # token, and
provided a reScanPrivateIdentifier in order to convert #a to # a.
3. I cleaned up the code in the checker.
2. Unrelated: I added a missing space in linkPart display.

* Cleanup lint + var naming

* investigate+clean up a couple of TODOs

* Fix lint in utilities.ts

* change name to JSDocMemberName

* address PR comments
2021-05-21 07:53:17 -07:00
Nathan Shively-Sanders 71cdf6a920
Private identifiers use standard identifier scanning (#44184)
* Private identifiers use standard identifer scanning

Previously they used an old copy of the identifier scanning code that
didn't handle extended unicode yet.

* gotta fix that const lint
2021-05-20 14:39:31 -07:00
Ron Buckton 4ce12f9f65
Move class name capture for private state until after declaration evaluates (#44186) 2021-05-20 14:35:40 -07:00
Andrew Casey 87d0b3e07a
Correct path segment regex (#44149)
The old version incorrectly matched anything with a leading or trailing
slash.  The empty segment should only be detected between two slashes.
2021-05-20 10:54:15 -07:00
Nathan Shively-Sanders 89a737c871
Improve parser recovery for unclosed/mismatched JSX elements (#43780)
* First draft

Everything works, the error messages for unmatched opening elements
could still use improvement, plus there is tonnes of unused and ugly
code.

1. Make sure the parser can recover from all kinds of unclosed tags.
2. Improve the parse tree for unmatched opening tags.
3. Better errors at some point.

* Lots of cleanup

* Improve readability of construction/fix lint

* improve line-length formatting
2021-05-20 07:20:57 -07:00
Nathan Shively-Sanders 4a59b63f35
Error for abstract property with initialiser (#43615)
* Error for abstract property with initialiser

* remove stray LF

* update baselines
2021-05-20 07:18:18 -07:00
Jesse Trinity 5770434891
Revert #43460 and #40884 (#44175)
* Revert "Only issue matching token errors on non-dupe locations (#43460)"

This reverts commit 76a2ae3d69.

* Revert "Adding Diagnostic message for missing ']' and ')' in Array literal and conditional statements (#40884)"

This reverts commit 555ef73da8.

* re-add clobbered merge lines
2021-05-19 16:54:07 -07:00
Anders Hejlsberg e67da8a748
Preserve generics in contextual types for rest arguments (#44122)
* Move all getIndexedAccessType flags to AccessFlags enum

* Preserve generics in contextual types for rest arguments

* Add regression test
2021-05-19 13:46:07 -07:00
Anders Hejlsberg 73736d9b84
Fix logic for determining whether to simplify keyof on mapped types (#44042)
* Fix logic for determining whether to simplify keyof on mapped types

* Add regression test

* Improve hasDistributiveNameType check

* Add more tests

* Address code review feedback

* Add more tests
2021-05-19 13:43:22 -07:00
Oleksandr T db01e84700
feat(eslint): consistent-type-assertions (#43556) 2021-05-18 06:20:57 -07:00
Eli Barzilay fc07ee2ad7 skipParenthesesUp() is exactly the same as walkUpParenthesizedExpressions()
Remove the former since the latter is based on the generel `walkUp()`.
2021-05-18 04:40:56 -04:00
David Michon 9136bb13fe
Generate SourceMap mappings string using array of character codes and fewer String.fromCharCode calls (#44031)
* Test normal char code array for source mappings

* Limit buffer size, minor performance tweaks

* Always commit at exactly chunk size

Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com>
2021-05-17 18:16:32 -07:00
Wesley Wigham f414d13679
Dont allow generic narrowing when contextually typed by a binding pattern (#44081) 2021-05-13 16:51:52 -07:00
Wesley Wigham f7a97b7759
Cache accessibe symbol chains and serialized type parameter name generation (#43973)
* Cache accessibe symbol chains, type parameter name generation

* Move signature declaration helper length approximation to start of function

* Add node result caching internal to `typeToTypeNodeHelper`

* Suggestion from PR
2021-05-12 12:11:20 -07:00
Oleksandr T 7aacd6b274
fix(43879): forbid async in the left hand in a for-of statement (#43886) 2021-05-12 06:11:08 -07:00
Oleksandr T 463c79440f
fix(43030): fix instantiated null/undefined type from JS initializer (#43933) 2021-05-11 15:57:16 -07:00
Daniel Rosenwasser d662d94957
Bump version to 4.4. (#44028)
* Bump version to 4.4.

* Update Baselines and/or Applied Lint Fixes

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-05-10 12:42:48 -07:00
Wenlu Wang 5b1e873b03
Update diagnostic message and quickfix for parameter property (#44010) 2021-05-08 23:22:20 -07:00
Sheetal Nandi e61d812cbb
Update the type reference cache with correct project options (#44004) 2021-05-07 16:58:41 -07:00
Anders Hejlsberg 42f0cf6ffc
Don't eagerly get apparent type of spread expression contextual type (#44002)
* Don't get apparent type of contextual type for spread expressions

* Add regression test
2021-05-07 15:44:17 -07:00
Ron Buckton cb9cd898d1
Revert #35877 - fix receiver on calls of imported and exported functions (#43993) 2021-05-07 13:42:12 -07:00
Sheetal Nandi e5395efe49
Add writeFile and customTransformers to build and buildReferences (#43984) 2021-05-07 12:13:17 -07:00
Sheetal Nandi cfed79b7a2
Correctly use ownMap from module resolution cache (#43986)
* Test showing the moduleResolutionCache reset issue with tsc --b --w

* Fix incorrect usage of ownMap by making it function returning ownMap instead of constant value
2021-05-07 09:56:29 -07:00
Nathan Shively-Sanders f6303652d2
Improve errors for incorrectly nested export default (#43967)
* Improve errors for incorrectly nested export default

The compiler and services don't handle incorrectly nested
`export default` well right now:

```ts
export = (x,y) => {
  export default { }
}
```

Asking for document highlights, find all references or quick info on
'export' or 'default' cause a crash. After the crash is fixed, the error
message is confusing and wrong: "An export assignment cannot be used outside a module."

This PR:

1. Skips document highlights for incorrectly nested export default.
2. Skips find all refs for incorrectly nested export default.
3. Switches the fallback binding for incorrectly nested export default
from Alias to Property. Neither is correct, but Property doesn't cause a
crash in alias resolution.
4. Improves the error message to reflect a post-ES module world, which
has export default and 'module' means 'ES module', not 'namespace'.

Fixes #40082 and the related bugs mentioned above.

* address PR comments
2021-05-07 08:09:38 -07:00
Andrew Casey 1ce15a4531
Fix perf regression from #42556 (#43949)
PR #42556 was a nice optimization that dramatically sped up comparisons of discriminated unions.  Unfortunately, the cost of determining whether a union is discriminated can be prohibitively high.  In particular, an internal team with a very large repo saw their type count double and their memory usage increase from 6GB to 9GB, breaking their build.  This changes splits the difference by not trying to compute the property types of intersection types - a notoriously slow operation.
2021-05-06 17:06:38 -07:00
Andrew Branch 96c48b746a
Fix package.json auto imports for pnpm without project references (#43892)
* Fix package.json auto imports for pnpm without project references

* Make property optional

* Revert unnecessary unnittest change

* Set symlinked files when setting symlinked directories

* Update `typeDirectiveIsEqualTo`

* Consider symlinks found during type reference directive resolution into `discoverProbableSymlinks`

* Rename `originalFileName` to `originalPath`, make internal
2021-05-06 14:51:30 -07:00
Nathan Shively-Sanders 71f338bad6
Revert "typeRelatedToSomeType passes through intersectionState (#43707)" (#43983)
This reverts commit db09cb5951.
2021-05-06 13:12:36 -07:00
Wesley Wigham a5607a4eab
Dont allow namespace reexport symbols when looking up valid local names (#43969) 2021-05-06 12:03:48 -07:00
Sheetal Nandi 233f28ca27
When directory watcher is invoked with any file from node_modules package, invalidate for file paths in that package (#43974)
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-05-06 09:48:26 -07:00
Ikko Ashimine 97f5c62956
Fix typo in system.ts (#43895)
assigment -> assignment
2021-05-06 01:40:00 -07:00
Wesley Wigham 456806b070
Allow filterType to consider union constraints of non-union types when determining never-ness (#43763)
* Allow filterType to consider union constraints of non-union types when determining never-ness

* Move impl to callback

* Baseline change in narrowing behavior into test, fix post-LKG build
2021-05-05 13:35:09 -07:00
Wesley Wigham b83148fe64
Unwrap substitutions on conditional check types before comparing them (#43888) 2021-05-05 13:33:45 -07:00
Wesley Wigham 84da19efc8
Add single-element fastpath to getSupertypeOrUnion (#43934) 2021-05-05 13:32:23 -07:00
Sheetal Nandi f7ef1540d3
Use options from referenced project for including resolved imports in the file when using sources of project reference (#43914)
* Test where allowJs present in referenced project affects picking up right set of import files

* use options from referened project for including resolved imports in the file when using sources of project reference
Fixes #43909
2021-05-03 11:35:21 -07:00
Sheetal Nandi 54096bdb96
Use project relative preference for declaration emit (#42232)
* Test where relative import isnt ideal in the declaration emit

* use project relative preference for declaration emit
Fixes #39117

* Fix incorrect path matching when calculating module specifier

* Use correct baseUrl for the module specifier
2021-04-30 13:22:05 -07:00
Sheetal Nandi c96b472e0b
Handle localness in special cases by checking exported variable assignment (#43851)
* Handle localness in special cases by checking exported variable assignment
Fixes #42976

* Fix existing tests where arrow now behaves similar to function expression

* Update src/services/goToDefinition.ts
2021-04-30 13:17:59 -07:00
Nathan Shively-Sanders c9eb62fafb
getExternalModuleMember:always resolve alias of moduleSymbol (#43718)
Previously, getExternalModuleMember passed through its received value of
`dontResolveAlias` to every function that accepted it. That includes (1)
resolution of the module symbol and (2) resolution of the module
specifier. However, in TS, the module symbol is never an alias anyway, so
dontResolveAlias doesn't make a difference. In JS, the module symbol
*can* be an alias, and it should always be resolved. That's what this PR
does.

Fixes #43713
2021-04-30 10:47:45 -07:00
Nathan Shively-Sanders 004b3ae018
Simplify arity errors, rewording spread errors (#43855)
* Scribbles + tests

The second test actually requires node types

* Basically working

The two simple fixes, in arity error reporting, are in, and the
simplification of arity error reporting is half-done. I haven't started
on any improvements to call assignability.

* trim out too-real test case

* Finish cleanup

And reword error a little.

* Simplify and reword spread errors

* handle spreads first

* update baselines

* Address PR comments
2021-04-29 14:38:50 -07:00
Oleksandr T 3e25424652
fix(43408): emit nullable/optional types on getters (#43476) 2021-04-29 09:20:40 -07:00
Acy Watson b31b0eb05c
Use single quotes consistently in diagnostic messages. (#43634) 2021-04-29 07:15:31 -07:00
Andrew Branch a14b22718a
Enforce keyword order of abstract and override (#43829)
* Enforce keyword order of abstract and override

* Update baselines

* Update existing test
2021-04-28 16:41:28 -07:00
Andrew Branch 791c747e06
Allow override as parameter property (#43831)
* Allow `override` as parameter property

* Update other baseline

* Add test for override on normal parameter

* Copy typo fix

* Update baselines

* Update API baseline
2021-04-28 16:41:09 -07:00
Nathan Shively-Sanders db09cb5951
typeRelatedToSomeType passes through intersectionState (#43707)
* typeRelatedToSomeType passes through intersectionState

Previously it didn't, even though it should have.

* fix parameter name lint
2021-04-28 16:12:20 -07:00
Andrew Branch 58c54127a9
Fix node.getStart() for nodes spanning multiline JSDoc comments (#43854) 2021-04-28 11:37:27 -07:00
Wesley Wigham 7748694d60
Relate non-augmenting subtypes without resorting to structural comparison (#43624)
* Relate non-augmenting array subtypes without resorting to structural comparison

* Fix lint

* Generalize performance enhancement

* Cache results, feed through via getNormalizedType to remove error intermediates

* Use newly freed up object flags to limit member setting, fix crash with those object flags

* Move flags because there is no TypeFlags.Reference 🤦
2021-04-27 22:52:12 -07:00
Wesley Wigham 5e4fcfbfb6
Add instantiation rules for reverse mapped types (#42449)
* Add instantiation rules for reverse mapped types

* Add smaller example of same issue
2021-04-27 15:01:46 -07:00
Wesley Wigham bbad560912
Refrain from attempting to perform parameter fixing on a generic signature multiple times (#43835)
* Refrain from attempting to perform parameter fixing on a generic signature multiple times

* Remove assertion
2021-04-27 10:49:27 -07:00
Nathan Shively-Sanders d5af89c552
Contextual typing checks property assignments for type annotation (#43598)
Property assignments can have a type annotation in JS. This PR adds a
check for it in contextual typing.

Fixes #43379
2021-04-26 09:19:24 -07:00
Andrew Branch b9c1e98544
Fix completions of exports elsewhere in same file (#43755)
* Fix completions of exports elsewhere in same file

* Undo messing up JSDoc-annotated module.exports assignments

* Add other failing contextual type test

* Rearrange contextual type logic for special assignments

* Rename helper function
2021-04-26 09:13:09 -07:00
Erik Brinkman 4d4ea66a9c
update contextual discrimination to include omitted members (#43633)
This diff extends the types checked by
discriminateContextualTypeByObjectMembers and
discriminateContextualTypeByJSXAttributes to also include any optional
components in the type union.

fixes #41759 although it doesn't address the better error reporting for
their last repro, which I'm not sure how to address.
2021-04-24 14:26:29 -07:00
Wesley Wigham dee4903f45
Compute dervied generic-ness for substitutions and create lower priority inferences for substitutes (#43765) 2021-04-23 15:51:05 -07:00
Andrew Branch bd7d0f26b2
Don’t allow an object literal with a spread as a fallback for destructuring a property not present in all constituents (#43783)
* Add test

* Don’t allow an object literal with a spread as a fallback for destructuring a property not present in all constituents
2021-04-23 14:44:57 -07:00
Sheetal Nandi f6d425e1e3
Module Resolution and Type Reference directive cache updates and its API changes (#43700)
* Make the module resolution cache apis for updating compiler options or clearing it

* Cache package.json lookup results from module resolution

* Use per directory cache for type reference directive resolution as well

* Update Baselines and/or Applied Lint Fixes

* Change trace according to feedback

* Update Baselines and/or Applied Lint Fixes

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-04-21 21:30:18 -07:00
Sheetal Nandi fb0b1d7295
Handle getter setter quickInfo (#43769)
Fixes #43413
2021-04-21 17:47:11 -07:00
Wesley Wigham f4b8adca6a
Comment copy edit 2021-04-21 12:51:36 -07:00
Wesley Wigham 8ea4ec9496
Add infer T constraint inference rule matching up mapped type templates across check/extends types (#43649) 2021-04-21 12:49:02 -07:00
Tiago Tristao 3d24b85f9e
Completion list for type literals in type arguments (#43526)
* Completion list for type literals in type arguments

* Add tests

* Refactor for better readability

* - Support non-identifier keys
- Move main logic onto tryGetGlobalSymbols function
2021-04-20 10:24:17 -07:00
Armando Aguirre f67ee44379
Instantiate getter when infering setter parameter value (#43564)
* Instantiate getter when infering setter parameter value

* Use esnext on tests

* Instantiate for JsDoc and getter from body

* PR comments

* Updated baseline
2021-04-19 23:23:40 -07:00
Wesley Wigham 167ebcd93b
Check type flags before checking multiple-meaning object flags (#43745) 2021-04-19 22:35:11 -07:00
Wesley Wigham 7e4400b9c3
Stop checking getter/setter compatability twice (#43741)
* Stop checking getter/setter compatability twice

* Ensure modifier errors are still emitted on both accessors, accept modified baselines
2021-04-19 15:53:48 -07:00
Anders Hejlsberg 52ec8ce740
Clean up ObjectFlags enum (#43732)
* Clean up ObjectFlags enum

* Accept new baselines
2021-04-19 15:33:36 -07:00
Wesley Wigham 85c9d2cc89
Use faster, stricter prop type comparison when merging props in union prop creation (#43696)
* Use faster, stricter prop type comparison when merging props in union prop creation

* Be better at determining this usage in methods, accept baselines

* Small style change
2021-04-19 15:25:12 -07:00
Andrew Casey c671fe1bc2
Skip up-to-date checks during force build (#43666)
* Skip up-to-date checks during force build

Save work by not checking timestamps or parsing the buildinfo file.
Retain correctness checks (like input file existence).

Suppress project status, which was confusing anyway.

* Print a message to indicate that --force is causing the rebuild

* Don't bother updating buildInfoChecked

* Add missing force check
2021-04-19 13:06:00 -07:00
Ron Buckton e0d551606f
Remove preprinter, add parenthesizer callback to emit (#43652) 2021-04-19 09:34:46 -07:00
Ryan Cavanaugh b1ab2b98be
Wire up 'writing' parameter through protected derived class detection (#43455)
Fixes #43443
2021-04-19 09:20:21 -07:00
Anders Hejlsberg 0f2dabcd4b
Don't re-alias top-level type aliases with local type aliases (#43701)
* No re-aliasing of top-level type aliases with local type aliases

* Accept new baselines
2021-04-17 07:07:46 -07:00
Sheetal Nandi 01264ac414
Reducing tsbuildinfo size further (#43695)
* Serialize compiler options that are needed from old state when creating new state

* Dont write affectsGlobalScope if not true

* Encode FileInfo for better serialization size

* Update src/compiler/builder.ts

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-04-16 23:22:14 -07:00
Wesley Wigham 0eee64f0eb
Node factory should insert override modifier between static and astnc (#43699) 2021-04-15 17:16:19 -07:00
Andrew Branch 06f25c0390
Enforce keyword order between override and static/async (#43660)
* Enforce keyword order between override and static/async

* Update old tests for new keyword order
2021-04-15 14:03:53 -07:00
Nathan Shively-Sanders 0987ee9e0e
Do not erase signatures in getSignatureOfTypeTag (#43688)
I don't see a reason for it, and it doesn't cause any tests to fail.
2021-04-15 10:53:23 -07:00
Nathan Shively-Sanders 3f93d420bf
Fix @typedef/@callback scope (#43682)
JSDoc typedefs don't actually have hosts, because they're not
semantically attached to a declaration. However, the parser still
attaches them to some declaration (or statement), but that declaration
is not related to the typedef.

Previously, delayedBindJSDocTypedefTag used getJSDocHost to walk past
the unrelated declaration, but #41858 correctly started categorising
typedefs as unattached, with no host, so the binder began falling
back to file scope.

The path to skip the unrelated declaration is always the same, though, so this
PR uses `typeAlias.parent.parent` instead of `getJSDocHost(typeAlias)`.
2021-04-14 16:56:37 -07:00
Wesley Wigham 3ab6809e38
Consider identical instances of the same symbol equivalent when creating union and intersection properties (#43560)
* Consider identical instances of the same symbol equivalent when creating union and intersection properties

* Also copy over mapper and type (if available) on cloned symbols

* Editorial feedback
2021-04-14 16:55:45 -07:00
Wesley Wigham 6c7c5e9ec2
Expand exception to contravariant constraint elision to all type variables (#43599)
* Expand exception to contravariant constraint elision to all type variables

* Comment update
2021-04-14 13:13:02 -07:00
Oleksandr T e87a0be959
fix(43444): add support JSDoc function signatures on returned function expressions (#43607)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-04-13 16:11:58 -07:00
Nathan Shively-Sanders 6a3d68905c
Add jsdoc to all js statements (#43659)
* Add jsdoc to if statements

This should only happen in JS files, however, and there needs to be some
conditional handling of jsdoc on statements that can't have jsdoc in TS
files.

* Finish change

* Add test
2021-04-13 15:30:22 -07:00
Anders Hejlsberg 5977233fd1
Reinstate constraint check for template literal types (#43661)
* Add missing constraint check for template literal types

* Add regression test
2021-04-13 12:17:55 -10:00
Wesley Wigham 6002cff776
Trim indexed access and type variable constraint error output (#43540) 2021-04-13 13:13:32 -07:00
Andrew Branch 06a73655d0
Don’t error for missing await when promise is referenced in condition body (#43593) 2021-04-13 12:15:48 -07:00
Nathan Shively-Sanders d6012219e0
@link and @see resolve C.m as a class property reference (#43625)
* Test + Initial scribbles

The test is pretty good, the scribbles are actually cleanup from last
PR, although they break some tests.

* undo scribbles, add nonworking class-hack

* Ad-hoc name resolution for @link and @see

Turns out that you can't reuse check* functions if you want to retrieve
all meanings of a reference.

* fix failing test

* inline hapax function

* Fix find-all-refs baseline print

* Try to resolve C.m as static first

* Add interface tests

Co-authored-by: Andrew Branch <andrew@wheream.io>
2021-04-13 08:13:18 -07:00
Nathan Shively-Sanders 7c10135d9d
Don't start jsdoc tag before whitespace (#43602)
Fixes #43580
2021-04-12 10:20:44 -07:00
Wenlu Wang b0c2860a68
ignore static and declared member if checking override (#43569)
* ignore static member if checking override

* Ignore declared member when check override

* Check static override too

* Add more tests
2021-04-09 10:43:33 -07:00
Sheetal Nandi 75e9c94e50
While writing tsbuildinfo sort the properties of compiler options to make sure they stay same if nothing changes. (#43601)
Fixes #43571
2021-04-08 16:32:09 -07:00
Josh Goldberg fe4a6709da
Specified diagnostic for CLI flags mismatched with/out --build (#43199)
* Specified diagnostic for CLI flags missing a required --build

* Switched to an alternateMode member

* Added --build-incompatible flags too

* Small fixups to remove a hardcoding

* Switched to ||= factories

* Not a function

* I think I get it now
2021-04-07 16:03:17 -07:00
Anders Hejlsberg d41943eb4e
Properly handle tagged primitives in control flow analysis (#43538)
* Ignore object types in intersections with primitive types

* Add regression test

* Also handle instantiable types constrained to object types

* Add another test

* Add ignoreObjects optional parameter to getTypeFacts
2021-04-07 11:29:46 -10:00
Josh Goldberg a4c683be12
Again: Improve error messages for empty DOM interface property access (#43007)
* Again: Improve error messages for empty DOM interface property access

* containerSeemsToBeEmptyDomElement

Co-authored-by: Daniel Rosenwasser <drosenwasser@microsoft.com>

* isEmptyObjectType; unescapeLeadingUnderscores

* Single tick quotes for now

* Undo accidental diagnostic change

* Correct new baseline

Co-authored-by: Daniel Rosenwasser <drosenwasser@microsoft.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-04-07 12:54:27 -07:00
Josh Goldberg 905a1fea39
Corrected parsing for decorators on 'this' parameters (#43175)
* Corrected parsing for decorators on 'this' parameters

* Moved checking to parser and added a specific test

* Remove unrelated checker.ts blank line

* Missed some baseeline updates...
2021-04-07 11:21:28 -07:00
Titian Cernicova-Dragomir 2484210a00
Gh 41788 incorrect output for esprivate with nested class in esnext (#42663)
* If target:esnext,then useDefineForClassFields: true will now be the default.

* Added error if a private identifier is used in a static a initializer if target:ESNext and useDefineForClassFields:false.

* Added test for new useDefineForClassFields default and error message.

* Fixed tests after changing the default of useDefineForClassFields to true for target esnext

* Fixed code review suggestions.

* Updated error message.

* Added missing static check for the containing property. Fixed other code review issues.
2021-04-07 08:23:16 -07:00
Nathan Shively-Sanders 2bb54dc11a
Fix getTypeFromJSDocVariadicType in callback tag (#43562)
* Fix getTypeFromJSDocVariadicType in @callback

Variadics have never worked there, I think.

* add test + fix lint

* remove outdated comment
2021-04-07 08:12:05 -07:00
Nathan Shively-Sanders dd1ef88d01
Use control flow to type CommonJS exports (#42751)
* Allow redeclaring CommonJS alias with initial undefined

This allows us to read our own output, plus the times when people
manually write exactly the same pattern.

Fixes #40555

* Use control flow to type commonjs exports

1. Could probably use a *lot* more tests.
2. getTypeOfAlias redoes some work from resolveAlias because it needs to
not resolve the alias completely, just to its export.

* fix lint, improve jsdoc

* Add tests, improve+fix control flow

1. Update the module.exports test to match the exports ones.
2. Add a test of evolving commonjs type.
3. Add a test of assignment as last statement.

(1) exposed a bug that required a better synthetic reference. (3)
exposed a bug that was most easily fixed by giving source files a
`endFlowNode` like functions and setting it in the binder.

* fix lint
2021-04-06 17:07:35 -07:00
Oleksandr T 3a22b3e701
fix(43535): preserves 'override' modifier in JavaScript output (#43536) 2021-04-06 11:31:54 -07:00
Pig Fang fb87079994
Enforce override precedes readonly (#43545) 2021-04-06 08:48:44 -07:00
Oleksandr T 8581a592bb
fix(43347): fix crash occurred when export type to existing commonJs imported name (#43369) 2021-04-06 08:46:22 -07:00
Wenlu Wang f526a38856
Always grammar checker for override (#43544) 2021-04-06 07:29:57 -07:00
Zen 3cf26e44ee
fix(43160): improve error location for functions without explicit return (#43367)
* fix(43160): improve error location for functions without explicit return

* handle functions returning never
2021-04-06 07:21:02 -07:00
Song Gao 2d66517312
fix quickinfo of narrowed private filed (#43356)
* fix quickinfo of narrowed private filed

* add test case.

* adapt review.
2021-04-05 13:24:19 -07:00
Anders Hejlsberg a7a010a994
Fix getRecursionIdentity function to always return some identity (#43527)
* Fix getRecursionIdentity, undo changes from #43435 (but keep tests)

* Remove test that takes excessively long to run

* Accept new baselines

* Fix formatting

* Add regression tests

* Reinstate test
2021-04-05 09:53:38 -10:00
Wesley Wigham cf8798d977
Make origin union cache key unique for key lists still under construction (#43339) 2021-04-05 11:47:49 -07:00
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