@@ -130,23 +130,23 @@ namespace ts.codefix {
130
130
let foundImport = false ;
131
131
const newNodes = flatMap ( declarationList . declarations , decl => {
132
132
const { name, initializer } = decl ;
133
- if ( isExportsOrModuleExportsOrAlias ( sourceFile , initializer ) ) {
134
- // `const alias = module.exports;` can be removed.
135
- foundImport = true ;
136
- return [ ] ;
137
- }
138
- if ( isRequireCall ( initializer , /*checkArgumentIsStringLiteralLike*/ true ) ) {
139
- foundImport = true ;
140
- return convertSingleImport ( sourceFile , name , initializer . arguments [ 0 ] , changes , checker , identifiers , target ) ;
141
- }
142
- else if ( isPropertyAccessExpression ( initializer ) && isRequireCall ( initializer . expression , /*checkArgumentIsStringLiteralLike*/ true ) ) {
143
- foundImport = true ;
144
- return convertPropertyAccessImport ( name , initializer . name . text , initializer . expression . arguments [ 0 ] , identifiers ) ;
145
- }
146
- else {
147
- // Move it out to its own variable statement. (This will not be used if `!foundImport`)
148
- return createVariableStatement ( /*modifiers*/ undefined , createVariableDeclarationList ( [ decl ] , declarationList . flags ) ) ;
133
+ if ( initializer ) {
134
+ if ( isExportsOrModuleExportsOrAlias ( sourceFile , initializer ) ) {
135
+ // `const alias = module.exports;` can be removed.
136
+ foundImport = true ;
137
+ return [ ] ;
138
+ }
139
+ else if ( isRequireCall ( initializer , /*checkArgumentIsStringLiteralLike*/ true ) ) {
140
+ foundImport = true ;
141
+ return convertSingleImport ( sourceFile , name , initializer . arguments [ 0 ] , changes , checker , identifiers , target ) ;
142
+ }
143
+ else if ( isPropertyAccessExpression ( initializer ) && isRequireCall ( initializer . expression , /*checkArgumentIsStringLiteralLike*/ true ) ) {
144
+ foundImport = true ;
145
+ return convertPropertyAccessImport ( name , initializer . name . text , initializer . expression . arguments [ 0 ] , identifiers ) ;
146
+ }
149
147
}
148
+ // Move it out to its own variable statement. (This will not be used if `!foundImport`)
149
+ return createVariableStatement ( /*modifiers*/ undefined , createVariableDeclarationList ( [ decl ] , declarationList . flags ) ) ;
150
150
} ) ;
151
151
if ( foundImport ) {
152
152
// useNonAdjustedEndPosition to ensure we don't eat the newline after the statement.
0 commit comments