Commit graph

409 commits

Author SHA1 Message Date
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
Andrew Casey 2601bbcea7 Add simple tests for Extract Constant 2017-09-26 17:29:35 -07:00
Andrew Casey eb1fb5c164 Rename extractMethod.ts to extractSymbol.ts 2017-09-26 17:29:34 -07:00
Andrew Casey 3eea1a9e9a Generalize extract method to handle constants as well
Major changes:

1) Instead of skipping undesirable scopes, include them and mark them
with errors.  Constants can be extracted into more scopes.

2) Update the tests to call through the "public" API.  This caused some
baseline changes.

3) Rename refactoring to "Extract Symbol" for generality.

4) Return a second ApplicableRefactorInfo for constants.  Distinguish
the two by splitting the action name.
2017-09-26 17:29:34 -07:00
Nathan Shively-Sanders fc933d7c33 Transform jsdoc types in the refactor, not emitter
The emitter now understands JSDoc types but emits them in the original
format.
2017-09-26 12:42:08 -07:00
Nathan Shively-Sanders 96b8093890 Move filenames to match refactoring rename 2017-09-26 09:08:39 -07:00
Nathan Shively-Sanders 13b37a4825 Change refactoring name and description 2017-09-26 08:58:18 -07:00
Andy a4cf79baa5 Span length is not optional (#18558)
* Span length is not optional

* Fix calculation of length
2017-09-25 09:47:53 -07:00
Nathan Shively-Sanders 6d218e2a48 Refactor JSDoc types to Typescript types
When the caret is on a Typescript declaration that has no type, but does
have a JSDoc annotation with a type, this refactor will add the
Typescript equivalent of the JSDoc type.

Notes:

1. This doesn't delete the JSDoc comment or delete parts of it. In fact,
due to bugs in trivia handling, it sometimes duplicates the comment.
These bugs are tracked in #18626.

2. As a bonus, when `noImplicitAny: true`, this shows up as a code fix in VS Code
whenever there is a no-implicit-any error. With `noImplicityAny: false`,
this code must be invoked via the refactoring command.
2017-09-25 08:56:51 -07:00
Andy 25ad0b5581 Apply "array-type" lint rule (#18699) 2017-09-22 16:14:41 -07:00
Andrew Casey a1dee452fa JavaScript: handle lack of modifiers on extracted method
The emitter expects undefined, rather than empty.  This only affects JS,
because TS applies `private` to all extracted methods.

(cherry picked from commit 9630c46ea7)
2017-09-20 16:25:15 -07:00
Andrew Casey cb63ea5242 Merge pull request #18563 from amcasey/GH18546
Stop requiring that the full range of a declaration fall within the selection
2017-09-19 10:47:16 -07:00
Andy 951974dff6 Use find array helper (#18557)
* Use `find` array helper

* Provide explicit type argument to `find`
2017-09-19 08:27:31 -07:00
Andrew Casey af49c60a2c Stop requiring that the full range of a declaration fall within the
selection

Fixes #18546
2017-09-18 19:17:47 -07:00
Andrew Casey 74139186ed Re-enable extraction of single tokens
Now that we explicitly prevent extraction of empty spans.
2017-09-15 10:28:20 -07:00
Andy 6e512a495f extractMethod: Don't try to extract an ExpressionStatement consisting of a single token (#18450)
* extractMethod: Don't try to extract an ExpressionStatement consisting of a single token

* Move to unit test
2017-09-14 11:16:21 -07:00
Andrew Casey be5c00f4c9 Merge pull request #18427 from amcasey/GH17869
Forbid extraction of empty spans
2017-09-13 16:43:14 -07:00
Andrew Casey e2d94a2922 Only introduce return properties at the top level
...not in nested functions.
2017-09-13 13:36:25 -07:00
Andrew Casey 255951c270 Stop preventing extraction when a type parameter wouldn't bind
...correctly in a containing scope.  It's not an issue because we'll
just declare a corresponding type parameter on the extracted function
and pass the original as a type argument.

Fixes #18142
2017-09-13 13:35:05 -07:00
Andrew Casey 34576c2521 Call getShorthandAssignmentValueSymbol rather than getSymbolAtLocation
...for shorthand property assignment names when collecting usages.
2017-09-13 13:31:42 -07:00
Andy c3199c7772 extractMethod: Support renameLocation (#18050)
* extractMethod: Support renameLocation

* Add tslint disable

* Properly analyze list of changes to always get a correct rename location

* Update test

* Ensure name is really unique

* Improvements to test code

* Respond to PR comments
2017-09-13 09:02:10 -07:00
Andrew Casey a02aaf2625 Forbid extraction of empty spans 2017-09-12 18:17:15 -07:00
Andrew Casey 40e459117a Merge pull request #18343 from amcasey/InsertionPosition
Improve insertion position of extracted methods
2017-09-12 16:48:45 -07:00
Andy e51e91dd2c Change wording of scope description (#18342) 2017-09-09 05:52:52 -07:00
Andrew Casey e77425f984 Delete staticAssertNever in favor of assertTypeIsNever 2017-09-08 14:36:21 -07:00
Andrew Casey 26903552fe Improve insertion position of extracted methods
Old: End of target scope
New: Before the first non-constructor function following the extracted
range in the target scope
2017-09-08 14:19:28 -07:00
Andrew Casey baefdd2ccb Revert "Make permittedJumps a parameter to eliminate save-restore pattern"
This reverts commit 57906fe90e8efd2fb285fcb67f018c0438ba06dd.
2017-09-07 16:22:12 -07:00
Andrew Casey e3808b65d4 Simplify and correct PermittedJumps computation
1. It was looking at the parent which wasn't guaranteed to be in the
extracted range.
2. It was checking direct, rather than indirect containment - apparently
to avoid applying the rules to certain expressions (which can't contain
jumps anyway, unless they're in anonymous functions, in which case
they're fine).

Fixes #18144
2017-09-07 16:21:20 -07:00
Andrew Casey a81fa7a801 Make permittedJumps a parameter to eliminate save-restore pattern 2017-09-07 16:13:27 -07:00
Andrew Casey 9d11fbb9b9 Correct permitted jumps check 2017-09-07 16:13:26 -07:00
Andrew Casey 0e50da62c4 Handle the combination of a write and a void return
When the return type is void, there's no `returnValueProperty`, but that
doesn't mean we don't need a `return` at the call site.

Fixes #18140.
2017-09-07 14:43:02 -07:00
Andy ed4e2e6e3b Ensure that emitter calls callbacks (#18284)
* Ensure that emitter calls calbacks

* Move new parameter to end of parameters

* Fix for ConditionalExpression

* Make suggested changes to emitter

* Fix parameter ordering

* Respond to minor comments

* Remove potentially expensive assertion

* More emitter cleanup
2017-09-07 14:30:19 -07:00
Andy b533b24686 extractMethod: Don't try to extract a single token (#18090)
* extractMethod: Don't try to extract a single token

* Update tests
2017-09-07 07:28:12 -07:00
Andy 53b5abe5bb Update fromCodeFixContext (#18290) 2017-09-07 07:19:00 -07:00
Matt Bierner c7b4ed3a91 Fix extract method for anon class expressions (#18168)
Check `scope.name` when trying to extract from an anon class
2017-08-31 13:21:08 -07:00
Andrew Casey 19c3a150e7 Allow cancellation during extract method's symbol walking 2017-08-29 15:38:43 -07:00
Andrew Casey a816079dda Add perf comment 2017-08-29 11:24:07 -07:00
Andrew Casey 01d7f0b699 Test that the return type of the extracted method counts as usage 2017-08-29 11:24:05 -07:00
Andrew Casey 30802cda97 Handle loose type parameters in Extract Method
Known limitations:

1. If a type parameter on an inner symbol shadows a type parameter on an
outer symbol, the generated code will be incorrect.  We should either
rename one or more type parameters or forbid the extraction.

2. Type arguments are always passed explicitly, even if they would be
inferred correctly.
2017-08-29 11:10:16 -07:00
Andy e73b10a304 Use isPartOfExpression in extractMethod, not isExpression (#18047)
* Use isPartOfExpression in extractMethod, not isExpression

* Add whitespace
2017-08-25 15:15:16 -07:00
Andy fe1242c8a9 Don't try to extract import to a method (#18025) 2017-08-25 09:53:56 -07:00
Andy 3a0ab74ed6 Test for action description of code actions, and simplify description for extracting method to file (#18030)
* Test for action description of code actions, and simplify description for extracting method to file

* Add unit test file missing from tsconfig.json (only affects gulp) and update tests

* Use the actual number

* Use "module scope" or "global scope" instead of "this file"
2017-08-25 09:53:28 -07:00
Basarat Ali Syed ac098535cb export UsageEntry used by already exported functions 🌹 (#17853) 2017-08-21 16:55:40 -07:00
Andy babb88a0aa Remove duplicate function (#17807) 2017-08-17 06:52:15 -07:00
Basarat Ali Syed e7ddaa7d49 export ScopeUsages 🌹 2017-08-15 15:17:19 +10:00
Ryan Cavanaugh 24de14a9be Use isReadonlyArray 2017-08-10 16:40:08 -07:00
Ryan Cavanaugh db37cea0b6 Use the function stack! 2017-08-10 16:38:24 -07:00
Ryan Cavanaugh a04633c22c Style fixes 2017-08-10 16:35:32 -07:00
Ryan Cavanaugh f957429efd Style fixups 2017-08-10 16:23:17 -07:00
Ryan Cavanaugh 12403d9f70 Various fixes 2017-08-10 13:07:42 -07:00
Ryan Cavanaugh c7f665faa1 Extract Method (squash) 2017-08-04 16:10:33 -07:00
Andy 30d973bdcb Rename symbol.name to escapedName and make name unescaped (#17412) 2017-07-25 14:22:26 -07:00
Andy 2a219af308 convertFunctionToEs6Class: Bail if this is not a JavaScript file (#17149) 2017-07-17 12:56:16 -07:00
Wesley Wigham 4e6b2f3c93 Created a branded type for identifier-escaped strings (#16915)
* Created a branded type for escaped strings

Then flowed it throughout the compiler, finding and fixing a handful of
bugs relating to underscore-prefixed identifiers in the process.
Includes a test for two cases noticed - diagnostics from conflicting
symbols from export *'s, and enum with underscore prefixed member emit.

* Correctly double underscores WRT mapped types

* Add fourslash tests for other fixed issues

* use function call over cast

* Update forEachEntry type accuracy

* Just use escaped names for ActiveLabel

* Remove casts from getPropertyNameForPropertyNameNode

* This pattern has occurred a few times, could use a helper function.

* Remove duplicated helper

* Remove unneeded check, use helper

* Identifiers list is no longer escaped strings

* Extract repeated string-getting code into helper

* Rename type and associated functions

* Make getName() return UnderscoreEscapedString, add getUnescapedName()

* Add list of internal symbol names to escaped string type to cut back on casting

* Remove outdated comments

* Reassign interned values to nodes, just in case

* Swap to string enum

* Add deprecated aliases to escapeIdentifier and unescapeIdentifier

* Add temp var

* Remove unsafe casts

* Rename escaped string type as per @sandersn's suggestion, fix string enum usages

* Reorganize double underscore tests

* Remove jfreeman from TODO

* Remove unneeded parenthesis
2017-07-06 14:45:50 -07:00
Ryan Cavanaugh b52747e12c Add property comments as well 2017-06-26 10:54:18 -07:00
Ryan Cavanaugh 04d750f9f8 Preserve method comments in JS->ES6 conversion. Fixes #16622 2017-06-22 11:45:34 -07:00
Ryan Cavanaugh f739f68231 Tidy up 2017-06-06 16:08:24 -07:00
Ryan Cavanaugh 1f3ef7df7a Refactor refactor 2017-06-06 14:58:18 -07:00
Andy Hanson 694efba7d2 Fix use of getTokenAtPosition to use updated signature 2017-05-22 07:48:40 -07:00
Ryan Cavanaugh f6fbe61718 Refactoring support (squash) 2017-05-19 10:45:49 -07:00