@@ -4,8 +4,8 @@ import {Change, InsertChange, NoopChange, MultiChange} from './change';
4
4
import { findNodes } from './node' ;
5
5
import { insertImport } from './route-utils' ;
6
6
7
- import { Observable } from 'rxjs/Observable' ;
8
- import { ReplaySubject } from 'rxjs/ReplaySubject' ;
7
+ import { Observable } from 'rxjs/Observable' ;
8
+ import { ReplaySubject } from 'rxjs/ReplaySubject' ;
9
9
import 'rxjs/add/observable/empty' ;
10
10
import 'rxjs/add/observable/of' ;
11
11
import 'rxjs/add/operator/do' ;
@@ -162,17 +162,17 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
162
162
return getSourceNodes ( source )
163
163
. filter ( node => {
164
164
return node . kind == ts . SyntaxKind . Decorator
165
- && ( < ts . Decorator > node ) . expression . kind == ts . SyntaxKind . CallExpression ;
165
+ && ( node as ts . Decorator ) . expression . kind == ts . SyntaxKind . CallExpression ;
166
166
} )
167
- . map ( node => < ts . CallExpression > ( < ts . Decorator > node ) . expression )
167
+ . map ( node => ( node as ts . Decorator ) . expression as ts . CallExpression )
168
168
. filter ( expr => {
169
169
if ( expr . expression . kind == ts . SyntaxKind . Identifier ) {
170
- const id = < ts . Identifier > expr . expression ;
170
+ const id = expr . expression as ts . Identifier ;
171
171
return id . getFullText ( source ) == identifier
172
172
&& angularImports [ id . getFullText ( source ) ] === module ;
173
173
} else if ( expr . expression . kind == ts . SyntaxKind . PropertyAccessExpression ) {
174
174
// This covers foo.NgModule when importing * as foo.
175
- const paExpr = < ts . PropertyAccessExpression > expr . expression ;
175
+ const paExpr = expr . expression as ts . PropertyAccessExpression ;
176
176
// If the left expression is not an identifier, just give up at that point.
177
177
if ( paExpr . expression . kind !== ts . SyntaxKind . Identifier ) {
178
178
return false ;
@@ -186,7 +186,7 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
186
186
} )
187
187
. filter ( expr => expr . arguments [ 0 ]
188
188
&& expr . arguments [ 0 ] . kind == ts . SyntaxKind . ObjectLiteralExpression )
189
- . map ( expr => < ts . ObjectLiteralExpression > expr . arguments [ 0 ] ) ;
189
+ . map ( expr => expr . arguments [ 0 ] as ts . ObjectLiteralExpression ) ;
190
190
}
191
191
192
192
@@ -229,14 +229,14 @@ function _addSymbolToNgModuleMetadata(ngModulePath: string, metadataField: strin
229
229
return metadata . toPromise ( ) ;
230
230
}
231
231
232
- const assignment = < ts . PropertyAssignment > matchingProperties [ 0 ] ;
232
+ const assignment = matchingProperties [ 0 ] as ts . PropertyAssignment ;
233
233
234
234
// If it's not an array, nothing we can do really.
235
235
if ( assignment . initializer . kind !== ts . SyntaxKind . ArrayLiteralExpression ) {
236
236
return null ;
237
237
}
238
238
239
- const arrLiteral = < ts . ArrayLiteralExpression > assignment . initializer ;
239
+ const arrLiteral = assignment . initializer as ts . ArrayLiteralExpression ;
240
240
if ( arrLiteral . elements . length == 0 ) {
241
241
// Forward the property.
242
242
return arrLiteral ;
@@ -245,11 +245,17 @@ function _addSymbolToNgModuleMetadata(ngModulePath: string, metadataField: strin
245
245
} )
246
246
. then ( ( node : ts . Node ) => {
247
247
if ( ! node ) {
248
- /* eslint-disable no-console */
249
248
console . log ( 'No app module found. Please add your new class to your component.' ) ;
250
249
return new NoopChange ( ) ;
251
250
}
251
+
252
252
if ( Array . isArray ( node ) ) {
253
+ const nodeArray = node as any as Array < ts . Node > ;
254
+ const symbolsArray = nodeArray . map ( node => node . getText ( ) ) ;
255
+ if ( symbolsArray . includes ( symbolName ) ) {
256
+ return new NoopChange ( ) ;
257
+ }
258
+
253
259
node = node [ node . length - 1 ] ;
254
260
}
255
261
@@ -258,7 +264,7 @@ function _addSymbolToNgModuleMetadata(ngModulePath: string, metadataField: strin
258
264
if ( node . kind == ts . SyntaxKind . ObjectLiteralExpression ) {
259
265
// We haven't found the field in the metadata declaration. Insert a new
260
266
// field.
261
- let expr = < ts . ObjectLiteralExpression > node ;
267
+ let expr = node as ts . ObjectLiteralExpression ;
262
268
if ( expr . properties . length == 0 ) {
263
269
position = expr . getEnd ( ) - 1 ;
264
270
toInsert = ` ${ metadataField } : [${ symbolName } ]\n` ;
@@ -326,7 +332,7 @@ export function addProviderToModule(modulePath: string, classifiedName: string,
326
332
* Custom function to insert an export into NgModule. It also imports it.
327
333
*/
328
334
export function addExportToModule ( modulePath : string , classifiedName : string ,
329
- importPath : string ) : Promise < Change > {
335
+ importPath : string ) : Promise < Change > {
330
336
return _addSymbolToNgModuleMetadata ( modulePath , 'exports' , classifiedName , importPath ) ;
331
337
}
332
338
0 commit comments