fix(bazel): downlevel decorators in fesm5 files (#23078)

Needed so that our bundles appear side-effect-free to tools like webpack

PR Close #23078
This commit is contained in:
Alex Eagle 2018-03-29 18:21:40 -07:00 committed by Igor Minar
parent 45e090b614
commit 481b22ecb0
4 changed files with 55 additions and 72 deletions

View File

@ -23,10 +23,13 @@ function main(args) {
const data = JSON.parse(fs.readFileSync(input, {encoding: 'utf-8'}));
data['compilerOptions']['target'] = 'es5';
data['bazelOptions']['es5Mode'] = true;
data['bazelOptions']['tsickle'] = false;
// Enable tsickle for decorator downleveling only
data['bazelOptions']['tsickle'] = true;
data['bazelOptions']['tsickleExternsPath'] = '';
data['compilerOptions']['outDir'] = path.join(data['compilerOptions']['outDir'], newRoot);
if (data['angularCompilerOptions']) {
// Don't enable tsickle's closure conversions
data['angularCompilerOptions']['annotateForClosureCompiler'] = false;
data['angularCompilerOptions']['expectedOut'] =
data['angularCompilerOptions']['expectedOut'].map(
f => f.replace(/\.closure\.js$/, '.js').replace(binDir, path.join(binDir, newRoot)));

View File

@ -172,6 +172,8 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
const bazelHost = new CompilerHost(
files, compilerOpts, bazelOpts, tsHost, fileLoader, allowNonHermeticReads,
generatedFileModuleResolver);
// Prevent tsickle adding any types at all if we don't want closure compiler annotations.
bazelHost.transformTypesToClosure = compilerOpts.annotateForClosureCompiler;
const origBazelHostFileExist = bazelHost.fileExists;
bazelHost.fileExists = (fileName: string) => {
if (NGC_ASSETS.test(fileName)) {

View File

@ -126,6 +126,9 @@ describe('@angular/core ng_package', () => {
expect(shx.cat('fesm5/core.js')).not.toContain('@fileoverview added by tsickle');
});
it('should have annotations rather than decorators',
() => { expect(shx.cat('fesm5/core.js')).not.toContain('__decorate'); });
it('should load tslib from external bundle', () => {
expect(shx.cat('fesm5/core.js')).not.toContain('function __extends');
expect(shx.cat('fesm5/core.js')).toMatch('import {.*__extends');

File diff suppressed because one or more lines are too long