mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
fix(29890): wrap variable/method/property to jsx expression
This commit is contained in:
@@ -915,6 +915,9 @@ namespace ts.refactor.extractSymbol {
|
||||
if (range.facts & RangeFacts.IsAsyncFunction) {
|
||||
call = factory.createAwaitExpression(call);
|
||||
}
|
||||
if (isInJSXContent(node)) {
|
||||
call = factory.createJsxExpression(/*dotDotDotToken*/ undefined, call);
|
||||
}
|
||||
|
||||
if (exposedVariableDeclarations.length && !writes) {
|
||||
// No need to mix declarations and writes.
|
||||
@@ -1118,12 +1121,16 @@ namespace ts.refactor.extractSymbol {
|
||||
variableType,
|
||||
initializer);
|
||||
|
||||
const localReference = factory.createPropertyAccessExpression(
|
||||
let localReference: Expression = factory.createPropertyAccessExpression(
|
||||
rangeFacts & RangeFacts.InStaticRegion
|
||||
? factory.createIdentifier(scope.name!.getText()) // TODO: GH#18217
|
||||
: factory.createThis(),
|
||||
factory.createIdentifier(localNameText));
|
||||
|
||||
if (isInJSXContent(node)) {
|
||||
localReference = factory.createJsxExpression(/*dotDotDotToken*/ undefined, localReference);
|
||||
}
|
||||
|
||||
// Declare
|
||||
const maxInsertionPos = node.pos;
|
||||
const nodeToInsertBefore = getNodeToInsertPropertyBefore(maxInsertionPos, scope);
|
||||
@@ -1194,12 +1201,6 @@ namespace ts.refactor.extractSymbol {
|
||||
const renameLocation = getRenameLocation(edits, renameFilename, localNameText, /*isDeclaredBeforeUse*/ true);
|
||||
return { renameFilename, renameLocation, edits };
|
||||
|
||||
function isInJSXContent(node: Node) {
|
||||
if (!isJsxElement(node)) return false;
|
||||
if (isJsxElement(node.parent)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function transformFunctionInitializerAndType(variableType: TypeNode | undefined, initializer: Expression): { variableType: TypeNode | undefined, initializer: Expression } {
|
||||
// If no contextual type exists there is nothing to transfer to the function signature
|
||||
if (variableType === undefined) return { variableType, initializer };
|
||||
@@ -1953,4 +1954,8 @@ namespace ts.refactor.extractSymbol {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isInJSXContent(node: Node) {
|
||||
return (isJsxElement(node) || isJsxSelfClosingElement(node) || isJsxFragment(node)) && isJsxElement(node.parent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user