feat(ivy): open up ivy_switch_mode to non-core packages (#28711)

Prior to this fix, using the compiler's ivy_switch mechanism was
only available to core packages. This patch allows for this variable
switching mechanism to work across all other angular packages.

PR Close #28711
This commit is contained in:
Matias Niemelä 2019-02-01 15:33:41 -08:00 committed by Igor Minar
parent 09d894c283
commit d0e81eb593
2 changed files with 32 additions and 3 deletions

View File

@ -280,9 +280,7 @@ export class NgtscProgram implements api.Program {
beforeTransforms.push(
generatedFactoryTransform(this.factoryToSourceInfo, this.importRewriter));
}
if (this.isCore) {
beforeTransforms.push(ivySwitchTransform);
}
beforeTransforms.push(ivySwitchTransform);
if (customTransforms && customTransforms.beforeTs) {
beforeTransforms.push(...customTransforms.beforeTs);
}

View File

@ -2932,6 +2932,37 @@ describe('ngtsc behavioral tests', () => {
});
});
});
describe('ivy switch mode', () => {
it('should allow for symbols to be renamed when they use a SWITCH_IVY naming mechanism', () => {
env.tsconfig();
env.write('test.ts', `
export const FooCmp__POST_R3__ = 1;
export const FooCmp__PRE_R3__ = 2;
export const FooCmp = FooCmp__PRE_R3__;`);
env.driveMain();
const source = env.getContents('test.js');
expect(source).toContain(`export var FooCmp = FooCmp__POST_R3__`);
expect(source).not.toContain(`export var FooCmp = FooCmp__PRE_R3__`);
});
it('should allow for SWITCH_IVY naming even even if it occurs outside of core', () => {
const content = `
export const Foo__POST_R3__ = 1;
export const Foo__PRE_R3__ = 2;
export const Foo = Foo__PRE_R3__;
`;
env.tsconfig();
env.write('test_outside_angular_core.ts', content);
env.write('test_inside_angular_core.ts', content + '\nexport const ITS_JUST_ANGULAR = true;');
env.driveMain();
const sourceTestOutsideAngularCore = env.getContents('test_outside_angular_core.js');
const sourceTestInsideAngularCore = env.getContents('test_inside_angular_core.js');
expect(sourceTestInsideAngularCore).toContain(sourceTestOutsideAngularCore);
});
});
});
function expectTokenAtPosition<T extends ts.Node>(