mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
Merge pull request #18423 from amcasey/GH18188
Call getShorthandAssignmentValueSymbol rather than getSymbolAtLocation
This commit is contained in:
commit
aade97111a
@ -709,6 +709,25 @@ function M3() { }`);
|
||||
}
|
||||
M3() { }
|
||||
constructor() { }
|
||||
}`);
|
||||
// Shorthand property names
|
||||
testExtractMethod("extractMethod29",
|
||||
`interface UnaryExpression {
|
||||
kind: "Unary";
|
||||
operator: string;
|
||||
operand: any;
|
||||
}
|
||||
|
||||
function parseUnaryExpression(operator: string): UnaryExpression {
|
||||
[#|return {
|
||||
kind: "Unary",
|
||||
operator,
|
||||
operand: parsePrimaryExpression(),
|
||||
};|]
|
||||
}
|
||||
|
||||
function parsePrimaryExpression(): any {
|
||||
throw "Not implemented";
|
||||
}`);
|
||||
});
|
||||
|
||||
|
||||
@ -1161,7 +1161,11 @@ namespace ts.refactor.extractMethod {
|
||||
}
|
||||
|
||||
function recordUsagebySymbol(identifier: Identifier, usage: Usage, isTypeName: boolean) {
|
||||
const symbol = checker.getSymbolAtLocation(identifier);
|
||||
// If the identifier is both a property name and its value, we're only interested in its value
|
||||
// (since the name is a declaration and will be included in the extracted range).
|
||||
const symbol = identifier.parent && isShorthandPropertyAssignment(identifier.parent) && identifier.parent.name === identifier
|
||||
? checker.getShorthandAssignmentValueSymbol(identifier.parent)
|
||||
: checker.getSymbolAtLocation(identifier);
|
||||
if (!symbol) {
|
||||
// cannot find symbol - do nothing
|
||||
return undefined;
|
||||
|
||||
62
tests/baselines/reference/extractMethod/extractMethod29.ts
Normal file
62
tests/baselines/reference/extractMethod/extractMethod29.ts
Normal file
@ -0,0 +1,62 @@
|
||||
// ==ORIGINAL==
|
||||
interface UnaryExpression {
|
||||
kind: "Unary";
|
||||
operator: string;
|
||||
operand: any;
|
||||
}
|
||||
|
||||
function parseUnaryExpression(operator: string): UnaryExpression {
|
||||
return {
|
||||
kind: "Unary",
|
||||
operator,
|
||||
operand: parsePrimaryExpression(),
|
||||
};
|
||||
}
|
||||
|
||||
function parsePrimaryExpression(): any {
|
||||
throw "Not implemented";
|
||||
}
|
||||
// ==SCOPE::inner function in function 'parseUnaryExpression'==
|
||||
interface UnaryExpression {
|
||||
kind: "Unary";
|
||||
operator: string;
|
||||
operand: any;
|
||||
}
|
||||
|
||||
function parseUnaryExpression(operator: string): UnaryExpression {
|
||||
return /*RENAME*/newFunction();
|
||||
|
||||
function newFunction() {
|
||||
return {
|
||||
kind: "Unary",
|
||||
operator,
|
||||
operand: parsePrimaryExpression(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function parsePrimaryExpression(): any {
|
||||
throw "Not implemented";
|
||||
}
|
||||
// ==SCOPE::function in global scope==
|
||||
interface UnaryExpression {
|
||||
kind: "Unary";
|
||||
operator: string;
|
||||
operand: any;
|
||||
}
|
||||
|
||||
function parseUnaryExpression(operator: string): UnaryExpression {
|
||||
return /*RENAME*/newFunction(operator);
|
||||
}
|
||||
|
||||
function newFunction(operator: string) {
|
||||
return {
|
||||
kind: "Unary",
|
||||
operator,
|
||||
operand: parsePrimaryExpression(),
|
||||
};
|
||||
}
|
||||
|
||||
function parsePrimaryExpression(): any {
|
||||
throw "Not implemented";
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user