66 * found in the LICENSE file at https://angular.io/license
77 */
88import { tags } from '@angular-devkit/core' ;
9- import { transformTypescript } from './ast_helpers' ;
9+ import { createTypescriptContext , transformTypescript } from './ast_helpers' ;
1010import { importFactory } from './import_factory' ;
1111
1212describe ( '@ngtools/webpack transformers' , ( ) => {
1313 describe ( 'import_factory' , ( ) => {
1414 it ( 'should support arrow functions' , ( ) => {
15+ const additionalFiles : Record < string , string > = {
16+ 'lazy/lazy.module.ts' : `
17+ export const LazyModule = {};
18+ ` ,
19+ } ;
1520 const input = tags . stripIndent `
1621 const ɵ0 = () => import('./lazy/lazy.module').then(m => m.LazyModule);
1722 const routes = [{
@@ -28,14 +33,20 @@ describe('@ngtools/webpack transformers', () => {
2833 ` ;
2934
3035 let warningCalled = false ;
31- const transformer = importFactory ( ( ) => warningCalled = true ) ;
32- const result = transformTypescript ( input , [ transformer ] ) ;
36+ const { program, compilerHost } = createTypescriptContext ( input , additionalFiles , true ) ;
37+ const transformer = importFactory ( ( ) => warningCalled = true , ( ) => program . getTypeChecker ( ) ) ;
38+ const result = transformTypescript ( undefined , [ transformer ] , program , compilerHost ) ;
3339
3440 expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
3541 expect ( warningCalled ) . toBeFalsy ( ) ;
3642 } ) ;
3743
3844 it ( 'should not transform if the format is different than expected' , ( ) => {
45+ const additionalFiles : Record < string , string > = {
46+ 'lazy/lazy.module.ts' : `
47+ export const LazyModule = {};
48+ ` ,
49+ } ;
3950 const input = tags . stripIndent `
4051 const ɵ0 = () => import('./lazy/lazy.module').then(function (m) { return m.LazyModule; });
4152 const routes = [{
@@ -45,35 +56,46 @@ describe('@ngtools/webpack transformers', () => {
4556 ` ;
4657
4758 let warningCalled = false ;
48- const transformer = importFactory ( ( ) => warningCalled = true ) ;
49- const result = transformTypescript ( input , [ transformer ] ) ;
59+ const { program, compilerHost } = createTypescriptContext ( input , additionalFiles , true ) ;
60+ const transformer = importFactory ( ( ) => warningCalled = true , ( ) => program . getTypeChecker ( ) ) ;
61+ const result = transformTypescript ( undefined , [ transformer ] , program , compilerHost ) ;
5062
5163 expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ input } ` ) ;
5264 expect ( warningCalled ) . toBeTruthy ( ) ;
5365 } ) ;
5466
55- it ( 'should support different arg name' , ( ) => {
67+ it ( 'should support resolving reexports' , ( ) => {
68+ const additionalFiles : Record < string , string > = {
69+ 'shared/index.ts' : `
70+ export * from './path/to/lazy/lazy.module';
71+ ` ,
72+ 'shared/path/to/lazy/lazy.module.ts' : `
73+ export const LazyModule = {};
74+ ` ,
75+ } ;
5676 const input = tags . stripIndent `
57- const ɵ0 = () => import('./lazy/lazy.module ').then(a => a .LazyModule);
77+ const ɵ0 = () => import('./shared ').then(m => m .LazyModule);
5878 const routes = [{
5979 path: 'lazy',
6080 loadChildren: ɵ0
6181 }];
6282 ` ;
83+
84+ // tslint:disable: max-line-length
6385 const output = tags . stripIndent `
64- const ɵ0 = () => import("./lazy/lazy.module.ngfactory").then(a => a .LazyModuleNgFactory);
86+ const ɵ0 = () => import("./shared/path/to/ lazy/lazy.module.ngfactory").then(m => m .LazyModuleNgFactory);
6587 const routes = [{
6688 path: 'lazy',
6789 loadChildren: ɵ0
6890 }];
6991 ` ;
92+ // tslint:enable: max-line-length
7093
71- let warningCalled = false ;
72- const transformer = importFactory ( ( ) => warningCalled = true ) ;
73- const result = transformTypescript ( input , [ transformer ] ) ;
94+ const { program , compilerHost } = createTypescriptContext ( input , additionalFiles , true ) ;
95+ const transformer = importFactory ( ( ) => { } , ( ) => program . getTypeChecker ( ) ) ;
96+ const result = transformTypescript ( undefined , [ transformer ] , program , compilerHost ) ;
7497
7598 expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
76- expect ( warningCalled ) . toBeFalsy ( ) ;
7799 } ) ;
78100 } ) ;
79101} ) ;
0 commit comments