mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 12:03:44 -05:00
Change wording of scope description (#18342)
This commit is contained in:
@@ -3696,7 +3696,7 @@
|
||||
"code": 95003
|
||||
},
|
||||
|
||||
"Extract function into {0}": {
|
||||
"Extract to {0}": {
|
||||
"category": "Message",
|
||||
"code": 95004
|
||||
}
|
||||
|
||||
@@ -4829,16 +4829,29 @@ namespace ts {
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function isFunctionLikeKind(kind: SyntaxKind): boolean {
|
||||
export function isFunctionLikeDeclaration(node: Node): node is FunctionLikeDeclaration {
|
||||
return node && isFunctionLikeDeclarationKind(node.kind);
|
||||
}
|
||||
|
||||
function isFunctionLikeDeclarationKind(kind: SyntaxKind): boolean {
|
||||
switch (kind) {
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function isFunctionLikeKind(kind: SyntaxKind): boolean {
|
||||
switch (kind) {
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
@@ -4846,9 +4859,9 @@ namespace ts {
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
case SyntaxKind.ConstructorType:
|
||||
return true;
|
||||
default:
|
||||
return isFunctionLikeDeclarationKind(kind);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Classes
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace ts.refactor.extractMethod {
|
||||
// Don't issue refactorings with duplicated names.
|
||||
// Scopes come back in "innermost first" order, so extractions will
|
||||
// preferentially go into nearer scopes
|
||||
const description = formatStringFromArgs(Diagnostics.Extract_function_into_0.message, [extr.scopeDescription]);
|
||||
const description = formatStringFromArgs(Diagnostics.Extract_to_0.message, [extr.scopeDescription]);
|
||||
if (!usedNames.has(description)) {
|
||||
usedNames.set(description, true);
|
||||
actions.push({
|
||||
@@ -543,44 +543,45 @@ namespace ts.refactor.extractMethod {
|
||||
}
|
||||
}
|
||||
|
||||
function getDescriptionForScope(scope: Scope) {
|
||||
if (isFunctionLike(scope)) {
|
||||
switch (scope.kind) {
|
||||
case SyntaxKind.Constructor:
|
||||
return "constructor";
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return scope.name
|
||||
? `function expression ${scope.name.text}`
|
||||
: "anonymous function expression";
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
return `function '${scope.name.text}'`;
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return "arrow function";
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return `method '${scope.name.getText()}`;
|
||||
case SyntaxKind.GetAccessor:
|
||||
return `'get ${scope.name.getText()}'`;
|
||||
case SyntaxKind.SetAccessor:
|
||||
return `'set ${scope.name.getText()}'`;
|
||||
}
|
||||
}
|
||||
else if (isModuleBlock(scope)) {
|
||||
return `namespace '${scope.parent.name.getText()}'`;
|
||||
}
|
||||
else if (isClassLike(scope)) {
|
||||
return scope.kind === SyntaxKind.ClassDeclaration
|
||||
? `class '${scope.name.text}'`
|
||||
: scope.name && scope.name.text
|
||||
? `class expression '${scope.name.text}'`
|
||||
: "anonymous class expression";
|
||||
}
|
||||
else if (isSourceFile(scope)) {
|
||||
return scope.externalModuleIndicator ? "module scope" : "global scope";
|
||||
}
|
||||
else {
|
||||
return "unknown";
|
||||
function getDescriptionForScope(scope: Scope): string {
|
||||
return isFunctionLikeDeclaration(scope)
|
||||
? `inner function in ${getDescriptionForFunctionLikeDeclaration(scope)}`
|
||||
: isClassLike(scope)
|
||||
? `method in ${getDescriptionForClassLikeDeclaration(scope)}`
|
||||
: `function in ${getDescriptionForModuleLikeDeclaration(scope)}`;
|
||||
}
|
||||
function getDescriptionForFunctionLikeDeclaration(scope: FunctionLikeDeclaration): string {
|
||||
switch (scope.kind) {
|
||||
case SyntaxKind.Constructor:
|
||||
return "constructor";
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return scope.name
|
||||
? `function expression '${scope.name.text}'`
|
||||
: "anonymous function expression";
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
return `function '${scope.name.text}'`;
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return "arrow function";
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return `method '${scope.name.getText()}`;
|
||||
case SyntaxKind.GetAccessor:
|
||||
return `'get ${scope.name.getText()}'`;
|
||||
case SyntaxKind.SetAccessor:
|
||||
return `'set ${scope.name.getText()}'`;
|
||||
default:
|
||||
Debug.assertNever(scope);
|
||||
}
|
||||
}
|
||||
function getDescriptionForClassLikeDeclaration(scope: ClassLikeDeclaration): string {
|
||||
return scope.kind === SyntaxKind.ClassDeclaration
|
||||
? `class '${scope.name.text}'`
|
||||
: scope.name ? `class expression '${scope.name.text}'` : "anonymous class expression";
|
||||
}
|
||||
function getDescriptionForModuleLikeDeclaration(scope: SourceFile | ModuleBlock): string {
|
||||
return scope.kind === SyntaxKind.ModuleBlock
|
||||
? `namespace '${scope.parent.name.getText()}'`
|
||||
: scope.externalModuleIndicator ? "module scope" : "global scope";
|
||||
}
|
||||
|
||||
function getUniqueName(isNameOkay: (name: string) => boolean) {
|
||||
let functionNameText = "newFunction";
|
||||
|
||||
Reference in New Issue
Block a user