@@ -9,7 +9,9 @@ const NormalModule = require('webpack/lib/NormalModule');
9
9
10
10
11
11
function _getContentOfKeyLiteral ( source : ts . SourceFile , node : ts . Node ) : string {
12
- if ( node . kind == ts . SyntaxKind . Identifier ) {
12
+ if ( ! node ) {
13
+ return null ;
14
+ } else if ( node . kind == ts . SyntaxKind . Identifier ) {
13
15
return ( node as ts . Identifier ) . text ;
14
16
} else if ( node . kind == ts . SyntaxKind . StringLiteral ) {
15
17
return ( node as ts . StringLiteral ) . text ;
@@ -241,11 +243,16 @@ function _removeModuleId(refactor: TypeScriptFileRefactor) {
241
243
242
244
refactor . findAstNodes ( sourceFile , ts . SyntaxKind . ObjectLiteralExpression , true )
243
245
// Get all their property assignments.
244
- . filter ( ( node : ts . ObjectLiteralExpression ) =>
245
- node . properties . some ( prop => _getContentOfKeyLiteral ( sourceFile , prop . name ) == 'moduleId' ) )
246
+ . filter ( ( node : ts . ObjectLiteralExpression ) => {
247
+ return node . properties . some ( prop => {
248
+ return prop . kind == ts . SyntaxKind . PropertyAssignment
249
+ && _getContentOfKeyLiteral ( sourceFile , prop . name ) == 'moduleId' ;
250
+ } ) ;
251
+ } )
246
252
. forEach ( ( node : ts . ObjectLiteralExpression ) => {
247
253
const moduleIdProp = node . properties . filter ( ( prop : ts . ObjectLiteralElement , idx : number ) => {
248
- return _getContentOfKeyLiteral ( sourceFile , prop . name ) == 'moduleId' ;
254
+ return prop . kind == ts . SyntaxKind . PropertyAssignment
255
+ && _getContentOfKeyLiteral ( sourceFile , prop . name ) == 'moduleId' ;
249
256
} ) [ 0 ] ;
250
257
// get the trailing comma
251
258
const moduleIdCommaProp = moduleIdProp . parent . getChildAt ( 1 ) . getChildren ( ) [ 1 ] ;
0 commit comments