335 Commits

Author SHA1 Message Date
Andy
b3edc8f9f4
Apply 'no-unnecessary-type-assertion' lint rule (#22005)
* Apply 'no-unnecessary-type-assertion' lint rule

* Fix type error

* Fix tsconfig.json

* Add --format back
2018-02-16 18:38:00 -08:00
Andy
458c12fa78
importFixes: Fix bug by using replaceNode and removing changeIdentifierToPropertyAccess (#21898) 2018-02-12 13:05:40 -08:00
Mohamed Hegazy
3fb481ff40
Multiple telemetry debug assert failure fixes (#21886)
* Use getAllowSyntheticDefaultImports to access `--allowSyntheticDefaultImport` value

* Fix #21788: Handel missing imporotClause case

* Fix #21789: Add a defensive check to forgottenThisPropertyAccess code fix for non-identifier locations

* Do not suggest prefix with `this` if the name we are looking for is diffrent from the errorLocation

* Fix #21796: Handel case of unknown module

* Add check to capture more info for #21800

* Fix #21807: check for symbol before looking up its flags

* Fix #21812: Gracefully fail if the token is not `this`.
2018-02-12 10:34:17 -08:00
Andrew Casey
ab5596e785 Call replaceNode rather than replaceRange
...where convenient.  Same for deleteNode/Range.
2018-02-09 17:51:28 -08:00
Mohamed Hegazy
4150a463e2
Fix #20805 (#21755)
* Add `-dev` to version patch number in master

* Refactor to handel non-identifier tokens for UMD modules

* Be more graceful handeling non-identifier tokens in import fixes

* Fix bad merge

* Remove check for isIdentifier
2018-02-08 10:32:08 -08:00
Andy
c4362ac4ba
Simplify use of FindAllReferences in inferFromUsage (#20551) 2018-02-07 13:25:36 -08:00
Andy
786bacfa3b
Fix bug: support non-Identifier previousToken in importFixes (#21650)
* Fix bug: support non-Identifier previousToken in importFixes

* Remove intersection type
2018-02-07 12:33:16 -08:00
Andy
57a50f4b9d
fixInvalidImportSyntax: Preserve comment (#21684) 2018-02-06 10:19:14 -08:00
Andy
d6f52c3477
importFixes: Bundle module specifiers with import kinds, and replace ImportCodeActionMap with existing functionality (#20700) 2018-02-06 08:57:32 -08:00
Andrew Casey
3020f3d2e6 Handle trivia in code fix forgotten-this
Fixes #21433
2018-01-30 13:25:39 -08:00
Andy
cae4bc5e83
Move createTextChange to services/utilities.ts (#21416)
* Move createTextChange to services/utilities.ts

* Use separate functions instead of overloads
2018-01-25 17:48:22 -08:00
Andy
7c4e755eff
When applying // @ts-ignore fix as a group, apply to a line only once. (#21413)
* When applying `// @ts-ignore` fix as a group, apply to a line only once.

* Rename line to lineNumber
2018-01-25 13:53:08 -08:00
Andy
d333d889c1
Test for (and fix) order of import fixes (#21398) 2018-01-24 15:06:52 -08:00
Andy
d46653a2ac
Handle undefined input to firstDefined (#21300) 2018-01-19 10:10:43 -08:00
Andrew Casey
ebbb3a4dc4
Merge pull request #21158 from amcasey/NewlineConsistency
Handle linebreaks consistently in code fixes and refactorings
2018-01-18 16:02:27 -08:00
Andrew Casey
d97dec8574 Fold newline logic into getNewLineOrDefaultFromHost 2018-01-18 13:56:12 -08:00
Andrew Casey
50fd476233 Make SymbolContext a subtype of TextChangesContext 2018-01-17 16:16:22 -08:00
Andrew Casey
3a38c8ea58 Replace TextChangesContext with RefactorOrCodeFixContext
Thanks to @andy-ms for the suggestion!
2018-01-17 15:43:36 -08:00
Andrew Casey
b4a382bdd2 Stop explicitly storing newline in refactoring/code fix contexts
It's already in the EditorSettings and the LanguageServiceHost.

Fixes #18291
Fixes #18445
2018-01-17 15:14:03 -08:00
Andrew Casey
9a83077d78 Add explanatory comment 2018-01-17 15:12:39 -08:00
Andrew Casey
5de6ac1a2f Simplify test cases 2018-01-17 15:06:54 -08:00
Andrew Casey
e354754b2a Special case arrow functions with only parameter unused
Fixes GH #18274
2018-01-17 15:06:53 -08:00
Wesley Wigham
76d9524866
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter

* Unification of writers is done-ish

* Make node builder support more flags

* Write out mixins like we used to

* Accept prototype-free baselines

* Use instantiated constraint when building mapped type nodes

* Accept better mapped type baselines

* Report inaccessible this in node builder

* Turns out there was a bug in our codefix, too

* Symbol display builder usage falling

* Replace signatureToString with a nodeBuilder solution

* Replace the last internal usages of the symbol writer

* Accept semicolon additions

* Accept updated symbol baseline output

* Start using node builder for some LS operations

* Remove those pesky trailing semicolons on signatures

* Get signature printing much closer to old output

* Parameter lists should not be indented by default, especially when single-line

* Signatures up to snuff

* Type quickinfo emit is up to snuff

* Start of symbol writer replacement, needs a bit more for full compat

* Slightly mor accurate to old behavior

* Replicate qualified name type argument output correctly

* Bring back the old symbol baselines

* Mostly identical to old symbol emit now

* Perfectly matches old behavior thus far

* Replace another usage of the symbol builder

* Another usage removed

* Another usage removed

* Remove final uses of symbol display builder

* Remove implementation and types for unused symbol display builder

* Cleanup in the checker

* monomorphize new emitter code

* Replace emitWithSuffix

* Push space character to interface with writer

* List emit

* Fix lack of usage of emitExpression

* writeList, not printList

* Remove listy writes and replace with new printer calls

* Move ListFormat into types.ts

* Remove most new XToString functions in favor of node builder functions

* Accept API breaks

* Add getSymbolDisplayBuilder polyfill

* Accept updated API baseline

* Move definition to make diff easier to read

* Reinternalize some things

* Remove trailign whitespace

* Reorder for zero diff

* Remove newline

* Make shim mor eperfectly imitate old behavior

* Style feedback

* Rename reset to clear to maintain backcompat with SymbolWriter

* Fix quickfix

* Keep EmitTextWriter internal

* Remove EmitTextWriter from public API

* Mimic default name declaration emit fix

* Fix tests broken by merge

* use isFunctionLike

* Cleanup, sync TypeFormat and NodeBuilder flags

* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism

* Use variable instead of ternary

* Write helper for emitNodeWithWriter

* Emitter cleanup

* Cleanup whitespace, comment

* Reuse printer

* Raise error if display parts writer uses rawWrite

* Hide writer parameter through different function instead of overload, rename function in emitter

* Make less printer

* fix lint
2018-01-16 09:53:42 -08:00
Sharon Rolel
c0bdd12c4c add fixAwaitInSyncFunction code fix (#21069)
* add fixAwaitInSyncFunction code fix

* Just insert the keyword

* only one codefix

* remove comment

* Change explicit return type T to Promise<T>

* Review changes

* Change codefix message
2018-01-09 17:15:08 -08:00
Andy
8bce69e6bd
Add refactoring to convert CommonJS module to ES6 module (#19916)
* Add refactoring to convert CommonJS module to ES6 module

* Code review

* includeGlobals -> excludeGlobals

* Improve handling of `module.exports = require("...")`

* Allow NoSubstitutionTemplateLiteral as argument to createLiteral
2018-01-09 13:15:47 -08:00
Andy
82fb294924
For import fix, support path mapping value that begins in "./" or ends in ".ts" (#21035)
* For import fix, support path mapping value that begins in "./" or ends in ".ts"

* Handle repeated "./" in path

* Rename parameters to indicate that they're relative to baseUrl

* Support relative path beginning with `..\`

* Remove unused function
2018-01-09 10:34:35 -08:00
Andrew Casey
ef5a289966
Merge pull request #21014 from amcasey/GH19115
Handle different default export forms the same way in import code fixes
2018-01-08 19:07:43 -08:00
Wesley Wigham
7e6315075d
Synthesize namespace records for proper esm interop (#19675)
* Integrate importStar and importDefault helpers

* Accept baselines

* Support dynamic imports, write helpers for umd module (and amd is possible) kinds

* Accept baselines

* Support AMD, use same helper initialization as is normal

* update typechecker to have errors on called imported namespaces and good error recovery with a quickfix

* Overhaul allowSyntheticDefaultExports to be safer

* Put the new behavior behind a flag

* Rename strictESM to ESMInterop

* ESMInterop -> ESModuleInterop, make default for tsc --init

* Rename ESMInterop -> ESModuleInterop in module.ts, add emit test (since fourslash doesnt do that)

* Remove erroneous semicolons from helper

* Reword diagnostic

* Change style

* Edit followup diagnostic

* Add secondary quickfix for call sites, tests forthcoming

* Add synth default to namespace import type, enhance quickfix

* Pair of spare tests for good measure

* Fix typos in diagnostic message

* Improve comment clarity

* Actually accept the updated changes to the esmodule interop description

* ESModule -> esModule

* Use find and not forEach

* Use guard

* Rely on implicit falsiness of Result.False

* These should have been emit flags
2018-01-08 16:36:23 -08:00
Andy
6f2ba15446
Start linting for double spaces (#20820)
* Start linting for double spaces

* Code review

* Fix cases that were excluded by countDoubleSpaces

* Remove extraneous closing parenthesis
2018-01-08 08:52:13 -08:00
Andrew Casey
1957dfef8e
Merge pull request #20991 from amcasey/GH18794
Refine extends-to-implements code fix
2018-01-05 17:52:22 -08:00
Andrew Casey
18f9d693fe Stop limiting getEscapedNameForExportDefault to the first declaration 2018-01-05 16:29:53 -08:00
Andrew Casey
47aad0b8fd Switch to block-bodied lambda 2018-01-05 16:12:12 -08:00
Andrew Casey
ded788e560 Slightly simplify getCodeActions 2018-01-05 14:54:59 -08:00
Andrew Casey
8f5a76d48b Make fixCannotFindModule return an empty array if there is no code action 2018-01-05 14:24:40 -08:00
Andrew Casey
a961d7aa04 Only replace implements with a comma if the heritage clauses are sensible 2018-01-04 18:05:58 -08:00
Andrew Casey
afae97ce6e Refine extends-to-implements code fix
1. Retain surrounding trivia when swapping the keyword.
 2. Insert commas at the full-starts, rather than starts, of existing
 keywords when merging with existing implements clauses.

Fixes #18794
2018-01-04 17:55:12 -08:00
Andrew Casey
1e93967ec4 Add regression tests 2018-01-04 15:34:19 -08:00
Andrew Casey
ff58f1f2f9 Handle different default export forms the same way in import code fixes
`export default C` and `export { C as default }` should be handled the
same as `export default class C { }`.

Fixes #19115
2018-01-04 15:34:19 -08:00
Wenlu Wang
2ea5f58d60 quick fix of indexed access type (#20956) 2018-01-04 12:45:16 -08:00
Andy
74b8160430
In import fixes, use a ".js" extension if other imports do (#20624)
* In import fixes, use a ".js" extension if other imports do

* Code review
2018-01-03 08:20:53 -08:00
Andy
813864f021
For import completion, use an existing namespace import (#20457) 2017-12-21 11:16:09 -08:00
Daniel Rosenwasser
69e091b40d
Merge pull request #19797 from charlespierce/implements_class_error_message
Add new error message when class implements class
2017-12-19 11:39:05 -08:00
Andrew Casey
adc3234e46 Don't insert a blank line after extracted locals at the start of the file 2017-12-15 15:49:27 -08:00
Ryan Cavanaugh
f6603cd9f2
Merge pull request #20545 from RyanCavanaugh/codefixOmnibus
Omnibus fixes for telemetry-sourced crashes
2017-12-13 12:49:58 -08:00
Andy
8ad4aeece1
Make ChangeTracker#newLineCharacter public, to avoid having to pass newLineCharacter around as a parameter (#20574)
* Make ChangeTracker#newLineCharacter public, to avoid having to pass newLineCharacter around as a parameter

* Don't require newLineCharacter as input to ChangeTracker methods, and make it private again
2017-12-12 12:23:13 -08:00
Andy
21ff2cd501
Remove unnecessary getFirstChildOfKind helper function (#20647) 2017-12-12 11:25:58 -08:00
Charles Pierce
c489dd96f6 Resolve merge conflicts in codeFix 2017-12-11 22:27:56 -08:00
Wesley Wigham
eba15b5990
Preserve literal types in contextual unions (#19966)
* Cherrypick non-comparability related changes from prolific literals PR

* Renames and other style changes

* Accept changes to new tests

* Exclude the domain root from contextual typing literals except for type variables

* Readd simple preservation fix

* Add huge map test

* Revert changes to widening on destructuring initalizers

* Use tristate for subtype-reduction type

* Rename type and argument

* Move longer-running test to user suite
2017-12-11 18:03:38 -05:00
Ryan Cavanaugh
92c3b23a32 Bail at the correct point when containingFunction is undefined 2017-12-07 14:27:46 -08:00
Ryan Cavanaugh
b7b43fe601 Fixes #20527 2017-12-07 12:39:16 -08:00