@@ -4,18 +4,24 @@ import {AotPlugin} from './plugin';
44import { TypeScriptFileRefactor } from './refactor' ;
55import { LoaderContext , ModuleReason } from './webpack' ;
66
7+ interface Platform {
8+ name : string ;
9+ importLocation : string ;
10+ }
11+
712const loaderUtils = require ( 'loader-utils' ) ;
813const NormalModule = require ( 'webpack/lib/NormalModule' ) ;
914
1015// 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+ }
1925} ;
2026
2127function _getContentOfKeyLiteral ( _source : ts . SourceFile , node : ts . Node ) : string {
@@ -234,8 +240,13 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
234240 } ) ;
235241
236242 calls . forEach ( call => {
243+ const platform = changeMap [ ( call . expression as ts . Identifier ) . text ] ;
244+
237245 // 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 ) ;
239250 } ) ;
240251
241252 bootstraps
@@ -245,13 +256,6 @@ function _replaceBootstrap(plugin: AotPlugin, refactor: TypeScriptFileRefactor)
245256 } ) ;
246257
247258 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- } ) ;
255259}
256260
257261export function removeModuleIdOnlyForTesting ( refactor : TypeScriptFileRefactor ) {
0 commit comments