@@ -4,18 +4,24 @@ import {AotPlugin} from './plugin';
4
4
import { TypeScriptFileRefactor } from './refactor' ;
5
5
import { LoaderContext , ModuleReason } from './webpack' ;
6
6
7
+ interface Platform {
8
+ name : string ;
9
+ importLocation : string ;
10
+ }
11
+
7
12
const loaderUtils = require ( 'loader-utils' ) ;
8
13
const NormalModule = require ( 'webpack/lib/NormalModule' ) ;
9
14
10
15
// This is a map of changes which need to be made
11
- const changeMap : { [ key : string ] : string } = {
12
- platformBrowserDynamic : 'platformBrowser' ,
13
- platformDynamicServer : 'platformServer'
14
- } ;
15
-
16
- const importLocations : { [ key : string ] : string } = {
17
- platformBrowser : '@angular/platform-browser' ,
18
- platformServer : '@angular/platform-server'
16
+ const changeMap : { [ key : string ] : Platform } = {
17
+ platformBrowserDynamic : {
18
+ name : 'platformBrowser' ,
19
+ importLocation : '@angular/platform-browser'
20
+ } ,
21
+ platformDynamicServer : {
22
+ name : 'platformServer' ,
23
+ importLocation : '@angular/platform-server'
24
+ }
19
25
} ;
20
26
21
27
function _getContentOfKeyLiteral ( _source : ts . SourceFile , node : ts . Node ) : string {
@@ -234,8 +240,13 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
234
240
} ) ;
235
241
236
242
calls . forEach ( call => {
243
+ const platform = changeMap [ ( call . expression as ts . Identifier ) . text ] ;
244
+
237
245
// Replace with mapped replacement
238
- refactor . replaceNode ( call . expression , changeMap [ ( call . expression as ts . Identifier ) . text ] ) ;
246
+ refactor . replaceNode ( call . expression , platform . name ) ;
247
+
248
+ // Add the appropriate import
249
+ refactor . insertImport ( platform . name , platform . importLocation ) ;
239
250
} ) ;
240
251
241
252
bootstraps
@@ -245,13 +256,6 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
245
256
} ) ;
246
257
247
258
refactor . insertImport ( entryModule . className + 'NgFactory' , ngFactoryPath ) ;
248
-
249
- // We need to import the additional imports which are used
250
- Object . keys ( importLocations )
251
- . filter ( imp => refactor . sourceMatch ( new RegExp ( imp ) ) )
252
- . forEach ( imp => {
253
- refactor . insertImport ( imp , importLocations [ imp ] ) ;
254
- } ) ;
255
259
}
256
260
257
261
export function removeModuleIdOnlyForTesting ( refactor : TypeScriptFileRefactor ) {
0 commit comments