Merge pull request #21835 from amcasey/GH21786
Handle variable declaration without initializer in Convert to ES6 Module
This commit is contained in:
commit
22c4862d9e
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/////*a*/const/*b*/ alias;
|
||||
////require("x");
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Convert to ES6 module");
|
||||
|
Loading…
Reference in a new issue