diff --git a/src/services/refactors/convertToEs6Module.ts b/src/services/refactors/convertToEs6Module.ts index 5a7f2e90718d8..65f9f58ccc494 100644 --- a/src/services/refactors/convertToEs6Module.ts +++ b/src/services/refactors/convertToEs6Module.ts @@ -33,8 +33,8 @@ namespace ts.refactor { return isExportsOrModuleExportsOrAlias(sourceFile, node as PropertyAccessExpression) || isExportsOrModuleExportsOrAlias(sourceFile, (node as PropertyAccessExpression).expression); case SyntaxKind.VariableDeclarationList: - const decl = (node as VariableDeclarationList).declarations[0]; - return isExportsOrModuleExportsOrAlias(sourceFile, decl.initializer); + const decl = firstOrUndefined((node as VariableDeclarationList).declarations); + return !!decl && isExportsOrModuleExportsOrAlias(sourceFile, decl.initializer); case SyntaxKind.VariableDeclaration: return isExportsOrModuleExportsOrAlias(sourceFile, (node as VariableDeclaration).initializer); default: diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_triggers_declarationList.ts b/tests/cases/fourslash/refactorConvertToEs6Module_triggers_declarationList.ts new file mode 100644 index 0000000000000..36ec32b0561e2 --- /dev/null +++ b/tests/cases/fourslash/refactorConvertToEs6Module_triggers_declarationList.ts @@ -0,0 +1,9 @@ +/// + +// @allowJs: true + +// @Filename: /a.js +////c[|o|]nst; +////require("x"); + +goTo.eachRange(() => verify.not.refactorAvailable("Convert to ES6 module"));