Commit graph

32005 commits

Author SHA1 Message Date
TypeScript Bot b34e705672 Update package-lock.json 2021-03-26 06:08:00 +00:00
Andrew Casey 6066eaec09
Port realpath workaround from release-4.2 (#43384)
* Don't use _fs.realpathSync.native on windows, a semi-revert of #41292 (#43348)

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

(cherry picked from commit e462dfa347)

* Un-reverse condition

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

Fixes #33722.
2021-03-25 15:48:34 -04:00
TypeScript Bot 42b0e3c463 Update package-lock.json 2021-03-25 06:11:10 +00:00
Titian Cernicova-Dragomir e638af7560
ES private class elements (#42458)
* Added support for private identifier methods.

* Added tests for private methods.

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

* Added private accessors tests

* Transform private methods

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

* Rename shouldTransformPrivateFields

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

* Accept baseline

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

* Use a single WeakSet for brand-check

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

* Accept baseline

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

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

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

* Add breaking checker test

Private methods inside class expressions should not error.

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

* Add to instances once per-instance

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

* Accept baseline

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

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

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

* Add a test for evaluating rhs before readonly assignment

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

* Transpile private accessors

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

* Accept baseline

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

* fix: handle readonly/writeonly accessors

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

* accept baseline

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

* add a test for private setter without a getter

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

* fix: getAllUnscopedEmitHelpers

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

* fix: better handling of duplicate names

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

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

* change error message

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

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

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

* fix: setter assignment returns rhs value

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

* add a test for setter assignment return value

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

* fix: handle duplicate accessors

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

* add tests for duplicate accessors

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

* docs: add missing parameter docs

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

* Fixed failing test.

* baseline-accept: ordering changes

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

* fix: attach weakSetName to property declaration

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

* add a test for nested private methods

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

* add a test with any

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

* Added support for static private fields accessors and methods.

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

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

* Added tests for private static fields methods and accessors.

* Fixed error messages and tests after merge.

* Accept new baseline.

* Improved duplicate identifier checks for static private class elements.

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

* Fixed code review issues.

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

* Changed emit for uninitialized private static fields.

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

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

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

* Fixed code review issues.

* Fixed code review issues for private class elements.

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

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

* collapse switch case

* fix class name

* simplify getPrivateMethodsAndAccessors

* remove findPreviousAccessorInfo

* lazily create weakSetName identifier

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

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

* Simplified emit for private identifier class elements.

* do not clone the receiver (#57)

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

* Added check for WeakSet collision.

* Added error for using a set only accessor.

* update keyof tests and ?? (#62)

* replace ?? with ||

* update keyof tests

* fix emit helpers comments

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

* add tests

* fix setter-only compound assignment

* fix tests

* fix duplicated trailing comments (#64)

* clear receiver pos and setTextRange on helper calls

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

Do three things to improve this:

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

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

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

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

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

* Incremental correctness checks

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

This reverts commit 451d4354b9.

* Fix parsing @link at end of comment

* Parse comments as string when no @link occurs

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

* Add preferences to getExtensionsOptions call

* Add test case

* Fix test case typos
2021-03-22 14:10:41 -07:00
Afonso Jorge Ramos b7c0e5da5d
Delete issue_template.md (#43320) 2021-03-22 10:39:37 -07:00
Wesley Wigham 9a256a1935
Adjust scanning of keywordy jsx namespace names, add grammar error for jsx dotted names containing namespace names (#43104) 2021-03-22 10:28:43 -07:00
TypeScript Bot 865cec3ece Update package-lock.json 2021-03-22 06:30:23 +00:00
Ron Buckton 03bf732f73
Accepts baseline change caused by #43035 (#43322) 2021-03-21 13:42:20 -07:00
TypeScript Bot fd494c11f9 Update package-lock.json 2021-03-20 06:24:32 +00:00
Ron Buckton 9af313db77
Use shared binary trampoline in checker (#43035) 2021-03-19 18:54:51 -07:00
Anders Hejlsberg 15fae38b39
Improve narrowing of generic types in control flow analysis (#43183)
* Narrow type variables with union constraints when merited by contextual type

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

* Accept new baselines

* Add tests

* Fix circularity for JSX elements

* Remove unnecessary isConstraintPosition information from flow cache key

* Update comment

* Add additional tests

* Rename to getNarrowableTypeForReference, remove getConstraintForLocation

* Add comment

* Fix removal of undefined in destructurings with initializers

* Use getContextFreeTypeOfExpression in discriminateContextualTypeByObjectMembers

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

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

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

* more changes

* only push values to array if unique

* address review comments

* Fix lint

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

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

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

* Compiles but provides spans instead of location pairs

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

* Switch to DocumentSpan

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

* Builds w/protocol types + conversions

* cleanup:better names and scrub TODOs

* fix test harness too

* Misc

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

* Parse and store links in the compiler

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

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

* more tests and some fixes

* Fix other failing tests

* fix bad merge

* polish parser

* improve names and array types

* slight tweaks

* remove some done TODOs

* more tests + resulting fixes

* add+fix cross-module tests

* Support `@see {@link`

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

* add server test

* Make comments actually part of the AST

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

* Make checker optional in getJSDocTags

Also change to JSDocCommentText from JSDocCommentComment

* Use getTokenValue instead of getTokenText

Measure twice, slice once

* Add missing support for top-level links

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

* add string back to comment type in node constructors

* Full parse of link tags and jsdoc comment text

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

* fix lint

* Fix missing newlines in inferFromUsage codefix

* Parse jsdoc comments as text node/link array

And switch to line+character offsets in the protocol

* Fix fourslash tests

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

* Improve types and documentation

* Test+fix @link emit, scrub other TODOs

* update API baselines

* test that goto-def works with @link

* Split link displaypart into 3

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

* update baselines

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

Instead of upgrading them to displayparts.

* Real server tests

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

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

* Add explanatory comment in test

* fix location in richResponse in protocol

* update API baseline

* Address PR comments

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

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

* Added bug regression test

* Simplify JsxText formatting

* Renamed isFormatting to allowMultilineJsxText

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

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

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

* Dont emit declaration map when emitting dts files for force emit for signature
2021-03-12 09:44:22 -08:00
TypeScript Bot 9c73e048ae Update package-lock.json 2021-03-12 06:25:10 +00:00
Nathan Shively-Sanders 2ea2f4f9a0
Bigint constructor forbids object null undefined (#43204)
* Update es2020.bigint.d.ts

* Update es2020.bigint.d.ts

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* Update package-lock.json

* add a test

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

* Switch to multiple error messages

* inline variable

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

* Baseline tsbuildinfo size in the readable baseline

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

* Explicitly write out Ternary.Maybe

* Add slightly modified example from #25413

* fix sick sentence

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

* Simplify things a bit, only instantiate once

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

* Fix block-scope capturing with prop initializers

Co-authored-by: Joey Watts <joey.watts.96@gmail.com>
2021-03-11 10:32:42 -08:00
Mateusz Burzyński 998ecd9c06
Add a test for JSX namespace lookup with jsx: preserve, jsxImportSource (#41676)
* Add a test for JSX namespace lookup with `jsx: preserve, jsxImportSource`

* updated baselines

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-03-11 09:07:33 -08:00
Matthew Pietz dcaefe732e
Accept generics for defineProperty (#42424)
* Accept generics for defineProperty

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

* Update baselines

* update missed baseline

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

* Work for narrowed non-unions

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

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