In convertFunctionToEs6Class.ts, share code for getting symbol (#19160)
This commit is contained in:
parent
8d47ef60a9
commit
bac30fc1a2
|
@ -17,16 +17,16 @@ namespace ts.refactor.convertFunctionToES6Class {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const start = context.startPosition;
|
||||
const node = getTokenAtPosition(context.file, start, /*includeJsDocComment*/ false);
|
||||
const checker = context.program.getTypeChecker();
|
||||
let symbol = checker.getSymbolAtLocation(node);
|
||||
let symbol = getConstructorSymbol(context);
|
||||
if (!symbol) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (symbol && isDeclarationOfFunctionOrClassExpression(symbol)) {
|
||||
if (isDeclarationOfFunctionOrClassExpression(symbol)) {
|
||||
symbol = (symbol.valueDeclaration as VariableDeclaration).initializer.symbol;
|
||||
}
|
||||
|
||||
if (symbol && (symbol.flags & SymbolFlags.Function) && symbol.members && (symbol.members.size > 0)) {
|
||||
if ((symbol.flags & SymbolFlags.Function) && symbol.members && (symbol.members.size > 0)) {
|
||||
return [
|
||||
{
|
||||
name: convertFunctionToES6Class.name,
|
||||
|
@ -48,11 +48,8 @@ namespace ts.refactor.convertFunctionToES6Class {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const start = context.startPosition;
|
||||
const sourceFile = context.file;
|
||||
const checker = context.program.getTypeChecker();
|
||||
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
|
||||
const ctorSymbol = checker.getSymbolAtLocation(token);
|
||||
const { file: sourceFile } = context;
|
||||
const ctorSymbol = getConstructorSymbol(context);
|
||||
const newLine = context.rulesProvider.getFormatOptions().newLineCharacter;
|
||||
|
||||
const deletedNodes: Node[] = [];
|
||||
|
@ -269,4 +266,10 @@ namespace ts.refactor.convertFunctionToES6Class {
|
|||
return filter(source.modifiers, modifier => modifier.kind === kind);
|
||||
}
|
||||
}
|
||||
|
||||
function getConstructorSymbol({ startPosition, file, program }: RefactorContext): Symbol {
|
||||
const checker = program.getTypeChecker();
|
||||
const token = getTokenAtPosition(file, startPosition, /*includeJsDocComment*/ false);
|
||||
return checker.getSymbolAtLocation(token);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue