Commit Graph

15167 Commits

Author SHA1 Message Date
Josh Goldberg
0298033db7 Specified error diagnostic for invalid variable names (#40105)
* Specified error diagnostic for invalid variable names

* Use callback directly, and isKeyword
2020-08-27 10:58:12 -07:00
Eli Barzilay
746bdb7946 Fix getContextualTypeForBindingElement for arrays
When handling an array type, the lookup should use the position index
instead of the identifier name.

Also uncomment the tests in the `staticFieldWithInterfaceContext.ts`
test which failed because of this bug.

Fixes #40158.
2020-08-26 16:28:50 -04:00
Kyℓe Hensel
c5446d1a47 don't emit "unused @ts-expect-error" in unchecked js files (#40046)
* don't emit unused ts-expect-error in unchecked js files

* simplify code
2020-08-25 11:04:23 -07:00
Nathan Shively-Sanders
4aadd5af41 Fix commonjs require of ES export (#40221)
The commonjs-specific code for resolving access expressions on `require`
assumes a fake commonjs export. For real exports, it needs to call
resolveSymbol since it's outside the normal alias-resolving
infrastructure.
2020-08-24 12:37:25 -07:00
Alexander T
2dd7a4bf93 fix(31046): add new diagnostic message for incompatible constructor signature (#40073) 2020-08-22 13:26:13 -07:00
Alexander T
9569198df6 fix(25770): add diagnostic message for the possible mapped type used as an index (#39973) 2020-08-21 10:42:48 -07:00
Alexander T
6ec3629ef4 fix(26325): use a unique name for reserved words in 'constructor like' function name (#39684) 2020-08-21 09:47:37 -07:00
Eli Barzilay
f9e360d44b Add missing contextual type to static PropertyDeclarations
Makes it possible to type class static fields.

Fixes #33897.
2020-08-20 19:12:55 -04:00
Ron Buckton
598e9b2e88 Allow trailing params of 'undefined', 'unknown', and 'any' to be optional in non-strictNullChecks JS (#40057) 2020-08-20 13:38:14 -07:00
Joost Koehoorn
2f2b679436 Optimize external source maps without full cache (#40130) 2020-08-19 16:05:32 -07:00
Nathan Shively-Sanders
55ca5e91b9 Fixes crash on chained property access on require (#40135)
From the user tests:

```js
const x = require('y').z.ka
```

would cause the crash because I forgot to call
getLeftMmostPropertyAccessExpression in one place.

Note that this doesn't fix the alias, it just stops the crash.
2020-08-19 12:59:22 -07:00
Wesley Wigham
44d2350e5f Fix tuple name homogeneity check (#40118) 2020-08-19 12:08:17 -07:00
Daniel Rosenwasser
31f4957494 Revert "Optimize source mapping into external source map sources (#40055)" (#40126)
This reverts commit 1e84ffc703.
2020-08-19 11:46:52 -07:00
Joost Koehoorn
1e84ffc703 Optimize source mapping into external source map sources (#40055) 2020-08-18 18:09:05 -07:00
Andrew Casey
5ff1b75aff Merge pull request #40043 from gluxon/uvException-hotspot
Set stackTraceLimit to 0 in fileSystemEntryExists
2020-08-18 13:54:58 -07:00
Nathan Shively-Sanders
6fea7ff536 Add unit tests for VersionRange (#40114)
* Add unit tests for VersionRange

Make it easier to understand the intended semantics next time I have to
read this code.

* I miss prettier
2020-08-18 13:06:17 -07:00
Andrew Branch
dbab46c363 The falsy part of any/unknown is any/unknown (#39529) 2020-08-18 11:06:44 -07:00
Wesley Wigham
f9cca25cd7 Fix lack of error on default export of nonexistant name (#40094)
* Modify test harness so it can report underlying issue, fix small parent pointer issue

* Fix underlying export asignment check issue and fix lints

* Ensure class/function duplicate declaration errors are reported regarless of which is encountered first

* Ensure flag conflict errors are reported regardless of which declaration is encountered first
2020-08-17 15:30:19 -07:00
Nathan Shively-Sanders
c3d41bbb73 Alias for commonjs require in JS (#39770)
* First attempt at aliases for require

* test+initial support for const x=require

* 1st round of baseline improvements

* 2nd round of baseline updates

* support property access after require

* check @type tag on require

* forbid expando missing namespaces on aliases

taken from #39558 as soon as it was created

* accept error baselines that are good, actually

* Scribbling on d.ts emit code

* use getSpecifierForModuleSymbol

* hideous hack for module.exports of aliases

* Fix module.exports.x --> export list emit

* fix isLocalImport predicate

* require only creates aliases in JS

* re-handle json imports

* update fourslash baseline

* Cleanup in the checker

1. Simplify alias resolution.
2. Simplify variable-like checking.
3. Make binding skip require calls with type tags -- they fall back to
the old require-call code and then check from there.

I haven't started on the declaration emit code since I don't know what
is going on there nearly as well.

* Function for getting module name from require call

* First round of cleanup plus a new test

Found one missing feature, not sure it's worth adding.

* more small cleanup

* more cleanup, including lint

* use trackSymbol, not serializeTypeForDeclaration

* Code review comments, plus remove unneeded code

Ad-hoc type reference resolution for `require` isn't needed anymore.

* find all refs works

* remove old ad-hoc code

* make it clear that old behaviour is not that correct

* update api baselines

* remove outdated comment

* PR feedback

1. Fix indentation
2. Add comment for exported JSON emit
3. Add test case for nested-namespace exports.

* add a fail-case test (which passes!)
2020-08-17 14:00:37 -07:00
Anders Hejlsberg
cd30534327 Recursive conditional types (#40002)
* Support recursive conditional types

* Accept new API baselines

* Accept new baselines

* Simplify recursive type tracking in type inference

* Accept new baselines

* Add tests

* Accept new baselines

* Revise recursion tracking in type inference

* Revise tests

* Accept new baselines

* Add more tests

* Accept new baselines
2020-08-15 18:22:30 -07:00
Brandon Cheng
930b81cc45 Set stackTraceLimit to 0 in fileSystemEntryExists
The exception thrown by Node.js's fs.statSync function contains a stack
trace that can be expensive to compute. Since this exception isn't used
by fileSystemEntryExists, we can safely set Error.stackTraceLimit to 0
without a change in behavior.

---

A significant performance improvement was noticed with this change while
profiling tsserver on packages within a proprietary monorepo.
Specifically, my team saw high self time percentages for Node.js's
uvException and handleErrorFromBinding internal functions. These
functions are executed within fs.statSync when it fails to find the
given path.

https://user-images.githubusercontent.com/906558/90183227-220cb800-dd81-11ea-8d61-f41f89481f46.png

fs.statSync: https://github.com/nodejs/node/blob/v14.4.0/lib/fs.js#L1030-L1037
handleErrorFromBinding: https://github.com/nodejs/node/blob/v14.4.0/lib/internal/fs/utils.js#L254-L269
uvException: https://github.com/nodejs/node/blob/v14.4.0/lib/internal/errors.js#L390-L443

 ## Measurements

After adding Error.stackTraceLimit = 0, we saw:

- For a large configured project with 12,565 files, tsserver reached the
  projectLoadingFinish event 48.78% faster. (~46.786s vs ~31.447s)
- For a medium project with 7,064 files, tsserver was 25.75% faster.
  (~20.897s vs ~16.618s)
- For a small project with 796 files, tsserver was only a negligible
  3.00% faster. (~3.545s vs ~3.442)

Measurements were taken on macOS 10.15.6, Node.js 14.4.0, and a recent
master commit of TypeScript (610fa28d). The average of 3 runs before and
after this change were taken.

I would normally include .cpuprofile and isolate-*-*-*.log files, but
can't post them publicly in this case. If there's any other summaries
the TypeScript team would be curious about I can report them.

 ## fs.statSync Misses

Within our monorepo, the fs.statSync misses were mostly searches for
alternative file extensions of module imports.

- For node_modules imports, a lot of .ts/.tsx lookups failed until the
  .d.ts file was found.
- Within projects with a lot of JSX files, .ts files were looked for
  before finding the .tsx version.
- In the medium scale project mentioned above, a total of 38,515
  non-existent files were queried during createProgram.
2020-08-14 16:22:09 -04:00
Sheetal Nandi
c95cffe111 Ensure file, include and exclude specs used are strings (#40041)
* Test displaying failure when specs used are not strings

* Ensure specs used are strings
Fixes #38164, #39856

* Feedback
2020-08-13 17:08:20 -07:00
Alexander T
edc88c51ca fix(15230): change the diagnostic message about a non-module file in an --isolatedModules project (#40032) 2020-08-13 14:03:17 -07:00
Alexander T
610fa28de5 feat(40004): make isNamedTupleMember public (#40005) 2020-08-12 20:46:40 -07:00
Sheetal Nandi
03d946d145 Revert to including only open files in partial semantic server mode (#40026) 2020-08-12 20:45:59 -07:00
Eli Barzilay
620e260576 Avoid the double-symbol trick for enums
Nameless jsdoc typedefs have their exportedness controlled by the
exportedness of the location they pull their name from.

Fixes #33575.
2020-08-12 18:40:57 -04:00
Alexander T
1f5caf554c fix(13503): fix crash on calling getTypeAtLocation with the SourceFile nodes (#39994) 2020-08-12 00:11:25 -07:00
Nathan Shively-Sanders
d371ae770d No this-property assignments in TS (#40009)
* No this-property assignments in TS

Even when `this` is aliased, which I mistakenly allowed in #39908.

* remove errant file
2020-08-11 15:46:49 -07:00
Wenlu Wang
57e2fe0462 Improve deprecated suggestion node position (#39702)
* Improve deprecated suggestion node position

* fix typo

* Simplify code

* merge helper function
2020-08-10 17:37:11 -07:00
Wenlu Wang
a80f60c6d6 fix export * as default syntax (#39803)
* fix export * as default syntax

* update comments
2020-08-10 16:56:45 -07:00
Nathan Shively-Sanders
1ec71f0e0c Bind alias ThisProperty assignment declarations (#39908)
* Bind alias ThisProperty assignment declarations

This is a quick prototype that does the wrong thing at the wrong time
with the wrong technique.

* Preliminary checker handling for aliases

Duplicative and untested, but I think I updated all the places that need
updating.

* new is error; old one should not have been removed

* I don't even know what's happening with this test

* cleanup and testing in the checker

* binder: use lookupSymbolForNameWorker instead of mutable

This should have about the same behaviour and is much easier to
understand.

Also refactor common code a bit.

* Shorter name of lookupSymbolForName

Once upon a time there was a parent/worker function, but now it's just a
single function again. No need for the -Worker suffix.

* remove oodate comment

* fix switch-case-break lint

* Refactor and move functions

* Rename and improve type of getContextualTypeForAssignmentDeclaration
2020-08-10 16:45:55 -07:00
Josejulio Martínez
668bbc64ff Export anonymous functions in 2 steps, declare as variable and then assign to exports. (#39820)
* Preserve the variable name when exporting an arrow or anonymous function
 This allows the browser or node to properly name the (arrow) function

* Updated tests to reflect previous change

* Remove duplicated comment

* Transforms variable.initializer using moduleExpressionElementVisitor

* PR feedback: rbuckton
 - Use isArrowFunction and isFunctionExpression

* PR feedback: rbuckton
- Consider ClassExpresion, they can also be named based on the
  variable.
2020-08-07 17:16:03 -07:00
Nathan Shively-Sanders
3328fdb2d8 Use isUncalledFunctionReference for aliases too (#39950)
* Use isUncalledFunctionReference for aliases too

Fixes bogus deprecated notices on imports of functions with deprecated
overloads, but with some non-deprecated overloads.

Fixes microsoft/vscode#104238

* Just check all declarations, don't call isUncalledFunction
2020-08-07 10:07:55 -07:00
Ron Buckton
fca9f451d8 Add missing 'importName' for private field helpers (#39932) 2020-08-06 13:27:19 -07:00
Nathan Shively-Sanders
c9f05af2c8 Merge pull request #37891 from Neonit/jsDocIndentationPreservation
Fix indentation preservation in JSDoc (#37717)
2020-08-04 16:09:50 -07:00
Sheetal Nandi
bcccae2fd4 Handle the fact that noResolveResolution resolution is reused (#39889)
Fixes #39795
2020-08-04 13:33:27 -07:00
Daniel Rosenwasser
d985e68ffa Bump version to 4.1. (#39894)
* Bump version to 4.1.

* Update baselines.
2020-08-03 23:38:55 -07:00
Andrew Branch
86a87c493c Limit auto import provider project size (#39855)
* Limit auto import provider project size

* Add test

* Make option configurable

* Fix test

* Only bail when setting is auto

* Fix other test

* Update API baseline
2020-08-02 17:47:49 -07:00
Wesley Wigham
94989789df In JS declaration emit, move imports painted in nested contexts to the root private context (#39818)
* In JS declaration emit, move imports painted in nested contexts to the root private context

* Add test for nathan
2020-07-31 18:25:37 -07:00
Nathan Shively-Sanders
d3877d294c Redo in narrowing for intersections (#39637)
* Redo in-narrowing for intersections

Still need to carve out an exception for globalThis

* exempt globalThis from `in` narrowing
2020-07-30 14:58:22 -07:00
Ron Buckton
32934a9989 Merge pull request #39824 from microsoft/fix35484
Allow assignments to a narrowable reference to be considered narrowable
2020-07-30 15:27:34 -04:00
Andrew Branch
7119e2b74f The iteration type of overloaded iterator signatures derives from the intersection of their return types (#39722) 2020-07-30 11:37:04 -07:00
Ron Buckton
315b5f4b78 PR Feedback 2020-07-30 11:13:58 -07:00
Orta Therox
faf128de15 Fix formatting scanner on JSX text that looks like trivia (#39718)
* Fix formatting scanner on JSX text that looks like trivia

* Combine if statements

Co-authored-by: Andrew Branch <andrew@wheream.io>
2020-07-30 13:56:14 -04:00
mshivaku99
bffe3540fa Issue35876: Give better error message when Classic Module Resolution with incorrect path (#38105)
* added Error 5084 to diagnosticMessages.json

* added test case errorForBareSpecifierWithImplicitModuleResolution1 to tests/cases/compiler

* modified checker.ts to report error 5084 when classic resolution and incorrect path are used

* added baseline changes

* passes all test cases including src/testRunner/unittests/ tests

* Update with feedback

* Make it check whether it is the right module resolution kind

* Use the right diagnostic message in tsserver tests

Co-authored-by: Meera Shivakumar <mshivaku@umich.edu>
Co-authored-by: Orta <git@orta.io>
2020-07-30 13:45:29 -04:00
Eli Barzilay
a320e1b554 Make getLocalSymbolForExportDefault look harder for an export
Look for a symbol that has a `.localSymbol` property instead of blindly
using the first one.

Fixes #37829.
2020-07-30 13:09:21 -04:00
Ron Buckton
21963ce337 Restore reference change 2020-07-29 18:41:05 -07:00
Ron Buckton
4c90ba9456 Temporary revert to compare user test baselines 2020-07-29 18:13:27 -07:00
Alexander T
bae111f0ae fix(39245): change related diagnostic for missing rest parameter arguments (#39356)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-07-29 17:25:13 -07:00
Ron Buckton
b9db6413bf Allow assignments to a narrowable reference to be considered narrowable 2020-07-29 16:37:25 -07:00