2662 Commits

Author SHA1 Message Date
Sheetal Nandi
c7f8959034 PR feedback. 2018-11-21 09:03:26 -08:00
Sheetal Nandi
6a37fd46fe Cache results for readFile, fileExists, directory exists, sourceFiles for .d.ts files across the build (only first time) 2018-11-20 15:16:15 -08:00
Nathan Shively-Sanders
ea8ccc2ce4
In JS, constructor functions infer from call+construct (#28353)
* constructor functions infer from call+construct

Also fix an incorrect combining of inferences for rest parameters: the
inferred types will be arrays in the body of the function and the
arguments from outside the function will be the element type.

* All functions infer from call+construct contexts
2018-11-16 09:51:07 -08:00
Wesley Wigham
7a71887c23
Build better import paths for declaration emit/typeToString from reexports if possible (#27340)
* Build better import paths from reexports if possible, issue error on node_modules import generation

* Small refactorings

* Add file-by-file cacheing

* Minor cleanups

* Adjust error message
2018-11-13 14:07:54 -08:00
Daniel Rosenwasser
f7ad54b432 Only complain about BigInt literals in pre-ESNext targets. 2018-11-09 16:20:54 -08:00
Ron Buckton
151dc074a8 Merge branch 'master' into sourceMapGenerator 2018-11-09 11:50:51 -08:00
Sheetal Nandi
c0587191fc
Merge pull request #28418 from ajafff/internal-comments
remove even more internal comments
2018-11-08 14:58:33 -08:00
Wesley Wigham
89fda5ca83
Fix enum const initializer visibility painting (#28415) 2018-11-08 12:33:54 -08:00
Klaus Meinhardt
e2947fac1c remove even more redundant internal comments 2018-11-07 16:12:48 +00:00
Anders Hejlsberg
8e0c4369b7
Merge pull request #28386 from Microsoft/removeTwoTypeFlags
Remove two flags from TypeFlags
2018-11-06 16:41:41 -08:00
Anders Hejlsberg
e63ffe54fd Move FreshLiteral flag from TypeFlags to ObjectFlags 2018-11-06 15:00:34 -08:00
Andy
772f6cdf48
Remove JSDocTag#atToken (#28376) 2018-11-06 09:54:23 -08:00
Anders Hejlsberg
aa023eb6e3 Remove TypeFlags.UnionOfPrimitiveTypes 2018-11-05 18:04:57 -08:00
Caleb Sander
28e9ec497c Address review comments 2018-11-05 11:36:32 -08:00
Caleb Sander
95c24c6c6a experimentalBigInt compiler flag 2018-11-05 11:36:31 -08:00
Caleb Sander
188c07865a Scan bigint literals 2018-11-05 11:36:31 -08:00
Caleb Sander
ac2a118f07 Add bigint type 2018-11-05 11:36:31 -08:00
Caleb Sander
ece27eb177 Utilities for PseudoBigInt 2018-11-05 11:36:30 -08:00
Nathan Shively-Sanders
8056e2b12f
infer from usage's unification uses multiple passes (#28244)
* infer from usage's unification uses multiple passes

Previously, the unification step of infer-from-usage codefix would stop
as soon an answer was found. Now it continues if the result is
*incomplete*, with the idea that later passes may provide a better
inference.

Currently, an *incomplete* inference is

1. The type any.
2. The empty object type `{}` or a union or intersection that contains
`{}`.

In the checker, any takes priority over other types since it basically
shuts down type checking. For type inference, however, any is one of the least
useful inferences.

`{}` is not a good inference for a similar reason; as a parameter
inference, it doesn't tell the caller much about what is expected, and
it doesn't allow the function author to use an object as expected. But
currently it's inferred whenever there's an initialisation with the
value `{}`. With this change, subsequent property assignments to the
same parameter will replace the `{}` with a specific anonymous type. For
example:

```js
function C(config) {
  if (config === undefined) config = {};
  this.x = config.x;
  this.y = config.y;
  this.z = config.z;
}
```

* Unify all passes of inference from usage

In the previous commit, I changed inference from usage to continue
inference if a the result was *incomplete*. This commit now runs all 4
inference passes and combines them in a unification step. Currently the
unification step is simple, it:

1. Gathers all inferences in a list.
2. Makes properties of anonymous types optional if there is an empty
object in the inference list.
3. Removes *vacuous* inferences.
4. Combines the type in a union.

An inference is *vacuous* if it:

1. Is any or void, when a non-any, non-void type is also inferred.
2. Is the empty object type, when an object type that is not empty is
also inferred.
3. Is an anonymous type, when a non-nullable, non-any, non-void,
non-anonymous type is also inferred.

I think I might eventually want a concept of priorities, like the
compiler's type parameter inference, but I don't have enough examples to
be sure yet.

Eventually, unification should have an additional step that examines the
whole inference list to see if its contents are collectively
meaningless. A good example is `null | undefined`, which is not useful.

* Remove isNumberOrString

* Unify anonymous types

@andy-ms pointed out that my empty object code was a special case of
merging all anonymous types from an inference and making properties
optional that are not in all the anonymous type. So I did that instead.

* Use getTypeOfSymbolAtLocation instead of Symbol.type!

* Unify parameter call-site inferences too

Because they still have a separate code path, they didn't use the new
unification code.

Also some cleanup from PR comments.

* Add object type unification test

Also remove dead code.

* Only use fallback if no inferences were found

Instead of relying on the unification code to remove the fallback.
2018-11-02 09:07:32 -07:00
Wesley Wigham
a4a1bed88b
Add showConfig tsc flag for debugging configs (#27353)
* Add showConfig tsc flag for debugging configs

* Merge showConfig implementation with init implementation, add basic unit tests

* Fix lint

* Add missing semicolon

* showConfig when theres no config file
2018-10-31 15:57:09 -07:00
Andy
672b0e3e16
Have flatMap return a ReadonlyArray by default (#28205) 2018-10-29 11:12:51 -07:00
Wesley Wigham
e2100cd2cc
Measure variance of aliased conditional types using variance markers (#27804)
* Measure variance of aliased conditional types using variance markers

* Just do variance probing for all type aliases

* Small limiter for predictability

* Inline property set, remove unused functions
2018-10-26 16:26:20 -07:00
Wesley Wigham
972c403cd8
JSX uses mixed signatures and union sigs use subtype on partial match (#28141)
* JSX uses mixed signatures and union sigs use subtype on partial match

* Small improvement
2018-10-26 16:01:32 -07:00
Wesley Wigham
05716a74a5
Add support for configuration inheritance via packages (#27348)
* Add support for configuration inheritance via packages

* Fix lint

* Propagate trace into config parse hosts
2018-10-25 10:19:57 -07:00
Nathan Shively-Sanders
fe2a33fcbc
Merge existing JSDoc comments (#27978)
* Correct indentation, using correct (I hope) indentation code

Note that part of the code, in formatting.ts, is cloned but should be
extracted to a function instead.

* Remove some possibly-superfluous code

But I see 4 failures with whitespace, so perhaps not.

* Restrict indentation change to avoid breaking baselines

The indentation code is very complex so I'm just going to avoid breaking
our single-line tests for now, plus add a simple jsdoc test to show that
multiline jsdoc indentation isn't destroyed in the common case.

* Switched over to construction for @return/@type

Still doesn't merge correctly though

* Add @return tags to emitter

* Merge multiple jsdocs

(not for @param yet)

* Merge multiple jsdoc for parameters too

* Emit more jsdoc tags

Not all of them; I got cold feet since I'll have to write tests for
them. I'll do that tomorrow.

* Many fixes to JSDoc emit

And single tests (at least) for all tags

* Cleanup in textChanges.ts

* Cleanup in formatting.ts

(Plus a little more in textChanges.ts)

* Cleanup in inferFromUsage.ts

* Fix minor omissions

* Separate merged top-level JSDoc comments with \n

instead of space.

* Don't delete intrusive non-jsdoc comments

* Cleanup from PR comments

1. Refactor emit code into smaller functions.
2. Preceding-whitespace utility is slightly easier to use.
3. Better casts and types in inferFromUsage make it easier to read.

* Fix bogus newline

* Use @andy-ms' cleanup annotateJSDocParameters
2018-10-24 16:14:52 -07:00
Sheetal Nandi
7ed9e44055
Merge pull request #28059 from ajafff/lsh-resolve-return-type
fix return type of resolveModuleNames and resolveTypeReferenceDirectives
2018-10-22 18:09:15 -07:00
Wesley Wigham
f701daf4e0
Infer over each mapped type constraint member if it is a union (#28006) 2018-10-22 16:33:43 -07:00
Klaus Meinhardt
3b058a4de4 fix compile errors, accept baselines 2018-10-22 21:12:12 +02:00
Andy
72244c5b03
Support 'isSourceFileFromExternalLibrary' for source files from '/// <reference types="" />'' (#28004)
* Support 'isSourceFileFromExternalLibrary' for source files from '/// <reference types="" />''

* Calculate `isExternalLibraryImport` at the end

* Calculate isExternalLibraryImport with symlink path
2018-10-19 18:00:45 -07:00
Wesley Wigham
69b1cb5bac
Add new special assignment kinds for recognizing Object.defineProperty calls (#27208)
* Add new special assignment kinds for recognizing Object.defineProperty calls

* Add support for prototype assignments, fix nits

* Fix code review comments

* Add test documenting behavior in a few more odd scenarios
2018-10-19 14:31:55 -07:00
Sheetal Nandi
91bb32ade4
Merge pull request #27560 from Microsoft/transitiveReferences
Resolve modules, type reference directives in context of referenced file
2018-10-18 13:03:10 -07:00
Wesley Wigham
7b5ef64e76
Unify JSX And Normal Call Checking Codepaths (#27627)
* Unify JSX Call Checking Codepaths

* Add tests for fixed issues

* Fix lint, move all error checking into the only-run-once resolveSignature call

* Remove unused (unreachable?) code path

* Consolidate a little more duplicated logic into signature checking

* Fix #19775 a bit more

* Cosmetic changes from CR
2018-10-16 20:16:00 -04:00
Sheetal Nandi
b69622a114 Merge branch 'master' into transitiveReferences 2018-10-16 10:41:17 -07:00
Anders Hejlsberg
709f5f2fc4 Handle circular mapped type instantiations for arrays and tuples 2018-10-15 10:18:54 -07:00
Sheetal Nandi
88f79de9f4 Merge branch 'master' into transitiveReferences 2018-10-09 14:03:58 -07:00
Ron Buckton
4982803a38 Merge branch 'master' into sourceMapGenerator 2018-10-08 18:01:37 -07:00
Andy
dd9b8cab34
Have scanJsDocToken scan keywords (#27162)
* Have scanJsDocToken scan keywords

* Update API
2018-10-08 14:42:51 -07:00
Wesley Wigham
b85e9e1cc1
Use relative module specifiers in error messages if possible (#27441)
* Use relative module specifiers in error messages if possible

* Dont share number
2018-10-08 14:36:37 -07:00
Nathan Shively-Sanders
a4a5b3806e Report circular JSDoc type references (#27404)
JSDoc types references can often be to values, which can often be
circular in ways that types tied to declarations cannot. I decided to
create a separate property on SymbolLinks rather than reusing
declaredType, although I'm not sure that's strictly required.
2018-10-08 08:56:29 -07:00
Wesley Wigham
4ad6541646
Store and check deferred nodes by containing file (#27378) 2018-10-05 14:40:09 -07:00
Sheetal Nandi
94df5167b0 Handle resolution caching when referenced tsconfig changes 2018-10-04 15:04:12 -07:00
Sheetal Nandi
0e4b10d726 Use resolution options of project reference if the file is from the project reference 2018-10-04 15:04:10 -07:00
Sheetal Nandi
0ac96580d5 Resolve project references transitively 2018-10-04 15:04:10 -07:00
Ron Buckton
a36e6e3976
Merge pull request #27410 from Microsoft/freeUpTransformFlags
Free up space in the TransformFlags enum
2018-10-03 12:39:09 -07:00
Nathan Shively-Sanders
21148b3b0a
Fix typo in PseudoPragma* types (#27437) 2018-09-28 10:39:30 -07:00
Andy
19af881f94
ExpressionWithTypeArguments parent may be a JSDocAugmentsTag (#27229) 2018-09-27 18:26:57 -07:00
Ron Buckton
d224ee02d7 Free up space in the TransformFlags enum 2018-09-27 17:55:07 -07:00
Ron Buckton
9cf201c512
Merge pull request #27204 from Microsoft/fixPerIteration
Fix per-iteration bindings in for-loop head
2018-09-27 13:23:03 -07:00
Anders Hejlsberg
5510e0755e Merge branch 'master' into typedBindCallApply
# Conflicts:
#	tests/baselines/reference/tsxTypeArgumentPartialDefinitionStillErrors.errors.txt
#	tests/baselines/reference/wrappedAndRecursiveConstraints4.errors.txt
2018-09-24 16:38:39 -07:00
Ron Buckton
efe76c4375 Fix per-iteration bindings in for-loop head 2018-09-18 15:58:18 -07:00