Commit graph

1761 commits

Author SHA1 Message Date
Nathan Shively-Sanders 11eabc0946
Skip parens and non-null assertions when looking for this-context (#23097)
* Skip parens and ! for getting this-context of call

* Add test and improve code a bit

* Use skipOuterExpressions instead
2018-04-03 06:23:59 -07:00
Anders Hejlsberg 751eab9eed
Merge pull request #23067 from Microsoft/fixTPReferenceInConditional
Fix type parameter reference checks in conditional types
2018-04-02 17:30:32 -07:00
Wesley Wigham 414bc49cc4
Module or import types (#22592)
* Type side of import types

* Value side of import types

* Accept library changes

* Refined implementation, more tests

* Allow resolutions to be performed late if the resolution still results in a file already in the build

* Add another test case

* Add some jsdoc usages

* Allow nodebuilder to use import types where appropriate

* Parse & check generic instantiations

* use import types in nodebuilder for typeof module symbols

* Wire up go to definition for import types

* Accept updated type/symbol baselines now that symbols are wired in

* PR feedback

* Fix changes from merge

* Walk back late import handling

* Remove unused diagnostic

* Remove unrelated changes

* Use recursive function over loop

* Emit type arguments

* undo unrelated change

* Test for and support import type nodes in bundled declaration emit
2018-04-02 10:18:23 -07:00
Nathan Shively-Sanders 5c442419dc
Include arrow functions as javascript initializers (#23068)
This means that they are treated as valid js containers, methods, etc.
2018-04-02 10:11:39 -07:00
Nathan Shively-Sanders 6d9a8250bd
Improve binding and jsdoc of chained special js assignments (#23038)
* Search for jsdoc on chained assignments

* Fix binding of chained binary expression js-assignments

* Test:chained jsdoc+chained prototype assignment

* Improve naming
2018-04-02 09:47:01 -07:00
Anders Hejlsberg ec02ccd575 Add regression test 2018-04-02 09:23:00 -07:00
Anders Hejlsberg b3829523b2
Merge pull request #23039 from Microsoft/fixConditionalConstraints
Improve conditional type constraints
2018-03-31 11:56:05 -07:00
Wesley Wigham 9b558f9535
Remove _this, _super, and _newTarget name conflict errors (#22890)
* Add new generated name kind for reused transpiler variables

* Remove error on _super or _newTarget conflict

* Add test with super helper conflict

* Remove error on _this conflict

* Fix lint

* Use flags instead of generated kinds, inline some things

* Accept rename

* Remove trailing whitespace

* Move helper emit into printer, rather than emitter"

* passthru module and target

* New test, accept baselines

* Make members private
2018-03-30 17:43:37 -07:00
Anders Hejlsberg b84e05e669 Add tests 2018-03-30 16:21:16 -07:00
Anders Hejlsberg 7714a2bb5b
Merge pull request #22989 from Microsoft/fixImpliedConstraint
Fix implied constraints in conditional types
2018-03-29 17:06:16 -07:00
Mohamed Hegazy e3f02b5608
Merge pull request #22275 from delftswa2018/21617-detailed-error-forof-iterators
Fix #21617: Give detailed message on `for-of` of iterators without downlevelIteration
2018-03-29 15:43:00 -07:00
Andy 9d713b6db6
Error on rest parameter with trailing comma (#22262)
* Error on rest parameter with trailing comma

* Error on binding patterns and improve error location
2018-03-29 13:12:23 -07:00
Andy a9aca81601
Error on for (const x in never) (#22988)
* Error on `for (const x in never)`

* Update diagnostic

* Provide argument to diagnostic
2018-03-29 11:39:30 -07:00
Anders Hejlsberg bd442b7e52 Add regression test 2018-03-29 10:22:11 -07:00
Andy 65659d7297
Don't allow to iterate over 'never' (#22964)
* Don't allow to iterate over 'never'

* Include type in error message
2018-03-29 10:01:21 -07:00
Nathan Shively-Sanders eca3d68eb4
@typedef supports nested @property names (#22967)
Previously it did not, because this capability is not documented on
usejsdoc.org. However, several people requested this feature.
2018-03-29 09:39:23 -07:00
Anders Hejlsberg 9dd31488f6
Merge pull request #22959 from Microsoft/fixInferTypeParameterLeak
Fix 'infer T' type parameter leaks
2018-03-28 15:45:09 -07:00
Anders Hejlsberg 83276ce163 Add another test 2018-03-28 15:21:29 -07:00
Anders Hejlsberg 0e446fe8c2 Add regression test 2018-03-28 13:16:29 -07:00
Nathan Shively-Sanders adf30dd694
isMethodLike recognises prototype-assignment methods (#22935)
* isMethodLike recognises prototype-assignment methods

* Require js prototype methods to be in JS files
2018-03-28 10:41:24 -07:00
Nathan Shively-Sanders 61aad4c7b8
Handle toplevel this-assignment (#22913)
Do nothing now. Someday we might handle it correctly.
2018-03-27 12:24:37 -07:00
Nathan Shively-Sanders c9ac15ae56
In JS, this assignments in constructors are preferred and nullable initializers become any (#22882)
* First draft:in js, constructor declaration is preferred

* Add tests

* initializer of null|undefined gives any in JS

Also move this-assignment fixes out of binder. I'm going to put it in
the checker instead.

* In JS, initializer null|undefined: any, []: any[]

* First draft of js prefer-ctor-types overhaul

* Update tests, update baselines

* Improve readability of constructor-type preference

* Cleanup: Remove TODO and duplication

* Add noImplicitAny errors

* Add comment
2018-03-26 13:42:34 -07:00
Anders Hejlsberg 5b1554f708 Change test to use type variables 2018-03-25 15:30:46 -07:00
Anders Hejlsberg 8f860f672f Add tests 2018-03-25 11:33:24 -07:00
Anders Hejlsberg 7c0cc84abd Add tests 2018-03-25 11:30:08 -07:00
Nathan Shively-Sanders e16bb3e418
Improve behaviour of ... inside JSDoc functions (#22809)
* No error for ... on last param of jsdoc function

* ... is a rest param w/array type in jsdoc function

* Simplify getTypeFromJSDocVariadicType
2018-03-22 16:17:16 -07:00
Wesley Wigham a909000b62
Parse and check type arguments on JSX opening and self-closing tags (#22415)
* Parse and check type arguments on JSX opening like elements

* Fix nits
2018-03-22 15:07:36 -07:00
Nathan Shively-Sanders 4462c159b1
Correctly track thisContainer for this-property-assignments in JS nested containers (#22779)
* Track thisContainer for this-property-assignments in JS

Previously it would update on every block, not just those that could
bind `this`.

In addition, if the constructor symbol still can't be found, then no
binding happens. This is usually OK because people don't add new
properties in methods too often.

* Update additional baselines

* Add lib:dom to new test

* Address PR comments

* Correct new name for saveThisParentContainer
2018-03-22 09:54:43 -07:00
Anders Hejlsberg e5f6ed0b60
Merge pull request #22707 from Microsoft/fixIndexedAccessInConditionalType
Fix indexed access in conditional type
2018-03-21 15:18:39 -07:00
Nathan Shively-Sanders de4a69cb72
In source files and blocks, bind function declarations before other statements (#22766)
* Add test case and temporarily disable inference

(Inference of class members from this-assignments inside a
prototype-assigned function.)

* Update baselines

* In blocks and source files, bind functions first

* Add tests from other bugs

* Remove temporary failsafe

* Update tests to restore intent and clean up errors

* Restore intent even better

* Restore intent even better x2

* Add missed baselines
2018-03-21 14:22:09 -07:00
Anders Hejlsberg eb3fd150a7 Add regression test 2018-03-21 13:35:15 -07:00
Anders Hejlsberg 4fef35cdd0 Add regression test 2018-03-21 10:03:48 -07:00
Anders Hejlsberg fa8564fa9e Add test to verify errors on nested 'infer T' declarations 2018-03-21 10:03:07 -07:00
Anders Hejlsberg c94d28dbc8 Add test 2018-03-21 06:47:57 -07:00
Nathan Shively-Sanders 1074819be3
Js constructor function fixes (#22721)
* Do not add undefined for this assignments in functions

* Test:constructor functions with --strict

* First draft -- works, but needs a stricter check added

* Update baselines

* Make undefined-skip stricter and more efficient

Symbol-based now instead of syntactic

* Exclude prototype function assignments

* Add explanatory comment
2018-03-20 11:24:09 -07:00
Nathan Shively-Sanders ab8233c5d3
Two JSdoc parsing fixes (#22705)
* Correctly parse JSDoc type *=

* Allow `markdown` quoted param names in JSDoc

* Add tests and update baselines

* Get correct span for the type '*'

* Fix whitespace lint

* Add unbracketed type test
2018-03-20 09:23:08 -07:00
Wesley Wigham eaabf920eb
Combine keyof T inferences (#22525)
* Combine keyof T inferences

* Extract covariant inference derivation into function

* Test:keyof inference lower priority than return inference

for #22376

* Update 'expected' comment in keyofInferenceLowerPriorityThanReturn

* Update comment in test too, not just baselines

* Fix typo

* Move tests
2018-03-19 16:56:51 -07:00
Anders Hejlsberg 16f571b026 Add tests 2018-03-19 16:29:00 -07:00
Nathan Shively-Sanders b56093f3ac
Fix type when annotated with a JSDoc function type (#22692)
* Fix type when annotated with a JSDoc function type

Previously,
1. A variable annotated with a JSDoc function type would not require all
its parameters to be provided. This should only apply to functions
without a type annotation.
2. A parameter in a function with a JSDoc function type annotation would
still have the type 'any'.
3. Two `var` declarations in a Typescript and Javascript file,
respectively, would error even when they had identical function types.

* Update baselines and add constructor test

* Handle ConstructorType too

* Add test:method sig inside literal type

* Contextually type parameters by parent sig's JSDoc

Instead of a syntactic check in getJSDocTag

* Remove redundant check:isUntypedSignatureInJSFile

* Positive check for value signatures

Instead of excluding type signatures piecemeal.
2018-03-19 16:00:45 -07:00
Nathan Shively-Sanders bb23e9601f
Parse JSDoc ...T and T= only at top-level JSDoc (#22661)
* Parse JSDoc ...T and T= only at top-level JSDoc

...T and T= should only be legal at the top level of a type, and only in
JSDoc, since at least T= is ambiguous elsewhere. This PR changes parsing
to make that happen. The resulting parse tree is now simpler, allowing
me to get rid of some code I had to add in the checker.

* Extract JSDoc type parsing into its own function

* PR comments:return from parseJSDocType
2018-03-16 16:08:42 -07:00
Nathan Shively-Sanders 3b6ae8536f
JSDoc ?Type adds optionality to parameters (#22646)
* jsdoc ?Type adds optionality to parameters

Chrome devtools expects that parameters with type `?T` (or `T?`) add
null to `T` and optionality to the parameter. Previously it only added
null to the type.

Currently the PR does *not* add undefined to the type of
`T`, which is expected by chrome-devtools-frontend, but is inconsistent
with typescript's rules. The implementation achieves this inconsistency by
exploiting the fact that checking the signature adds optionality and
checking the parameter adds `undefined`.

* Update chrome-devtools-frontend baseline

* Add optionality only for jsdoc postfix=

* Skip jsdoc prefix types in isJSDocOptionalParameter

Previously isJSDocOptionalParameter was incorrect for types like
`?number=`, which are optional but have JSDocNullableType as their root
type node.
2018-03-16 13:28:24 -07:00
Andy b9f60566d0
For f.prototype.m = function() { this.x = 0; } make x a member of f, not of the function expression (#22643) 2018-03-16 11:35:51 -07:00
Nathan Shively-Sanders 677d860b44
No error on unmatchable @param tags (#22510)
* No errr on unmatchable `@param` tags

Such as when the initializer is not a function, or when the function
mentions `arguments` in its body.

* Do not require dummy param for JS uses of arguments

1. JS functions that use `arguments` do not require a dummy parameter in
order to get a type for the synthetic `args` parameter if there is an
`@param` with a `...` type.
2.JS functions that use `arguments` and have an `@param` must have a
type that is a `...` type.

* Check for array type instead of syntactic `...`

* Address PR comments

* Update baselines
2018-03-14 10:17:54 -07:00
Nathan Shively-Sanders 0fa838a3ef
Brackets and postfix= in @param add undefined (#22514)
* Brackets and postfix= in `@param` add undefined

Previously they only added optionality.
Note that, unlike Typescript, when a parameter initializer is specified
in jsdoc, it does not remove undefined in the *body* of the function.
That's because TS will generate initialisation code, but JS won't, so
the author will have to manually write code to remove undefined from the
type.

```js
/** @param {number} [a=101] */
function f(a) {
  // a: number | undefined here
  if (!a) {
    a = 101
  }
  // a: number here
}
```

Note that we don't check that
1. the initializer value is actually assigned to the parameter.
2. the initializer's type matches the declared type of the parameter.

Pretty much we just parse it and leave it alone.

* Address PR comments
2018-03-13 15:56:38 -07:00
Andy e48bcd60ba
Treat 'yield;' as 'yield undefined;' (#22297)
* Treat 'yield;' as 'yield undefined;'

* Use undefinedWideningType
2018-03-08 15:41:04 -08:00
Nathan Shively-Sanders e4610e3418
Import types in JS with var x = require('./mod') (#22161) 2018-03-08 11:11:51 -08:00
Nathan Shively-Sanders 04ceb3d9bd Disallow JS/non-JS merge without crashing
Note that the error location is misleading because it's reported inside
the merge step for the js initializer.
2018-03-08 09:49:23 -08:00
Nathan Shively-Sanders d86440f94f Merge branch 'master' into js-object-literal-assignments-as-declarations 2018-03-07 14:51:55 -08:00
Anders Hejlsberg 07ed899b46 Merge branch 'master' into checkInferredConstraints 2018-03-05 06:32:11 -08:00
Anders Hejlsberg 70818ae716
Merge pull request #22313 from Microsoft/fixDistributiveConditionalTypes
Fix distributive conditional types
2018-03-05 06:23:45 -08:00