3640 Commits

Author SHA1 Message Date
TypeScript Bot
7b14d41642
Cherry-pick PR #43024 into release-4.2 (#43032)
Component commits:
bd2fd3b5e0 Only filter ignored paths from module specifier generation if there exists a better option

a687bae32b Nit

7597f5236f Merge branch 'master' into bug/42785

Co-authored-by: Andrew Branch <andrew@wheream.io>
2021-03-01 16:39:34 -08:00
TypeScript Bot
d9710135fc
Cherry-pick PR #42971 into release-4.2 (#42972)
Component commits:
9f9825a4f0 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.

75449de4be Add bug number and accept baselines

Co-authored-by: Nathan Shively-Sanders <nathansa@microsoft.com>
2021-02-25 16:54:58 -08:00
TypeScript Bot
08ad0e2b88
Cherry-pick PR #42943 into release-4.2 (#42964)
Component commits:
361e19bbe8 Ensure no duplicates in named union list

615050437b Add regression test

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
2021-02-25 14:18:56 -08:00
TypeScript Bot
57ba6ddaee
Cherry-pick PR #42846 into release-4.2 (#42852)
Component commits:
0edae127ae Reduce void | undefined only in conjunction with subtype reduction

6b487a6db5 Accept new baselines

e7b6601de7 Add regression test

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
2021-02-17 17:48:43 -08:00
TypeScript Bot
16f2556473
Cherry-pick PR #42779 into release-4.2 (#42820)
Component commits:
214ef0c750 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.

1d347785de Merge branch 'master' into no-did-you-mean-to-call-error-on-casts

b3be79ad0f Skip parentheses

2a288127e9 Merge branch 'master' into no-did-you-mean-to-call-error-on-casts

Co-authored-by: Nathan Shively-Sanders <nathansa@microsoft.com>
2021-02-16 13:19:19 -08:00
TypeScript Bot
7f64b3a82c
Cherry-pick PR #42626 into release-4.2 (#42780)
Component commits:
214ef0c750 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.

1d347785de Merge branch 'master' into no-did-you-mean-to-call-error-on-casts

