Commit Graph

11139 Commits

Author SHA1 Message Date
Andy
9ee5167030 Evaluate isPrototypePropertyAssignment lazily (#22728) 2018-03-20 12:33:30 -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
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
Andy
737859e3c1 Put simpler condition in front of more complex one (#22696) 2018-03-19 13:35:19 -07:00
Andy
096b2b0712 Use isFunctionLike instead of switch (#22698) 2018-03-19 13:35:01 -07:00
AdityaDaflapurkar
76fefddcaa Remove type assertion in sum function (#22670) 2018-03-19 08:19:24 -07:00
Anders Hejlsberg
20c008ecab Mark implied object destructuring patterns as object literal types 2018-03-17 12:02:19 -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
Andy
92ec1149ac getAllJSDocTagsOfKind always returns a defined result (#22652) 2018-03-16 14:01:28 -07:00
Andy
28ff6b6ef3 Store import nodes in SourceFile.imports instead of StringLiteral nodes (#22495)
* Store import nodes in SourceFile.imports instead of StringLiteral nodes

* Change SourceFile#imports storage back

* Code review

* StringLiteral -> StringLiteralLike
2018-03-16 14:01:00 -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
99d5058568 Add 'isPrototypeAccess' helper (#22648)
* Add 'isPrototypeAccess' helper

* Fix type error
2018-03-16 13:27:47 -07:00
Wesley Wigham
2d01d76ee5 Change es2015 transform to retain comments on for of loop bodies (#22396) 2018-03-16 12:57:38 -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
Sheetal Nandi
d4788f5d41 Merge pull request #22520 from Microsoft/betterDelete
Do not send first missing file event as well, Do not close typing installers watches just to recreate them
2018-03-16 11:17:23 -07:00
Wesley Wigham
bfe755c6ce Revert assertion addition (#22622) 2018-03-16 09:04:55 -07:00
Wesley Wigham
19ec83fcdf Refactor declaration emitter into declaration transformer (#21930)
* Refactor declaration emitter into declaration transformer

* Slight cleanup from code review feedback

* Incorporate fix for new test

* Swaths of PR feedback

* Merge public methods

* Per-file output

* Preserve input import ordering more often

* Unify jsdoc comment start detection under more lenient rule

* Move to per-file transformations to reduce the memory that msut be retained

* Fix typo
2018-03-15 22:23:10 -07:00
Andy
eb4dba7ad4 Disable assertion for deferredUnusedIdentifierNodes (#22604) 2018-03-15 10:49:39 -07:00
Klaus Meinhardt
7715b5139b Signature#declaration can be undefined (#22515) 2018-03-14 13:24:41 -07:00
Andy
1736741e54 Simplify implementation of firstOrUndefined and lastOrUndefined (#22572) 2018-03-14 12:40:48 -07:00
Andy
5f1668e53d Use type predicate for getFirstJSDocTag (#22573)
* Use type predicate for getFirstJSDocTag

* Restore API
2018-03-14 12:40:30 -07:00
Nathan Shively-Sanders
3728ec353a Improve unmatched jsdoc param error (#22577)
* Improve unmatched jsdoc parameter error message

* Remove extraneous carriage return
2018-03-14 12:36:01 -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
Andy
d1d69602ae getJSDocParameterTags: Always return defined result (#22523)
* getJSDocParameterTags: Always return defined result

* Make line shorter

* Simplify remaining use
2018-03-13 17:56:00 -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
23a64fe804 Remove redundant call to checkNodeDeferred (#22516)
* Remove redundant call to `checkNodeDeferred`

* Use a set to speed up `contains` checks
2018-03-13 15:46:25 -07:00
Sheetal Nandi
4046bb15ac Do not send first missing file event as well. 2018-03-13 15:09:13 -07:00
Andy
0c6ef348ce Simplify parseJsxChildren (#22511) 2018-03-13 12:28:21 -07:00
Mohamed Hegazy
85df31cde4 Merge pull request #22512 from Microsoft/fixUseOfProcess
Do not use unguarded process in tsc.ts
2018-03-13 11:24:31 -07:00
Sheetal Nandi
32018f66bb Merge pull request #22496 from Microsoft/suppressMultipleDelete
Do not send delete event every poll for missing folder
2018-03-13 11:11:51 -07:00
Mohamed Hegazy
708caf9a72 Do not use unguarded process in tsc.ts 2018-03-13 11:03:12 -07:00
Nathan Shively-Sanders
25f7e0b735 Fix crash after var = require('x') type resolution (#22452)
* Harden var x=require name resolution+update chrome baseline

Chrome-devtools crashed after the new `var = require('x')` resolution
because it forgot to check whether the declaration had an initializer.

* Update chrome-devtools-frontend baseline
2018-03-13 10:44:02 -07:00
Sheetal Nandi
3f2ff0125a Merge pull request #22450 from Microsoft/reenableTest
Enable the commented out test and convert folder entries to sorted list
2018-03-12 14:47:02 -07:00
Andy
ac5a39c709 Fix bug: Don't skip emitting JSX attributes (#21777) 2018-03-12 14:03:25 -07:00
Sheetal Nandi
88c5e2295b Do not send delete event every poll for missing folder
Fixes #22494
2018-03-12 13:52:15 -07:00
Sheetal Nandi
a0cd8d3f7d Ensure our readonly emptyArray stays non modified. 2018-03-09 16:56:14 -08:00
Martyn Janes
bcf6e342f1 Fix typo in emitDeclarationOnly error message for declaration required 2018-03-09 22:37:10 +03:00
Andy
2170f6e1f8 FunctionLike = SignatureDeclaration (#22365) 2018-03-08 16:31:42 -08:00
Andy
e48bcd60ba Treat 'yield;' as 'yield undefined;' (#22297)
* Treat 'yield;' as 'yield undefined;'

* Use undefinedWideningType
2018-03-08 15:41:04 -08:00
Andy
28e8c4f3b8 Factor out a getYieldedTypeOfYieldExpression helper (#22416) 2018-03-08 15:06:29 -08:00
Wesley Wigham
87d88e2ba3 Handle resolving and unknown symbols in getLiteralTypeFromPropertyName (#22406) 2018-03-08 13:35:55 -08:00
Sheetal Nandi
17b10dc2a9 Merge pull request #21243 from Microsoft/watchOptions
Different watchFile and watchDirectory options through environment variable
2018-03-08 12:44:53 -08:00
Nathan Shively-Sanders
a81f264d70 Call process.stdout._handle.setBlocking(true) (#22389)
* Call process.stdout._handle.setBlocking(true)

This prevents output from being truncated when the compiler can output
errors to stdout faster than it can receive them. This may slow down
performance for compilations for many errors, but those were already
quite slow.

* Disable tslint no-unnnecessary-type-assertion-2

It is wrong. It *is* necessary.
2018-03-08 12:38:30 -08:00
Sheetal Nandi
8378f692c7 Directly assign values for watchFile and watchDirectory in node System 2018-03-08 12:18:04 -08:00
Andy
a49e83ffa7 annotateWithTypeFromJSDoc: Use changes.insertTypeAnnotation instead of replaceNode (#22404) 2018-03-08 11:47:30 -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
f8134d0b45 Merge branch 'master' into js-object-literal-assignments-as-declarations 2018-03-08 10:40:55 -08:00
Nathan Shively-Sanders
35730f2879 Improve error span:duplicate symbols cross-js/ts
when the JS symbol is a JS initializer
2018-03-08 10:33:38 -08:00