Commit graph

409 commits

Author SHA1 Message Date
BigAru 5ec1201e3a exclude nested functions and classes at containingThis check 2019-01-23 19:36:00 +01:00
BigAru dbd58599f4 do not provide refactoring when it contains this
because this behaves differently in arrow than in function
2019-01-22 05:42:01 +01:00
BigAru 52e94d2b80 Merge remote-tracking branch 'upstream/master' into m-lambda-to-fn 2019-01-22 05:10:32 +01:00
Gabriela Britto 919ed79f3a implement new parameter creation 2019-01-18 16:49:11 -08:00
Andrew Casey 3e256e14dc Add fourslash tests 2019-01-16 19:18:25 -08:00
Andrew Casey 7102de77d3 Consider JSX namespace imports when moving statements between files
Each of the old and new files should end up with a JSX namespace import
iff it contains JSX.

Fixes #27939
2019-01-16 18:55:27 -08:00
Gabriela Britto 705ac60a59 WIP 2019-01-16 15:49:09 -08:00
Gabriela Britto 9aeeae54b0 create refactoring for converting to named parameters 2019-01-15 16:56:53 -08:00
Wesley Wigham 4f7184a587
Fix all new lint failures (#29080) 2018-12-18 11:34:02 -08:00
Andy Hanson 643678bb54 generateGetAccessorAndSetAccessor: Don't use FindAllReferences 2018-11-14 15:05:46 -08:00
Sheetal Nandi d569743640
Merge pull request #28194 from iliashkolyar/add_missing_apostrophe_in_codefix
Add missing apostrophe to codefix suggestion
2018-11-12 09:31:24 -08:00
Andy e335a360c8
Change 'if' in combined switch case to two separate cases (#28444) 2018-11-09 12:48:47 -08:00
BigAru dfb86acbb9 check if functionExpression name is used 2018-11-08 05:51:53 +01:00
BigAru 9a466f4e9c update getAvailableActions 2018-11-07 13:57:50 +01:00
BigAru 5dfc71c14a Merge remote-tracking branch 'upstream/master' into m-lambda-to-fn 2018-11-07 13:47:26 +01:00
BigAru dc81a7f668 apply feedback from pr 2018-11-07 10:49:59 +01:00
BigAru 739e1e9786 fix for unnecessary duplication of comment 2018-11-07 08:49:50 +01:00
Andy afbf89e3b3
Refactors can return ReadonlyArray<ApplicableRefactorInfo> (#28305)
* Refactors can return ReadonlyArray<ApplicableRefactorInfo>

* Remove unnecessary type assertions
2018-11-02 10:07:21 -07:00
Giovanni Heilmann 8bc7f43665 Make conditions more expressive 2018-10-31 14:27:36 +01:00
BigAru d97e07360c apply feedback from pr 2018-10-31 14:27:36 +01:00
BigAru 595131868f add testcase and apply feedback from pr 2018-10-31 14:27:36 +01:00
BigAru 649b53c8de apply feedback from pr 2018-10-31 14:27:36 +01:00
BigAru 3e7dcad726 make guideline compliant 2018-10-31 14:27:36 +01:00
BigAru 6bd26cd2e5 extract creation of funcDeclaration 2018-10-31 14:27:36 +01:00
BigAru a9cb623795 extract creation of block 2018-10-31 14:27:36 +01:00
BigAru 39c3928e5d refactor small progress 2018-10-31 14:27:36 +01:00
BigAru 6922f6c4ca refactor getInfo getAvailableActions 2018-10-31 14:27:36 +01:00
BigAru 7c78cd5c6f fix for tslint error 2018-10-31 14:27:36 +01:00
BigAru 62b9fccb98 fix bug modifiers by toNamed 2018-10-31 14:27:36 +01:00
BigAru e697856a7d change refactor name 2018-10-31 14:27:36 +01:00
BigAru 367f47e755 fix multi decl bug 2018-10-31 14:27:36 +01:00
BigAru 4c80de9078 add multi vardecl 2018-10-31 14:27:36 +01:00
BigAru f558f2f6cd add working getEditsForAction 2018-10-31 14:27:36 +01:00
BigAru 6cfbee7f30 add getAvailableActions 2018-10-31 14:27:36 +01:00
BigAru 8cb019d793 add skeleton 2018-10-31 14:27:36 +01:00
iliashkolyar 583dbc571e Add missing apostrophe to codefix suggestion 2018-10-28 23:18:19 +02:00
Andy d3d4f83f89
Remove hack to get target of GetAccessor symbol (#27868)
* Remove hack to get target of GetAccessor symbol

* Add tests and get moveToNewFile to work with binding patterns
2018-10-22 11:44:06 -07:00
Andy 0a97663843
Add 'prefixText' and 'suffixText' when renaming shorthand properties (#27356)
* Add 'prefixText' and 'suffixText' when renaming shorthand properties

* Make prefixText and suffixText missing instead of undefined

* Fix test
2018-09-26 16:58:01 -07:00
Nathan Shively-Sanders 6bd1da20c9
Rename JS-specific concepts (#26795)
* Rename JS concepts

1. Assignment declaration -- an assignment that is treated like a
declaration. Previously called [JS] special (assignment|declaration),
among other things.
2. Expando -- a value that can be used as a target in assignment
declarations. Currently, a class, function or empty object literal.
Functions are allowed in Typescript, too. Previously called a JS
container, JS initializer or expando object.
3. JavaScript -> Javascript. This is annoying to type, and looks like
'Java Script' in a camelCase world.

Everything is a pure rename as far as I know. The only test change is
the API baselines, which reflect the rename from SymbolFlags.JSContainer
to SymbolFlags.Assignment.

* Remove TODO

* Rename Javascript->JS

Note that this introduces a variable name collision in a couple of
places, which I resolved like this:

```ts
const isInJavascript = isInJSFile(node);
```
2018-09-12 10:44:46 -07:00
Andy 1a05f13aef
moveToNewFile: Don't remove empty named imports (#26265) 2018-08-07 12:54:46 -07:00
Andy d40d54984e
Support deleting all unused type parameters in a list, and deleting @template tag (#25748)
* Support deleting all unused type parameters in a list, and deleting @template tag

* Support type parameter in 'infer'
2018-07-27 11:55:31 -07:00
Andy 5f4a03c408
Ensure TypeChecker#getTypeAtLocation returns a defined result (#25583)
* Ensure TypeChecker#getTypeAtLocation returns a defined result

* Update additional baseline
2018-07-11 16:33:56 -07:00
Andy ded446573a
ChangeTracker: Combine deleteDeclaration, deleteNode, and deleteNodeInList (#25276)
* ChangeTracker: Combine deleteDeclaration, deleteNode, and deleteNodeInList

* Change name

* Update API (#24966)
2018-06-29 19:53:32 -07:00
Andy 13bc46d970
getTokenAtPosition: default includeJsDocComment to true (#25015)
* getTokenAtPosition: default includeJsDocComment to true

* Update API (#24966)

* Flip meaning of parameter

* Update API (#24966)

* Remove all `ignoreJsDocComment` uses (fixes #25162)
2018-06-26 16:20:44 -07:00
Andy 0b5b7ef547
Fix removal of default import (#25200) 2018-06-25 12:41:32 -07:00
Andy 806a661be3
Add refactor to convert named to default export and back (#24878)
* Add refactor to convert named to default export and back

* Support ambient module

* Handle declaration kinds that can't be default-exported

* Update API (#24966)
2018-06-25 10:34:24 -07:00
Andy 7f553f4f93
refactorConvertToGetAccessAndSetAccess: Don't trigger on leading trivia (#25054)
* refactorConvertToGetAccessAndSetAccess: Don't trigger on leading trivia

* Update API (#24966)
2018-06-19 13:46:03 -07:00
Andy 4a7a550502
moveToNewFile: Reuse code from importFixes for inserting import (#24957)
* moveToNewFile: Reuse code from importFixes for inserting import

* Fix test failures

* Update API baselines (#24966)
2018-06-14 15:41:47 -07:00
kingwl 0d730c008a Merge branch 'master' into add-braces 2018-06-09 01:32:53 +08:00
Andy 0fefaf286d
moveToNewFile: Infer quote preference (#24652) 2018-06-07 12:10:48 -07:00
Andy d8cea359f7
moveToNewFile: Update namespace imports (#24612) 2018-06-04 11:30:14 -07:00
Andy 046c5ea6c1
moveToNewFile: Ignore reference to global (#24651) 2018-06-04 10:35:23 -07:00
Andy 2cb46407b1
moveToNewFile: Remove newlines after last moved statement (#24503) 2018-05-30 15:16:03 -07:00
Andy 43bf039a94
Add refactor to convert namespace to named imports and back (#24469)
* Add refactor to convert namespace to named imports and back

* Add tests and comments

* Code review

* Handle shorthand property assignment and re-export

* Don't use forEachFreeIdentifier

* Fix rename after "."
2018-05-30 14:11:53 -07:00
王文璐 590476bf06 add more test and fix others 2018-05-25 10:25:52 +08:00
Andy bc570cd85f
moveToNewFile: Respect UserPreferences#quote (#24365) 2018-05-24 09:36:37 -07:00
王文璐 d470f32d8a Merge branch 'master' into add-braces 2018-05-24 18:03:02 +08:00
Wenlu Wang 4606709672 add code fix convert to mapped object type (#24286)
* add code fix convert to mapped object type

* add support for type literal and improve test

* fix typo

* add support for heritageClauses

* only determine declaration is not class
2018-05-23 14:09:49 -07:00
王文璐 de75f14d2b fix void return statement 2018-05-23 10:49:57 +08:00
王文璐 1a59eb3949 update body only 2018-05-23 10:22:17 +08:00
王文璐 0c06126d60 fix converter 2018-05-23 10:22:17 +08:00
王文璐 bd9a8b5c0c stash 2018-05-23 10:20:03 +08:00
王文璐 32be0c7099 add tests and fix 2018-05-23 10:19:08 +08:00
王文璐 5a69d9c255 add support for add or remove braces to arrow function 2018-05-23 10:16:59 +08:00
Andy ba63f49513
moveToNewFile: Don't provide refactor if selection is just imports (#24336) 2018-05-22 15:21:04 -07:00
Andy e53e56cf82
Enable '--strictNullChecks' (#22088)
* Enable '--strictNullChecks'

* Fix API baselines

* Make sys.getEnvironmentVariable non-nullable

* make properties optional instead of using `| undefined` in thier type

* reportDiagnostics should be required

* Declare firstAccessor as non-nullable

* Make `some` a type guard

* Fix `getEnvironmentVariable` definition in tests

* Pretend transformFlags are always defined

* Fix one more use of sys.getEnvironmentVariable

* `requiredResponse` accepts undefined, remove assertions

* Mark optional properties as optional instead of using `| undefined`

* Mark optional properties as optional instead of using ` | undefined`

* Remove unnecessary null assertions

* Put the bang on the declaration instead of every use

* Make `createMapFromTemplate` require a parameter

* Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional

* Plumb through undefined in emitLsit and EmitExpressionList

* `ElementAccessExpression.argumentExpression` can not be `undefined`

* Add overloads for `writeTokenText`

* Make `shouldWriteSeparatingLineTerminator` argument non-nullable

* Make `synthesizedNodeStartsOnNewLine` argument required

* `PropertyAssignment.initializer` cannot be undefined

* Use one `!` at declaration site instead of on every use site

* Capture host in a constant and avoid null assertions

* Remove few more unused assertions

* Update baselines

* Use parameter defaults

* Update baselines

* Fix lint

* Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions

* Make Node#symbol and Type#symbol non-optional to reduce assertions

* Make `flags` non-nullable to reduce assertions

* Convert some asserts to type guards

* Make `isNonLocalAlias` a type guard

* Add overload for `getSymbolOfNode` for `Declaration`

* Some more `getSymbolOfNode` changes

* Push undefined suppression into `typeToTypeNodeHelper`

* `NodeBuilderContext.tracker` is never `undefined`

* use `Debug.assertDefined`

* Remove unnecessary tag

* Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 14:46:57 -07:00
Andy 5622bc2dd6
moveToNewFile: Support selecting the name of a declaration (#24331) 2018-05-22 14:00:29 -07:00
Andy c09cc70ebe
Fix bug: VariableDeclaration initializer may be undefined (#24256) 2018-05-21 07:58:33 -07:00
Andy 76573c6520
getEffectiveTypeParameterDeclarations: Always return a defined result (#24251) 2018-05-18 10:17:35 -07:00
Mohamed Hegazy 8c2ed976a5
Merge pull request #24187 from Kingwl/disallow-in-function-like-initializer
disallow acesssor generate in function like initializer
2018-05-17 19:41:01 -07:00
王文璐 45c06cfd11 only allow refactor if selected span overlaps name declaration 2018-05-18 10:07:45 +08:00
Andy d579793d0a
moveToNewFile: Fix bug for missing importClause (#24224) 2018-05-17 14:32:12 -07:00
Andy 09b9ec43e3
moveToNewFile: Fix bug for VariableDeclaration missing initializer (#24214) 2018-05-17 12:38:20 -07:00
Andy 176e35b9c3
moveToNewFile: Don't move imports (#24177) 2018-05-17 09:54:47 -07:00
Nathan Shively-Sanders aa7e2b0f07
Add callback tag, with type parameters (#23947)
* Add initial tests

* Add types

* Half of parsing (builds but does not pass tests)

* Parsing done; types are uglier; doesn't crash but doesn't pass

* Bind callback tag

Builds but tests still don't pass

* Only bind param tags inside callback tags

* Fix binding switch to only handle param tags once

* Checking is 1/3 done or so.

Now I'm going to go rename some members to be more uniform. I hate
unnnecessary conditionals.

* Rename typeExpression to type (for some jsdoc)

(maybe I'll rename more later)

* Rename the rest of typeExpressions

Turns out there is a constraint in services such that they all need to
be named the same.

* Few more checker changes

* Revert "Rename the rest of typeExpressions"

This reverts commit f41a96b24d.

* Revert "Rename typeExpression to type (for some jsdoc)"

This reverts commit 7d2233a00e.

* Finish undoing typeExpression rename

* Rename and improve getTypeParametersForAliasSymbol

Plus some other small fixes

* Core checking works, but is flabbergastingly messy

I'm serious.

* Callback return types work now

* Fix crash in services

* Make github diff smaller

* Try to make github diff even smaller

* Fix rename for callback tag

* Fix nav bar for callback tag

Also clean up some now-redundant code there to find the name of typedefs.

* Handle ooorder callback tags

Also get rid of redundant typedef name code *in the binder*. It's
everywhere!

* Add ooorder callback tag test

* Parse comments for typedef/callback+display param comments

* Always export callbacks

This requires almost no new code since it is basically the same as
typedefs

* Update baselines

* Fix support for nested namespaced callbacks

And add test

* Callbacks support type parameters

1. Haven't run it with all tests
2. Haven't tested typedef tags yet
3. Still allows shared symbols when on function or class declarations.

* Template tags are now bound correctly

* Test oorder template tags

It works.

* Parser cleanup

* Cleanup types and utilities

As much as possible, and not as much as I would like.

* Handle callback more often in services

* Cleanup of binder and checker

* More checker cleanup

* Remove TODOs and one more cleanup

* Support parameter-less callback tags

* Remove extra bind call on template type parameters

* Bind template tag containers

Doesn't quite work with typedefs, but that's because it's now stricter,
without the typedef fixes. I'm going to merge with jsdoc/callback and
see how it goes.

* Fix fourslash failures

* Stop pre-binding js type aliases

Next up, stop pre-binding js type parameters

* Further cleanup of delayed js type alias binding

* Stop prebinding template tags too

This gets rid of prebinding entirely

* Remove TODO

* Fix lint

* Finish merge with use-jsdoc-aliases

* Update callback tag baselines

* Rename getTypeParametersForAliasSymbol

The real fix is *probably* to rename Type.aliasTypeArguments to
aliasTypeParameters, but I want to make sure and then put it in a
separate PR.
2018-05-17 09:28:11 -07:00
王文璐 755b443b6d disallow acesssor generate in function like initializer 2018-05-17 10:18:20 +08:00
Mohamed Hegazy 13ac88647f
Merge pull request #24162 from Kingwl/fix-generate-accessor-starting-underscore
fix generate accessor if starting with underscore
2018-05-16 12:06:15 -07:00
王文璐 b7f725d1b8 fix generate accessor if starting with underscore 2018-05-16 15:34:11 +08:00
王文璐 0fde07f1c5 fix trailing comma in accessor generator 2018-05-16 14:47:44 +08:00
Andy 7271ec1240
Add 'move to new file' refactor (#23726)
* Add 'move to new file' refactor

* Code review, and support commonjs

* Compute movedSymbols completely before using, and support `export import`

* Fix assertion error: sort empty change before non-empty change

* Remove extra newline

* Add allowTextChangesInNewFiles preference

* Add the new file to 'files' in tsconfig

* Avoid parameter initializer

* Update API baselines

* Use path relative to tsconfig.json

* Code review

* Fix error where node in tsconfig file was missing a source file
2018-05-10 11:17:04 -07:00
kingwl 44d10dcf59 fix incorrect find reference pos 2018-05-11 01:49:40 +08:00
王文璐 340e8cd56a find reference at begin of constructor 2018-05-10 11:20:07 +08:00
王文璐 8414a962ba update all reference in constructor 2018-05-09 18:41:46 +08:00
王文璐 88bf9277ff add support for readonly modifier 2018-05-08 12:26:34 +08:00
Andy a05feed839
generateGetAccessorAndSetAccessor: Preserve a parameter property declaration (#23318) 2018-05-07 11:33:00 -07:00
Andy cae464058a
Delete "delete me" files (#23446) 2018-04-16 15:29:02 -07:00
Andy cc6bc763bc
Simplify getConvertibleFieldAtPosition (#23315) 2018-04-16 09:30:10 -07:00
Ryan Cavanaugh ff60520460 Merge branch 'master' into referencesDogfood_1 2018-04-12 12:26:10 -07:00
Andy 05c746b547
generateGetAccessorAndSetAccessor: Share modifier-creating code (#23311) 2018-04-12 11:13:25 -07:00
Ryan Cavanaugh df95de3231 Merge branch 'master' into referencesDogfood_1 2018-04-11 16:17:38 -07:00
Ryan Cavanaugh 9a5a5b10a3 Remove all reference comments from services 2018-04-11 15:39:12 -07:00
Andy fef28665f7
generateGetAccessorAndSetAccessor: Fix typos and use type predicate (#23310) 2018-04-11 13:21:47 -07:00
Wenlu Wang 9c0671d661 add refactor of convert private field to getter and setter (#22143)
* add refactor of convert private field to getter and setter

* fix refactor

* stash

* refactor accessor generate

* revert merge union type

* refeactor and accept baseline

* add support of PropertyAssignment and StringLiteral

* add support for js file

* allow static modifier in js file
2018-04-10 11:51:41 -07:00
Andy 1e227c6d77
Add type predicate helper functions to Type (#23066) 2018-04-04 08:10:09 -07:00
Andy ea6740fa91
replaceNode: Always use non-adjusted end (#22519)
* replaceNode: Always use non-adjusted end

* Never adjust start position either

* Fix excess property checks, remove unnecessary arguments

* Make 'insertText' and 'newLineCharacter' private

* Use replaceNode in one more place now that it doesn't affect comments

* Update replaceNodeRange too

* Always ask for ChangeNodeOptions
2018-03-27 10:34:16 -07:00
Andy e5f91f5948
Convert annotateWithTypeFromJSDoc refactor to a codefix (#22336)
* Convert annotateWithTypeFromJSDoc refactor to a codefix

* Compute isJsFile once at top
2018-03-06 07:49:21 -08:00
Josh Goldberg 7826b38426 Apply 'no-unnecessary-initializer' lint rule (#22014)
* Apply 'no-unnecessary-initializer' lint rule

Forbids `let`/`const` statements to be initialized to `undefined`, since that's the initial value by default anyway.
The auto-fixer also happened to remove two unnecessary `as number` casts in `src/harness/parallel/worker.ts`.

For historical data: to run with `--fix`, I modified the line in `Jakefile.js` that declared the `cmd` for running TSLint.

* Moved worker.ts type assertions to parameters
2018-03-06 07:30:40 -08:00
Andy 2ac2291b84
Convert use-default-import refactor to a codefix (#22334) 2018-03-05 12:43:01 -08:00
Andy 87c3cca3f0
Make convertFunctionToEs6Class a codefix (#22241)
* Make convertFunctionToEs6Class a codefix

* Change diagnostic message
2018-03-02 12:57:29 -08:00
Andy 16fc256823
Convert 'installTypesForPackge' refactor to a suggestion (#22267)
* Convert 'installTypesForPackge' refactor to a suggestion

* Have checker collect a list of suggestion diagnostics instead of redoing work in calculateSuggestionDiagnostics

* Add comment

* Add diagnostic even with `--allowJs`
2018-03-01 14:41:55 -08:00
Andy a564912d9a
Apply 'no-unnecessary-qualifier' lint rule (#22009) 2018-03-01 14:20:18 -08:00
Andy fa4619c5c1
Add 'info' diagnostics (#22204)
* Add 'info' diagnostics

* Code review
2018-02-28 11:16:32 -08:00
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
Andrew Casey ddf206b184
Merge pull request #21845 from amcasey/GH21793
Harden Extract Symbol against symbols without declarations
2018-02-12 10:40:31 -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 e65a1a429c Harden Extract Symbol against symbols without declarations
Fixes #21793
2018-02-09 19:42:34 -08:00
Andrew Casey 025418fdb0 Handle class declarations without names in Extract Symbol
Fixes #21816
2018-02-09 19:09:25 -08:00
Andrew Casey 22c4862d9e
Merge pull request #21835 from amcasey/GH21786
Handle variable declaration without initializer in Convert to ES6 Module
2018-02-09 18:21:50 -08:00
Andrew Casey 1baae42149 Handle variable declaration without initializer in Convert to ES6 Module
Fixes #21786
2018-02-09 18:08:47 -08:00
Andrew Casey ab5596e785 Call replaceNode rather than replaceRange
...where convenient.  Same for deleteNode/Range.
2018-02-09 17:51:28 -08:00
Andy 425a4182a3
Handle empty declaration list in Convert to ES6 Module (#21843)
* Handle empty declaration list in Convert to ES6 Module

* Fix test
2018-02-09 14:46:57 -08:00
Andrew Casey 6dd88b39d5
Merge pull request #21781 from amcasey/TextChangesReplace
Tidy up textChanges.replace*
2018-02-09 10:35:20 -08:00
Andrew Casey f77cefee88 Introduce *WithNodes paralleling textChanges.Replace*
1) Take options
2) Return `this`
3) Use adjusted positions
2018-02-08 15:52:12 -08:00
Andy 05510a8612
Don't use export function for a function whose name differs from its exported name (#21739)
* Don't use `export function` for a function whose name differs from its exported name

* Fix lint
2018-02-08 09:53:53 -08:00
Andrew Casey 9bc0d33512 Move bug URLs into assert messages 2018-01-26 11:12:34 -08:00
Andrew Casey 8ec36e988d Add asserts upstream from #20809 2018-01-26 10:52:25 -08:00
Andrew Casey 08aa2653dd Remove incorrect assert 2018-01-24 12:46:26 -08:00
Andrew Casey 2f3b06a3cd Handle extraction ranges including case clause expressions
(mostly by rejecting them)

Fixes #20559
2018-01-23 11:09:27 -08:00
Andrew Casey 4f11dd68ab Handle extracting case clause expression as constant 2018-01-23 11:08:45 -08:00
Andy a6c42a63a1
Remove unused properties from interface Refactor (#21286) 2018-01-18 16:39:33 -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
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
Andrew Casey 9efab94dfd Annotate fewer extracted constants with types
Expose `isContextSensitive` from the checker and omit type annotations
for expressions for which it returns false.
2017-12-15 15:11:17 -08:00
Andrew Casey e9ac87c2d6 Don't insert a blank line after extracted locals
Still insert a blank line after extracted properties.
2017-12-15 15:11:16 -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 b629ff4204
Fix bug: FunctionDeclaration may have missing name (#20618) 2017-12-11 09:45:20 -08:00
Andy 56a046ddf4
installTypesForPackage refactor: Trigger even if resolved to a ".js" file (#20353)
* installTypesForPackage refactor: Trigger even if resolved to a ".js" file

* Use `extensionIsTypeScript`
2017-11-30 08:41:15 -08:00
Andy e7adb1ce79
Bundle fileName with CodeActionCommand (#19881)
* Bundle fileName with CodeActionCommand

* Update test

* Fix API tests

* Add new overloads in services

* Fix overload

* Update API baselines
2017-11-17 14:16:38 -08:00
Andy 5ad7e9516b
Remove unnecessary wrapper classes in ts.formatting.Rule (#19744)
* Remove unnecessary wrapper classes in ts.formatting.Rule

* RulesProvider -> immutable FormatContext

* Remove Rules class, just use a list of rules

* Remove Shared namespace, replace Shared.TokenRange with TokenRange

* Simplify TokenRange

* Separate Rule and RuleSpec

* Move FormattingRequestKind to formattingContext.ts

* Simplify references

* Fix lint

* Revert removal of trailing newlines
2017-11-08 13:39:03 -08:00
Ron Buckton 3f248ecfe1
Merge pull request #19452 from Microsoft/compareStrings
Clean up outdated string comparison logic
2017-11-06 18:48:15 -08:00
Andy 0a7b7e07ee
Apply 'variable-name' tslint rule (#19743) 2017-11-06 09:23:47 -08:00
Ron Buckton 31c3d444f1 Merge branch 'master' into compareStrings 2017-11-03 23:01:51 -07:00
Andy d54ad4b01a
Add refactoring to use default import (#19659)
* Add refactoring to use default import

* Add localizable description
2017-11-03 08:31:13 -07:00
Andy cc2a2a79b5
Use NodeFlags to detect nodes in ambient contexts instead of climbing ancestors (#17831)
* Use NodeFlags to detect nodes in ambient contexts instead of climbing ancestors

* Set context flags on tokens

* Remove 'isDeclarationFile' parameter to 'initializeState' and move to 'parseSourceFileWorker'

* Changes based on code review

* Update API baselines
2017-11-03 08:08:48 -07:00
Andy f4236ec5c8
Rename "isPartOfExpression" (#18469) 2017-10-31 08:05:39 -07:00
Andrew Casey a89c055a48
Merge pull request #19578 from amcasey/GH19395
Don't pass synthesized node to typeToTypeNode
2017-10-30 16:35:20 -07:00
Mohamed Hegazy 6c71ca84e7
Add utility function to check for strict option flags (#19427)
* Add utility function to check for strict option flags
- Correctelly check for noImplicitAny in checker
- Correctelly check for noImplicitAny in installTypesForPackage refactor

* Respond to code review comments

* Accept baselines

* Revert "Accept baselines"

This reverts commit cf4ef62830.

* Move type alias to core
2017-10-30 13:05:54 -07:00
Andrew Casey aa59a69e14 Correct typo - pass correct argument
All of the other calls in extractSymbol are already correct.
2017-10-30 11:21:22 -07:00
Ron Buckton 24437774a8 Further simplification 2017-10-26 11:56:29 -07:00
Ron Buckton dfa1ffe650 Cleanup and reordering 2017-10-25 18:00:59 -07:00
Ron Buckton c0ed26e605 Simplify comparers 2017-10-25 17:46:39 -07:00
Ron Buckton 130c407708 More control over which collator to use in each situation 2017-10-25 16:30:19 -07:00
Andrew Casey e4d5d1c16d Extract refineNode into its own function 2017-10-24 11:33:30 -07:00
Andrew Casey 1b6e991924 Demote some extraction ranges to produce better results
Attempt to extract return expressions, rather than return statements, and
initializers, rather than variable declarations.
2017-10-24 11:13:49 -07:00
Mohamed Hegazy e0d76d1dca Check for --strict along with --noImplicitAny for code fix 2017-10-20 14:39:58 -07:00
Andy a53d3bb5aa Remove some unnecessary undefined checks in extractSymbol (#19256) 2017-10-19 08:15:01 -07:00
Nathan Shively-Sanders f82dd7b1da Move isJSDocIndexSignature to utilities 2017-10-18 13:16:22 -07:00
Nathan Shively-Sanders aa73ed8226 Fix bugs in jsdoc annotation refactor
1. Transform index signatures to TS index signatures.
2. Print object literals on a single line.
3. Only offer the refactor when it could add types. (There must not be a
type annotation already, and there must be a JSDoc that applies.)
2017-10-18 13:07:54 -07:00
Nathan Shively-Sanders 64fc495234 Collapse jsdoc annotation refactors to one
Previously there were two, and two always fired.
2017-10-17 16:33:52 -07:00
Andy d05443bb1d Add quickfix and refactoring to install @types packages (#19130)
* Add quickfix and refactoring to install @types packages

* Move `validatePackageName` to `jsTyping.ts`

* Remove combinePaths overloads

* Respond to code review

* Update api baselines

* Use native PromiseConstructor

* Return false instead of undefined

* Remove getProjectRootPath

* Update api
2017-10-17 15:04:09 -07:00
Andy bac30fc1a2 In convertFunctionToEs6Class.ts, share code for getting symbol (#19160) 2017-10-16 11:41:35 -07:00
Nathan Shively-Sanders 22769d95e1 Merge pull request #18747 from Microsoft/refactor-jsdoc-types-to-typescript
Refactor jsdoc types to typescript
2017-10-13 10:21:54 -07:00
Nathan Shively-Sanders 4cf06bbb02 Fix spacing lint 2017-10-13 10:02:04 -07:00
Nathan Shively-Sanders 84e3507151 return more Debug.fails instead of undefined. 2017-10-13 09:45:41 -07:00
Nathan Shively-Sanders c83daa6481 JSDoc->type refactor:Renames+improve never handling 2017-10-13 09:38:01 -07:00
Nathan Shively-Sanders f35764d4ec Fix duplicated JSDoc comments
Incorporate suppressLeadingAndTrailingTrivia just added by @amcasey.
2017-10-12 14:28:34 -07:00
Andrew Casey 2ea4cfe23b Insert a line break before a function at EOF if needed
This is a pre-existing issue that became more obvious after refining
trivia handling.
2017-10-12 14:19:36 -07:00
Nathan Shively-Sanders c2c18a8d06 Merge branch 'master' into refactor-jsdoc-types-to-typescript 2017-10-12 14:18:28 -07:00
Nathan Shively-Sanders 123347d5c4 Convert @template tag to type parameters in refactor 2017-10-12 11:40:07 -07:00
Andrew Casey 4de6b0dd2d Introduce and consume suppressLeadingAndTrailingTrivia
Fixes #18626
2017-10-12 11:34:34 -07:00
Mohamed Hegazy 260d37e8ea Merge branch 'master' into refactor-jsdoc-types-to-typescript 2017-10-12 10:23:21 -07:00
Andrew Casey 73826bdb7b Allow Extract Constant into enclosing scope in spite of RangeFacts.UsesThis 2017-10-12 09:32:05 -07:00
Andrew Casey 568c8a3298 Allow extraction of variable decls used outside the extracted range
If there are only declarations, use the new function as the initializer
for a destructuring declaration.

If there are declarations and writes, changes all of the `const`
declarations to `let` and add `| undefined` onto any explicit types.
Use destructuring assignment to accomplish both "initialization" and
writes.

I don't believe there is a case where there are both declarations and a
return (since the declarations wouldn't be available after the return).

UNDONE: this could probably be generalized to handle binding patterns
but,
for now, only identifiers are supported.

Fixes #18242
Fixes #18855
2017-10-11 16:38:38 -07:00
Andrew Casey bada0095ed Merge pull request #18979 from amcasey/DeepClone
Introduce getSynthesizedDeepClone
2017-10-11 16:36:25 -07:00
Wesley Wigham 9f4130b204 Fix incorrect cast target (#19093)
Found while updating #18285 to latest master. Not sure what this fixes, but it was definitely incorrect - `node` must be a `Block` at this point, so this cast must have been intended for `node.parent`, which was checked against `TryStatement` right before it.
2017-10-11 14:52:23 -07:00
Nathan Shively-Sanders d7424b00b2 Merge branch 'master' into refactor-jsdoc-types-to-typescript 2017-10-11 13:41:45 -07:00
Nathan Shively-Sanders 4930cad653 Convert all JSDoc parameters and return types of functions 2017-10-11 13:33:31 -07:00
Charles Pierce 576bd8c25f Ensure Async Modifier is maintained through ES6 Class Conversion (#19092) 2017-10-11 09:04:51 -07:00
Sheetal Nandi a7fa187fb2 Merge pull request #19058 from Microsoft/whenWatchesFail
Swallow the directory watcher exceptions and ignore them
2017-10-10 18:32:22 -07:00
Sheetal Nandi e30a66d22f Add utitlity for stringContains 2017-10-10 17:16:39 -07:00
Charles Pierce 249c2cbaf7 Maintain Export Modifier when Refactoring to ES6 Class #18435 (#19070) 2017-10-10 15:39:59 -07:00
Andrew Casey ad148dbc88 Use deep cloning, rather than thunking for repeated substitution
Replaces b244cd4fb4
2017-10-05 15:46:14 -07:00
Andrew Casey 530e107d51 Merge pull request #18936 from amcasey/GH18899
Localize more Extract Function/Constant strings
2017-10-04 13:33:06 -07:00
Andrew Casey 02f2a29ca2 Stop combining already-translated strings 2017-10-04 12:39:32 -07:00
Andrew Casey bcdfdd276f Call getLocaleSpecificMessage 2017-10-03 18:10:58 -07:00
Andrew Casey 559689f66f Localize more Extract Function/Constant strings
Fixes #18899
2017-10-03 17:18:12 -07:00
Andrew Casey 443812a045 Stop extracting void and never constants 2017-10-03 15:07:39 -07:00
Andrew Casey d1015bff06 Merge pull request #18926 from amcasey/ExtractConstantArrow
Disallow constant extraction into expression-bodied arrow functions
2017-10-03 14:29:01 -07:00
Andrew Casey 2cb965c268 Disallow constant extraction into expression-bodied arrow functions
...until https://github.com/Microsoft/TypeScript/issues/18924 is fixed.
2017-10-03 13:34:20 -07:00
Andrew Casey b9fb1733ef Merge pull request #18919 from amcasey/ExtractLocalRefinements
Improve Extract Constant's handling of expression statements
2017-10-03 13:19:39 -07:00
Andrew Casey 7b1147fbce Stop inadvertently exempting expression statements from check 2017-10-03 12:23:32 -07:00
Andrew Casey 2a4ab08655 Refine extraction of expression statements
1) Replace range, rather than node, to leave trivia intact.
2) Only replace node in the innermost scope - otherwise insert as usual
and delete the original statement.
2017-10-03 11:18:40 -07:00
Andy b111493276 Remove unnecessary *OrUndefined calls (#18889)
* Remove unnecessary *OrUndefined calls

* Add 'first'
2017-10-03 10:24:39 -07:00
Andrew Casey b21d8a4742 Merge pull request #18900 from amcasey/ReduceDup
Refactor to reduce property duplication
2017-10-03 10:04:03 -07:00
Andrew Casey 3b4cbebee0 Handle repeated substitution of the same symbol during extraction
Old: Insert the same Node for every occurrence.  The position was
repeatedly mutated during printing.
New: Thunk the Node so that a new one is constructed for every
occurrence.

Fixes #18857
2017-10-02 16:51:13 -07:00
Andrew Casey e1380a866e Refactor to reduce property duplication 2017-10-02 16:41:40 -07:00
Andrew Casey 2df7058af7 Merge pull request #18861 from amcasey/ConstantInsertionPosition
Improve insertion positions of extracted constants
2017-10-02 16:39:32 -07:00
Nathan Shively-Sanders 6831e65235 Merge branch 'master' into refactor-jsdoc-types-to-typescript 2017-10-02 16:24:00 -07:00
Andrew Casey 724f71cae1 Describe the innermost scope as "enclosing scope" for constants
Using the same description as for functions was confusing because the
extracted constant was inserted below the top-level of that scope.
2017-10-02 15:57:36 -07:00
Andrew Casey ba5f09b66d Localize 'in' in extraction description 2017-10-02 15:30:52 -07:00
Andrew Casey bcc93f2c08 Loosen restriction on usages in innermost scope
Now that we're smarter about where we declare the extracted local, we
can ignore usage problems in the innermost script - it'll always have
access to the same symbols as the extracted expression.
2017-09-29 18:00:27 -07:00
Andrew Casey c08308a0f1 Reuse getSourceFileImportLocation 2017-09-29 17:37:39 -07:00
Andrew Casey 9097a07758 Improve insertion positions of extracted constants
...mostly by putting them closer to the extraction site.

They now also follow all leading comments in a file (unfortunately,
including the doc comment on the first declaration).

Bonus: Special case declaration lists - declare the new variable as part
of the list, rather than before it, in case it depends on an earlier
entry.
2017-09-29 15:52:56 -07:00
Andrew Casey 41676248e5 Eliminate special case for extracting from a binary operator chain
1) It assumed left-associativity and was, therefore, wrong for (e.g.)
exponentiation.
2) Arguably, if a user selects `a + |b + c|`, they want to extract `b +
c`, not `a + b + c`.  Not being able to do so is surprising (and we may
eventually want to allow it), but so is having the rest of the
least-common subtree extracted.

Fixes #18268
2017-09-28 14:54:52 -07:00
Nathan Shively-Sanders d797b4ab76 Correctly transform jsdoc parameter types
And give a better name for rest params
2017-09-28 11:40:56 -07:00
Nathan Shively-Sanders 724a813105 Merge branch 'master' into refactor-jsdoc-types-to-typescript 2017-09-28 09:17:28 -07:00
Andrew Casey 386e76543a TODOs for repeated substitution 2017-09-27 18:08:35 -07:00
Andrew Casey e6bfce193c Add additional TODO about insertion positions 2017-09-27 10:40:12 -07:00
Andrew Casey 13e60bc497 Use resources, rather than string literals, in test baselines 2017-09-27 10:35:13 -07:00
Andrew Casey cb6037b563 Forbid extraction of constants to class scopes in JS 2017-09-27 10:30:02 -07:00