7383 Commits

Author SHA1 Message Date
Andy
ced4c00522
importFixes: Distinguish when we need to import JSX constructor or JSX namespace (#22828) 2018-03-26 14:05:03 -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
Wesley Wigham
6af764c560
Declaration maps and transparent goto definition using them (#22658)
* Add compiler option to enable declaration sourcemaps

* Transparent goto definition for sourcemapped declaration files

* Post-rebase touchups

* Rename API methods

* Fix lints

* Fix typo in name XD

* Log sourcemap decode errors

* Share the cache more, but also invalidate it more

* Remove todo

* Enable mapping on go to implementation as well

* Allow fourslash to test declaration maps mroe easily

* more test

* Handle sourceRoot

* Add tests documenting current behavior with other sourcemapping flags

* Ignore inline options for declaration file maps, simplify dispatch in emitter

* Change program diagnostic

* Fix nit

* Use charCodeAt

* Rename internal methods + veriables

* Avoid filter

* span -> position

* Use character codes

* Dont parse our sourcemap names until we need to start using them

* zero-index parsed positions

* Handle sourceMappingURL comments, including base64 encoded ones

* Unittest b64 decoder, make mroe robust to handle unicode properly

* Fix lint

* declarationMaps -> declarationMap

* Even more feedback

* USE Mroe lenient combined regexp

* only match base64 characters

* Fix nit
2018-03-26 12:15:34 -07:00
Anders Hejlsberg
fe8f239648
Merge pull request #22869 from Microsoft/fixConditionalTypeVariance
Fix conditional type variance
2018-03-26 09:36:16 -07:00
Anders Hejlsberg
d7df84d641
Merge pull request #22850 from Microsoft/tupleTypeInference
Only make inferences from tuple types of right arity
2018-03-26 09:35:45 -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
Anders Hejlsberg
c2a53f90de Add regression tests 2018-03-23 17:41:55 -07:00
Andy
9557e4ad96
Handle completions in interface / type literal similar to class (#22701)
* Handle completions in interface / type literal similar to class

* Code review
2018-03-23 16:04:29 -07:00
Anders Hejlsberg
1c2f3d228c Add regression test 2018-03-23 09:48:00 -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
ca1d19a579
Always make a new jsxAttributes type, dont reuse emptyObjectType (#22810)
* Always make a new jsxAttributes type, dont reuse emptyObjectType

* Break up conditional a bit
2018-03-22 15:16:33 -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
Wesley Wigham
a7b066fe04
Allow local class declarations to be returned as mixins (#22807) 2018-03-22 15:02:54 -07:00
Andy
94570eedcc
Don't provide spelling suggestion for module (#22805) 2018-03-22 14:27:34 -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
Andy
f2f2393f4b
convertFunctionToEs6Class: Copy comments from constructor to class (#22738) 2018-03-22 08:12:02 -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
ee546fb30f
Merge pull request #22764 from Microsoft/fixInferTypeDeclarationFiles
Fix missing 'infer T' in declaration files
2018-03-21 14:17:51 -07:00
Anders Hejlsberg
eb3fd150a7 Add regression test 2018-03-21 13:35:15 -07:00
Nathan Shively-Sanders
c930895d80
Undo 'any' inference propagation (#22736)
* Undo 'any' inference propagation

Removing this only changes one test slightly, and fixes JQuery types,
which rely on the old method of inference.

* Add jquery regression test and update baselines

* Restore any inference propagation to wildcard only
2018-03-21 11:13:39 -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
Andy
cc3921323c
Support services settings (#22236)
* Support services settings

* Code review

* More review

* Use different names for Options and GetCompletionsAtPositionOptions (todo: come up with better names)

* More renames

* More renaming

* Support quote style in importFixes

* Add `importModuleSpecifierPreference` option

* Support quote style for `throw new Error('Method not implemented.')` (#18169)

* options -> preferences
2018-03-20 13:07:59 -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
Andy
c7215a181c
findAllRefs: give entry for union its own definition (#22694) 2018-03-19 11:58:20 -07:00
Anders Hejlsberg
979bda484c Add regression test 2018-03-17 12:23: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
Andy
adf3635a1f
For import fix, for "foo/index" module, use "foo" as default export name, not "index" (#22651) 2018-03-16 14:00:33 -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
Wesley Wigham
2d01d76ee5
Change es2015 transform to retain comments on for of loop bodies (#22396) 2018-03-16 12:57:38 -07:00
Matt Bierner
9774cd5eb5 Fix await code action crashes when await is not in a function (#22623)
Fixes #22614
2018-03-16 11:53:17 -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
Matt Bierner
984aaa3ee9 Fix completions and brace in empty file (#22620)
Fixes #22618
2018-03-16 11:05:33 -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
85e9cce3c7
Don't add external module completions in a pure commonjs file (#22583) 2018-03-15 08:13:16 -07:00
Andy
e7ce3f9457
useNonAdjustedEndPosition when replacing import node (#22517)
* useNonAdjustedEndPosition when replacing import node

* Never adjust positions, and add trivia test
2018-03-14 11:46:45 -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
Mohamed Hegazy
708caf9a72 Do not use unguarded process in tsc.ts 2018-03-13 11:03:12 -07:00
Andy
83b438ffa6
fixUnusedIdentifier: Don't remove setter parameter (#22488) 2018-03-12 16:07:20 -07:00
Andy
ac5a39c709
Fix bug: Don't skip emitting JSX attributes (#21777) 2018-03-12 14:03:25 -07:00
Nathan Shively-Sanders
be1c11581e
Add js user tests (#22449)
* Add some new user tests to test salsa

* Use current latest, not "latest"

* Add other js user tests

* Add new baselines

* Fix new user tests' typeroot. Move github to octokit/rest
2018-03-09 15:59:46 -08:00