Commit Graph

8206 Commits

Author SHA1 Message Date
Wesley Wigham
d433c6ed05 Track late bound names in binding patterns (#26336) 2018-08-17 16:30:01 -07:00
Anders Hejlsberg
3e201e7809 Merge pull request #26517 from Microsoft/fixMappedArrayTypeConstraint
Fix mapped array type constraint
2018-08-17 10:52:42 -07:00
Anders Hejlsberg
596493cce4 Add tests 2018-08-17 10:11:28 -07:00
Tim Schaub
6fd725f3ea Skip whitespace or asterisk in JSDoc param type and name (#26067) 2018-08-16 16:16:09 -07:00
Ryan Cavanaugh
7a658256a2 Merge pull request #26431 from mattmccutchen/issue-26430
Mapped types like Pick<T, K> should adopt property documentation from T.
2018-08-16 13:35:55 -07:00
Nathan Shively-Sanders
75071a2509 Allow super references to constructor function methods (#26482)
Previously, they were mistakenly treated as private because of a check
that required all super property accesses (like `super.x()`) to be
references to a MethodDeclaration or MethodSignature. This change also
allows PrototypeProperty special assignment kinds.
2018-08-16 09:20:30 -07:00
Anders Hejlsberg
178f792f18 Merge pull request #26340 from Microsoft/neverIndexedAccess
T[K] should be 'never' when T is 'never'
2018-08-15 16:07:11 -07:00
Sheetal Nandi
969b46e44b Merge pull request #26458 from Microsoft/pathMappingResultsToNodeModules
When path mapping results to file in node_modules, mark it as external library
2018-08-15 15:28:50 -07:00
Nathan Shively-Sanders
cc67ce1141 Property assignments in Typescript (#26368)
* Allow special property assignments in TS

But only for functions and constant variable declarations initialised with
functions.

This specifically excludes class declarations and class expressions,
which differs from Javascript. That's because Typescript supports
`static` properties, which are equivalent to property assignments to a
class.

* Improve contextual typing predicate

Don't think it's right yet, but probably closer?

* More fixes.

The code is still fantastically ugly, but everything works the way it
should.

Also update baselines, even where it is ill-advised.

* Cleanup

* Remove extra whitespace

* Some kind of fix to isAnyDeclarationName

It's not done yet.

Specifically, in TS:
Special property assignments are supposed to be declaration sites (but not all
top-level assignments), and I think I
got them to be. (But not sure).

In JS:
Special property assignments are supposed to be declaration sites (but not all
top-level assignments), and I'm pretty sure ALL top-level assignments
have been declaration sites for some time. This is incorrect, and
probably means the predicate needs to be the same for both dialects.

* Add fourslash and improve isAnyDeclarationName

Now JS behaves the same as TS.

* Cleanup from PR comments
2018-08-15 15:25:25 -07:00
Nathan Shively-Sanders
08eb99d8ec For a this-property assignment with an empty object initializer, use type annotation if present (#26428)
* This-property w/empty object init: use type annotation

* JS initializer type doesn't apply to this-property assignments

* Move getJSExpandoType into getWidenedType* functions

Plus some cleanup.

* Improved style from PR comments

* Parameters are not expando
2018-08-15 14:53:30 -07:00
Daniel Rosenwasser
dfef227b18 Merge pull request #26473 from Microsoft/doGlobalImplicitThisRight
Fix bad message for captured global 'this'.
2018-08-15 13:08:38 -07:00
Sheetal Nandi
b983da55fd Merge pull request #26457 from Microsoft/baseUrlPathMappingResolveJsonModule
Do not include json file unless --resolveJsonModule is specified
2018-08-15 11:43:01 -07:00
Nathan Shively-Sanders
2bfd919b6a Narrow on element access of literal (#26424)
* Narrow literal element accesses

This means that, for example, the tuple `[number, string?]` allows its
second element to be narrowed with element access:

```ts
export function f(pair: [number, string?]): string {
  return pair[1] ? pair[1] : 'nope';
}
```

* Update baselines

* Cleanup

* More cleanup

* Test dashes in property names

* More cleanup

* Delete undead code
2018-08-15 09:58:39 -07:00
Daniel Rosenwasser
dc1fbc24cd Updated test cases. 2018-08-14 23:02:08 -07:00
Sheetal Nandi
a32f62b310 Write tests to demonstrate how baseUrl + pathMapping to node_modules behaves 2018-08-14 16:26:41 -07:00
Sheetal Nandi
aa8f1e5b6a Test when module resolution because of path mapping takes to json file
Test for #26402
2018-08-14 16:23:07 -07:00
Nathan Shively-Sanders
29ca93ba48 Classes can extend Javascript constructor functions (#26452)
* Classes can extend JS constructor functions

Now ES6 classes can extend ES5 constructor functions, although only
those written in a JS file.

Note that the static side assignability is checked. I need to write
tests to make sure that instance side assignability is checked too.
I haven't tested generic constructor functions yet either.

* Test static+instance assignability errors+generics

Note that generics do not work.

* Cleanup from PR comments

* Even more cleanup

* Update case of function name
2018-08-14 14:43:04 -07:00
James Keane
a1089893bd Fixes #26128 - signature comp for jsdoc @class. (#26160)
* Fixes #26128 - signature comp for  jsdoc @class.

Another issue caused by js functions tagged with jsdoc
`@constructor` not having construct signatures.

A jsdoc function type that constructs a type (`function(new: Ex)`),
has a construct signature and return value inferred as the
constructed type where as a jsdoc `@constructor` has no construct
signatures, and it's call signature has a void return type
(or undefined).

i.e:
```javascript
/** @constructor **/ function E() {};

// typeof E -> call signature: () => void

/** @param {function(new: E)} d */ function c(d) {}

// typeof d -> construct: () => E
```

--

This commit fixes this (in an inelegant way) by considering `@class` function signatures as construct signatures and synthesizing it's return value _only for signature comparison_.

There might be a slight performance hit, since the synthesized return value is not cached; but changing the `@class` function's return type in `getReturnTypeOfSignature` causes other issues.

* Update jsdoc function test to fix mistake.
2018-08-14 13:35:51 -07:00
Matt McCutchen
d7b802577c Mapped types like Pick<T, K> should adopt property documentation from T.
Fixes #26430.
2018-08-13 19:56:20 -04:00
Andy
e8b72aa7d9 Error on accessing private property through destructuring assignment, and mark property used (#26381)
* Error on accessing private property through destructuring assignment, and mark property used

* Factor out getTypeOfObjectLiteralDestructuringProperty
2018-08-13 14:08:00 -07:00
Andy
ad63468ed5 noUnusedLocals: f(x = 1) does not use x (#26366) 2018-08-13 11:14:52 -07:00
Sheetal Nandi
2b83b67aa3 Merge pull request #26140 from Kingwl/completionUnionType
improve completions for union type in type arguments
2018-08-13 10:36:19 -07:00
Nathan Shively-Sanders
a6c5d50749 Allow type predicates in JSDoc (#26343)
* Allow type predicates

1. Parse type predicates. Note that they are parsed everywhere, and get
the appropriate error when used places besides a return type.
2. When creating a type predicate, correctly find the function's parameters
starting from the jsdoc return type.

* Fix type of TypePredicateNode.parent: add JSDocTypeExpression

* Update API baselines

* Handle JSDoc signature inside @type annotations

* Fix circularity when getting type predicates

Also move createTypePredicateFromTypePredicateNode closer to its use

* More cleanup based on review comments
2018-08-10 15:31:39 -07:00
Andy
46d3caab7c Don't error on destructure of private property with computed property syntax (#26360) 2018-08-10 15:11:04 -07:00
Sheetal Nandi
c8e10a9a66 Merge pull request #26296 from ajafff/modulenameresolver-cache
fix moduleNameResolver cache
2018-08-10 14:36:54 -07:00
Andy
4bb740218d getDefaultExportInfo: Use getImmediateAliasedSymbol instead of getAliasedSymbol (#26364) 2018-08-10 14:35:18 -07:00
Klaus Meinhardt
3469b62be6 review comments 2018-08-10 22:25:27 +02:00
Wesley Wigham
19e04b2cdb Dont use baseURL relative absolute paths in declaration emit, use absolute paths in bundle emit (#26341) 2018-08-10 12:54:45 -07:00
Andy
a73161e9d5 Don't store @template constraint in a TypeParameterDeclaration node (#26283)
* Don't store @template constraint in a TypeParameterDeclaration node

* Code review

* Update API
2018-08-09 17:39:15 -07:00
Andy
5efd1cb4a7 fixAddMissingMember: Support interface and don't crash on type parameter (#25995)
* fixAddMissingMember: Support interface and don't crash on type parameter

* Remove InfoBase
2018-08-09 17:32:28 -07:00
Andy
639fdcc916 Don't include class getter in spread type (#26287)
* Don't include class getter in spread type

* Code review
2018-08-09 15:34:29 -07:00
Andy
55a620c433 Don't crash on computed property in destructure (#26334) 2018-08-09 15:29:45 -07:00
Anders Hejlsberg
89a8b5094a Add test 2018-08-09 16:33:54 -04:00
Wesley Wigham
fce3d9f34d Check the ambientness of a symbol name before attempting to trim it (#26312)
* Check the ambientness of a symbol name before attempting to trim it

* Use find instead of forEach, remember to also exclude global augmentations
2018-08-09 13:20:37 -07:00
Wesley Wigham
f6af618ab9 Still generate signatures in SkipContextSensitive mode just to match on return types (#25937)
* Still generate signatures in SkipContextSensitive mode just to match on return types

* Add cache for context-free type of a signature node

* Accept post-merge baseline
2018-08-09 10:17:50 -07:00
Anders Hejlsberg
01f6093a9c Merge pull request #26143 from mattmccutchen/issue-26130
Have getAssignmentReducedType use the comparable relation instead of typeMaybeAssignableTo.
2018-08-09 07:43:46 -07:00
Anders Hejlsberg
20ebe1eb2b Merge pull request #26244 from Microsoft/fixThisAndContextualTypes
Revise logic that computes the contextual type for a parameter
2018-08-09 06:07:11 -07:00
王文璐
23601a10b8 improve completions for union type in type arguments 2018-08-09 17:26:34 +08:00
Ryan Cavanaugh
6210b7db54 Merge pull request #26245 from Kingwl/fix-compiler-crash
fix compiler crash (#26209)
2018-08-08 11:12:16 -07:00
Andy
1a05f13aef moveToNewFile: Don't remove empty named imports (#26265) 2018-08-07 12:54:46 -07:00
Andy
794f3a5e76 goToTypeDefinition: Go to function return type (#25952)
* goToTypeDefinition: Go to function return type

* Add more tests

* If a function returns 'void' or some other type with no definition, just return the function definition.
2018-08-07 12:54:19 -07:00
Andy
eaf0d59d35 Fix bug: symbol.valueDeclaration not guaranteed to be defined (#26267) 2018-08-07 12:13:45 -07:00
王文璐
639190d607 fix compiler crash (#26209) 2018-08-07 10:09:26 +08:00
Andy
937afab4b0 Support signature help for contextual parameter type (#26022) 2018-08-06 16:46:30 -07:00
Anders Hejlsberg
eeb19c1e22 Merge pull request #26236 from Microsoft/fixCircularReturnType
Fix circular return type issue
2018-08-06 16:38:31 -07:00
Anders Hejlsberg
9d71023b5c Add fourslash tests 2018-08-06 16:33:21 -07:00
Andy
d0ed21cad1 completions: 'true' and 'false' are type keywords (#26237) 2018-08-06 12:42:56 -07:00
Klaus Meinhardt
7299bceafb infer number index signature in JS object literals (#26221)
Fixes: #26208
2018-08-06 11:52:51 -07:00
Anders Hejlsberg
cfa29ae2fa Merge branch 'master' into fixCircularReturnType
# Conflicts:
#	src/compiler/diagnosticMessages.json
2018-08-06 10:53:20 -07:00
Anders Hejlsberg
6a17f4d162 Merge branch 'master' into fixCircularReturnType
# Conflicts:
#	tests/baselines/reference/recursiveResolveDeclaredMembers.types
#	tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.types
2018-08-06 10:42:35 -07:00