Commit graph

15144 commits

Author SHA1 Message Date
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
Neonit d6af9b7cbc Fix indentation preservation in JSDoc (#37717)
This fixes two bugs in the parseJSDocCommentWorker().

1. The initial indent was calculated wrongly. It was set to the
   difference between the index of the last newline or beginning of file
   and the current start marker (position of /**). By calculating it
   this way, the newline character itself is counted as indentation
   character as well. The initial indent is used as margin for the
   whole comment. The margin contains the amount of characters to skip
   before the actual content or payload of a comment line. The algorithm
   does not skip non-whitespace characters at the beginning of the
   content, but it would strip away one whitespace character for
   indented content (which does matter, if there is e.g. a Markdown
   code block with indentation in the comment).

2. When reducing initial whitespace sequences of comment lines by the
   remaining margin the algorithm cut off one character too much. This
   might have been introduced to fix 1. It had a similar effect as 1.
2020-04-10 17:46:08 +02: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
Nathan Shively-Sanders 6c5c48c74c
Exempt ambient [#]private from unused error (#37050)
* Exempt ambient [#]private from unused error

These declarations exist to create nominality so they _must_ be unused.
There should be no error for them.

* Switch to fourslash test

I don't know how to baseline suggestion diagnostics in the compiler
tests.
2020-02-27 13:18:43 -08:00
Sheetal Nandi 188c3b7046
Measure module and type reference directive times (#37054) 2020-02-27 10:22:40 -08:00
Titian Cernicova-Dragomir f883bf3acb
Adding support for @implements. (#36292)
* Adding support for @implements.

* Fixed code review issues for @implements, added some more tests.

* Fixed declaration emit for @interface

* Improved getImplementsTypes to not cache the results since it is only used once.

* Removed unnecessary checks from getImplementsTypes
2020-02-27 09:27:37 -08:00
Alexander T baff821594
fix(36989): 'async' modifier cannot be used in an ambient context.ts (#37010)
* fix(36989): omit 'async' modifier for methods in declaration files.

* remove useless condition
2020-02-27 00:11:29 -08:00
Sheetal Nandi d07761fe39
Allow --composite false or --composite null on the command line (#36997)
* Add tests for specifying composite as command line option

* Allow passing --composite false on commandline

* Add test to verify tsc --composite false from command line

* Handle "undefined" as option value to be set to undefined for that option

* Support "null" as option to be converted to undefined which is normally end result from our config file as well

* Support null as option for any tsconfig only option as well, and dont support undefined

* Fix public api test case

* Validates objects instead of stringify result

* Add composite true to base source
2020-02-26 15:26:26 -08:00
Ryan Cavanaugh c4e96856ac
Detect circularities when removing 'undefined' from defaulted params (#37023)
Fixes #37008

Note that referencing a variable in its initializer is a TDZ error;
the OP report had OOB logic that prevented this in practice (?)
2020-02-26 14:59:04 -08:00
Andrew Casey b424f36e9a
Expose call count for instantiateType in extendedDiagnostics (#36797)
* Expose call count for instantiateType in extendedDiagnostics

* Update API baselines
2020-02-26 12:55:28 -08:00
Nathan Shively-Sanders af901ba911
No error on this exprs in static property inits (#36781)
No error on `this` expressions in static property declaration
initialisers when targetting ESNext and with useDefineForClassFields. In
this case the emit is correct and the types are correct, so the error
should not be issued.
2020-02-26 09:07:45 -08:00
Wesley Wigham 454cdb8279
Retain undefined initializations (#36806)
* Emit an export assignment even when the initializer is elided

* User a void 0; and elide assignments for enum/namespace-sourced exported variables

* HAHA, SIMPLIFY GREATLY
2020-02-26 08:48:18 -08:00
Wesley Wigham 15dd0002ef
Unwrap substitutions both before _and_ after potential simplification (#32116)
* Unwrap substitutions both before _and_ after potential simplification

* Repeatedly unwrap/simplify until no more can be performed

* Use seperate loops for source and target to reduce redundant calls

* Move loop into function

* Inline worker
2020-02-25 17:36:56 -08:00
Wesley Wigham 4d5464e1f9
Revert "Support declaration emit for late bound element accesses assigned to functions in both TS and JS (#36593)" (#37034)
This reverts commit 3e4ce4777d.
2020-02-25 16:40:38 -08:00
Anders Hejlsberg 9ed73ebbbf
Properly handle control flows from returns in try/catch within IIFE (#36901)
* Properly handle control flows from returns in try/catch within IIFE

* Accept new baselines

* Add tests

* Accept new baselines

* When end of finally is unreachable, end of try statement is too

* Add additional test case
2020-02-25 16:14:00 -08:00
Sheetal Nandi e89df5ce6f
Handle getScriptVersion correctly to ensure program structure is checked correctly (#36808)
* Fix tests when there are project references but has disableSourceOfProjectReferenceRedirect

* Handle getScriptVersion correctly to ensure program structure is checked correctly
Fixes #36748

* Harness's language service host doesnt have getProjectVersion.
This means earlier we were creating fresh program everytime we did LS operation
Now we reuse same program, so quick info depends on order of quickinfo demands

* Because same program is used, it unvails a bug that if `export=` is evaluated before finding references, it cant find all definitions from the merge

* Update src/server/project.ts

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

* Make clearSourceMapperCache required

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-02-25 16:11:21 -08:00
Wesley Wigham e99173a6f9
Ignore data- props when excess property checking (#36952) 2020-02-25 15:52:24 -08:00
Ryan Cavanaugh 43863cafe2
Check for undefined source.symbol (#37021)
Fixes #37014
2020-02-25 13:46:24 -08:00
Wesley Wigham 3e4ce4777d
Support declaration emit for late bound element accesses assigned to functions in both TS and JS (#36593) 2020-02-25 13:45:27 -08:00
Wesley Wigham 7d8dc730b7
Baseline arity checks for jsx sfc tags (#36643)
Finish comment

PR feedback
2020-02-25 13:44:22 -08:00
Wesley Wigham e536c89872
Add js-equivalent test for the binary expression stress and introduce trampoline into getJSSyntacticDiagnosticsForFile (#36724)
* Add js-equivalent test for the binary expression stress and introduce trampiline into getJSSyntacticDiagnosticsForFile

* Update src/compiler/parser.ts

Comment text update

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

* Fix lint

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-02-25 13:29:34 -08:00
Wesley Wigham 01f81dfc00 Add helpers to helper list, per comment on #36806 2020-02-25 11:46:05 -08:00
Wesley Wigham e54b796301
Declare dependencies between helpers in the declaritive fashion introduced by #35967 (#37001) 2020-02-25 11:29:59 -08:00
Wesley Wigham e120762390
Remove unneeded branch from getHelperName (#36998) 2020-02-25 11:29:45 -08:00
ExE Boss 5e40f32f66
fix(helpers): Use hasOwnProperty.call 2020-02-25 14:13:58 +01:00
Ron Buckton 177713ef45
Switch Debug.assertX functions to use asserts conditions (#36995)
* Switch Debug.assertX functions to use asserts conditions

* Replace assert functions with ts.noop when assertion level too low
2020-02-24 18:20:58 -08:00
Andrew Casey b5bd38bcdc
Convert UnionOrIntersectionType.couldContainTypeVariables to ObjectFlags (#36947)
...to save space (and possibly to reduce de-opts, since it appears to be
lazily set).
2020-02-24 18:18:39 -08:00
Andrew Casey 865c1209de
Use couldContainTypeVariables to short-circuit instantiateType (#36951)
This is particularly impactful for large unions of string literals.
2020-02-24 17:50:44 -08:00
Nathan Shively-Sanders 3e3df8702c
Fix crash on aliased,exported @enum tag in jsdoc (#36996)
THe code to bind `@enum` and `@typedef` didn't handle the case that the
`@enum` was on a property assignment to an alias of module.exports.
Specifically, `x` needs to be correctly aliased to the file's symbol in
the example below:

```
var x = module.exports = {};
/** @enum {string} */
x.E = {
  A: "A"
};
```
2020-02-24 16:13:18 -08:00
Wesley Wigham 65e7acce58
Use getters to define live export bindings refresh (#35967)
* use getters to define live export bindings

* fix scoping in export* helper

* Object.defineProperty cannot be used in ES3 target

* Accept changed baselines

* Use function expression, not arrow function

* Update importStarHelper to match export helper in binding-making

* Fix whitespace

* Adjust whitespace in edited helpers

* Use new helper for setting bindings, use unscoped __exportStar helper for exports so helpers get reused more

* Accept updated baselines

* Use __createBinding for individual reexports when target is es3

* Remove unneeded type assertion

* Singeline the helpers

* Add check for createBinding helper, accept updated baselines with shortened helper

Co-authored-by: Michael Rawlings <mirawlings@ebay.com>
2020-02-24 15:36:14 -08:00
Ryan Cavanaugh 2b69b2281a
Properly handle both special export forms when renaming (#36914)
* Properly handle both special export forms when renaming

Fixes #36713

* Lint
2020-02-24 13:17:02 -08:00
Ron Buckton fd8000dd59
Fix class emit in converted loop body (#36795) 2020-02-24 10:55:13 -08:00
Wesley Wigham ebca423a6e
Add elaboration & quickfix for async-able arrow function (#36342) 2020-02-21 15:51:02 -08:00
Nathan Shively-Sanders 6b645f582b
Fix find-refs crash on JSDocNamepath (#36941)
JSDocNamepaths span a lot of identifiers that we don't actually care
about, so it's incorrect for createChildren to add its children as
synthetic nodes.
2020-02-21 15:37:11 -08:00
Klaus Meinhardt 24dd93fc2b
Fix access of protected members on generic this-type (#36928)
Fixes: #36926
2020-02-21 09:33:21 -08:00
Andrew Branch 4d1a1b850a
Expose importModuleSpecifierEnding to protocol (#36725)
* Expose importModuleSpecifierEnding to protocol

* Update API baselines

* Add explicit auto setting
2020-02-20 13:59:56 -08:00
Wesley Wigham 7f02927b78
use const instead of let for new class iife assignments (#36907) 2020-02-20 12:48:02 -08:00
Alexander T bf6be75131
feat(36048): handle uncalled function checks in ternaries (#36402) 2020-02-20 09:29:41 -08:00
Wesley Wigham 4a34294908
Unify padding impls and consistently use them 2020-02-19 17:21:51 -08:00
Wesley Wigham 5144330c98
Fix implicit dependencies on es6 lib exposed by node changes 2020-02-19 16:43:40 -08:00
Andrew Branch 1236a1006c
Fix initialization error when destructuring from object literal that includes a spread assignment (#36865)
* Add test

* Fix superfluous error when destructuring from object that includes spread assignment

* Update baseline to include error case

* Remove redundant check
2020-02-19 08:28:12 -08:00
Charles 7cc4a8df94
Wrap classes with decorators or static properties in an IIFE, even for ES2015+ (#32011)
* Always wrap classes with decorators or static properties in an IIFE

Currently only script targets less than or equal to ES5 will wrap classes.  However, the wrapping is also crucial to file size optimizations for ES2015+ as well.  Without the IIFE wrapper, minification tools do not elide the class.  This is due to references to the class being present within the downlevelled decorator and static property code.
This change represents the full completion of issue #15857

* Accept new baselines
2020-02-14 16:28:55 -08:00
Klaus Meinhardt 9b518c8f53
Exempt ambient private properties from noImplicitAny (#36640) 2020-02-14 15:01:18 -08:00
Josh Goldberg 1aaf314678
Marked internal createAnonymousType type as allowing undefined Symbols (#36016) 2020-02-14 14:52:05 -08:00
Andrew Branch b1e706d911
Set correct pos for NamespaceExport (#36794)
* Set correct pos for NamespaceExport

* Update tests
2020-02-14 12:45:26 -08:00
Anders Hejlsberg 7a1c5b7a20
Avoid expensive relationship checking in mapped type member resolution (#36754)
* Avoid expensive relationship checking in mapped type member resolution

* Accept new baselines
2020-02-12 15:05:01 -08:00
Wesley Wigham 2b64731a97
Fix getTypeAtLocation for as const to not issue a diagnostic (#36741)
* Fix getTypeAtLocation for `as const` to not issue a diagnostic

* use existing helpers for checks

* Fix lint
2020-02-12 13:43:02 -08:00
Ron Buckton 195f6bb2ab Merge branch 'separate-nodetypes' of https://github.com/Swatinem/TypeScript into Swatinem-separate-nodetypes 2020-02-12 11:52:53 -08:00
Nathan Shively-Sanders 01c86c749d
Fix get candidate for overload failure checking (#36744)
* getCandidateForOverloadFailure:call resolveUntypedCall

This re-adds the missed errors and marks as used missed nodes from the
user and RWC baselines.

* Update baselines and remove new test

It was redundant with the old tests

* Defer resolveUntypedCall on resolution failure to give priority to parameter types fixed by overload signatures

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-02-12 11:42:56 -08:00
Ron Buckton cf6b641709
Merge branch 'master' into separate-nodetypes 2020-02-12 11:23:51 -08:00
Wesley Wigham 6f079a4ebc Update versionMajorMinor to match package.json 2020-02-11 15:34:17 -08:00
Wesley Wigham 8481bc1d98
Do not report errors when we fail to find a module symbol at an import specifier when invoked via API (#36742) 2020-02-11 14:49:11 -08:00
Nathan Shively-Sanders a772c26a71
Error when property is specified more than once via a spread (#36727)
* add tests but not baselines or fixes

* Update original change

Still probably wrong; probably doesn't even compile beacuse I'm just
typing on my laptop.

* fix error code ok

* notes to self

* Error: property is specified more than once via spread

* make jsx tests stricter

* update semicolon error message

* use ?. because it is great

* use maybeTypeOfKind in new code

* restore jsx error

* add tests
2020-02-11 10:23:15 -08:00
Brad Zacher 348c4dddc6
Throw syntax error for } and > in JSX text (#36636)
* Throw syntax error for `}` and `>` in JSX text

Fixes #36341

* Add codefix for error
2020-02-11 11:44:17 -05:00
Wesley Wigham aece8c06b0
Allow intersections (and substitutions) to be checks against discriminable unions (#36663) 2020-02-10 15:26:46 -08:00
Nathan Shively-Sanders 71c1da020f
redo #28564 (#36665) 2020-02-07 09:55:29 -08:00
Nathan Shively-Sanders 1e48cbe2c9
Fix jsdoc comment parsing initial state (#36661)
* Fix jsdoc comment parsing initial state

Jsdoc comment parsing can be invoked in two modes:

1. top-level parsing, for comments not inside a tag.
2. tag parsing, for comment that occur after the semantic parts of a
tag.

Top-level parsing skips an initial * because it assumes that it is starting
at the very beginning of a JSDoc comment. Tag parsing does not.

The two modes are distinguished by an optional second parameter named
`margin`. When `margin` is provided, it provides an initial indent used
for comment alignment.

Previously, the check for `margin` was a truthy check `if (margin)`.
This check incorrectly treats `margin=""` the same as
`margin=undefined`.

This PR changes the check to `if (margin !== undefined)`, which
correctly treats `margin=""` the same as `margin="    "`.

* Fixes for broken tests

1. Use SawAsterisk start state.
2. @template needs to skip asterisk in addition to whitespace while
parsing type parameter names.

* undo code move
2020-02-07 08:35:40 -08:00
Anders Hejlsberg b8b59489e1
Cache results of isGenericObjectType and isGenericIndexType (#36622) 2020-02-05 16:04:05 -08:00
Anders Hejlsberg de37c87252
Optimize deferred type references (#36607)
* Improve reasoning about when to create deferred type references

* Accept new baselines

* Fix minor issues

* Handle default type arguments case in isDeferredTypeReferenceNode
2020-02-05 16:03:42 -08:00
Anders Hejlsberg 0a160323df
Faster exit from isTypeRelatedTo with identityRelation (#36590)
* Faster exit from isTypeRelatedTo with identityRelation

* Reorganize a bit
2020-02-05 16:03:09 -08:00
Wenlu Wang 70399e146e
add support for Lift Template Literal Restriction (#23801)
* add support for Lift Template Literal Restriction

* rename file and improve comment and tests

* fix NoSubstitutionTemplateLiteral support

* extract tagged template and add more test

* avoid useless parameter

* fix incorrect return node if cannot transform

* accept baseline

* correctly baseline

* accept baseline

* fix merge break

* fix merge break

* inline rescan template head or no subsititution template

* update scan error

* add comment and fix lint

* refactor and fix lint

* avoid blank

* fix merge conflict

* fix again

* fix again

* use multiple target

* fix space lint

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-02-05 08:59:51 -08:00
Andrew Branch 20471182fc
Fix crash when trying to import a non-exported type (#36619)
* Fix crash when trying to import a non-exported type

* Add related info on each declaration
2020-02-05 08:27:49 -08:00
hafiz 09441107c1
Expose hasOnlyExpressionInitializer as a public type guard (#33229)
Exposes `hasOnlyExpressionInitializer` as a public function so users of
TypeScript compiler APIs do not have to roll their own
`HasExpressionInitializer` type guards.

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-02-04 16:01:20 -08:00
Andrew Casey da8d3ef0a8
Drop support for defunct Chakra host (#33797) 2020-02-04 15:53:45 -08:00
Alexander T 8c31700735
Enable @typescript-eslint/space-before-function-paren, @typescript-eslint/no-unused-expressions (#36569)
* use @typescript-eslint/no-unused-expressions instead of no-unused-expressions

* enable @typescript-eslint/space-before-function-paren
2020-02-04 14:43:25 -08:00
Orta 7726464abd
De-duplicate indentations in JSX Texts (#36552)
* WIP on making the JSX text node not include whitespace

* Scans to the last newline for JSX correctly

* Handle JSX closing element wrapping

* Offload all jsx text indentation handling to indentMultilineCommentOrJsxText

* Switch from find node -> find inde in formatting

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-02-03 17:09:50 -05:00
Andrew Branch ef8eb0c876
Fix contextually typed object literal completions where the object being edited affects its own inference (#36556)
* Conditionally elide a parameter from contextual type signature calculation

* Slightly different approach to forbid inference to specific expressions

* Handle nested literals and mapped types correctly

* Delete unused cache

* Rename ContextFlags.BaseConstraint and related usage

* Add tests from my PR

* Update ContextFlags comment

Co-Authored-By: Wesley Wigham <wwigham@gmail.com>

* Update comments and fourslash triple slash refs

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-01-31 15:37:18 -08:00
Nathan Shively-Sanders ad249043da
resolvedJSDocType should cache on node, not symbol (#36561) 2020-01-31 15:19:45 -08:00
Andrew Branch 86556d6c03
Fix export * that resolves to something type-only (#36558)
* Fix `export *` that resolves to something type-only

* Add same tests but non-tsserver
2020-01-31 15:09:27 -08:00
Ron Buckton fcf28506aa
Fix overzealous renaming of emit helpers in es module emit (#36541) 2020-01-31 10:41:47 -08:00
Ron Buckton 24d8f795b2
Fix crash in emitTokenWithComment (#36542) 2020-01-31 10:41:09 -08:00
Sheetal Nandi 80ad0de87e
Fixes to handle file names in module resolution watching and createGetCanonicalFileName (#36106)
* Add test case to verify directory casing preservation when watching

* Fix unicode file name handling when watching failed lookup locations

* Add special file name lower conversion routine and use that instead of toLowerCase
Fixes #31819 and #35559

* Remove unicode from code

* Replace toLocaleLowerCase on filenames with ts.toFileNameLowerCase

* Make the intent of using toFileNameLowerCase more clear and why we make the restriction on turkish I with dot on top of it

* Update baselines for newly added tests in master
2020-01-31 10:40:57 -08:00
Eli Barzilay 75d1ead3fd Improvements based on @sandersn's notes 2020-01-30 22:42:04 -05:00
Eli Barzilay 1a1ed7464d Add a similar test for target.symbol.valueDeclaration
(With the same question still open.)
2020-01-30 22:42:04 -05:00
Eli Barzilay 68a9d4592f Avoid testing isClassDeclaration if there's no valueDeclaration
I'm not sure if this is enough -- perhaps it's better to make the test
dig through the interface/s to the class?

Fixes 36059.
2020-01-30 22:42:04 -05:00
Ron Buckton f24f36350b
Fixes JSX attribute escaping when parent pointers are missing (#35743)
* Fixes JSX attribute escaping when parent pointers are missing

* Fix whitespace change
2020-01-30 16:52:31 -08:00
Hye Sung Jung 8ed129771f
fix spelling errors (#36523)
* fix spelling errors

* remove changes in lib/*
2020-01-30 13:39:54 -08:00
Sheetal Nandi 4c378c09dc
Report config file parsing diagnostics correctly with tsc --b (#36520)
* Refactor the test

* Add tests for syntax errors in tsconfig not being reported

* Report config file parsing diagnostics correctly
Fixes #36515

* Fix errors in existing tests for unintended tsconfig parse errors

* Fix lint
2020-01-30 11:18:06 -08:00
Nathan Shively-Sanders c1e45ac8af
Fix use-before-def errors for ESNext property declarations (#36465)
* Fix use-before-def errors for ESNext property declarations

Fixes #36441
Fixes #36442

* Handle property declarations in nested classes
2020-01-30 10:58:07 -08:00
Anders Hejlsberg 8a0b8822b2
Fix contextually typed parameter issues (#36476)
* Fix multiple issues with contextually typed parameters

* Accept new baselines

* Fix lint error

* Add tests

* Address CR feedback

* Add fourslash tests
2020-01-30 10:50:39 -08:00