fix(compiler-cli): flat module index metadata should be transformed (#23129)

Currently, the flat module index metadata is produced directly from
the source metadata. The compiler, however, applies transformations
on the Typescript sources during transpilation, and also equivalent
transformations on the metadata itself. This transformed metadata
doesn't end up in the flat module index.

This changes the compiler to generate the flat module index metadata
from its transformed version instead of directly from source.

PR Close #23129
This commit is contained in:
Alex Rickabaugh
2018-04-02 13:05:08 -07:00
parent aaefd51a88
commit f99cb5c995
4 changed files with 66 additions and 19 deletions

View File

@ -1009,7 +1009,8 @@ describe('ngc transformer command-line', () => {
"angularCompilerOptions": {
"flatModuleId": "flat_module",
"flatModuleOutFile": "${outFile}",
"skipTemplateCodegen": true
"skipTemplateCodegen": true,
"enableResourceInlining": true
},
"files": ["public-api.ts"]
}
@ -1038,7 +1039,8 @@ describe('ngc transformer command-line', () => {
],
exports: [
FlatComponent,
]
],
providers: [{provide: 'test', useFactory: () => true}],
})
export class FlatModule {
}`);
@ -1053,6 +1055,20 @@ describe('ngc transformer command-line', () => {
shouldExist('index.metadata.json');
});
it('should downlevel flat module metadata', () => {
writeFlatModule('index.js');
const exitCode = main(['-p', path.join(basePath, 'tsconfig.json')], errorSpy);
expect(exitCode).toEqual(0);
shouldExist('index.js');
shouldExist('index.metadata.json');
const metadataPath = path.resolve(outDir, 'index.metadata.json');
const metadataSource = fs.readFileSync(metadataPath, 'utf8');
expect(metadataSource).not.toContain('templateUrl');
expect(metadataSource).toContain('"useFactory":{"__symbolic":"reference","name":"ɵ0"}');
});
describe('with tree example', () => {
beforeEach(() => {
writeConfig();