mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 16:34:36 -05:00
Handle variable declaration without initializer in Convert to ES6 Module
Fixes #21786
This commit is contained in:
@@ -33,14 +33,17 @@ namespace ts.refactor {
|
||||
return isExportsOrModuleExportsOrAlias(sourceFile, node as PropertyAccessExpression)
|
||||
|| isExportsOrModuleExportsOrAlias(sourceFile, (node as PropertyAccessExpression).expression);
|
||||
case SyntaxKind.VariableDeclarationList:
|
||||
const decl = firstOrUndefined((node as VariableDeclarationList).declarations);
|
||||
return !!decl && isExportsOrModuleExportsOrAlias(sourceFile, decl.initializer);
|
||||
return isVariableDeclarationTriggerLocation(firstOrUndefined((node as VariableDeclarationList).declarations));
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return isExportsOrModuleExportsOrAlias(sourceFile, (node as VariableDeclaration).initializer);
|
||||
return isVariableDeclarationTriggerLocation(node as VariableDeclaration);
|
||||
default:
|
||||
return isExpression(node) && isExportsOrModuleExportsOrAlias(sourceFile, node)
|
||||
|| !onSecondTry && isAtTriggerLocation(sourceFile, node.parent, /*onSecondTry*/ true);
|
||||
}
|
||||
|
||||
function isVariableDeclarationTriggerLocation(decl: VariableDeclaration | undefined) {
|
||||
return !!decl && !!decl.initializer && isExportsOrModuleExportsOrAlias(sourceFile, decl.initializer);
|
||||
}
|
||||
}
|
||||
|
||||
function isAtTopLevelRequire(call: CallExpression): boolean {
|
||||
|
||||
Reference in New Issue
Block a user