@@ -23,6 +23,7 @@ import {
23
23
isNumericLiteral ,
24
24
isObjectLiteralExpression ,
25
25
isPropertyAccessExpression ,
26
+ isShorthandPropertyAssignment ,
26
27
isTypeQueryNode ,
27
28
isVariableDeclarationInVariableStatement ,
28
29
isVariableStatement ,
@@ -102,7 +103,6 @@ registerRefactor(refactorName, {
102
103
103
104
getEditsForAction ( context , actionName ) {
104
105
Debug . assert ( actionName === refactorName , "Unexpected refactor invoked" ) ;
105
-
106
106
const { file, program, startPosition } = context ;
107
107
108
108
// tryWithReferenceToken is true below since here we're already performing the refactor.
@@ -152,7 +152,7 @@ function getInliningInfo(file: SourceFile, startPosition: number, tryWithReferen
152
152
}
153
153
154
154
// Try finding the declaration and nodes to replace via the reference token.
155
- if ( tryWithReferenceToken ) {
155
+ if ( tryWithReferenceToken || isShorthandPropertyAssignment ( parent ) ) {
156
156
let definition = checker . resolveName ( token . text , token , SymbolFlags . Value , /*excludeGlobals*/ false ) ;
157
157
definition = definition && checker . getMergedSymbol ( definition ) ;
158
158
@@ -191,7 +191,7 @@ function getReferenceNodes(declaration: InitializedVariableDeclaration, checker:
191
191
const cannotInline = FindAllReferences . Core . eachSymbolReferenceInFile ( declaration . name as Identifier , checker , file , ref => {
192
192
// Only inline if all references are reads. Else we might end up with an invalid scenario like:
193
193
// const y = x++ + 1 -> const y = 2++ + 1
194
- if ( FindAllReferences . isWriteAccessForReference ( ref ) ) {
194
+ if ( FindAllReferences . isWriteAccessForReference ( ref ) && ! isShorthandPropertyAssignment ( ref . parent ) ) {
195
195
return true ;
196
196
}
197
197
@@ -216,7 +216,7 @@ function getReferenceNodes(declaration: InitializedVariableDeclaration, checker:
216
216
return references . length === 0 || cannotInline ? undefined : references ;
217
217
}
218
218
219
- function getReplacementExpression ( reference : Node , replacement : Expression ) : Expression {
219
+ function getReplacementExpression ( reference : Node , replacement : Expression ) {
220
220
// Make sure each reference site gets its own copy of the replacement node.
221
221
replacement = getSynthesizedDeepClone ( replacement ) ;
222
222
const { parent } = reference ;
@@ -244,5 +244,9 @@ function getReplacementExpression(reference: Node, replacement: Expression): Exp
244
244
return factory . createParenthesizedExpression ( replacement ) ;
245
245
}
246
246
247
+ if ( isIdentifier ( reference ) && isShorthandPropertyAssignment ( parent ) ) {
248
+ return factory . createPropertyAssignment ( reference , replacement ) ;
249
+ }
250
+
247
251
return replacement ;
248
252
}
0 commit comments