Commit graph

15121 commits

Author SHA1 Message Date
kingwl
ff4fca527d Fix cfa 2020-05-16 08:09:40 +08:00
Wenlu Wang
944bcf8459 Update src/compiler/transformers/utilities.ts
Co-Authored-By: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2020-05-16 08:09:39 +08:00
kingwl
ede6214157 Add more check 2020-05-16 08:09:39 +08:00
kingwl
82fe658a48 Add cfa 2020-05-16 08:09:38 +08:00
kingwl
9190a2c4e8 Add contextual types infer 2020-05-16 08:09:38 +08:00
kingwl
f922427196 Add mission semi 2020-05-16 08:09:37 +08:00
kingwl
da16b3e30b Add more case 2020-05-16 08:09:36 +08:00
kingwl
1d93db81cc Add logical assignment operator 2020-05-16 08:09:32 +08:00
Eli Barzilay
33c3e9e2c6 Make processTaggedTemplateExpression visit a returned node
This problem was introduced in 70399e146e (from PR #23801), which added
a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`,
before that, it would fallback to the default of `visitNode`.  So re-add
that happen in `processTaggedTemplateExpression`.

Since it doesn't hurt, I left a `Debug.checkDefined(property.name)`
instead of `!`-ing it.

Fixes #38558.
2020-05-15 19:46:45 -04:00
Ron Buckton
1cbe7ef000
Fix crash in JS declaration emit (#38508)
* Fix crash in JS decl emit

* Emit as class with private ctor
2020-05-15 14:00:59 -07:00
Wesley Wigham
7fc456f2d7
Include unknown in spread prop override check (#38577) 2020-05-14 14:36:38 -07:00
Greg Hurrell
cfc4573c82 Fix (cosmetic) typos in checker.ts comments
Just some small things I noticed while looking at some recent PRs.
2020-05-14 19:40:41 +02:00
Anders Hejlsberg
c1f676dd3f
Perform intersection reduction before and after getApparentType (#38565)
* Perform intersection reduction before and after getApparentType

* Add regression tests
2020-05-13 20:57:17 -07:00
Daniel Rosenwasser
b682ee1a8a
Merge pull request #38489 from microsoft/removeDuplicateInfo
Remove duplicate JSDoc comments
2020-05-12 12:52:15 -07:00
Daniel Rosenwasser
c2b559403d
Merge pull request #38502 from alan-agius4/export-star-colon
fix: add missing semi-colon to `__exportStar` unnamed function
2020-05-12 10:59:03 -07:00
Nathan Shively-Sanders
cbf15bb6ed
feat(38225): change diagnostic message for remove braces from arrow function body (#38226) 2020-05-12 07:27:09 -07:00
Alan Agius
7ec21e93fe fix: add missing semi-colon to __exportStar unnamed function
Fixes #38501
2020-05-12 13:27:01 +02:00
Alexander T
ee3f2ce362 regression(38485): allow using rawText property in processing a tagged template 2020-05-12 12:30:46 +03:00
Daniel Rosenwasser
f9e1bcd0c4
Merge pull request #38439 from lissein/void-0-template-strings
Changed template strings to emit void 0 instead of undefined (#38430)
2020-05-11 17:09:28 -07:00
Daniel
e9867a7353 Add and use the 'intersperse' helper function. 2020-05-11 22:17:01 +00:00
Ron Buckton
d07e866a28
Fix for jsdoc modifiers on constructor params (#38403)
* Fix for jsdoc modifiers on constructor params

* Update Public API baseline and fix unique symbol grammar check for js
2020-05-11 15:07:43 -07:00
Nathan Shively-Sanders
1a88430a7e
Improve assert message in binder (#38270)
* Improve assert message in binder

Looking at the code, I don't think the assert can ever fire, but it
clearly does, or did in the past. This will make it easier for people to
create a repro.

* fix lint

* Use BindableStaticNameExpression not BindableStaticAccessExpression

This type does allow identifiers, but those are ruled out earlier, so I added
an assert for that case.
2020-05-11 13:40:54 -07:00
Wenqi
1b7b3eb0f7
report error for duplicate @type declaration (#38340) 2020-05-11 12:47:49 -07:00
lissein
946abeadb0 Changed template strings to emit void 0 instead of undefined (#38430)
undefined is not a keyword in es5 and es3 so we now emit void 0 instead in template strings.
2020-05-09 04:53:14 +02:00
Wesley Wigham
7b03835b77
Fix js missing type arguments on existing nodes and jsdoc object literal declaration emit (#38368)
* Fix js missing type arguments on existing nodes and jsdoc object literal declaration emit

* Add special lookups test case, rename helper

* Accept slightly modified baselines
2020-05-08 10:46:28 -07:00
David Sherret
84f89f8702 Fix some JSDoc factory function return types. 2020-05-08 12:26:50 -04:00
Anders Hejlsberg
0091fd6c64
Exclude arrays and tuples from full intersection property check (#38395)
* Exclude arrays and tuples from full intersection property check

* Add regression test
2020-05-07 15:03:51 -07:00
Anders Hejlsberg
7798f532df
Fix crash caused by assertion with evolving array type (#38398)
* Properly finalize evolving array type in getTypeAtFlowCall

* Add regression test
2020-05-07 14:05:57 -07:00
Jack Williams
05d59a1f1a
Unify logic in typeof narrowing (#33434) 2020-05-06 15:15:24 -07:00
Alexander T
683b3ec058
feat(37782): 'declare method' quick fix for adding a private method (#37806)
* feat(37782): add quick-fix action to declare a private method for names that start from underscore

* better merge order in messages json

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-05-06 15:10:02 -07:00
Wenlu Wang
e66ce879a9
expose jsdoc factory (#29539)
* expose jsdoc factory

* refactor jsdoc factory

* correctly jsdoc factory types

* update jsdoc factory

* Add check for delete expression must be optional

* accept new basseline

* Revert "Add check for delete expression must be optional"

This reverts commit 76937c3b1a.

* remove newline

* make linter happy

* Add deprecated comment

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-05-06 15:06:12 -07:00
Nathan Shively-Sanders
35c1ba67ba
Update LKG 2020 05 06 (#38371)
* Update LKG

* remove now-extraneous casts
2020-05-06 14:42:05 -07:00
Josh Goldberg
be2eb8a2e1
Allowed comment directives to be multiline (#38228)
* Allowed comment directives to be multiline

* Added tests, and perhaps fixed a test runner bug?

* I think it's going to need a consistent variable to loop over

* Used dynamically computed indexes in verifies

* Added multiline tests

* Increased flexibility for multiline comment parsing

* Undid a couple of formatting changes; removed backslashes from multiline regexp

* Added baseline tests for multiline comment skipping

Co-authored-by: Orta Therox <orta.therox@gmail.com>
2020-05-06 13:09:29 -07:00
Ron Buckton
4b08c0582d
Fix regression in name resolution in parameter (#38351) 2020-05-06 12:04:28 -07:00
Alexander T
ec93a7cf7b
fix(36055): forbid union type with invalid types in the 'in' operator (#37786) 2020-05-06 11:41:50 -07:00
Anders Hejlsberg
2524fb164a
Consistent narrowing by discriminant (#38311)
* Consistent requirements for narrowing by discriminant

* Add tests
2020-05-05 20:06:07 -07:00
Alexander T
c219fdae08
fix(37703): forbid required parameter after optional (#38155) 2020-05-05 10:29:17 -07:00
Marcel Laverdet
44c6cf74cb
Fix updateBinary operator parameter (#38129)
* Fix `updateBinary` `operator` parameter

There is an issue in `updateBinary` where attempting to update
`operator` without updating `left` or `right` results in a silent no-op.

* Use defaulted parameter in `updateBinary`
2020-05-05 09:05:02 -07:00
Anders Hejlsberg
e6390efb01
Properly handle private/protected members in unions of object types (#38277)
* Property handle private/protected properties in unions of object types

* Add regression test
2020-05-04 15:28:00 -07:00
Wesley Wigham
d9c9c9d9e4
Harden node builder APIs to no longer return undefined for a node when NodeBuilderFlags.IgnoreErrors is provided (#38273) 2020-05-04 14:47:39 -07:00
Sheetal Nandi
aa37b28246
Fix incorrect line text computation to stop comment directive searching (#38296)
Fixes #38289
2020-05-04 13:02:54 -07:00
Anders Hejlsberg
a09470f013
Fix index signatures on unions of intersections (#38278)
* Add missing getApparentType call

* Add regression tests
2020-05-04 12:46:14 -07:00
Eli Barzilay
ba02f4303e Make getAwaitedType private
Also, fix an additional baseline change and break up huge line.
2020-05-04 13:18:52 -04:00
Alexander T
0503da225d feat(36266): add a quick fix for incorrect return types in async functions 2020-05-04 13:18:52 -04:00
Leko
275ed548df disallows exponentials with BigInts for targets lower than ES2016 2020-05-04 13:14:48 -04:00
Wesley Wigham
5b0194b311
Fix jsdoc variadic type nodes not being remapped to equivalent TS in output (#38276) 2020-05-02 01:43:59 -07:00
Andrew Branch
53320f59a4
Fix crash on duplicate default exports (#38272) 2020-04-30 12:21:02 -07:00
Jacob Bandes-Storch
0b1cb74530
fix order and tests 2020-04-29 23:04:24 -07:00
Jacob Bandes-Storch
fd4eccee6c
Merge remote-tracking branch 'upstream/master' into diagnose-accidental-accessor-call 2020-04-29 23:00:16 -07:00
Jacob Bandes-Storch
6051fc1814
move to invocationErrorDetails 2020-04-29 22:58:18 -07:00
Orta
0258db2210
Adds support for looking up past Blocks in expando objects (#38031)
* Adds support for looking up past Blocks in expando objects

* Adds JS tests to validate the JS parsing also works

* Get the top level block expando tests green
2020-04-29 10:35:33 -04:00
Anders Hejlsberg
d9ad27f2dd
Early couldContainTypeVariables check in instantiateType (#37844)
* Shared early couldContainTypeVariables check in instantiateType

* Defer creation of map object in createUnionOrIntersectionProperty

* Types with top-level non-generic type alias reference no type variables
2020-04-28 17:02:52 -07:00
Anders Hejlsberg
3919042c7f
Control flow for constructor initialized properties (#37920)
* Use CFA to determine types of properties declared by this.xxx assignments

* Accept new baselines

* Also use CFA in constructor functions

* Accept new baselines

* Fix lint error

* Only widen fresh literal types in CFA of assignment to auto-typed

* Auto-typing for declared properties with no type annotation or initializer

* Add optionality if declaration includes '?' modifier

* Always use CFA for properties with no initializer in .js files

* Small fix
2020-04-28 16:59:03 -07:00
Anders Hejlsberg
a0ebd2c26e
Guard against recursion in inferTypeForHomomorphicMappedType (#38224)
* Guard against recursion in inferTypeForHomomorphicMappedType

* Add regression test
2020-04-28 16:56:35 -07:00
Anders Hejlsberg
16d2eb7075
Error on this.xxx access of previously declared but uninitialized property (#38030)
* Error on this.xxx access of previously declared but uninitialized property

* Add tests

* Accept new baselines
2020-04-28 12:52:14 -07:00
Nathan Shively-Sanders
12cd15c867
this: undefined in modules (#37784)
It's always supposed to have been this way, but I was worried about how
breaky the change would be when adding globalThisType. This PR is
experiment to see how much.

Fixes #35882 maybe
2020-04-28 10:42:24 -07:00
Alexander T
57f161eaa8 feat(38225): change diagnostic message for remove braces from arrow function body 2020-04-28 10:44:36 +03:00
Josh Goldberg
d4825ab90f I did everything you said I followed all the rules 2020-04-27 19:59:41 -04:00
Daniel Rosenwasser
466d0c0ecb
Bump version number to 4.0 (#38215) 2020-04-27 14:09:58 -07:00
Daniel Rosenwasser
6a6c83cf9a
Revert "Revert "Add check for delete expression must be optional (#37921)" (#38154)" (#38173)
This reverts commit 1b8c68d746.
2020-04-27 13:23:45 -07:00
Wesley Wigham
4a5eeb0bb2
Skip comparing optional property flag when comparing against discriminant properties (#38101) 2020-04-24 18:33:30 -07:00
Daniel Rosenwasser
1b8c68d746
Revert "Add check for delete expression must be optional (#37921)" (#38154)
This reverts commit 39beb1d011.
2020-04-24 16:05:18 -07:00
Ryan Cavanaugh
84c83da3a9
Revert #37106 (#38172) 2020-04-24 16:04:33 -07:00
Ron Buckton
968943f355
Reset error variable in downlevel for-await-of loop (#38170)
* Rename forAwait tests

* Reset error var in for-await loop
2020-04-24 14:59:41 -07:00
Andrew Branch
ce95d9ca6b
Fix values and types merging in JS module exports (#37896)
* Fix values and types merging in JS module exports

* Fix everything

* Share `setValueDeclaration` between binder (local merge) and checker (cross-file merge)

* Revert accidental changes to baselines

* Update baseline from master merge
2020-04-24 13:49:48 -07:00
Wesley Wigham
1785d6c707
Special-case export assigned namespaces in getSpecifierForModuleSymbol so they behave like their containing module symbol (#38151) 2020-04-24 13:10:34 -07:00
Andrew Branch
fe140acc09
Fix truthiness call check for this-property access (#38163) 2020-04-24 13:02:17 -07:00
Ron Buckton
38ff7762ec
Fix temp variable scoping in async generators (#38121) 2020-04-24 12:10:29 -07:00
Ron Buckton
a7d6825e25
Fix temp vars referenced in parameter (#38130)
* Fix temp vars referenced in parameter

* Update error message
2020-04-23 20:45:39 -07:00
Wesley Wigham
815dc90dc5
Issue an error on cross-file merges we cant emit (#38148) 2020-04-23 19:01:16 -07:00
Andrew Branch
9569e8aaa4
Fix newline issues when adding multiple imports (#38119)
* Add new import declarations in a single TextChanges call

* Refactor
2020-04-23 11:59:38 -07:00
Nathan Shively-Sanders
032aa90289
Filter undefined from binding elements with initialisers without undefined in the type (#38122)
* Filter undefined from binding elts w/o undefined-containing inits

* use getTypeOfInitializer instead

* improve comment based on Wesleys suggestion
2020-04-22 15:45:15 -07:00
Nathan Shively-Sanders
f248567dab
Filter undefined only in binding patterns in params (#38116)
initialiser. But this is only correct when the initialiser is for a
parameter. For example:

```ts
declare let x: { s: string } | undefined;
const { s } = x;
```

This PR removes undefined from the type of a binding pattern only when
the binding pattern's parent is a parameter. This fixes the regression
from 3.8. However, it's still not the ideal fix; we should be able to
use control flow to solve this problem. Consider:

```ts
const { s }: { s: string } | undefined = { s: 'hi' }
declare function f({ s }: { s: string } | undefined = { s: 'hi' }): void
```

Neither line should have an error, but the first does in 3.8 and after
this change.
2020-04-22 09:56:32 -07:00
Josh Goldberg
99cdb64839 Used DH's suggested heuristic 2020-04-22 12:48:23 -04:00
Wenlu Wang
39beb1d011
Add check for delete expression must be optional (#37921)
* Add check for delete expression must be optional

* Add more tests
2020-04-22 03:12:01 -07:00
Andrew Branch
7d4fc73331
Fix preserveNewlines printer option when a list child has the same start or end as its parent (#37846)
* Fix preserveNewlines printer option when a list child has the same start or end as its parent

* Fix leading line separator calculation and JSX bug
2020-04-21 15:34:30 -07:00
Wesley Wigham
a72e49e875
Delay pulling on signature contextual type until absolutely needed (#37851) 2020-04-21 13:29:45 -07:00
Wesley Wigham
136f728bb0
Fix js declaration emit for inherited and this-typed inherited fields (#37970) 2020-04-21 13:13:50 -07:00
Nathan Shively-Sanders
6ea291a142
Remove superCallShouldBeFirst error (#37947)
* Remove superCallShouldBeFirst error

It seems redundant since TS gives an error on any use of `this` before
super, and non-`this` uses before `super` should be fine.

Fixes #37371

* Revert "Remove superCallShouldBeFirst error"

This reverts commit 3c09153c8a.

* error except for target:"esnext" && useDefineForClassFields
2020-04-21 12:58:37 -07:00
Nathan Shively-Sanders
63ff6572ae
Fix use-before-def with methods on esnext+useDefineForClassFields (#38033)
* Fix use-before-def with methods on esnext+useDefineForClassFields

It was incorrectly flagging methods as used before their definition, but
this is allowed under any emit.

* Add instance function test case
2020-04-21 08:09:25 -07:00
Josh Goldberg
d12b741004 Excluded type unions from the generale source types 2020-04-20 23:32:34 -04:00
Sheetal Nandi
e7774c6144
Handle non literal computed name when trying to get the name for object literal property name in json object (#37988)
Fixes #37984
2020-04-20 12:58:38 -07:00
Eli Barzilay
9c1157a801
fix(37242): add reference to return type for JSDocFunctionType (#37911) 2020-04-20 14:17:03 -04:00
Anders Hejlsberg
5d78cbdbbd
Propagate nonInferrableType in &&, || and ?? operators (#38035)
* Propagate nonInferrableType in &&, || and ?? operators

* Add regression test

* Simpler solution: getTypeFacts(neverType) should return TypeFacts.None
2020-04-20 11:04:24 -07:00
Josh Goldberg
035b9ac1c1 Lint fix 2020-04-19 22:09:53 -04:00
Josh Goldberg
769a2f2cfc Eased up on some of the more aggressive reporting changes 2020-04-19 20:25:24 -04:00
Josh Goldberg
b14b231d26 Report primitive type in literal-to-primitive relation complaints 2020-04-19 13:26:38 -04:00
Jacob Bandes-Storch
d00f2b53ad
replace the original not-callable error 2020-04-18 21:23:31 -07:00
Alexander T
a2628c9088 fix(37242): add reference to return type for JSDocFunctionType 2020-04-17 09:05:23 +03:00
Wesley Wigham
deb5bac520
Use string representation for negative numeric property names (#37936) 2020-04-15 21:11:05 -07:00
Wesley Wigham
cdc384006c
Fix crash on declaration emit for globalThis (#37992) 2020-04-15 13:37:51 -07:00
Alexander T
a16c44180a
fix(37940): add space after parameter decorator (#37959) 2020-04-15 11:42:29 -07:00
okmttdhr
06e05f25e1
Improve error message for computed enums (#37790)
* Add error message for computed enums

* Add test case for computed enums

* Accept baselines

* Fix returned value when error
2020-04-15 13:50:33 -04:00
Anders Hejlsberg
92cd3ae299
No iteration type errors during CFA (#37965)
* No iteration type errors during CFA

* Add regression test
2020-04-15 10:34:07 -07:00
Ashley Claymore
4538640d8a
Added error when Enum member initaliser references itself (#34655)
Fixes #34606
2020-04-14 15:20:19 -04:00
Wesley Wigham
edd4e0a42b
Add fastpath to isRelatedTo for type references (#37481)
* Add fastpath to isRelatedTo for type references

* Do not check intersections or unions to ignore propegating reference flags, properly set comparing jsx flag

* Re-remove unneeded check

* Just check for TypeFlags.Object

* Remove else clause
2020-04-13 15:54:37 -07:00
Wesley Wigham
6a5508b343
Update __exportStar helper to skip default and __esModule members (#37236)
* Update __exportStar helper to skip default and __esModule

* Accept new baselines

* Remove esmodule check from helper
2020-04-13 13:10:24 -07:00
Wesley Wigham
141ee01c8c
Retain imports in declaration emit if they augment an export of the importing file (#37820)
* Retain imports in declaration emit if they augment an export of the importing file

* (sp)

* Check that a merge occurs, just because
2020-04-13 12:31:14 -07:00
Nathan Shively-Sanders
5f46d42ad1
Error on missing BigInt in es2020 (#37899)
* Error on missing BigInt in ES2020 too.

Previously it was only on ESNext, but bigint ships in ES 2020.

There are no tests for this; passing `false` doesn't cause any tests to
fail at least.

* add tests
2020-04-13 08:30:59 -07:00
Jacob Bandes-Storch
d00a5c954f
Add _0_is_declared_here pointing to accessor declaration 2020-04-11 15:58:35 -07:00
Jacob Bandes-Storch
61f60057f1
Better error message for accidental calls to get-accessors 2020-04-11 15:52:17 -07:00
Nathan Shively-Sanders
eb105efdcd
Avoid circular reference in this-property assignments (#37827)
* Avoid circular reference in this-property assignments

To do this, don't check this-property assigments that have the
this-property of the lhs appearing somewhere on the rhs:

```js
class C {
  m() {
    this.x = 12
    this.x = this.x + this.y
  }
}
```

I tried suppressing the circularity error, but because we cache the
first type discovered for a property, this still results in an implicit
any for `x` in the previous example. It just doesn't have an error.

Fixes #35099

* Add test case + rename function

* Use isMatchingReference
2020-04-10 16:41:31 -07:00
Alexander T
795a5c83fe
fix(37150): ignore private fields in string index type checking (#37183) 2020-04-10 12:53:53 -04:00
Anders Hejlsberg
52dc9f2282
No recursive intersection property checks (#37854)
* No recursive intersection property checks

* Add comment
2020-04-09 19:23:36 -07:00
Anders Hejlsberg
6b1c102bd1
No excessive stack depth global errors (#37873)
* Report excessive stack depth on current node when no error node available

* Accept new baselines
2020-04-09 19:05:35 -07:00
Nathan Shively-Sanders
3030cd8eff refactoring done except for deduping 2020-04-09 16:43:31 -07:00
Andrew Branch
95cc1c279e
Fix crash from missing valueDeclaration on intersection property (#37696)
* Add crashing test

* Fix missing valueDeclaration on intersection symbol property

* Remove assertion from serializeAsClass
2020-04-09 14:00:21 -07:00
Ron Buckton
4a646c9640
Fix parenthesization rules for yield (#37849) 2020-04-09 13:17:46 -07:00
Ravi van Rooijen
2a25901c54
Fix code block in jsdoc (#37864) 2020-04-09 13:31:41 -04:00
Andrew Branch
24a17acf2c
Error on invalid uses of namespace export (#37715) 2020-04-09 09:42:16 -07:00
Andrew Branch
57f9076612
Remove extraneous string escape from convert to template string refactor (#37743)
* Add failing test

* Remove extraneous string escape

* Revert unnecessary change
2020-04-09 09:40:28 -07:00
Nathan Shively-Sanders
3ffe253166 Always error when property overrides accessor or vice versa
Previously this was only an error when useDefineForClassFields: true,
but now it's an error for all code. This is a rare mistake to make, and
usually only occurs in code written before `readonly` was available.

Codefix to come in subsequent commits.
2020-04-09 08:27:08 -07:00
Wesley Wigham
3d3854c93d
Set contextual type on elaborated error node rather than passing it, so its discriminated (#37828) 2020-04-09 02:55:39 -07:00
Ron Buckton
5db4e7add3
Fix async function block return expr error in js (#37845) 2020-04-08 15:26:56 -07:00
Wesley Wigham
b4838c8b62
Use comments from host variable declaration when exporting a signature in js declarations (#37594) 2020-04-08 13:32:17 -07:00
Ron Buckton
5a7916962d
Fix metadata serialization for invalid jsdoc types (#37836) 2020-04-08 12:06:40 -07:00
zhangciwu
126c6ab80d
Fix easy misunderstanding "! ===" (#37838)
* Remove unnecessary Non-null assertion operator

* Wrap Non-null assertion operator inside parentheses
2020-04-08 08:17:22 -07:00
Eli Barzilay
e4babd40e0 Skip isBlockScopedNameDeclaredBeforeUse error in interface or type declarations
Fixes #35947.
2020-04-07 16:12:18 -04:00
Eli Barzilay
dcc6c9461e Minor improvement
Get the `declaration` container just once instead of in three places.
(Minor change: one place used to start looking from
`declaration.parent`, but that shouldn't make any difference.)  Also,
don't pass it to the helper functions since they're local anyway.
2020-04-07 16:12:18 -04:00
Orta
3398c9bfe1
Make skipLibCheck: true the default in --init (#37808) 2020-04-07 15:00:44 -04:00
Andrew Branch
3e86f15f51
Disambiguate types with same name from different namespaces in mapToTypeNodes (#37543)
* Disambiguate types with same name from different namespaces in mapToTypeNodes

* Update baseline with additional example

* Fix typo
2020-04-07 10:55:56 -07:00
Nathan Shively-Sanders
7ca6334dbd
Look for outer type parameters on VariableStatements (#37819)
This only applies in JS, where `@template` tags can apply to
initialisers of variable declarations:

```js
/**
 * @template T
 * @returns {(b: T) => T}
 */
const seq = a => b => b
```

Fixes #36201
2020-04-07 08:04:33 -07:00
Anders Hejlsberg
a2609b1f1b
Extra check in assignment of intersections with generic constituents (#37537)
* Consolidated extra property check with intersections

* Fix comment

* Add tests

* Properly propagate intersectionState

* Route property check through recursive type tracking logic

* Accept new baselines

* Skip check when apparent type of source is never

* Accept new baselines

* Only check when apparent type of source is a structured type
2020-04-06 13:36:20 -07:00
Anders Hejlsberg
5a4024dd9d
Generic functions are never context sensitive (#37811)
* Functions with type parameters are never contextsensitive

* Add tests
2020-04-06 11:55:39 -07:00
Nathan Shively-Sanders
eac073894b
Fix serialisation of static class members in JS (#37780)
* Fix serialisation of static class members in JS

Previously static class members would be treated the same way as expando
namespace assignments to a class:

```ts
class C {
  static get x() { return 1 }
}
C.y = 12
```

This PR adds a syntactic check to the static/namespace filter that
treats symbols whose valueDeclaration.parent is a class as statics.

Fixes #37289

* fix messed-up indent

* Extract function
2020-04-03 20:06:05 -07:00
Orta
20ecbb0f46
Allow Source Mapping inside destructuring assignment (#37298)
* Add support for source maps inside of destructured code

* Adds tests for the source maps inside destructured code
2020-04-03 17:23:02 -04:00
Wesley Wigham
7317292782
Consider arrays and tuples within one another as possibly requiring deferral (#37776) 2020-04-03 14:14:13 -07:00
Nathan Shively-Sanders
7cf4b12d88
Fix crash for private identifier in expando assignments (#37764)
* Fix crash for private identifier in expando assignments

It does this by disallowing private identifiers from expando assignments
entirely. I haven't thought of a scenario where they make sense, but I
haven't thought about it exhaustively either.

Fixes #37356

* Update baselines

I think the new error is probably better. It's certainly different!
2020-04-03 10:29:22 -07:00
Wesley Wigham
6d25c01d09
Cache the regularized form of union types (#37749)
* Cache the regularized form of union types

* Inline function because why not

* Introduce two fastpasths into isRelatedTo
2020-04-02 23:54:24 -07:00
Anders Hejlsberg
349ae45a2c
Reduce intersections with conflicting privates, elaborate on reasons (#37762)
* Elaborate on reasons for 'never' intersections

* Accept new API baselines

* Accept new baselines

* Add tests

* Accept new baselines

* Address CR feedback
2020-04-02 18:00:59 -07:00
Nathan Shively-Sanders
527f467926
Remove error when spreading optional any (#37757)
Previously, spreading an optional any gave a bogus error when the name
conflicted with earlier properties in the object literal. Now the code
checks any types for optionality before issuing the error.

Fixes #37740
2020-04-02 15:04:45 -07:00
Wenlu Wang
afc41f095d
Quick fix for functions lacking return expressions (#26434)
* stash

* add surmise for return type

* add support for more case

* add more test case

* add more testcase and fix all test

* fix changed diagnosis

* fix broken test case

* add more case

* rename quickfix

* fix conflict

* fix fix desc

* fix semi

* Avoid replace brace with paren

* Split fix all action

* Add return work in same line

* fix test cases

* rename baseline

* refactor and handle comment

* Support semi

* make helper internal
2020-04-02 10:06:14 -07:00
Wesley Wigham
78a99241d8
Reuse input type nodes when serializing signature parameter and return types (#37444)
* Accept change

* Accept the huge set of ever so slightly changed baselines

* Update return type logic to only reuse nodes if original nodes share scope with current node, like property types, only reuse nodes if symbols referened are acessible, reuse nodes for property signatures, too

* Only reuse nodes when a context is provided (otherwise identifier printback may fail)

* Only track symbol if symbol is found and no error is recorded

* Fix type parameter reuse lookup

* Forbid cjs module.exports references in retained nodes

* Adjust check for cjs export references to not include bad module type in output

* Add symbol to all identifiers we see in existing nodes for quickinfo

* Accept fourslash baseline updates

* Accept slightly updated baseline post-merge

* Do not copy original nodes for error types, replace empty type references with any
2020-04-01 19:50:21 -07:00
Wesley Wigham
15aff05ff6
Explicitly merge module augmentation members into the exports added by export * declarations (#37691)
* Explicitly merge module augmentation members into the exports added by export * declarations

* Use ?., add namespace merge test

* Add missing merged symbol call to handle enum/ns merges during entity name lookup

* Add test with error case

* Handle missing value declarations in more places, unify duplicate declaration error handling to improve assignment declaration duplicate errors
2020-04-01 16:36:28 -07:00
Alexander T
c546988e50
fix(37456): omit type arguments from JsxSelfClosingElement, JsxOpeningElement nodes (#37739) 2020-04-01 16:27:33 -07:00
Wesley Wigham
326e1c9ff8
Disallow partial matches for discriminant properties when generating error messages (#37589) 2020-04-01 15:39:12 -07:00
Alexander T
697d1042eb
fix(37519): forbid trailing comma in a index signature (#37535) 2020-04-01 15:38:10 -07:00
Nathan Shively-Sanders
95a124f802
Fix crash on bad namespace parse (#37626)
* Fix crash on bad namespace parse

`global` inside a class body is parsed as a module declaration, and in
the following example has no body:

```ts
class C {
  global x
}
```

`x` is parsed as a separate ExpressionStatement. This caused a crash in
emit because the code didn't expect a module declaration with no body.

* inline node.body variable

* fix missed references to body
2020-04-01 15:05:49 -07:00
Sheetal Nandi
0b38a9a2b0
Add support for extraFileExtensions on WatchCompilerHost (#37726)
To support typescript-eslint/typescript-eslint#1813
2020-04-01 11:13:21 -07:00
Wesley Wigham
0e48e68ed1
Fix post-LKG build 2020-04-01 10:53:46 -07:00
Simon Jaeger
9c4cbd64fb
fix #32843 : evaluate right scope when checked if all type parameter are unused for jsdoc @template (#33320)
Co-authored-by: magierjones <simon.jaeger@magierjones.de>
2020-03-31 15:32:15 -07:00
Nathan Shively-Sanders
4dc827e22a
Fix emit of simple module.exports.C.prototype pattern (#37719)
Extends the fix of #36108 so that the simple example gets correct emit;
the complex test case I came up with still doesn't work correctly, but
the actual code froma #35228 is fixed.
2020-03-31 14:59:47 -07:00
pizzacat83
a46e9aea10
support 'in' type guard of intersections (#37106) 2020-03-31 13:37:08 -07:00
Andrew Branch
23b500cadf
Don’t offer this. completions on self, window, global, globalThis. Disambiguate this. completions from others in details requests. (#37652)
* Special-case window, self, global, globalThis methods

* Disambiguate global and this property completions in details requests

* Hide the Map<boolean> implementation

* Update old tests

* Replace SymbolOriginKind stringification with dedicated enum
2020-03-31 12:40:57 -07:00
Anders Hejlsberg
2b0f351005
Fix narrow-by-constructor logic (#37698)
* Fix narrow-by-constructor logic

* Add regression test
2020-03-30 19:31:16 -07:00
Nathan Shively-Sanders
f17174ceb0 Fix build after merging #35862 2020-03-30 15:13:20 -07:00
Titian Cernicova-Dragomir
3433434142
Fixed issue where missing method call went unreported if the call target symbol did no have an id assigned or if the called property was used inside the if block on a different target. (#35862) 2020-03-30 14:45:32 -07:00
Jack Williams
0e15b9f245
Make never rest type top-like (#35438)
* Make never rest type top-like

* Add higher-order test

* properly support types which reduce to never

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-03-30 14:16:07 -07:00
Wesley Wigham
2f0cc51fee
Fix contextual types for maybe-async callbacks (#37205)
* Fix contextual types for maybe-async callbacks

* Remove comment
2020-03-30 14:15:51 -07:00
Neal Burger
9cd4b070ab
Add link to documentation in tsconfig.json template generated by tsc --init (#34686)
* Add Advanced Compile Options to --init command

* removed advanced options and descriptioncolumn

* tests: fix tsconfig.json baselines

* tests: fix failing tests

* feat: adjusted link to specification

* fix: removed duplicate increment flag

* chore: moved position back

* return of the comments

* fix for missalignment

* return of the comment
2020-03-30 14:14:00 -07:00
uhyo
1f56ab02f0
Improve error message for invalid return type of JSX component (#32702)
* New diagnostic message for wrong JSX function component

* Component and Mixed type

* fix existing tests

* add new test for JSX component return type error

* fix tslint error

* update diagnostic message to include component name

* accept baseline

* update tests

* missing semicolon

* accept baseline

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-03-30 13:04:33 -07:00
Jack Williams
4c440e5e5b
Fix #31319 : Narrow unit-unit inequality tests using comparability (#33071)
* Narrow unit-unit inequality tests using comparability

* Accept updated baselines

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-03-30 12:49:53 -07:00
Alexander T
d8170faee1
fix(33054): allow variables starting with an underscore in for/of statement (#36739) 2020-03-30 11:18:18 -07:00
Alexander T
96f01227d4
fix(36909): wrong error message when trying to named-import an export (#36925) 2020-03-28 12:16:50 -07:00
Alexander T
3c130d1317
feat(37092): improve error message about missing default export (#37212) 2020-03-27 14:33:01 -07:00
Sheetal Nandi
7f5994958b
Handle comment directives in incremental parsing (#37632)
* Add test case that shows failure to handle commentDirectives in incremental parsing
Testcase for #37536

* Handle comment directives in incremental parsing
Fixes #37536
2020-03-27 12:00:34 -07:00
Sheetal Nandi
0ae938b718
Report error when cannot read file (#37611)
This also consolidates helper for readFile failure
2020-03-25 21:29:02 -07:00
Ron Buckton
9119fe3797
Fix sys.debugMode when using VSCode's new preview debugger (#37558) 2020-03-25 19:18:36 -07:00
Ron Buckton
4fc4c4e3d6
Revert 'awaited' type (#37610) 2020-03-25 18:39:45 -07:00
Sheetal Nandi
84a3252e76
Handle packages inside another node modules package when auto importing (#37561)
Fixes #37542
2020-03-25 16:27:02 -07:00
Sheetal Nandi
fd9e602fcf
When the global file is deleted mark all files as changed (#37538)
* Add test case when the errors are not refreshed if global file is deleted
Testcase for #36728

* When the global file is deleted mark all files as changed
Fixes #36728

* Update other baselines to fix file info
2020-03-25 16:26:10 -07:00
Ron Buckton
b58a29b808
Fix emit for optional chain with non-null assertion (#36539)
* Fix emit for optional chain with non-null assertion

* Treat '!' differently inside chain vs end of chain

* remove dead code and fix comment
2020-03-25 15:28:13 -07:00
Wesley Wigham
4567fc4f1a
Ensure computed property names are always checked (#37307) 2020-03-25 15:16:54 -07:00
Sheetal Nandi
6c1e8aa0ad
Sort the arrays of fileNames in the build info (#37541)
* Sort the arrays of fileNames in the build info
Earlier we did this in testing to ensure we could baseline now moved to actual build info writing
Fixes #37156

* Sort using compareStringsCaseSensitive
2020-03-25 14:57:46 -07:00
Rustin
8615eecfc1
Enhancement new expression with type arguments without parenthesized argument list error message (#37576)
* Enhancement new expression with type arguments without parenthesized argument list error message

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

* add baselines

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

* use parseErrorAt

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

* refine code

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

* Space before paren

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2020-03-25 12:37:46 -07:00
Andrew Branch
37569d01f6
Convert to async function: handle type arguments to then/catch (#37463)
* Handle type arguments to then/catch

* Keep single-line types on a single line
2020-03-24 09:56:47 -07:00
Sheetal Nandi
11043b0951
Check JSDocPropetyTag (#37544)
Fixes #37040
2020-03-23 17:20:35 -07:00
Jack Works
38e717a244
fix: hyphened name not auto-completed by the ls (#37455)
* fix: hyphened name not auto-completed by the ls

* fix: accept new baseline

* Adds a test to validate the hypened identifiers in JSX

Co-authored-by: Orta Therox <orta.therox@gmail.com>
2020-03-23 17:08:44 -04:00
Anders Hejlsberg
fde9c7f555
Narrowing from truthy unknown to object (#37507)
* For x && typeof x === 'object', narrow x to just type object

* Add tests

* Allow arbitrary nesting / add comments

* Add additional tests
2020-03-20 17:09:24 -07:00
Ron Buckton
e3ec7b18b8
Add the 'awaited' type operator (#35998)
* Add the 'awaited' type operator

* Add script to manually add reviewers to a PR when GH 'Suggested Reviewers' breaks

* Fix lint error in review script

* Only defer generic awaited type for possible thenable

* Add variance-like behavior for awaited

* Switch awaited type params to 'unreliable' variance

* fix typo in inferTypes

* LKG without syntax in lib

* LKG with new syntax in lib

* Add 'strictAwaitedTypes' flag

* Treat strictAwaitedTypes as strict-mode flag

* Rename TAll, remove duplicate definition of 'race'

* Apply suggestions from code review

Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com>

* Fix inference priority

* Update comment to isGenericAwaitableType

* Add overloads for then/catch to Promise

* Add inference heuristic for T | PromiseLike<T> (for any PromiseLike)

* Remove strictAwaitedTypes flag

Co-authored-by: ExE Boss <3889017+ExE-Boss@users.noreply.github.com>
2020-03-20 16:09:01 -07:00
Sheetal Nandi
8f64d667f2
If emitting declaration file, update the d.ts signature in state to not have to save all files when different file changes without changing its shape (#37483)
* Add test that calling getAffectedFiles on two different files (even if the second one is saved) returns all files

* If emitting declaration file, update the d.ts signature in state to not have to save all files when different file changes without changing its shape
Fixes #30508
2020-03-20 10:16:41 -07:00
Sheetal Nandi
5e9c43607f
Handle auto import scenarios when using project references (#37482)
* Add test for project reference and auto import
Test for #34677

* Add project reference redirect to the possible file name to import if file is source of project reference redirect
Fixes the auto import suggestion when project is built

* Use fileExists that mimics presence of project reference redirect file when trying to get auto import file name
2020-03-19 16:53:44 -07:00
Eli Barzilay
ec95c27b4d
Fix getSignatureOfTypeTag (#37473)
Prevents infinite looping as in #37265.

Fixes #37265
2020-03-19 19:02:39 -04:00
Anders Hejlsberg
e15a9fb3a8
Track tuple type recursion in inferFromObjectTypes (#37479)
* Track recursive tuple types in inferFromObjectTypes

* Add regression test
2020-03-19 14:05:33 -07:00
Sheetal Nandi
7e07a2b5d1
Allow rich response for compile on save (#37462)
Fixes #30739
2020-03-19 14:03:21 -07:00
Wesley Wigham
c513a4adea
Allow nested conditionals to be related via constraints (#37208)
* Allow nested conditionals to be related via constraints

* Delete word in comment
2020-03-19 12:03:50 -07:00
Allan Guwatudde
a83ce339c9
Fix poor error span for unclosed JSX tags in the presence of whitespace/comments (#37419)
* Improve jsx tag error span

* Move solution to parseJsxChild func

* Add tests and update baselines

* Update comment in src/compiler/parser.ts

Co-Authored-By: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Use skipTrivia to check for whitespaces and other trivia

* Import React into  errorSpanForUnclosedJsxTag.tsx

* .

* .

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2020-03-19 11:40:43 -07:00
Wesley Wigham
e2156a1535
Add huge maximal length for noTruncation mode (#37461) 2020-03-19 10:45:00 -07:00
Andrew Branch
237ea526f9
Preserve newlines from original source when printing nodes from TextChanges (#36688)
* Allow emitter to write multiple newlines in node lists

* Progress

* Progress

* Fix recomputeIndentation

* Add tests, fix leading line terminator count

* Do a bit less work when `preserveNewlines` is off

* Fix accidental find/replace rename

* Restore some monomorphism

* Fix single line writer

* Fix other writers

* Revert "Fix other writers"

This reverts commit 21b0cb8f3b.

* Revert "Fix single line writer"

This reverts commit e535e279f9.

* Revert "Restore some monomorphism"

This reverts commit e3ef42743a.

* Add equal position optimization to getLinesBetweenRangeEndAndRangeStart

* Add one more test

* Actually save the test file

* Rename preserveNewlines to preserveSourceNewlines

* Make ignoreSourceNewlines internal

* Optimize lines-between functions

* Add comment;

* Fix trailing line terminator count bug for function parameters

* Preserve newlines around parenthesized expressions

* Back to speculative microoptimizations, yay

* Don’t call getEffectiveLines during tsc emit at all
2020-03-19 09:46:00 -07:00
Wesley Wigham
667f3b411e
Allow assertion signatures to narrow by discriminant (#37310) 2020-03-18 21:16:55 -07:00
Alexander T
ac3dc0c4d4
fix(37287): check appropriate context with enabled useDefineForClassFields (#37323) 2020-03-18 17:03:07 -07:00
Alexander T
0aa2e2783c
feat(37409): add fix all quick fix to fixInvalidJsxCharacters (#37436) 2020-03-18 09:54:17 -07:00
Anders Hejlsberg
0222211acb
Support for/of variables in assertion checking (#37432)
* Support for/of variables in assertion checking

* Integrate with "dotted name" logic

* Add tests
2020-03-17 19:20:56 -07:00
David Sherret
48e1745d6d
Fix Node#getStart(sourceFile, true) throwing when node has a js doc and no parent (#37439)
* Fix missing source file argument.

* Add test

* fix lint

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-17 16:08:57 -07:00
Alexander T
66aa9e77bf
fix(36247): disallow 'constructor' as a parameter property name (#37285) 2020-03-17 14:48:05 -07:00
Josh Goldberg
878f447798
Clarified file-not-found error for reference paths without extensions (#35956)
* Clarified file-not-found error for reference paths without extensions

* Updated error message to include extensions

* update baselines missed in merge

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-17 14:21:23 -07:00
Sheetal Nandi
e60bbac84f
Fix declaration emit when the packages are included through symlinks (#37438)
* Convert symlink scenarios to virtual FS where its symlinks are correctly maintained
Adds test for #36866

* Fix the casing issue when redirects differ in casing of the file

* Make ModuleSpecifierResolutionHost internal

* Refactoring for ModuleSpecifierResolutionHost

* If any of the file path option is from node_modules folder, consider only paths in node_modules folder

* Update src/services/utilities.ts

Co-Authored-By: Andrew Branch <andrewbranch@users.noreply.github.com>

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2020-03-17 13:21:40 -07:00
Alexander T
a510cad873
fix(36936): fix crash caused by resolving non existent export (#37077) 2020-03-17 13:21:20 -07:00
Alexander T
f1eb9898fb
feat(36908): add 'property overwritten by spread' error for jsx attributes. add related span for conflicting declaration in spread (#37329) 2020-03-17 13:13:38 -07:00
Andy Hanson
b0450aed56
Add codefix for --noImplicitThis (#27565)
* Add codefix for --noImplicitThis

* Code review

* Back to building post-merge

* Remove redundant functions + update tests

Infer-from-usage also inserts `this: any` parameters when needed, so I
removed that from fixImplicitThis.

Otherwise, fixImplicitThis has better suggestions than inferFromUsage,
so I moved inferFromUsage later in the suggestion order.

* More redundancy removal

Don't need to add `@this` anymore either since inferFromUsage will do
that.

* More baseline updates

From moving inferFromUsage down in priority I think?

* remove now-redundant ad-hoc jsdoc emit

* fix more bad merge

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-17 13:00:14 -07:00
Anders Hejlsberg
9120497a33
Flatten immediately nested conditional types in the false position (#36583)
* Flatten immediately nested conditional types in the false position

* Add test

* Accept new baselines

* Handle nested distributive types with different checkType

* Allow deeply nested immediately resolving conditionals without any syntactic requirements or implementation contortions

Extract logic into function

Co-authored-by: Wesley Wigham <wewigham@microsoft.com>
2020-03-16 16:40:04 -07:00
Sheetal Nandi
2458c8a016
When the imported module is through node_modules and symlink to folder that isnt node_modules (#37387)
* Add tests that fail because of symlink to non common directory node_modules

* When the imported module is through node_modules and symlink to folder that isnt node_modules
Most of the monorepo like scenarios are like this so looking at symlink to decide if file can be imported is essential
Fixes #28689
2020-03-16 11:15:39 -07:00
Anders Hejlsberg
b8baf48043
Fix assignment of intersections to objects with optional properties (#37195)
* Treat intersections of only objects as a single object in relations

* Exclude intersections containing non-inferrable types

* Accept new baselines

* Update test

* Accept new baselines

* Add tests
2020-03-14 09:45:05 -07:00
Klaus Meinhardt
8b6bd41ce7
getPropertiesOfUnionOrIntersectionType: handle types with index signature (#31979)
* getPropertiesOfUnionOrIntersectionType: handle types with index signature

Fixes: #31565

* fix test

* more testing

* fix typo in checker.ts

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-13 14:30:53 -07:00
Alexander T
fc30095e8b
feat(33792): add new quick fix service to handle missing call in condition (#37152) 2020-03-13 13:38:44 -07:00
Wesley Wigham
47b60ece0b
Make substitution types even if the substitution base isnt a type variable (#37348)
* Make substitution types even if the substitution base isnt a type variable

* Broaden usage of getConditionalFlowTypeOfType to _all_ type lookups

* Align comments
2020-03-13 11:02:11 -07:00
Alexander T
b41eb1bc61
feat(36249): add quick-fix action to declare a property as private which starts from underscore (#36632) 2020-03-13 10:33:56 -07:00
Wesley Wigham
df523b30cf
Filter the type of a binding pattern to not include undefined is the pattern parent has an initializer (#37309) 2020-03-12 17:50:05 -07:00
Donald Pipowitch
e0f6ecd957
improve error message TS2307 (#27054)
* improve error message TS2307

* add updates missed from merge

* update more missed baselines

* remove incorrectly re-added test files

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-12 15:55:54 -07:00
Sheon Han
b014e2b568
Show token hints for missing closing braces (#36317)
* Add error for missing brace in object literal

* Add new baseline test

* Update all affected tests
2020-03-12 15:52:02 -07:00
Ryan Cavanaugh
0426e48828
Fix crash when host.getSourceFile returns undefined (#37373)
Another day, another incorrect non-null assertion

Fixes #37368
2020-03-12 15:45:56 -07:00
M.Yoshimura
f06f809c75
Treat write-only-access to a class member with setter as a reference. (#35922)
* Treat write-only-access to a class member with setter as a reference.

* Add test case for unused private members, special-casing the member with a setter.
2020-03-12 15:41:40 -07:00
Jack Williams
dcc73944f4
Fix 33436 (#35225)
* Fix 33436

* Fix code

* Fix error message after bad merge

* Remove whitespace
2020-03-12 15:40:14 -07:00
Klaus Meinhardt
7bd6209fbc
Don't parse duplicate JSDoc for ExpressionStatement starting with ParenthesizedExpression (#36289)
* don't parse JSDoc on ExpressionStatement if it starts with ParenthesizedExpression

* update test
2020-03-12 14:42:49 -07:00
Sheetal Nandi
a76a16696d
Move useSourceOfProjectReferenceRedirect to program so other hosts can use it too, enabling it for WatchHost (#37370) 2020-03-12 13:11:11 -07:00
Sheetal Nandi
1f710167de
Ensure that we have seenAffectedFiles map when files are added to pending emit because they were present in the old state (#37302)
* Make the systems for baselining default to pretty

* Ensure that we have seenAffectedFiles map when files are added to pending emit because they were present in the old state
This happens in build scenarios since semantic diagnostics are queried before emit and hence files are added to seenAffectedFiles pending emit
Fixes #37269
2020-03-12 10:54:30 -07:00
Anders Hejlsberg
41a80f5d92
No infinite recursion in excess property and weak type checks (#37360)
* New IntersectionState.ExcessCheck flag to ensure no infinite recursion

* Add regression test
2020-03-12 09:40:15 -07:00
Andrew Casey
9e97b00ca1
adds error message for using value as type argument (#37359)
This addresses issue #28975
(https://github.com/microsoft/TypeScript/issues/28975).

When providing a value as a type argument, we can suggest a more specific
error message: "Did you mean to use typeof T?"

adds error message

WIP: Detect error

WIP: progress

updated tests

janky implementation

adds test coverage around literal types being unaffected

refactor out isIdentifierATypeArgument function

adds test case for type alias

adds test case for nested type arguments

fixes linting errors

merge master into branch to overwrite changes

changes value as type error message

This suggests 'typeof T' as a potential alternative when we give an error
about using value T as a type.

remove stale tests from old change

Co-authored-by: John Patterson <john@johnppatterson.com>
2020-03-11 19:18:17 -07:00
Sheetal Nandi
1a9c8197ff
Optimize module resolution cache for watch and editor (#37055)
* Refactor resolveName

* Have resolutions of failed lookups as array and resolved to fileName map
2020-03-11 14:35:26 -07:00
Anders Hejlsberg
6856c012d2
Use objects instead of closures for type mappers (#36576)
* Use objects instead of closures for type mappers

* Flatten combined type mappers

* Single point of creation for type mappers

* More optimizations

* Fix lint error

* Fewer symbol instantiations / discard type mapper after instantiation

* More optimizations

* Simplify mapper layout and cache in composite mappers

* Removing cache as it doesn't seem to matter much

* Get rid of identityMapper
2020-03-11 13:28:49 -07:00
Austin Cummings
ae3d28b5eb
Implement constructor type guard (#32774)
* Implement constructor type guard

* Fix code review issues for constructor type guard.
- Do not limit constructor expression to only identifiers
- Fix `assumeTrue` and operator no-narrow check
- Use better way to check that identifier type is a function
- Loosen restriction on what expr is left of ".constructor"
- Update typeGuardConstructorClassAndNumber test to include else cases

* Fix grammar & spacing in `narrowTypeByConstructor`

* fix bad merge

* switch (back?) to crlf

* update baselines

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-11 13:16:33 -07:00
Anders Hejlsberg
b78ef30cb7
No union subtype reduction during type inference (#37327)
* No union type subtype reduction in getImplicitIndexTypeOfType

* Add regression test
2020-03-11 10:27:51 -07:00
Arpad Borsos
5937ffdf25
Add constructor functions for {Symbol,Node}Links (#36845)
Using a constructor function like this can help node better optimize
object allocation. This improves memory usage when compiling
`src/compiler` from **277M** to **270M**, a nice ~3% win.
2020-03-11 08:40:51 -07:00
Wenlu Wang
20625a964b
add promise.any (#33844)
* add promise.prototype.any

* add AggregateError

* Update src/lib/esnext.promise.d.ts

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

* update baseline again

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-11 08:36:00 -07:00
Jack Williams
67ca82b375
Add flag to omit default case (#33574) 2020-03-10 15:04:03 -07:00
Anders Hejlsberg
c4da90368f
Infer to erased signatures (#37261)
* Use erased signatures as inference targets

* Add tests
2020-03-10 08:42:36 -07:00
Sheetal Nandi
e68524a8d2
Handle WatchCompilerHost without timeout methods to retrieve correct Program (#37308) 2020-03-09 16:30:52 -07:00
Josh Goldberg
bf15eac16e
Removed unused host variable in createProgramHost (#37278)
As stated in 26417, `host` is only ever written to and never read from. `createProgramHost` is the only place I could find that provides a member for `ProgramHost`'s `onCachedDirectoryStructureHostCreate`, so that's removed as well.
2020-03-09 13:53:49 -07:00
Andrew Branch
bc0e5a241c
Fix longer type-only property access in non-emitting heritage clauses (#37264)
* Fix longer type-only property access in non-emitting heritage clauses

* Rename misnomer function
2020-03-09 12:05:36 -07:00
Sheetal Nandi
8dede43365
Reset hasChangedAutomaticTypeDirectiveNames once new program is created (#37266)
* Allow passing watch to the change as parameter

* Reset hasChangedAutomaticTypeDirectiveNames once new program is created
Also dont invoke afterProgramCreate if the program is not new
2020-03-06 18:21:16 -08:00
Ben Lichtman
631def81d5
Merge pull request #37260 from uniqueiniquity/watchFileExistsFix
Fix fileExists check for a watch program
2020-03-06 13:01:03 -08:00
Ben Lichtman
0ed21e34ed Fix file exists check for watch program 2020-03-06 09:44:16 -08:00
Nathan Shively-Sanders
458977b94b
Reinstate incorrectly removed esnext.bigint (#37233)
* Reinstate incorrectly removed esnext.bigint

From a bad merge I made in #33845

* fix esnext.bigint alias
2020-03-05 10:11:48 -08:00
Orta
ffde92349d
Added @ts-expect-error to @ts-ignore directives (#36014)
* Added @ts-expect-error to @ts-ignore directives

Similar to `// @ts-ignore`, but will itself cause a new error diagnostic if it does not cause an existing diagnostic to be ignored.

Technical summary:
1. The scanner will now keep track of `CommentDirective`s it comes across: both `@ts-expect-error` and `@ts-ignore`
2. During type checking, the program will turn those directives into a map keying them by line number
3. For each diagnostic, if it's preceded by a directive, that directive is marked as "used"
4. All `@ts-expect-error` directives not marked as used generate a new diagnostic error

* Renamed to getDiagnosticsWithPrecedingDirectives per suggestion

* Added JSDoc comment I thought I did already

Co-authored-by: Orta <orta.therox+github@gmail.com>
2020-03-05 10:37:36 -05:00
Nathan Shively-Sanders
0a1af90bb6
add string.prototype.replaceAll (#33845)
* add string.prototype.replaceAll

* accept baseline

* fix bad merge in tests

* update missed baselines

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-04 13:25:17 -08:00
Nathan Shively-Sanders
061338e82b
Don't inferFromIndexTypes() twice (#34501)
* Don't inferFromIndexTypes() twice

* Add tests
2020-03-04 13:19:35 -08:00
Eli Barzilay
5c8def9a06 Fix emitting ?.
Use `emit()` for writing `questionDotToken`, leading to properly calling
the emit hooks (which `emitTokenWithComment` doesn't) and printing the
comments.  This fixes #35372 by calling its hooks to set the `.__pos`
and `.__end` fields.

Also, remove `getDotOrQuestionDotToken` which was used only here --
mainly because it seems likely to encourage misusing the
`questionDotToken` again.

Also, fix a bunch of `visitor` -> `tokenVisiton` calls in
`visitorPublic.ts`.
2020-03-04 14:52:33 -05:00
Ryan Cavanaugh
67930fc163
Don't crash when there's no class type to derive a 'this' type from (#37164)
Fixes #37161
2020-03-04 09:34:28 -08:00
Wesley Wigham
dfc0b58fe7
Preserve arity for preserving js optional parameters (#37173) 2020-03-04 00:48:53 -08:00
Nathan Shively-Sanders
b481dd4d4b
More precise property-overwritten-by-spread errors (#37192)
* More precise property-overwritten-by-spread errors

Trying to do this check in getSpreadType just doesn't have enough
information, so I moved it to checkObjectLiteral, which is a better
place for issuing errors anyway.

Unfortunately, the approach is kind of expensive in that it

1. creates a new map for each property and
2. iterates over all properties of the spread type, even if it's a
union.

I have some ideas to improve (1) that might work out. I'm not sure how
bad (2) is since we're going to iterate over all properties of all
constituents of a union.

Fixes #36779

* another test and rename
2020-03-03 15:10:19 -08:00
Alexander T
3046a54401
fix(36883): accessor allows this parameter but is not checke… (#36889) 2020-03-03 12:26:41 -08:00
Alexander T
176241cca9
fix(36238): allow aliases in spelling suggestions (#37168) 2020-03-03 10:58:29 -08:00
Wesley Wigham
5941c6e1b1
Emit an any for namepath types (#37176) 2020-03-03 10:55:21 -08:00
Alexander T
ab8adc5f95
fix(37135): handle PrivateIdentifiers in isPropertyName (#37184) 2020-03-03 10:51:50 -08:00
Wesley Wigham
b9c0999a2a
Thread host.useCaseSensitiveFileNames through program and node builder into specifier generation (#37170) 2020-03-03 10:50:01 -08:00
Wesley Wigham
67c6cebfc8
Reinterpret a type parameter constrained to any as an upper bound constraint (#29571)
* Reinterpret a type parameter constrained to any as an upper bound constraint

* Use real constraqint in alias in test

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-03 09:51:15 -08:00
Andrew Casey
dd6811fbe3
Stop looking for the default configured project at node_modules (#35011)
* Optionally stop looking for the default configured project at
node_modules

* Make stopping at node_modules non-optional

* Generalize and simplify the change - node_modules files don't have default configured projects
2020-03-02 16:52:03 -08:00
Wesley Wigham
ff0422091f
Update LKG (#37175)
* Update LKG

* Remove unneeded check (handled by top of function)
2020-03-02 15:15:41 -08:00
Wesley Wigham
af4201ff51
Retain reexports in js emit even when they export nothing (#37124) 2020-03-02 14:33:53 -08:00
Wesley Wigham
d209092ccc
Use merged symbol to pick up js-alias-merged members on export assignments (#37162) 2020-03-02 12:57:00 -08:00
Nathan Shively-Sanders
392fd0ac0b
Remove bogus @implements errors (#37114)
* Remove bogus @implements errors

Make the search for the actual host more comprehensive by reusing the
code that previously only searched for functions. I don't know what to
call this function now, since the old name wasn't accurate either.

* undo gratuitous name change

* Improve name and make calling more uniform

It's slightly less efficient but I think worthwhile for readability.
2020-03-02 09:48:53 -08:00
Anders Hejlsberg
a5796cf3b2
Remove ordering restrictions in control flow analysis (#37134)
* Don't reset CFA type for x.y when x is narrowed

* Add tests

* Accept new baselines

* Remove unnecessary type assertion
2020-02-29 12:03:09 -08:00
Anders Hejlsberg
be4b814a4c
Reduce intersections by discriminants (#36696)
* Treat never-like intersections as never

* Accept new baselines

* Fix compiler issues revealed by increased intersection correctness

* Delete fourslash tests that are no longer applicable

* Include isNeverLikeIntersection check in getNormalizedType

* Erase never-like types in several more places

* Check that base types are not never-like

* Add comments

* Revert isNeverLikeType check in getIndexType (keyof shouldn't resolve member types)

* Introduce getReducedType for union and intersection types

* Don't reduce in getApparentType

* Avoid relationship check in resolveMappedTypeMembers

* Accept new baselines

* Don't call getReducedType in getIndexType

* Ensure reduced and unreduced forms of a type can compare identical

* Reduce types before converting them to string representation

* Accept new baselines

* Reduce intersections before obtaining keyof X

* Add tests

* Accept new baselines

* Fix comment in tests

* Don't infer from empty intersection types

* Add tests

* Accept new baselines

* Defer instantiation of mapped type property types

* Accept new baselines

* Include more precise type in diagnostic

* Accept new baselines

* Minor optimization

* Improve error message

* Optional properties in intersections are never discriminants
2020-02-28 17:06:44 -08:00
Wesley Wigham
f31ff2dac0
Revert #36907 (#37122) 2020-02-28 15:53:24 -08:00
Andrew Branch
f9945f5acf
Full support for CommonJS auto-imports in JS (#37027)
* Support add new requires

* Always use destructuring for requiring default exports

* Add more tests

* Update existing fourslash tests

* Use `getExportsAndPropertiesOfModule`

* Add UMD test

* Apply suggestions from code review

Fix typos

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

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-02-28 14:34:20 -08:00
Wesley Wigham
c6c2c4c8d5
Hoist initial assignment to exported names in cjs to they are not blocked by bindings made by __exportStar (#37093)
* Hoist initial assignment to exported names in cjs to they are not blocked by bindings made by __exportStar

* Copy hoisted identifiers so they do not create sourcemaps

* Accept updated baselines
2020-02-28 13:25:28 -08:00
Andrew Branch
0a6ee7753d
Grammar error on export type * (#37064)
* Recognize `export type *` syntax, but disallow it

* Add more comments to test

* Revert recognizing invalid forms as type-only

* Revert more
2020-02-27 16:35:15 -08:00
Pathurs
5c85febb0c
Fix Get/Set being enumerable (#32264)
* Fix Get/Set being enumerable

fixes #3610

* fix tests

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-02-27 14:08:20 -08:00
Wesley Wigham
e7c578a67d
Reapply contextual type when recalculating array literals as tuples (#37071) 2020-02-27 14:02:28 -08:00
Eli Barzilay
e71614a185 Proper treatment of splicing tuples in array literals
Fixes #32465.

After this was done, I continued to extend the implementation to handle
TupleLike types but it'ss broken since JS doesn't allow splicing
TupleLike values into array literals so pulled that out, and instead
keeping it for reference below.  (It Includes tests, which are broken
too.)

modified   src/compiler/checker.ts
@@ -22268,6 +22268,21 @@ namespace ts {
                         else hasNonEndingSpreadElement = true;
                     }
                 }
+                else if (spreadType && isTupleLikeType(spreadType)) {
+                    let i = 0, tupleEltType: Type | undefined;
+                    while (tupleEltType = getTypeOfPropertyOfType(spreadType, "" + i as __String)) {
+                        elementTypes.push(tupleEltType);
+                        i++;
+                    }
+                    const stringIndexInfo = getIndexInfoOfType(spreadType, IndexKind.String);
+                    const numberIndexInfo = getIndexInfoOfType(spreadType, IndexKind.Number);
+                    if (stringIndexInfo || numberIndexInfo) {
+                        if (stringIndexInfo) elementTypes.push(stringIndexInfo.type);
+                        if (numberIndexInfo) elementTypes.push(numberIndexInfo.type);
+                        if (i === elementCount - 1) hasEndingSpreadElement = true;
+                        else hasNonEndingSpreadElement = true;
+                    }
+                }
                 else {
                     if (inDestructuringPattern && spreadType) {
                         // Given the following situation:
new file   tests/cases/compiler/spliceTupleLikesWIntegers.ts
@@ -0,0 +1,23 @@
+declare const sb: { [0]: string, [1]: boolean };
+
+let k1: [number, string, boolean];
+k1 = [1, ...sb];
+
+let k2: [number, string, boolean, number];
+k2 = [1, ...sb, 1];
+
+// declare const sb_: [string, ...boolean[]];
+
+// let k3: [number, string, ...boolean[]];
+// k3 = [1, ...sb_];
+
+// declare const sbb_: [string, boolean, ...boolean[]];
+
+// let k4: [number, string, ...boolean[]];
+// k4 = [1, ...sbb_];
+
+// let k5: [number, string, boolean, ...boolean[]];
+// k5 = [1, ...sbb_];
+
+// let k6: [number, string, boolean, boolean, ...boolean[]];
+// k6 = [1, ...sbb_];
new file   tests/cases/compiler/spliceTupleLikesWStrings.ts
@@ -0,0 +1,23 @@
+declare const sb: { 0: string, 1: boolean };
+
+let k1: [number, string, boolean];
+k1 = [1, ...sb];
+
+let k2: [number, string, boolean, number];
+k2 = [1, ...sb, 1];
+
+declare const sb_: { 0: string, [s: string]: (boolean|string) };
+
+let k3: [number, string, ...(boolean|string)[]];
+k3 = [1, ...sb_];
+
+declare const sbb_: { 0: string, 1: boolean, [s: string]: (boolean|string) };
+
+let k4: [number, string, boolean, ...(boolean|string)[]];
+k4 = [1, ...sbb_];
+
+// let k5: [number, string, boolean, ...(boolean|string)[]];
+// k5 = [1, ...sbb_];
+
+// let k6: [number, string, boolean, boolean, ...(boolean|string)[]];
+// k6 = [1, ...sbb_];
2020-02-27 16:43:29 -05:00