Commit graph

2169 commits

Author SHA1 Message Date
Wesley Wigham f07404938f
Replace subtype check in derivedness check with flags and structure checks (#27403)
* Replace subtype check in derivedness check with flags and structure checks

* Remove now extraneous clause
2018-10-04 12:55:39 -07:00
Martin Probst 539c455942 Rename to _superIndex to test conflict
Change-Id: I30af09343446126ba73ed40199ecc3f0ed515b3e
2018-10-04 08:07:42 +02:00
Andy 9bdd6a3b55
Support loading "index.d.ts" using "typesVersions" without "types", "typings", or "main" (#27514)
* Support loading "index.d.ts" using "typesVersions" without "types", "typings", or "main"

* Update baseline
2018-10-03 11:44:16 -07:00
Jack Williams 342fda98d8 Allow trailing void arguments to be omitted 2018-10-03 19:35:05 +01:00
Anders Hejlsberg 9851d6f457
Merge pull request #27490 from Microsoft/indexedAccessConstraint
Limit unsound indexed access type relations
2018-10-03 10:58:45 -07:00
Martin Probst f0826cfeaa Per-property super accessors in async functions.
TypeScript must hoist accessors for super properties when converting
async method bodies to the `__awaiter` pattern for targets before
ES2016.

Previously, TypeScript would reify all property accesses into element
accesses, i.e. convert the property name into a string parameter and
pass it to `super[...]`. That breaks optimizers like Closure Compiler or
Uglify in advanced mode, when property renaming is enabled, as it mixes
quoted and un-quoted property access (`super['x']` vs just `x` at the
declaration site).

This change creates a variable `_superProps` that contains accessors for
each property accessed on super within the async method. This allows
accessing the properties by name (instead of quoted string), which fixes
the quoted/unquoted confusion. The change keeps the generic accessor for
element access statements to match quoting behaviour.

Fixes #21088.
2018-10-03 15:46:04 +02:00
Anders Hejlsberg 34994627f0 Add tests 2018-10-01 16:21:35 -07:00
Ryan Cavanaugh 3331d073c4
Merge pull request #26070 from ajafff/tuple-rest
Infer array rest as tuple if possible
2018-10-01 13:56:28 -07:00
Nathan Shively-Sanders 6d92a2942f
Fix parent points in unreachable code (#27400) (#27406)
In the binder, unreachable code mistakenly skips the `bindJSDoc` call in
`bindChildrenWorker`, which sets parent pointers. The fix is to call
`bindJSDoc` in the case of unreachable code as well.
2018-09-28 08:31:56 -07:00
Wesley Wigham 26eb6ab6f4
Primitives should not be instanceof... anything (#27402) 2018-09-27 15:49:51 -07:00
Anders Hejlsberg d7219b21c2
Merge pull request #27357 from Microsoft/fixBivariantInferences
Make contravariant inferences only from pure contravariant positions
2018-09-26 14:03:59 -07:00
Nathan Shively-Sanders 98ec1e8730
Fix commonjs export= merging (#27368) (#27371)
I'm surprised we haven't seen more of this; I suspect it's because the
mixed `module.exports=` + `export.foo=` pattern isn't that common.
However, it'll happen any time that the exported symbol is unknown;
getCommonJsExportEquals blithely clones unknownSymbol and proceeds to
stick the `exports.foo=` properties onto it.

This causes problems later, because the compiler checks for
unknownSymbol with `===`. The fix is to not stick properties onto a
clone of unknownSymbol. This makes the correct errors appear and removes
the crash.
2018-09-26 12:40:30 -07:00
Nathan Shively-Sanders 4fac5f26dc
Fix crash in use-before-def checking of enum tag (#27350) (#27354) 2018-09-26 09:05:18 -07:00
Anders Hejlsberg 4bb5cfb9bb Add regression test 2018-09-25 18:17:21 -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 5fb39769ad
Merge pull request #27271 from Microsoft/fix24570-3
Fix iterated type in for-await-of
2018-09-21 12:28:18 -07:00
Ron Buckton 112fe6e2cc Fix iterated type in for-await-of 2018-09-21 10:40:45 -07:00
Ron Buckton 3a4d0b237f Add more tests for await 2018-09-21 10:32:28 -07:00
Ron Buckton 63adc5fb40 Add contextual typing for await operand 2018-09-21 10:32:18 -07:00
Ron Buckton 80dba4d63b Support promise-like types in contextual return type of async function 2018-09-21 10:32:00 -07:00
Nathan Shively-Sanders 90d3f8b573
Only report expando use-before-def for identical control flow containers (#27199) 2018-09-18 15:28:16 -07:00
Anders Hejlsberg c0eb742cf3 Merge branch 'master' into fixEmptyObjectFalsiness 2018-09-18 06:28:27 -07:00
Nathan Shively-Sanders 59e4770a51
Fix enum tag circular references (#27161)
* Fix enum tag circular references

Also, don't try to resolve enum tag types in Typescript.

* Improve comment
2018-09-17 16:06:17 -07:00
Nathan Shively-Sanders c9f190283e
Fix non-toplevel prototype assignment (#27096)
* Fix non-toplevel prototype assignment

binder was using the wrong node to lookup the containing class type for
prototype assignment, so it incorrectly put the prototype declaration on
the class' symbol.

This correction to the binder in turn required a change in
getJSClassType in the checker. It now has to look at the "prototype"
property for the prototype instead of looking on the class symbol's exports
(which makes no sense).

* Refactor per PR suggestion
2018-09-17 13:07:05 -07:00
Anders Hejlsberg eb06af1901 Add tests 2018-09-17 13:01:53 -07:00
Nathan Shively-Sanders 989a717b04
Definite assignment checking for expando properties (#27128) 2018-09-17 12:56:39 -07:00
Nathan Shively-Sanders 394ee31a56
Fix cross-file merge of assignment decl valueDeclaration (#26918)
* Fix cross-file merge of assignment decl valueDeclaration

Previously mergeSymbol in the checker always updated valueDeclaration if
target.valueDeclaration was an assignment declaration. The binder only
updates target.valueDeclaration if it is an assignment declaration and
source.valueDeclaration is *not* an assignment declaration. Now the
checker behaves the same way as the binder.

* Update baselines

* Add a fix for #27099

Makes commonjs merge with globals when appropriate.

* Add a separate jsGlobalAugmentations table

Instead of trying to filter these augmentations out of the normal symbol
table of commonjs modules.
2018-09-16 07:46:03 -07:00
Andy f71d6005a2
Use nextToken() after parsing a tag name so we can parse type keywords (#26915)
* Use nextToken() after parsing a tag name so we can parse type keywords

* Make callback to skipWhitespaceOrAsterisk non-optional
2018-09-13 15:49:06 -07:00
Nathan Shively-Sanders 614423b287
Fix this-type in prototype-assigned object literals (#26925)
* Fix this-type in prototype-assigned object literals

Some cases were missing from tryGetThisTypeAt.
Fixes #26831

* Lookup this in JS only for  @constructor+prototype assignments
2018-09-12 16:21:17 -07:00
Anders Hejlsberg b67a261eba Merge branch 'master' into typedBindCallApply
# Conflicts:
#	src/compiler/diagnosticMessages.json
2018-09-11 10:48:18 -07:00
Anders Hejlsberg e9679f0191 Add tests 2018-09-11 06:43:17 -07:00
Ron Buckton a255d9a163 Merge branch 'master' into typesVersions 2018-09-07 13:52:12 -07:00
Ryan Cavanaugh ed70d4887a
Merge pull request #25633 from Kingwl/strictParameter
add use strict and simple parameter check
2018-09-05 17:15:52 -07:00
Ryan Cavanaugh 1e2fb9f0ae
Merge pull request #26465 from rnathanday/master
include leading non-ASCII horizontal whitespace
2018-09-05 12:38:09 -07:00
Ryan Cavanaugh 6465e9dcdd
Merge pull request #26292 from Kingwl/tupleIndexAccessCheck
check index access for fixed length tuple
2018-09-05 12:10:46 -07:00
Ryan Cavanaugh 5d65e86756
Merge pull request #23253 from Kingwl/definite-assignment-assertion-improve
improve parser and error message if definite assignment assertions in…
2018-09-05 11:49:13 -07:00
Nathan Shively-Sanders ff05082e45
Bind non-expando property assignments at top-level (#26908)
* Bind non-expando property assignments at toplevel

Previously, only property assignments with expando initialisers were
bound in top-level statements. Now, all property assignments are bound.

This requires a matching change in the checker to make sure that these
assignments remain context sensitive if their valueDeclaration is a
'real' declaration (ie a non assignment-declaration).

* Add baselines for new test
2018-09-05 10:53:43 -07:00
Tim Schaub 262ea5b06e Skip asterisks after newline when parsing JSDoc types (#26528)
* Skip asterisks after newline when parsing JSDoc types

* Single boolean expression

* Test for parsing and printing multiline function signatures with *
2018-09-04 15:41:08 -07:00
Nathan Shively-Sanders 64ac5a53f4
Fixes for type parameter name resolution in JS (#26830)
* check for expando initializers in resolveEntityName

when resolving type parameters in a prototype property assignment
declaration. For example, this already works:

```js
/** @template T */
function f(x) { this.x = x }
/** @returns {T} */
f.protototype.m = function () { return this.x }
```

This now works too:

```js
/** @template T */
var f = function (x) { this.x = x }
/** @returns {T} */
f.prototype.m = function () { return this.x }
```

Fixes #26826

* Lookup type parameters on prototype-assignment methods

In the same way that they're looked up on prototype-property methods.

That is, this previously worked:

```js
/** @template T */
function f() { }
/** @param {T} p */
f.prototype.m = function () { }
```

And this now works too:

```js
/** @template T */
function f() { }
f.prototype = {
  /** @param {T} p */
  m() { }
}
```

Note that the baselines still have errors; I'll file a followup bug for
them.

* Look up types on property assignments too
2018-09-04 14:47:18 -07:00
Nathan Shively-Sanders c929e74310
Add [Constructor]Parameter types to lib.d.ts (#26243) 2018-08-31 07:46:16 -07:00
Nathan Shively-Sanders cc3d011333
Infer this parameters (#26800)
Previously we didn't. I can't remember why, probably because I
overlooked it in the initial PR.
2018-08-31 07:45:34 -07:00
Nathan Shively-Sanders b687caf3eb
No excess property error for spread properties (#26798)
That is, properties in an object literal type that came from a spread
assignment never cause an excess property error.
2018-08-30 16:16:58 -07:00
Nathan Shively-Sanders d3f96015f1
Fix namespace expando merge (#26690)
* Allow JSContainers to merge with namespaces

Expando functions marked with JSContainer previously failed to merge
with namespaces. This change adds JSContainer to ValueModuleExcludes,
allowing this kind of merge.

* Improve symbol flags to fix namespace/expando merging

Calls to bindPropertyAssignment now provide which special assignment
kind they originated from. This allows better symbol flags to be set:

1. Property assignments get the FunctionScopedVariable flag, since they are
equivalent to a `namespace` exporting a `var`.
2. Prototype property assignments get the Method flag if the initialiser
is functionlike, and Property otherwise.
3. Prototype assignments get the flag Property.

(3) is still not entirely correct (it's missing the Prototype flag),
but is what existed previously. I'll try adding the Prototype flag to
see whether it changes any baselines.

* Add cross-file merge test

* Update missed baselines

* Namespace declarations are primary for merging purposes

Also, property-assignments go back to being property declarations, not
function-scoped variable declarations

* Revert unneeded changes

* Revert unneeded changes (in a codefix this time)

* Put JSContainer on all assignment declarations

This allows most of the new special-case merge code to go away. It now
uses the JSContainer special-case code, which already exists.

* Missed comment

* Fix extra newline lint
2018-08-30 13:18:50 -07:00
Tim Schaub 20a2b0cade Ignore newline and asterisk when parsing JSDoc typedef (#26775) 2018-08-30 10:01:33 -07:00
Wenlu Wang 038f665171 fix lookup regression again (#26762)
* fix lookup regression again

* add test case
2018-08-30 08:48:49 -07:00
Anders Hejlsberg a28791565d
Merge pull request #26746 from Microsoft/noUnionInferences
Don't infer unions for disjoint callback parameter candidates
2018-08-29 15:45:43 -07:00
Nathan Shively-Sanders 29dbabe2e1
In JS, fix contextual type of this assignments (#26743)
in object literal methods inside an object literal with a type
annotation.

Note that this does not change:

1. The type of `this` in object literal methods.
2. The fact that this-property assignments are still declarations. They
just don't block contextual typing like most declarations do.

This change is a bit expensive. It first calls getThisContainer, which
walks the tree upward. Then it calls checkThisExpression, which will
usually call getContextualType on the object literal method. If the new
code then returns true, it will proceed to redo much of that work.

Calling checkThisExpression should not cause incorrect circularity
failures; we only have to inspect the shape of the object literal and
not the types of its properties to determine its type.
2018-08-29 15:06:38 -07:00
Anders Hejlsberg c48c3632bd Update tests 2018-08-29 14:02:15 -07:00
Ron Buckton 210de32933 Merge branch 'master' into typesVersions 2018-08-29 13:26:13 -07:00
Anders Hejlsberg a2d2f5aee6 Merge branch 'master' into complexRestParameterTypes 2018-08-29 07:51:07 -07:00
Wenlu Wang f67d7e01cf add test case and fix regression (#26726) 2018-08-29 06:58:55 -07:00
王文璐 597bb0e764 Merge branch 'master' into strictParameter 2018-08-29 18:28:36 +08:00
Ron Buckton 5f6a2cbf69 Merge branch 'master' into typesVersions 2018-08-28 17:37:23 -07:00
Ron Buckton 37c33f4369 Use semver ranges 2018-08-28 17:24:02 -07:00
Ron Buckton 37ec065d93 Add path back-reference tests 2018-08-28 11:44:40 -07:00
Ron Buckton dc5cd9676b Switch to paths-like pattern matching 2018-08-28 09:33:03 -07:00
王文璐 f1c5fa5b35 Merge branch 'master' into strictParameter 2018-08-28 17:37:58 +08:00
王文璐 8869f39c25 accept more case 2018-08-28 16:41:26 +08:00
王文璐 d758075597 add special check for parameter initializer lookup if targeting es2015+ 2018-08-28 15:02:28 +08:00
Anders Hejlsberg bd40583beb
Merge pull request #26698 from Microsoft/indexedAccessConstraints
Improve indexed access type relations
2018-08-27 18:14:43 -07:00
Nathan Shively-Sanders a2e4a282e7
Get [type] parameter types from @type tag (#26694)
* Get [type] parameter types from @type tag

Previously only the return type was used in cases like this:

```js
/** @type {<T>(param?: T) => T | undefined} */
function g(param) {
  return param;
}
```

Now the type parameters from the type tag are used, and the compiler
gets the type of the parameter by using the position in the signature of
the type tag.

Fixes #25618

* Fix split ifs according to PR comments
2018-08-27 16:52:35 -07:00
Anders Hejlsberg 9f83958dbe Add tests 2018-08-27 16:06:17 -07:00
Nathan Shively-Sanders b50c37de78
No assert for nameless typedefs (#26695)
The assert is over-optimistic and should be removed until we can parse
every possible thing that people might put in a JSDoc type position.

Fixes #26693
2018-08-27 14:12:14 -07:00
Nathan Shively-Sanders 6419240ab2
Declaration emit includes function properties (#26499)
* Declaration emit includes function properties

It does this by printing the type as an object literal type:

```ts
function f() { }
f.p = 1
```

Appears in a d.ts as

```ts
declare var f: {
  (): void;
  p: number;
}
```

It would also be possible to represent it as a namespace merge. I'm not
sure which is better.

```ts
declare function f(): void;
declare namespace f {
  export var p: number;
}
```

In order to avoid a private-name-used error (though I think it was
actually *unused*), I also had to change the nodeBuilder code to match.
This is arguably harder to read. So it's possible that I should instead
keep the nodeBuilder version as `typeof f` and make an exception for
private name use.

* Emit namespace merge instead of object type

This makes the change smaller, overall.

* Fix isJSContainerFunctionDeclaration+namespace merges

Also improve emit style to match other namespace emit.

* Add isPrivate + test case from PR comments
2018-08-27 10:29:53 -07:00
Nathan Day 3ec2c45f5f include leading non-ASCII horizontal whitespace in SyntaxKind.WhitespaceTrivia token 2018-08-25 13:15:56 -04:00
Anders Hejlsberg 676892ee56 Add tests 2018-08-25 07:55:13 -07:00
Nathan Shively-Sanders 0043ba16b1
Allow weak type detection for intersection sources (#26668)
Previously, intersections were only allowed as targets, but this was
just an artifact of the original implementation, which operated inside
the structural part of isRelatedTo. Removing this restriction catches
subtle bugs in React user code, where a function named `create` returns
a mapped type whose types are all branded numbers. The display of these
properties, for some original type `T`, is not `number & { __ }` but
the much-less-obvious `RegisteredStyle<T>`.
2018-08-24 10:30:39 -07:00
Nathan Shively-Sanders 03653934c3
Don't create expando object literals in TS (#26525)
Previously, getWidenedTypedFromJSPropertyAssignment was not called for
Typescript code. Since property assignments on functions, it is. That
meant that property assignments would incorrectly create a JS container
for empty object literals in a property assignment, even in Typescript:

```ts
const one = () => 1
one.p = {}
one.p.q = {} // should not work in Typescript!
```

Now empty object literals never create expando objects in Typescript,
because getJSExpandoObjectType requires the declaration to be in a JS
file.
2018-08-23 08:21:28 -07:00
Anders Hejlsberg 74c57caa90 Add regression test 2018-08-22 07:16:31 -07:00
Ron Buckton 79d7f371bb Merge branch 'master' into typesVersions 2018-08-21 15:47:10 -07:00
Andy 72886512a6
When --noImplicitAny is enabled, don't report errors suggesting that a 'void' function can be 'new'ed (#26579) 2018-08-21 10:02:02 -07:00
Ron Buckton 42c9208fd1
Merge pull request #26564 from Microsoft/fix26497
Emit lib reference directives in declaration output
2018-08-21 09:48:07 -07:00
Ron Buckton 015babb6f7 Initial support for 'typesVersions' 2018-08-20 16:57:18 -07:00
Ron Buckton 1de8cd3f62 Emit lib reference directives in declaration output 2018-08-20 16:54:51 -07:00
Matt McCutchen cc1c2ab6b2 Go back to the old narrowing algorithm (pre #26143) and avoid #26130 by
skipping narrowing if the old algorithm produces a type to which the
assigned type is not assignable.

This also means we'll no longer narrow for erroneous assignments where
the assigned type is not assignable to the declared type.  This is the
reason for the numericLiteralTypes3 baseline change.

Fixes #26405.
2018-08-17 21:35:03 -04: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
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
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
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
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
王文璐 6432bd9def check index access for fixed length tuple 2018-08-10 10:49:37 +08: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
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 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
Anders Hejlsberg efdbbd1cf3 Add regression tests 2018-08-06 10:02:33 -07:00
Ryan Cavanaugh 3ab7a98ecf
Merge pull request #26121 from mattmccutchen/issue-23999
"Could not find a declaration file for module" error needs to use the unmangled package name where appropriate.
2018-08-01 20:55:31 -07:00
Matt McCutchen d45e422b46 Have getAssignmentReducedType use the comparable relation instead of
typeMaybeAssignableTo.

typeMaybeAssignableTo decomposed unions at the top level of the assigned
type but didn't properly handle other unions that arose during
assignability checking, e.g., in the constraint of a generic lookup
type.

Fixes #26130.
2018-08-01 23:26:17 -04:00
James Keane 50f442f9ff Fixes #26122 - erroneous "TS2350" for js constructors called with incorrect parameters (#26124)
* Fixes #26122.

When `resolveCall` does not resolve in `resolveNewExpression`, the error should only be thrown if there is a *defined* signature that is not-void.

* Fix other baselines to remove erroneous TS2350.
2018-08-01 13:40:55 -07:00
Matt McCutchen d054621477 "Could not find a declaration file for module" error needs to use the
unmangled package name where appropriate.

Add a test case for an untyped sub-module of a scoped package with
typings.  The other diagnostic message is covered by existing tests; I
guess no one looked at the baselines closely enough.

Fixes #23999.
2018-08-01 14:13:38 -04:00
Klaus Meinhardt 8630396d8a update test 2018-08-01 09:59:50 +02:00
王文璐 02f5365e08 improve error message and update testcase 2018-08-01 13:45:57 +08:00
王文璐 813f28a4f8 Merge branch 'master' into strictParameter 2018-08-01 10:11:13 +08:00
James Keane dfedb24f75 Jsdoc @constructor - in constructor properly infer this as class instance (#25980)
* Properly infer `this` in tagged `@constructor`s.

`c.prototype.method = function() { this }` was already supported.

This commit add support to two more kinds relying on the JSDoc
`@constructor` tag. These are:
 1. `/** @constructor */ function Example() { this }`
 2. `/** @constructor */ var Example = function() { this }`

* Update the baseline for js constructorFunctions.

C3 and C4 `this` was set as `any`, now it is properly showing as
the class type.

* Fix lint errors

* Add circular initialisers to constructo fn tests.

* Error (`TS2348`) if calling tagged js constructors

When calling a JS function explicitly tagged with either `@class` or
`@constructor` the checker should throw a TS2348 not callable error.

* Don't resolve jsdoc classes with construct sigs.

This undoes the last commit that sought to change how js functions
tagged with `@class` were inferred. For some reason, currently
unknown, giving those functions construct signatures causes issues
in property assignment/member resolution (as seen in the
`typeFromPropertyAssignment12` test case).

Instead of changing the signature resolution, the error is explicitly
generated in `resolveCallExpression` for those functions.
2018-07-31 13:52:39 -07:00
Nathan Shively-Sanders a21ac11582
In JSDoc, resolve import types as values too (#26066)
* In JSDoc, resolve import types as values too

This is something that we probably should have been doing for some time.
Fixes #26049

* Fix whitespace lint
2018-07-31 11:07:06 -07:00
Anders Hejlsberg 4bc7f1570b
Merge pull request #26063 from Microsoft/mappedTypesArraysTuples
Improved mapped type support for arrays and tuples
2018-07-31 10:54:44 -07:00
Nathan Shively-Sanders 4d84bde9b3
Only bind module.exports if no local definition exists (#25869)
* Only bind module.exports if no local definition exists

Note that this uses `lookupSymbolForNameWorker`, which is really a
best-effort check since it only knows about symbols that it has already
encountered.

As a side-effect, even when `module` is bound as part of a
`module.exports` reference, it only declares it once instead of one
declaration per reference.

* Only type module.exports inside module files

It is an error inside script files, but the binder sometimes creates a
ModuleExports symbol because we doesn't know whether we have a commonjs
module until after binding is done.

* Only bind module.exports in a commonjs module

Note that this, too, is a best-effort check since evidence of
commonjs-ness may be found after a *reference* to module.exports. (A
reference to module.exports alone is not enough evidence that a file is
commonjs. It has to have an assignment to it.)
2018-07-30 12:27:59 -07:00
Anders Hejlsberg 32a9ec6c30 Add tests 2018-07-29 15:25:54 -07:00
Nathan Shively-Sanders 25fb5419c0
Support the JSDoc @enum tag (#26021)
* Support the JSDoc @enum tag

`@enum` is used on a variable declaration with an object literal
initializer. It does a number of things:

1. The object literal has a closed set of properties, unlike other
object literals in Javascript.
2. The variable's name is resolvable as a type, but it just has the
declared type of the enum tag.
3. Each property's type must be assignable to the enum tag's declared type,
which can be any type.

For example,

```js
/** @enum {string} */
const Target = {
  START: "START",
  END: "END",
  MISTAKE: 0, // error 'number' is not assignable to 'string' -- see (3)
}

Target.THIS_IS_AN_ERROR; // See (1)
/** @type {Target} See (2) */
var target = Target.START;
```

* Fix lint, add new test case, update API baselines
2018-07-28 07:53:08 -07:00
王文璐 c531065fd0 Merge branch 'master' into definite-assignment-assertion-improve 2018-07-26 18:06:47 +08:00
Anders Hejlsberg 1aa2b15f8c Add regression test 2018-07-25 12:42:47 -07:00
Anders Hejlsberg dd4fd8c60e
Merge pull request #25913 from Microsoft/fixCircularConstraintCheck
Fix circular constraint check
2018-07-25 06:46:51 -07:00
Anders Hejlsberg aeae05eaf5 Add regression test 2018-07-24 15:33:02 -07:00
Matt McCutchen f72193eedc Report a semantic error for an arrow function with a "this" parameter.
Fixes #9744.
2018-07-23 10:42:56 -04:00
Nathan Shively-Sanders 31d599abaf
Check module.exports (#25732)
* Revert "Revert "Explicitly typed special assignments are context sensitive (#25619)""

This reverts commit 16676f2707.

* Revert "Revert "Explicitly typed prototype assignments are context sensitive (#25688)""

This reverts commit ff8c30d636.

* Initial, wasteful, solution

It burns a check flags. Probably necessary, but perhaps not.

I haven't accepted baselines, but they are a bit questionable. I'm not
sure the synthetic type is right, because I expected to see
{ "exports": typeof import("x") } but instead see { "x": typeof
import("x") }.

* Update some baselines

* module.exports= always uses lhs type

Conflicts between exports property assignments and exports assignments
should get a union type instead of an error.

* Fix lint and accept good user baselines

* Add tests based on user tests.

These currently fail.

* Fix all but 1 of user test bugs found by typing module.exports

Still quite messy and full of notes

* Follow merged symbols+allow any object type

This allows exports like `module.exports = new EE` to have properties
added to them.

Still messy, but I'm going to run user tests and look for regressions.

* Update improved user baselines

* Fix infinite recursion when checking module.exports

* Fix bogus use-before-def error

getExportSymbolOfValueSymbolIfExported should always merge its returned
symbol, whether it's symbol.exportSymbol or just symbol.

* Update user test baselines

* Cleanup

* More small cleanup

* Bind `module` of `module.exports` as a special symbol

Previously it was also special, but created during name resolution in
the checker. It made sense when there was only one special symbol for
all files, but now there is one `module` symbol per file.
2018-07-20 10:59:26 -07:00
Nathan Shively-Sanders 1cedab18be
Fix parsing of parenthesized JSDoc parameters (#25799)
* Fix parsing of parenthesized JSDoc parameters

Parenthesis can start a jsdoc function parameter since it is just a
type, and parenthesis can start a type:

```js
/** @type {function(((string))): void} */
```

However, this is not legal in other parameter lists:

```ts
function x((((a))): string) { }
```

This change makes jsdoc function parameter lists parse differently than
normal parameter lists by allowing parenthesis as a start character of
jsdoc parameters.

* Parse nested uses of jsdoc function types

* Fix test
2018-07-19 12:50:36 -07:00
Wenlu Wang ed8b76424e add grammar check for labeled declaration (#25317)
* add grammar check for labeled function declaration

* fix debug failed on labeled class declaration

* move labeled statement check to binder and add more pattern for check

* update diagnostic message

* update baseline
2018-07-18 15:37:27 -06:00
Nathan Shively-Sanders 1edc975f15
Revert the revert of explicitly typed special assignments (#25727)
* Revert "Revert "Explicitly typed special assignments are context sensitive (#25619)""

This reverts commit 16676f2707.

* Revert "Revert "Explicitly typed prototype assignments are context sensitive (#25688)""

This reverts commit ff8c30d636.
2018-07-17 10:02:51 -07:00
Nathan Shively-Sanders 16676f2707 Revert "Explicitly typed special assignments are context sensitive (#25619)"
This reverts commit 32e60a9647.
2018-07-16 12:39:08 -07:00
Nathan Shively-Sanders ff8c30d636 Revert "Explicitly typed prototype assignments are context sensitive (#25688)"
This reverts commit 5b21cbc0c9.
2018-07-16 12:38:27 -07:00
Nathan Shively-Sanders 5b21cbc0c9
Explicitly typed prototype assignments are context sensitive (#25688)
* Explicitly typed prototype assignments:ctx sensitive

Follow up to #25619: Add the necessary code to type `prototype`
correctly in prototype assignments so that code like
`F.prototype = { ... }` properly makes the object literal context
sensitive.

* Fix lint
2018-07-16 10:03:39 -07:00
王文璐 cdfef4fa57 add use strict and simple parameter check 2018-07-16 17:40:57 +08:00
Nathan Shively-Sanders 32e60a9647
Explicitly typed special assignments are context sensitive (#25619)
* Explicitly typed js assignments: context sensitive

Explicitly typed special assignments should be context sensitive if they
have an explicit type tag. Previously no special assignments were
context sensitive because they are declarations, and in the common,
untyped, case we inspect the right side of the assignment to get the
type of the left side, and inspect the right side of the assignment to
get the type of the left side, etc etc.

Note that some special assignments still return `any` from
checkExpression, so still don't get the right type.

Fixes #25571

* Change prototype property handling+update bselines

* Fix indentation in test

* Update baselines
2018-07-12 15:28:53 -07:00
Andy f500289a44
Stricter test that JSDoc @type tag matches function signature (#25615) 2018-07-12 14:02:02 -07:00
Anders Hejlsberg 5822a8c923 Merge branch 'master' into genericRestArityCheck
# Conflicts:
#	src/compiler/checker.ts
2018-07-12 08:20:48 -10:00
Nathan Shively-Sanders bd7b97ce61
Get return type from @type tag (#25580)
* Get return type from `@type` tag

This only happens in the checker, where the type is easily accessible.
The syntax-based check in getEffectiveReturnTypeNode as a fast path, and
for other uses that don't want to make a call to getTypeFromTypeNode.

Fixes #25525

* Implement PR suggestions

* Error when type tag isn't callable

* Fix lint
2018-07-12 10:49:41 -07:00
Anders Hejlsberg 55180f7725 Add tests 2018-07-12 07:07:13 -10:00
Nathan Shively-Sanders 42a2d9e568
Excess property understands conditional types (#25584)
Previously it did not, causing misleading excess property errors. Note
that assignability errors with conditional types are still usually
confusing. This PR doesn't address that.

Also, make sure that exact matches in getSpellingSuggestion are skipped.
2018-07-11 11:24:40 -07:00
Nathan Shively-Sanders c344a3ea5b
Fix bogus use before def in jsdoc (#25532)
Block scoped variables, classes and enums would issue a bogus
use-before-def error in jsdoc because name resolution always adds Value,
even when resolving a type.

Fixes #25097
2018-07-10 08:33:19 -07:00
Nathan Shively-Sanders 6589e867fe
getJSDocReturnType gets return type from @type tags (#25486)
* get return type from `@type` tags

Previously, getJSDocReturnType did not check the `@type` tag for a type
node that has a return type. Now it does.

* Improve doc comment of getJSDocReturnType

* More type predicates in type guards!

* Update API baselines with new documentation (?!)
2018-07-06 10:46:43 -07:00
Nathan Shively-Sanders c228924543
Index signatures contribute properties to unions (#25307)
* Index signatures contribute properties to unions

This means that in a union like this:

```ts
type T = { foo: number } | { [s: string]: string }
```

`foo` is now a property of `T` with type `number | string`. Previously
it was not.

Two points of interest:

1. A readonly index signature makes the resulting union property readonly.
2. A numeric index signature only contributes number-named properties.

Fixes #21141

* Correctly handle numeric and symbol property names

1. Symbol-named properties don't contribute to unions.
2. Number-named properties should use the numeric index signature type,
if present, and fall back to the string index signature type, not the
other way round.
2018-07-06 10:46:05 -07:00
Nathan Shively-Sanders 50ef631b59
Support prototype assignment with a function declaration (#25300)
Previously variable declaration+function expression worked.
Note that class expression/class declaration do not work, due to the way
they are specified. I added a test for future reference.
2018-07-05 09:04:28 -07:00
Anders Hejlsberg eb7ff43f95
Merge pull request #25408 from Microsoft/contextualTupleTypes
Infer tuple types for contextually typed rest parameters
2018-07-03 14:02:48 -10:00
Anders Hejlsberg e5d520e463 Add tests 2018-07-02 17:50:42 -10:00
Wesley Wigham 7084e6cf47
Adds related spans and error grouping for duplicate identifier errors (#25328)
* Adds related spans and error grouping for duplicate identifier errors

* Trim trailing whitespace

* Record related info in error baselines

* Make error more whimsical
2018-07-02 10:47:52 -07:00
Wesley Wigham 18e3f487a4
Support LibraryManagedAttributes<TComponent, TAttributes> JSX namespace type (#24422)
* WIP

* Allow type alias for managed type

* Add a large test

* Accept updatedbaselines

* Fix typo in test, add one more example
2018-06-29 18:45:29 -07:00
Nathan Shively-Sanders 5c2eeb20b1
Destructuring declaration prefers type annotation type (#25282)
* Destructuring declaration prefers type annotation type

Previously, getTypeForBindingElement would always union the declarations type and
the type of the default initializer. Now, if the declaration has a type
annotation, it does not union with the initializer type. The type
annotation's type is the one used.

* Small cleanup in parentDeclarationHasTypeAnnotation

* Refactoring based on PR comments

* Combine getCombined*Flags into a single helper function

Retain the individual functions since they are used a lot.

* Remove unneeded temp
2018-06-28 10:41:38 -07:00
Nathan Shively-Sanders 9025bc7c69
Fix control flow loop in yield expression (#25228)
* Fix control flow loop in yield expression

Yet again, the fix is to stop using checkExpressionCached.

* Update lib in test to reduce number of errors
2018-06-26 12:50:29 -07:00
Nathan Shively-Sanders 9044589377
Fix duplicate errors in js special assignments (#24508)
* Fix duplicate errors in js special assignments

* Simplify checkExpressionCached call to checkExpression

* Accept baselines after merge

* Use Map for deferredNodes and improve NoDeferredCheck comment

I added an assert when a duplicate was added, but it caused 18 failures
in our test suite.

* Remove NoDeferredCheck
2018-06-26 12:40:58 -07:00
Anders Hejlsberg 70975cd08f
Merge pull request #24897 from Microsoft/restTuples
Tuples in rest parameters and spread expressions
2018-06-25 19:26:35 -07:00
Anders Hejlsberg d869e56d33 Add tests 2018-06-25 10:45:38 -10:00
Andy e8e80d2bbd
Don't crash on property access with type (#25170)
* Don't crash on property access with type

* Move test
2018-06-25 11:25:52 -07:00
Anders Hejlsberg 9cd8eadfd2 Update tests 2018-06-24 14:32:50 -10:00
Anders Hejlsberg b0d8c6551e Merge branch 'master' into restTuples
# Conflicts:
#	src/compiler/checker.ts
2018-06-22 06:10:50 -10:00
Anders Hejlsberg c2310009e1 Update tests 2018-06-21 17:02:35 -10:00
Nathan Shively-Sanders 0bb897273f
Parse nested prop and param tags the same way (#25139)
That is, only nest them if their name matches the provided parent name.
Otherwise do not nest them.

Note that this commit changes the behaviour of an incorrect typedef that
contains both an `@type` child tag and `@property` child tags.

Previously, the `@type` would be incorrectly nested under a `@property`
tag with type `object`, just like `@property` tags would be. Now, the
`@type` tag causes the entire typedef to ignore the `@property` tags and
treat the typedef as if it were an instance of the
typedef-and-nested-type pattern:

```js
/**
 * @typedef {Object} name
 * @type {{ the, actual, type }}
 */
```
2018-06-21 16:12:55 -07:00
Nathan Shively-Sanders a7af92eb63
check return tag in getTypePredicateOfSignature (#25130) 2018-06-21 11:30:37 -07:00
Andy 2b9166b2f9
Don't recommend to install '@types/foo' if that already exists (#24815)
* Don't recommend to install '@types/foo' if that already exists

* Add different extra diagnostic text if the @types package exists

* Update API (#24966)
2018-06-21 10:19:14 -07:00
Nathan Shively-Sanders 43d0794ba3
Fix crash when binding jsdoc-style inner namepaths (#25106)
* getDeclarationIdentifier handles undefined name

getNameOfDeclaration actually doesn't handle all declarations, only
those that produce names that could be reasonably used as an identifier.
Until now, getDeclarationIdentifier assumed that getNameOfDeclaration
always returned a name. This caused crashes whenever we tried to get the
name of something like a Constructor.

* Add test and baselines

* getNameOfDeclaration can return undefined

This requires all callers to handle it, which turns out now to be too
disruptive.

* Fix lint
2018-06-21 10:01:39 -07:00
Nathan Shively-Sanders 0f55566cf4
In JS, always check the extends tag of a class before its heritage clause (#25111)
* Check extends tag first in getClassExtendsHeritageClauseElement

Previously getBaseTypeNodeOfClass checked, but this is only used in a
few places.

* Fix names and add test

* Update API baseline

* Move jsdocAugments tests to conformance/jsdoc

* Better naming in checkClassLikeDeclaration
2018-06-20 16:28:30 -07:00
Anders Hejlsberg 4f99bc19c8 Merge branch 'master' into restTuples
# Conflicts:
#	tests/baselines/reference/APISample_Watch.errors.txt
#	tests/baselines/reference/APISample_WatchWithDefaults.errors.txt
#	tests/baselines/reference/APISample_WatchWithOwnWatchHost.errors.txt
#	tests/baselines/reference/APISample_compile.errors.txt
#	tests/baselines/reference/APISample_jsdoc.errors.txt
#	tests/baselines/reference/APISample_linter.errors.txt
#	tests/baselines/reference/APISample_parseConfig.errors.txt
#	tests/baselines/reference/APISample_transform.errors.txt
#	tests/baselines/reference/APISample_watcher.errors.txt
#	tests/baselines/reference/api/tsserverlibrary.d.ts
#	tests/baselines/reference/api/typescript.d.ts
2018-06-16 07:47:30 -07:00
Nathan Shively-Sanders 4db1c132b7
No dupe jsdoc for assignment inside an initializer (#24973) 2018-06-14 15:32:10 -07:00
Nathan Shively-Sanders 57e652dd02
Js/check type tags (#24967)
* Check the type expression of `@type` tags

* Update existing tests and baselines
2018-06-14 13:11:52 -07:00
Anders Hejlsberg 0cc0fad381 Add tests 2018-06-14 13:06:37 -07:00
Nathan Shively-Sanders a56b272d38
In JS, fix crash with in a file with conflicting ES2015/commonjs exports (#24960)
* fix crash with conflicting ES2015/commonjs modules

* Refactor based on PR comments
2018-06-14 11:18:23 -07:00
Nathan Shively-Sanders 2a8c4d1bd7
Support @this tags (#24927)
* Type check `@this` tags

No special support in fourslash yet, so quickinfo probably doesn't work.

* Do no require braces and update API baselines
2018-06-13 10:11:12 -07:00
Nathan Shively-Sanders 5be8f1f9f9
Better handling of circular JS containers in getTypeOfVariableOrParameterOrProperty (#24732)
* avoid circularity in getTypeOfVariableOrParameterOrProperty

Modify getTypeOfVariableOrParameterOrProperty to get the type of the
variable declaration before widening it. This essentially avoids some
circularities by (1) setting the type of the variable declaration to the
unwidened type (2) updating the type of the variable declaration to the
widened one.

You will still get a circular noImplicitAny in (1), for expressions that
actually are circular, but not in (2), for the containers of things that
are not themselves circular.

* Stop checking js init object literals via checkObjectLiteral

* checkBinaryExpression: new code for special assignments

* Chained lookup for js initializer type

* Check for JS-specific types only once

Also make sure to respect the type annotation if there is one.

* Accept API changes
2018-06-12 09:42:26 -07:00
Nathan Shively-Sanders 923a8aab0e
Add Variable to HasExports (#24871)
JS containers are variables, but may have exports just like classes and
modules.
2018-06-11 14:45:27 -07:00
Mohamed Hegazy 35d25ff280
Merge pull request #24645 from Kingwl/this-type-accessibility
allow access protected member in this parameter context
2018-06-11 13:17:58 -07:00
Ron Buckton 2b4569c04f Fix prologue order in async function 2018-06-07 13:34:16 -07:00
Mohamed Hegazy 34dd7738c9
Merge pull request #24672 from bakkot/binding-comma
Allow trailing commas after non-rest elements in destructuring
2018-06-06 13:00:17 -07:00
Nathan Shively-Sanders 30994c86e4
Improve valueDeclaration for js module merges (#24707)
Nearly everything in a merge of JS special assignments looks like a
valueDeclaration. This commit ensures that intermediate "module
declarations" are not used when a better valueDeclaration is available:

```js
// File1.js
var X = {}
X.Y.Z = class { }

// File2.js
X.Y = {}
```

In the above example, the `Y` in `X.Y.Z = class { }` was used as the
valueDeclaration for `Y` because it appeared before `X.Y = {}` in the
compilation.

This change exposed a bug in binding, #24703, that required a change in
typeFromPropertyAssignmentOutOfOrder. The test still fails for the
original reason it was created, and the new bug #24703 contains a repro.
2018-06-06 11:11:15 -07:00
Nathan Shively-Sanders d6250c8342
Fix circularity error when extending class in same JSContainer (#24710)
Do this by not widening properties of an object literal that are

1. JS initialisers
2. and not an object literal

These properties have types that will never widen, so the compiler
shouldn't ask for the types earlier than it strictly needs to.
2018-06-06 09:13:38 -07:00
王文璐 0bcbbbdd58 disallow static field access 2018-06-05 18:42:21 +08:00
Kevin Gibbons 87bb5e3cbb Allow trailing commas after-rest elements in destructuring 2018-06-04 14:58:30 -07:00
Nathan Shively-Sanders 7db4b1cbc7
Fix property assignment on aliases (#24659)
Aliases don't have valueDeclarations, which caused a crash when passed
to isJavascriptContainer before.
2018-06-04 13:34:23 -07:00
Nathan Shively-Sanders 34e68efdae
Template tag allows specification of constraints (#24600)
* Parse (and mostly support) template tag constraints

A bunch of tests hit the asserts I added though.

* Messy version is finished. Need to add a few tests

* Refactor to be smaller

* Small refactor + Add one test

* Another test

* Minor cleanup

* Fix error reporting on type parameters on ctors

* Simplify syntax of `@template` tag

This is a breaking change, but in my sample, nobody except webpack used the
erroneous syntax. I need to improve the error message, so
jsdocTemplateTag3 currently fails to remind me of that.

* Better error message for template tag

* Fix fourslash baselines

* Another fourslash update

* Address PR comments

* Simplify getEffectiveTypeParameterDeclarations

Make checkGrammarConstructorTypeParameters do a little more work
2018-06-04 11:42:46 -07:00
王文璐 9767fbba09 allow access protected member in this parameter context 2018-06-04 15:16:59 +08:00
Anders Hejlsberg 54f9c17045 Add regression test 2018-06-03 11:59:24 -07:00
Anders Hejlsberg 6f2001fb23 Add tests 2018-06-02 17:43:37 -07:00
Nathan Shively-Sanders d187de2076
Better JS container binding (#24367)
* Static assignments to class expressions work

* Bind static properties of functions too

Also update SymbolLinks in getTypeOfFuncClassEnumModule so that the
type gets cached correctly.

* Remove initializer handling:obj literals+type lookup

Also include a couple of improved baselines

* Fix 1-nested js containers:binding+cross-file merge

* Consolidate check into one utility

The utility is horrible and needs to change, but at least it's in one
place.

Next step is to make the utility like getDeclarationOfAlias, except
getDeclarationOfJSAlias.

* Defaulted assignments now (mostly) work

* Default assignment definitely work, and IIFEs kind of do

* n-nested undeclared containers now seem to work

Merging even seems to work ok.

* Handle prototype+prototype property assignments

Perhaps in the wrong way. I have an idea how to simplify them.

* Remove prototype special-case

1. It's not completely removed; the checker code in
getJavascriptClassType needs to be fixed, among other places.
2. I didn't actually remove the code so that it will be easier to see
what used to be there on Monday.

Regardless, the code will be much simpler and seems to be mostly
improved with very little work so far.

* Allow more merges+accept baselines

* Update more baselines

* Fix js initializer check in bindPropertyAssignment

* Fix codefixes

* Rest of strictNullChecks cleanup + other cleanup

1. Remove a few TODOs
2. Remove extraneous SymbolFlag
3. Simplify isSameDefaultedName

* Binder cleanup

* Checker cleanup

* Almost done with utilities cleanup

* Utilities cleanup

* Require js initializer to be (1) JS (2) initializer

Change getDeclarationOfJSInitializer to require that the provided js
initializer be in a javascript file, and that it is the initializer of
the retrieved declaration.

* Use getSymbolOfNode instead of accessing symbol directly

* Ugh. Start over with just test cases

* Handle additional cases in getTypeOfVariableOrParameterOrProperty

These are cases in a really embarrassing check, in which we admit that
the symbol flags steered us wrong and switch to
getTypeOfFuncClassEnumModule instead (which never asserts).

* Add test case for #24111

* Address PR comments
2018-05-31 11:41:26 -07:00
Nathan Shively-Sanders cdfa63aa40
Fix exported type resolution in commonjs (#24495)
* Fix resolution of exported types in commonjs

It is fine to resolve the types of exported classes in ES6:

```js
export class C {
}
var c = new C()
```

But not for commonjs exported classes:

```js
module.exports.C = class {
}
var c = new C() // should error
```

Fixes #24492

* All jsdoc type aliases are available locally in commonjs modules

* Check that location isSourceFile before commonJsModuleIndicator
2018-05-30 14:12:38 -07:00
Anders Hejlsberg a8a31ed508
Merge pull request #24439 from Microsoft/unknownType
New 'unknown' top type
2018-05-30 10:22:02 -07:00
Nathan Shively-Sanders 22cdff59e4
Better fix for bogus duplicate identifier in module exports (#24491) 2018-05-30 09:59:14 -07:00
Anders Hejlsberg e22a9d6fc1 Merge branch 'master' into unknownType 2018-05-30 07:45:10 -07:00
Anders Hejlsberg 577662de42 Update tests 2018-05-29 17:55:57 -07:00
Nathan Shively-Sanders 36c580378f
Fix duplicate identifier error with module.exports (#24466)
A bug in checkSpecialAssignment added bogus duplicate identifier errors
when using module.exports assignment to export a class. This commit
fixes that.
2018-05-29 14:29:48 -07:00
Nathan Shively-Sanders 15bfaf1cf6
Skip IntrinsicAttributes elaboration in JSX errors (#24461)
* Skip IntrinsicAttributes elaboration in JSX errors

Do not issue an error message for a source type that comes from JSX
attributes and a target type that is an intersection containing
IntrinsicAttributes or IntrinsicClassAttributes. This will make error
messages simpler and less confusing.

Note:
1. There will always be elaboration under the skipped message, so this
won't elide errors completely.
2. Rarely (once in the tests) the intersection type will have more that
one non-Intrinsic* member. However, these additional members don't
provide useful information either, so it's fine to skip them.

* Add test of IntrinsicAttributes error

* Fix indentation in test
2018-05-29 14:00:26 -07:00
Anders Hejlsberg c694ffe7a5 Update tests 2018-05-29 12:54:12 -07:00
Anders Hejlsberg 31c73defa7 Update tests 2018-05-27 15:44:01 -07:00
Anders Hejlsberg 73af0adcf0 Add tests 2018-05-27 10:37:59 -07:00
Mohamed Hegazy a7a68d9591 Merge branch 'fix-es5-export-class-name-object' of https://github.com/Kingwl/TypeScript into Kingwl-fix-es5-export-class-name-object 2018-05-25 15:45:31 -07:00
Nathan Shively-Sanders e250942d6a
Disallow nested object param syntax in callback tag (#24392)
* Callback tag:Disallow nested-object-param syntax

Previously this caused a crash in parsing. If/when we want to support
this syntax, we will need to fix this crash.

* Update baselines
2018-05-24 15:11:33 -07:00
kingwl cb2be44d02 fix export class declare with name object targeting es5 (#17494) 2018-05-24 18:16:38 +08:00
Mohamed Hegazy 10ac8b47e5
Merge pull request #22022 from Kingwl/enum-eval-div-zero
disallow nan and infinity in enum member
2018-05-23 15:32:35 -07:00
Andy 982c8d0af9
Add suggestion diagnostics for unused label and unreachable code (#24261)
* Add suggestion diagnostics for unused label and unreachable code

* Always error on unused left hand side of comma
2018-05-22 07:56:29 -07:00
Anders Hejlsberg 9d4096f9c4 Add tests 2018-05-21 16:43:55 -07:00
Nathan Shively-Sanders 6450490844
Fix jsdoc type resolution [merge to master] (#24204)
* Fix JSDoc type resolution

Breaks type parameter resolution that is looked up through prototype
methods, though. I need to fix that still.

* Check for prototype method assignments first

* Undo dedupe changes to getJSDocTags

* JS Type aliases can't refer to host type params

Previously, js type aliases (@typedef and @callback) could refer to
type paremeters defined in @template tags in a *different* jsdoc tag, as
long as both tags were hosted on the same signature.

* Reduce dedupe changes+update baseline

The only reason I had undone them was to merge successfully with an
older state of master.
2018-05-17 10:46:10 -07:00
Nathan Shively-Sanders aa7e2b0f07
Add callback tag, with type parameters (#23947)
* Add initial tests

* Add types

* Half of parsing (builds but does not pass tests)

* Parsing done; types are uglier; doesn't crash but doesn't pass

* Bind callback tag

Builds but tests still don't pass

* Only bind param tags inside callback tags

* Fix binding switch to only handle param tags once

* Checking is 1/3 done or so.

Now I'm going to go rename some members to be more uniform. I hate
unnnecessary conditionals.

* Rename typeExpression to type (for some jsdoc)

(maybe I'll rename more later)

* Rename the rest of typeExpressions

Turns out there is a constraint in services such that they all need to
be named the same.

* Few more checker changes

* Revert "Rename the rest of typeExpressions"

This reverts commit f41a96b24d.

* Revert "Rename typeExpression to type (for some jsdoc)"

This reverts commit 7d2233a00e.

* Finish undoing typeExpression rename

* Rename and improve getTypeParametersForAliasSymbol

Plus some other small fixes

* Core checking works, but is flabbergastingly messy

I'm serious.

* Callback return types work now

* Fix crash in services

* Make github diff smaller

* Try to make github diff even smaller

* Fix rename for callback tag

* Fix nav bar for callback tag

Also clean up some now-redundant code there to find the name of typedefs.

* Handle ooorder callback tags

Also get rid of redundant typedef name code *in the binder*. It's
everywhere!

* Add ooorder callback tag test

* Parse comments for typedef/callback+display param comments

* Always export callbacks

This requires almost no new code since it is basically the same as
typedefs

* Update baselines

* Fix support for nested namespaced callbacks

And add test

* Callbacks support type parameters

1. Haven't run it with all tests
2. Haven't tested typedef tags yet
3. Still allows shared symbols when on function or class declarations.

* Template tags are now bound correctly

* Test oorder template tags

It works.

* Parser cleanup

* Cleanup types and utilities

As much as possible, and not as much as I would like.

* Handle callback more often in services

* Cleanup of binder and checker

* More checker cleanup

* Remove TODOs and one more cleanup

* Support parameter-less callback tags

* Remove extra bind call on template type parameters

* Bind template tag containers

Doesn't quite work with typedefs, but that's because it's now stricter,
without the typedef fixes. I'm going to merge with jsdoc/callback and
see how it goes.

* Fix fourslash failures

* Stop pre-binding js type aliases

Next up, stop pre-binding js type parameters

* Further cleanup of delayed js type alias binding

* Stop prebinding template tags too

This gets rid of prebinding entirely

* Remove TODO

* Fix lint

* Finish merge with use-jsdoc-aliases

* Update callback tag baselines

* Rename getTypeParametersForAliasSymbol

The real fix is *probably* to rename Type.aliasTypeArguments to
aliasTypeParameters, but I want to make sure and then put it in a
separate PR.
2018-05-17 09:28:11 -07:00
Nathan Shively-Sanders 0ba8998c82
Fix stack overflow in merge symbol (#24134)
* JS initializers use original valueDecl, not mutated

target's valueDeclaration is set to the source's if it is not present.
This makes it incorrect to use getJSInitializerSymbol because it relies
on the symbol's valueDeclaration.

This fix just saves the original valueDeclaration before mutating and
uses that.

* Compare merged targetInitializer to target

Instead of the unmerged one

* Add test of stack overflow
2018-05-15 12:49:54 -07:00
王文璐 ad5a4c7097 add prependRange and move more variable declaration 2018-05-10 15:54:51 +08:00
Anders Hejlsberg 238177657f Add regression test 2018-05-08 09:42:21 -07:00
王文璐 a20470e005 disallow nan and infinity in enum member 2018-05-04 10:28:59 +08:00
Ron Buckton f67afa098f Unpatch vfs resolver and default lib rename 2018-05-03 14:18:50 -07:00
Ron Buckton d62a11ffc0 Merge branch 'master' into vfs 2018-05-01 18:58:31 -07:00
Anders Hejlsberg 4c933aef9a Check that test cases produce expected types 2018-05-01 13:05:49 -07:00
Anders Hejlsberg 59355cbfdb Add regression tests 2018-05-01 12:44:46 -07:00
Nathan Shively-Sanders 5ea4d3b2bb
No error for require, module.exports or exports in Javascript (#23743)
* No error for require

Still errors for module and exports, and require's type is now
incorreclty 'any'; I broke module resolution somehow. Needs
investigation.

* module/exports symbols+update isCommonJsRequire

Everything passes the tests but the code can be improved

* Update baselines

* Cleanup

* Update baselines of new tests

* Get rid of exports symbol

It wasn't doing anything anyway.
2018-04-30 15:47:59 -07:00
Nathan Shively-Sanders 7cda045d52
Always export typedefs (#23723)
* Always export typedefs

This actually just required deleting a check in declareModuleMembers
and checking for external AND commonjs modules in a couple of places.

However, while experimenting with this feature, I discovered that even
previously-exported typedefs would only be exported if they came after a
commonjs export node. So I added a commonjs check to the pass in the
parser. It will not catch nested module.exports, but it will catch
top-level assignments.

The new test tests both changes.

* Post-bind typedef instead of pre-checking for commonjs

* Duplicate identifier errors

* Fix class type reference resolution+update baselines

* Move to a type-based check for duplicate identifiers
2018-04-30 14:55:26 -07:00
Anders Hejlsberg 936444ad7b Add tests 2018-04-29 07:55:23 -07:00
Anders Hejlsberg 25d5952096
Merge pull request #23751 from Microsoft/reduceIntersectionTypes
Remove redundant primitive types from intersections
2018-04-28 11:42:56 -07:00
Daniel Rosenwasser 443c1c7965
Merge pull request #23327 from Microsoft/importDotMeta
Support 'import.meta'
2018-04-27 20:52:28 -07:00
Daniel Rosenwasser 12a3e39dca Specify ESNext module in test. 2018-04-27 18:17:49 -07:00
Anders Hejlsberg 38d1f7f0d2 Add tests 2018-04-27 16:50:09 -07:00
Anders Hejlsberg 6c28da328e
Merge pull request #23672 from Microsoft/intersectionWithUnionConstraint
Type relationships for intersections with union constraints
2018-04-27 15:53:00 -07:00
Anders Hejlsberg 5ecd03e8c0
Merge pull request #23660 from Microsoft/fixIndexTypeTargetConstraint
Fix constraint of 'keyof T[K]' in target position
2018-04-27 15:52:21 -07:00
Nathan Shively-Sanders 3631af6486
Remove readonly from object rest properties (#23746)
* Remove readonly from object rest properties

Works the same as removing it from object spread properties

* Fix bug number in test
2018-04-27 14:54:59 -07:00