Co-authored-by: Nathan Shively-Sanders <nathansa@microsoft.com>
2021-02-16 11:25:58 -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
Wesley Wigham
4c43e09c9e
Add fallback error locations for nameless declarations, better class error locations (#42585) 2021-02-05 12:07:14 -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
Oleksandr T
4c118ae67b
fix(39022): wrap export references UnaryExpression to ParenthesizedExpression (#41156) 2021-02-03 18:26:33 -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
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
Wesley Wigham
5a21291b7c
Propegate contextual types through nonnull assertion operators (#42526) 2021-01-28 09:24:54 -08:00
Wesley Wigham
517f32940a
Add regression test for #37314 (#42525) 2021-01-27 15:30:59 -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
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
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
Wesley Wigham
0d494abc77
Add missing unwrap call for the inferredExtendsType (#42409) 2021-01-19 18:02:35 -08:00
Wesley Wigham
ab32fcadbd
Fix type parameter lookup for TypeAlias LibraryManagedAttributes (#42245) 2021-01-15 17:23:01 -08: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
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
Oleksandr T
1cd8ee4b8d
fix(42088): fix crash on unreachability condition in for statement (#42110) 2021-01-10 15:42:39 -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
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
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
Wesley Wigham
72dfc589a1
Retain CheckFlags.Late on symbols manufactured based on Late-bound symbols (#42205) 2021-01-04 15:49:52 -08:00
Anders Hejlsberg
22bee779d7
Properly make inferences from partial source type (#42038)
* Slightly less picky check in typesDefinitelyUnrelated

* Accept new baselines

* Add regression test
2020-12-19 07:18:44 -10:00
Wesley Wigham
c3ff0d4c17
Under jsx: preserve, actually preserve expressions which contain only comments (#41757)
* Under jsx: preserve, actually preserve expressions which contain only comments

* Even better best effort comment preservation in JSX comments
2020-12-18 11:42:33 -08:00
Wesley Wigham
caebbe6714
Dont check computed name visibility results when the computed name representation is not in use (#41806) 2020-12-18 11:41:55 -08:00
Song Gao
8cbc576954
Fix #41800 correctly. (#41895)
* fix as suggestion.

* Update moduleSpecifiers.ts

* compare symbol rather than string

* fix typo.

* fix

* fix lint.

* better name and more clear code

* fix comment.

Co-authored-by: Orta Therox <git@orta.io>
2020-12-16 18:56:18 -08:00
Wesley Wigham
b217f22e79
Allow identical type parameter lists to merge in union signatures (#31023)
* Have signature identity checks look at the base constraint of type parameters, allow identical type parameter lists to merge in union signatures

* Update text in fourslash test

* Add whitespace to fix lint, remove duplicate impl

* Consolidate names

* Remove comparisons of type parameter defaults, add more test cases
2020-12-16 13:17:57 -08:00
Wesley Wigham
675cd4d7ce
Ensure factory symbol remains unused in react-jsx mode when not referenced in user code (#41905) 2020-12-16 13:11:48 -08:00
Anders Hejlsberg
bec8071c65
Simplify constraint depth limiter logic (#41972)
* Explore at least 10 levels of constraints before checking for deeply nested types

* Simplify constraint depth limiter logic

* Add regression test

* Accept new baselines
2020-12-15 17:08:36 -10:00
Andrew Branch
035c7ca905
Elide export assignment when it does not resolve to a value (#41904)
* Only mark aliases that resolve to values referenced

* Update other affected baselines

* Remove redundant check
2020-12-10 10:17:28 -08:00
Anders Hejlsberg
646f5b3c4e
Preserve substitution types in check position of conditional types (#41841)
* Preserve substitution types in check types of conditional types

* Undo changes from #32093

* Add regression tests

* Accept new baselines
2020-12-07 16:38:00 -10:00
Orta Therox
71e881a7ee
Undo #39258 (isArray changes) see overview at #41808 (#41851) 2020-12-07 21:59:26 +00:00
Song Gao
37e898cfd7
import statement from "node" in js source file could produce correct declaration path. (#41816)
* fix #41800

* add test

* fix test
2020-12-07 13:54:47 +00:00
Oleksandr T
a5c3cb4194
Improve uncalled function checks with parenthesized expressions in condition (#41748) 2020-12-04 16:20:14 -08:00
Wesley Wigham
0da5a7e4ba
Add missing BinaryExpression source side cases to isMatchingReference (#41765) 2020-12-01 14:47:14 -08:00
Wesley Wigham
2a3f5508ec
addImplementationSuccessElaboration admits declarations with no symbol (#41758) 2020-12-01 12:19:12 -08:00
Toan Nguyen
0c76803854
Fix typos in comments (#41307)
* Fix typo fuction -> function

* Fix typo assignement -> assignment
2020-11-30 15:02:07 -08:00
Nathan Shively-Sanders
06fb724cd1
Improve uncalled function checks (#41599)
Fixes #41586
Fixes #41588

1. For binary expressions, if the immediate parent is an IfStatement,
then check the body of the if statement. I didn't walk upward to find an
IfStatement because in my experimentation I found that binary expression
uncalled-function errors are only issued when the expression is on the left of the
top-most binary expression.

2. For property accesses with interspersed calls, I added a
CallExpression case. In fact, any expression could appear here, but I
only want to fix calls for now since that's all we've observed in
Definitely Typed, and we didn't see anything else in the user tests or RWC
tests. I also didn't examine parameters of the intermediate call
expressions, but I don't think it's needed since the intent is to avoid
false positives.
2020-11-30 14:27:19 -08:00
Anders Hejlsberg
ec1490fb44
Properly cache types for shared control flow nodes (#41665)
* Properly cache shared flow node types

* Add test
2020-11-25 14:51:38 -10:00
Oleksandr T
d163ab67c8
fix(41240): allow emitting numeric with underscored separators as-is in esnext target (#41435) 2020-11-23 17:01:42 -08:00
Martin Probst
6b04f50394
Do not parse template arguments in JavaScript files. (#36673)
Fixes #36662.
2020-11-19 11:41:35 -08:00
Oleksandr T
9bbbe5c0c7
fix(41227): change message about incorrect property access with possible replacement with static access (#41275) 2020-11-18 12:50:32 -08:00