@@ -81,6 +81,62 @@ const inputNoPure = tags.stripIndent`
8181 }], null, null); })();
8282` ;
8383
84+ const inputArrowFnWithBody = tags . stripIndent `
85+ export class AppModule {
86+ }
87+ AppModule.ɵmod = i0.ɵɵdefineNgModule({ type: AppModule, bootstrap: [AppComponent] });
88+ AppModule.ɵinj = i0.ɵɵdefineInjector({ factory: function AppModule_Factory(t) { return new (t || AppModule)(); }, providers: [], imports: [[
89+ BrowserModule,
90+ AppRoutingModule
91+ ]] });
92+ (() => { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(AppModule, { declarations: [AppComponent,
93+ ExampleComponent], imports: [BrowserModule,
94+ AppRoutingModule] }); })();
95+ (() => { i0.ɵsetClassMetadata(AppModule, [{
96+ type: NgModule,
97+ args: [{
98+ declarations: [
99+ AppComponent,
100+ ExampleComponent
101+ ],
102+ imports: [
103+ BrowserModule,
104+ AppRoutingModule
105+ ],
106+ providers: [],
107+ bootstrap: [AppComponent]
108+ }]
109+ }], null, null); })();
110+ ` ;
111+
112+ const inputArrowFnWithImplicitReturn = tags . stripIndent `
113+ export class AppModule {
114+ }
115+ AppModule.ɵmod = i0.ɵɵdefineNgModule({ type: AppModule, bootstrap: [AppComponent] });
116+ AppModule.ɵinj = i0.ɵɵdefineInjector({ factory: function AppModule_Factory(t) { return new (t || AppModule)(); }, providers: [], imports: [[
117+ BrowserModule,
118+ AppRoutingModule
119+ ]] });
120+ (() => (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(AppModule, { declarations: [AppComponent,
121+ ExampleComponent], imports: [BrowserModule,
122+ AppRoutingModule] }))();
123+ (() => i0.ɵsetClassMetadata(AppModule, [{
124+ type: NgModule,
125+ args: [{
126+ declarations: [
127+ AppComponent,
128+ ExampleComponent
129+ ],
130+ imports: [
131+ BrowserModule,
132+ AppRoutingModule
133+ ],
134+ providers: [],
135+ bootstrap: [AppComponent]
136+ }]
137+ }], null, null))();
138+ ` ;
139+
84140describe ( '@ngtools/webpack transformers' , ( ) => {
85141 describe ( 'remove-ivy-dev-calls' , ( ) => {
86142 it ( 'should allow removing only set class metadata with pure annotation' , ( ) => {
@@ -304,5 +360,41 @@ describe('@ngtools/webpack transformers', () => {
304360
305361 expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
306362 } ) ;
363+
364+ it ( 'should remove setClassMetadata and setNgModuleScope calls inside arrow-function-based IIFEs that have bodies' , ( ) => {
365+ const output = tags . stripIndent `
366+ export class AppModule {
367+ }
368+ AppModule.ɵmod = i0.ɵɵdefineNgModule({ type: AppModule, bootstrap: [AppComponent] });
369+ AppModule.ɵinj = i0.ɵɵdefineInjector({ factory: function AppModule_Factory(t) { return new (t || AppModule)(); }, providers: [], imports: [[
370+ BrowserModule,
371+ AppRoutingModule
372+ ]] });
373+ ` ;
374+
375+ const result = transform ( inputArrowFnWithBody , ( getTypeChecker ) =>
376+ removeIvyJitSupportCalls ( true , true , getTypeChecker ) ,
377+ ) ;
378+
379+ expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
380+ } ) ;
381+
382+ it ( 'should remove setClassMetadata and setNgModuleScope calls inside arrow-function-based IIFEs that have an implicit return' , ( ) => {
383+ const output = tags . stripIndent `
384+ export class AppModule {
385+ }
386+ AppModule.ɵmod = i0.ɵɵdefineNgModule({ type: AppModule, bootstrap: [AppComponent] });
387+ AppModule.ɵinj = i0.ɵɵdefineInjector({ factory: function AppModule_Factory(t) { return new (t || AppModule)(); }, providers: [], imports: [[
388+ BrowserModule,
389+ AppRoutingModule
390+ ]] });
391+ ` ;
392+
393+ const result = transform ( inputArrowFnWithImplicitReturn , ( getTypeChecker ) =>
394+ removeIvyJitSupportCalls ( true , true , getTypeChecker ) ,
395+ ) ;
396+
397+ expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
398+ } ) ;
307399 } ) ;
308400} ) ;
0 commit comments