Merge pull request #21835 from amcasey/GH21786

Handle variable declaration without initializer in Convert to ES6 Module
This commit is contained in:
Andrew Casey 2018-02-09 18:21:50 -08:00 committed by GitHub
commit 22c4862d9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View file

@ -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 {

View file

@ -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");