Skip to content

Commit e375792

Browse files
committed
wip
1 parent 26d33a0 commit e375792

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

typescript/src/codeActions/custom/splitDeclarationAndInitialization.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ export default {
2424
const { factory } = ts
2525
const nodeStart = node.pos + node.getLeadingTriviaWidth()
2626
const varName = declaration.name.text
27-
changesTracker.insertNodeAt(
28-
sourceFile,
29-
nodeStart,
30-
factory.createVariableDeclarationList(
31-
[factory.createVariableDeclaration(factory.createIdentifier(varName), undefined, typeNode)],
32-
ts.NodeFlags.Let,
33-
),
34-
)
27+
const isJs = !!(node.flags & ts.NodeFlags.JavaScriptFile)
28+
const variableDeclaration = factory.createVariableDeclaration(factory.createIdentifier(varName), undefined, isJs ? undefined : typeNode)
29+
changesTracker.insertNodeAt(sourceFile, nodeStart, factory.createVariableDeclarationList([variableDeclaration], ts.NodeFlags.Let))
30+
if (isJs && typeNode) {
31+
const typeTag = factory.createJSDocTypeTag(/*tagName*/ undefined, factory.createJSDocTypeExpression(typeNode), /*comment*/ undefined)
32+
changesTracker.addJSDocTags(sourceFile, node, [typeTag as any])
33+
}
3534
changesTracker.replaceNode(
3635
sourceFile,
3736
node,

0 commit comments

Comments
 (0)