9857 Commits

Author SHA1 Message Date
Ron Buckton
c03b2eed76 Add support for Inverse Offset and Range types 2020-02-13 14:53:18 -08:00
Orta
7726464abd
De-duplicate indentations in JSX Texts (#36552)
* WIP on making the JSX text node not include whitespace

* Scans to the last newline for JSX correctly

* Handle JSX closing element wrapping

* Offload all jsx text indentation handling to indentMultilineCommentOrJsxText

* Switch from find node -> find inde in formatting

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-02-03 17:09:50 -05:00
Alexander T
1c42fd4bdf
fix(33600): disallow convertFunctionToEs6Class Quick Fix for IIFE (#36580) 2020-02-03 16:52:08 -05:00
Andrew Branch
ef8eb0c876
Fix contextually typed object literal completions where the object being edited affects its own inference (#36556)
* Conditionally elide a parameter from contextual type signature calculation

* Slightly different approach to forbid inference to specific expressions

* Handle nested literals and mapped types correctly

* Delete unused cache

* Rename ContextFlags.BaseConstraint and related usage

* Add tests from my PR

* Update ContextFlags comment

Co-Authored-By: Wesley Wigham <wwigham@gmail.com>

* Update comments and fourslash triple slash refs

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-01-31 15:37:18 -08:00
Andrew Branch
86556d6c03
Fix export * that resolves to something type-only (#36558)
* Fix `export *` that resolves to something type-only

* Add same tests but non-tsserver
2020-01-31 15:09:27 -08:00
Ron Buckton
8db1d7bc6d
Do not adjust location for import/export keywords with more than one possible binding (#36560) 2020-01-31 14:58:30 -08:00
Ron Buckton
9a357c19f3
Fix wrong script info used to resolve line/offset for call hierarchy items (#36559) 2020-01-31 14:41:25 -08:00
Ron Buckton
01af3aa483
Support 'find references' on most declaration-related keywords (#36490)
* Allow 'find references' to work on most declaration keywords

* Add support for rename

* Add more keywords, move logic out of checker and into services

* Add additional type and expression keywords
2020-01-31 11:53:57 -08:00
Ron Buckton
fcf28506aa
Fix overzealous renaming of emit helpers in es module emit (#36541) 2020-01-31 10:41:47 -08:00
Ron Buckton
24d8f795b2
Fix crash in emitTokenWithComment (#36542) 2020-01-31 10:41:09 -08:00
Eli Barzilay
ad8feb5f90 Filter out private fields in string literal property completions.
Also some minor simplifications.

Fixes 36082.
2020-01-30 22:42:32 -05:00
Eli Barzilay
1a1ed7464d Add a similar test for target.symbol.valueDeclaration
(With the same question still open.)
2020-01-30 22:42:04 -05:00
Eli Barzilay
68a9d4592f Avoid testing isClassDeclaration if there's no valueDeclaration
I'm not sure if this is enough -- perhaps it's better to make the test
dig through the interface/s to the class?

Fixes 36059.
2020-01-30 22:42:04 -05:00
Hye Sung Jung
8ed129771f
fix spelling errors (#36523)
* fix spelling errors

* remove changes in lib/*
2020-01-30 13:39:54 -08:00
Alexander T
bfff11530f
fix(35069): insert blank line after last new import (#36531) 2020-01-30 11:20:09 -08:00
Nathan Shively-Sanders
c1e45ac8af
Fix use-before-def errors for ESNext property declarations (#36465)
* Fix use-before-def errors for ESNext property declarations

Fixes #36441
Fixes #36442

* Handle property declarations in nested classes
2020-01-30 10:58:07 -08:00
Anders Hejlsberg
8a0b8822b2
Fix contextually typed parameter issues (#36476)
* Fix multiple issues with contextually typed parameters

* Accept new baselines

* Fix lint error

* Add tests

* Address CR feedback

* Add fourslash tests
2020-01-30 10:50:39 -08:00
Andrew Branch
2fac535158
Fix type-only imports in interface 'extends' and import=/export= (#36496)
* Handle when files get checked in different orders

* Fix interface extends clause

* Fix import= something type only from a module

* Revert apparently unnecessary addition

* Revert "Revert apparently unnecessary addition"

This reverts commit 7444b0b72ea2e628ff414b675ef42723a6a7695d.

* Disallow `import = a.b.c` on anything with type-only imports

* Safety first

* Add test for TS Server single-file open

* Add big comment

* Extract error reporting function for import aliases

* Delete blank line

* Un-export, comment, and colocate some utils

* Combine 3 type-only marking function calls into one

* Add more export default tests
2020-01-29 15:00:17 -08:00
Nathan Shively-Sanders
36169b4d13
Class fields w/esnext+[[Define]]:no shadow error (#36405)
* Class fields w/esnext+[[Define]]:no shadow error

With useDefineForClassFields: true and ESNext target, initializer
expressions for property declarations are evaluated in the scope of
the class body and are permitted to reference parameters or local
variables of the constructor. This is different from classic
Typescript behaviour, with useDefineForClassFields: false. There,
initialisers of property declarations are evaluated in the scope of
the constructor body.

Note that when class fields are accepted in the ECMAScript
standard, the target will become that year's ES20xx

* add negative test case

* Add explanatory comment
2020-01-29 14:47:44 -08:00
Nathan Shively-Sanders
8da3eff7b0
Subtypes of ErrorConstructor extend it (#35549)
Previously subtypes of Error extended Error, but the matching subtypes
of ErrorConstructor did not extend ErrorConstructor. The members in
es5.d.ts are identical, so there's no need except for allowing interface
merging into ErrorConstructor to affect subtypes as well.
2020-01-29 13:26:00 -08:00
Nathan Shively-Sanders
1bbcb5553a
@typedef's nested Object syntax disallows type arguments (#36172)
Previously the jsdoc index signature syntax was incorrectly treated the
same as Object:

```js
/** @typedef {Object} AllowsNesting
 * @property ... */
/** @typedef {Object.<string,string>} IncorrectlyAllowsNesting */
```

Fixes #34911
2020-01-29 12:53:00 -08:00
Nathan Shively-Sanders
0cf100dcf8
Add constructor functions to aliasable expressions (#36108)
* Add constructor functions to aliasable expressions

Fixes #35228, at least the crash. There are still a couple of errors
that are probably incorrect.

Note that isJSConstructor relies on parent pointers and the ability to
merge symbols, so I had to move isAliasSymbolDeclaration (back?) to the
checker.

* add simple test case

* remove errors in test

* fix bad merge
2020-01-29 09:36:59 -08:00
Brandon Bloom
49282d9fba
Nested this container (#36495)
* Add nestedThisContainer test

* Fix #36492
2020-01-29 09:35:23 -08:00
Alexander T
9fd0202e9f
fix(36481): allow renaming private fields (#36499) 2020-01-29 09:21:19 -08:00
Sheetal Nandi
869a8211fc
Make javascript require goto def similar to ts import equals (#36487)
Fixes #34996
2020-01-28 16:23:56 -08:00
Sheetal Nandi
8eee8db192
NoEmit and incremental are allowed with listFilesOnly (#36488)
Fixes #32882
2020-01-28 15:59:09 -08:00
Ben Lichtman
e87b2e3506
Merge pull request #36063 from uniqueiniquity/addWeakCompletionProperty
Add completion property to identify completions from unchecked files
2020-01-28 13:53:47 -08:00
Sheetal Nandi
0e9416c7c8
Disallow incremental with noEmit (#36483)
Fixes #32882
2020-01-28 13:11:45 -08:00
Sheetal Nandi
f91f762ced
Fix js declaration emit for exporting default which looks like namespace merge (#36482)
Fixes #35074
2020-01-28 12:21:36 -08:00
Alexander T
2cc7a5d6bf fix(33362): 'extract to function' for variable that is assigne… (#36455) 2020-01-28 12:10:12 -08:00
Andrew Branch
cf33f7bff6
Don’t use 'import =' for auto-import when esModuleInterop is on unless it’s already been done (#36475)
* Revisit esModuleInterop import kind priority yet again

* Test was wholly redundant

* Check for precedent is simpler now
2020-01-28 11:05:04 -08:00
Andrew Branch
1bb6ea038f
Allow type-only namespace imports in implements clauses (#36464)
* Add test

* Allow type-only symbols in implements clauses

* Add more complex test
2020-01-27 16:13:30 -08:00
Sheetal Nandi
a87512d21b
Add # to completion trigger character, (#36462)
Handle private identifiers little better by creating token for private identifier when its just #
Report same error as invalid character but from language service we can now provide completions for this.#

Fixes #36367, #36250
2020-01-27 14:25:20 -08:00
Orta
3ece65a94c
When looking at outlines for try functions, allow for not finding a child to provide a span when requesting outlines (#36389) 2020-01-27 15:59:49 -05:00
Andrew Branch
e1bce187a8
Type-only auto imports (#36412)
* WIP

* Promote existing type-only imports to regular if needed

* Add completions test adding to type-only import

* Update tests, revert whole-import-clause replacement codefix strategy to preserve import specifier formatting

* Revert unnecessary changes

* Delete unused function

* }
2020-01-27 12:53:32 -08:00
Nathan Shively-Sanders
757e67041e
Fix getExpandoSymbol for already-expando symbols (#36457)
* Fix getExpandoSymbol for already-expando symbols

getExpandoSymbol is intended to get the symbol of the expando in a
declaration like

```js
var C = class {
}
```

However, when this occurs in a `module.exports` assignment, alias
resolution already jumps to the exported symbol -- in this case the
expando symbol:

``js
// @filename: first.js
module.exports = class {
}
// @filename: other.js
/* @type {import("./first")} */
var C
```

`getExpandoSymbol` is then called on `class { }` instead of
`module.exports = class { }`.

Previously, `getExpandoSymbol` would incorrectly treat `class { }` the
same as the export assignment and get the expando ... from the expando
itself. This resulted in merging the expando with itself, which causes
bogus errors and could cause other problems.

Now `getExpandoSymbol` checks that the expando "initializer" is
different from the declaration.

* Better check for getExpandoSymbol of expando

Check the declaration directly instead of the initialiser.
2020-01-27 12:32:56 -08:00
Alexander T
c239626f23 fix(36140): handle quotesPreference option in interface implementation (#36398) 2020-01-27 12:25:31 -08:00
Andrew Branch
20e8eba143
Issue better error for exporting primitive type (#36424)
* Issue better error for exporting primitive type

* Delete nonsense
2020-01-27 08:11:21 -08:00
Alexander T
30545006df fix(36068): Incorrect quick fix for undeclared private field i… (#36373) 2020-01-24 18:28:42 -08:00
Wesley Wigham
18cd79e179
Allow infer type variables to have constraints inferred (#32093)
* Allow `infer` type variables to have constraints infered and allow the breakdown of substitutes in simplifiable source inferences

* Still skip conditional inference when `extends infer Q` so such a pattern still acts as a constraint size breaker
2020-01-24 16:59:20 -08:00
Wesley Wigham
08e6bc20bb
Trampolines for large binary expressions (#36248)
* WIP

* Test no longer crashes, but emit trampoline is incomplete and skips pipeline phases

* Fix lints, use non-generator trampoline in emit (still skips pipeline)

* Final version with emitBinaryExprssion work stack that is only used if possible

* Fix lints

* retarget to es2015 for testing

* Use bespoke state machine trampolines in binder and checker

* Remove now extraneous code in parser

* Adjust fixupParentReferences to use a depth first preorder traversal rather than breadth first

* Reintroduce incremental fast bail in fixupParentReferences

* Revert target to es5

* PR feedback

* Small edit for devops rebuild with updated definition

* Fix comment nits, add internally extraneous check back into transformer
2020-01-24 16:29:55 -08:00
Klaus Meinhardt
8e0b091795 es2018: visit other binding elements when transforming object destructuring with rest (#35872)
* es2018: visit other binding elements when transforming object destructuring with rest

fixes: #35771

* more tests
2020-01-24 15:50:29 -08:00
Wesley Wigham
7c05e1a78c
Add --force option to npm install commands in dockerfiles (#36431) 2020-01-24 15:29:27 -08:00
Wesley Wigham
9ef9bb04f1
Fix crash on erroneous enum member merged with exported type alias (#36429) 2020-01-24 15:00:15 -08:00
Nathan Shively-Sanders
368db997ed
ESNext+[[Define]]: reference to param props illegal (#36425)
* ESNext+[[Define]]: reference to param props illegal

When target: "esnext" and useDefineForClassFields: true, property
declaration initialisers should not be able to reference parameter
properties; class fields are initialised before the constructor runs,
but parameter properties are not:

```ts
class C {
  foo = this.bar
  constructor(public bar: string) { }
}
```

emits code that looks like this:

```js
class C {
  bar
  foo = this.bar
  constructor(bar) {
    this.bar = bar
  }
}
new C('x').foo.length // crashes; foo is undefined
```

This PR adds an error on foo's declaration with ESNext+[[Define]].

* improve test
2020-01-24 14:53:28 -08:00
Nathan Shively-Sanders
43fc19c958
Emit statements before super (#36417)
* Emit statements before super

When statements come before super, Typescript's emit is incorrect,
whether there is an error or not. This change preserves statements that
come before super whether there is an error or not.

Here is the case with no errors:

```ts
class Test extends Array {
  p: number
  constructor() {
    console.log("p is initialised in the constructor below super()")
    super()
    this.p = 1
  }
}
```

Notice that `p` is manually initialised in the constructor after
`super()` instead of at the property declaration.

* Update baselines

Parameter properties in the error case now move below the super call.
This is an improvement because it means the code is more likely to execute
correctly.

* remove outdated comments
2020-01-24 14:52:48 -08:00
Sheetal Nandi
29895e8906
Handle header comments better by comparing its end line with first node line (#36413)
Fixes #31508
2020-01-24 11:20:41 -08:00
Andrii Dieiev
420b478c65 Add prefix/suffix only to binding element name (#33538) 2020-01-24 10:46:41 -08:00
Wesley Wigham
9e712dd097
Consider SymbolFlags.Method as function-esque during js declaration emit (#36274) 2020-01-24 10:29:23 -08:00
Klaus Meinhardt
49eb0d7a2b Disallow 'declare' modifier on private named properties (#36381)
Fixes: #36345
2020-01-23 13:18:10 -08:00