GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Initial implementation of Extract Constant by amcasey · Pull Request #18783 · microsoft/TypeScript Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @@ -1,823 +0,0 @@ | |||
| /// <reference path="..\harness.ts" /> | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This wasn't detected as a rename because large chunks of it were pulled out into extractRanges.ts and extractSymbolTestHelpers.ts.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// <reference path="extractTestHelpers.ts" /> | ||
|
|
||
| namespace ts { | ||
| describe("extractConstants", () => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
extractConstants [](start = 14, length = 16)
This test coverage isn't great because I didn't want to revise everything as soon as I updated the insertion locations.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| `, | ||
| [ | ||
| "Cannot extract range containing conditional break or continue statements." |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can we symbolically refer to these strings?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Possibly. This was all copied from the old extractMethods.ts.
In reply to: 141221847 [](ancestors = 141221847)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const extractMethod: Refactor = { | ||
| name: "Extract Method", | ||
| description: Diagnostics.Extract_function.message, | ||
| namespace ts.refactor.extractSymbol { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
extractSymbol [](start = 22, length = 13)
Ryan Cavanaugh (@RyanCavanaugh), the interesting changes are here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| a() { | ||
| let z = 1; | ||
| return this./*RENAME*/newFunction(); | ||
| return this./*RENAME*/newMethod(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
newMethod [](start = 34, length = 9)
Slightly non-trivial baseline update
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| refactorName: "Extract Method", | ||
| actionName: "scope_0", | ||
| refactorName: "Extract Symbol", | ||
| actionName: "function_scope_1", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
1 [](start = 32, length = 1)
0 is now the method itself. We won't insert a function there, but we will insert a local.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const visibleDeclarationsInExtractedRange: Symbol[] = []; | ||
|
|
||
| const expressionDiagnostics = | ||
| isReadonlyArray(targetRange.range) && !(targetRange.range.length === 1 && isExpressionStatement(targetRange.range[0])) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please use "extract local" on this expression
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
On which expression? targetRange.range?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Everything to the left of the ?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That breaks control flow type checking.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| isFunctionLikeDeclaration(scope) && scope.kind !== SyntaxKind.FunctionDeclaration | ||
| ? [createDiagnosticForNode(scope, Messages.CannotExtractToOtherFunctionLike)] | ||
| : []); | ||
| constantErrorsPerScope.push(expressionDiagnostics); |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The re-use of the same array object going into multiple positions in constantErrorsPerScope makes me nervous since this is currently mutable - let's change both to ReadonlyArray<Diagnostic>[]
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Reading further down the function, I'm now confused
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
.slice()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| break; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would assert prevChild !== undefined here since it's not obvious by construction that this is impossible
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sure, but it follows from the fact that extraction position is in a child that begins before the extraction position (i.e. there will be at least one iteration and that iteration won't kick out based on the position).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Confirm that the constraint is preserved. | ||
| testExtractMethod("extractMethod15", | ||
| `function F<T>(t1: T) { | ||
| function G<U extends T[]>(t2: U) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Was it a test correctness thing to change F to G here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We de-dup actions by description and I wanted to see all of them.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Testcase we were looking at /*! * MIT APACHE */ "use strict"; "use module"; namespace Y { } namespace X { namespace Y { export const j = 10; namespace Z { export const y = j * j; } } } as well as and |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I can repro the assert in a unit test. This looks relevant: https://github.com/Microsoft/TypeScript/pull/18484/files#diff-20a9fa4d3e9d09f60c275a3dda245867 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ryan Cavanaugh (@RyanCavanaugh) The problem we were seeing (in our case, an assert about token spans) will occur any time a substitution is applied more than once. Since the same issue affects Extract Function, I'm going to handle it in a separate PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ryan Cavanaugh (@RyanCavanaugh) I believe all outstanding issues can be addressed in subsequent PRs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Many fixes to follow. 😄 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.