fix(compiler): allow to use lowering with export *.

Previously, we generated incorrect code when a file
had lowerings and also exported another file via `export *`
that also had lowerings in it.
This commit is contained in:
Tobias Bosch
2017-09-24 11:19:01 -07:00
committed by Victor Berchet
parent 3799f43c71
commit e31a76ce24
3 changed files with 83 additions and 33 deletions

View File

@ -711,6 +711,38 @@ describe('ngc transformer command-line', () => {
expect(main(['-p', basePath], errorSpy)).toBe(0);
shouldExist('module.js');
});
it('should allow to use lowering with export *', () => {
write('mymodule.ts', `
import {NgModule} from '@angular/core';
export * from './util';
// Note: the lamda will be lowered into an exported expression
@NgModule({providers: [{provide: 'aToken', useValue: () => 2}]})
export class MyModule {}
`);
write('util.ts', `
// Note: The lamda will be lowered into an exported expression
const x = () => 2;
export const y = x;
`);
expect(compile()).toEqual(0);
const mymoduleSource = fs.readFileSync(path.resolve(outDir, 'mymodule.js'), 'utf8');
expect(mymoduleSource).toContain('ɵ0');
const utilSource = fs.readFileSync(path.resolve(outDir, 'util.js'), 'utf8');
expect(utilSource).toContain('ɵ0');
const mymoduleNgFactoryJs =
fs.readFileSync(path.resolve(outDir, 'mymodule.ngfactory.js'), 'utf8');
// check that the generated code refers to ɵ0 from mymodule, and not from util!
expect(mymoduleNgFactoryJs).toContain(`import * as i1 from "./mymodule"`);
expect(mymoduleNgFactoryJs).toContain(`"aToken", i1.ɵ0`);
});
});
function writeFlatModule(outFile: string) {