fix(ivy): add @nocollapse when writing closure-annotated code (#25775)

Closure requires @nocollapse on Ivy definition static fields in order
to not convert them to standalone constants. However tsickle, the tool
which would ordinarily be responsible for adding @nocollapse, doesn't
properly annotate fields which are added synthetically via transforms.
So this commit adds @nocollapse by applying regular expressions against
code during the final write to disk.

PR Close #25775
This commit is contained in:
Alex Rickabaugh
2018-08-28 14:13:22 -07:00
committed by Igor Minar
parent 7ba0cb7c93
commit a0c4b2d8f0
4 changed files with 92 additions and 37 deletions

View File

@ -0,0 +1,26 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {nocollapseHack} from '../../src/transformers/nocollapse_hack';
describe('@nocollapse hack', () => {
it('should add @nocollapse to a basic class', () => {
const decl = `Foo.ngInjectorDef = define(...);`;
expect(nocollapseHack(decl)).toEqual('/** @nocollapse */ ' + decl);
});
it('should add nocollapse to an if (false) declaration of the kind generated by tsickle', () => {
const decl = `
if (false) {
/** @type {?} */
Foo.ngInjectorDef;
}
`;
expect(nocollapseHack(decl)).toContain('/** @nocollapse @type {?} */');
});
});