fix(ivy): add flag to skip non-exported classes (#33921)

In ViewEngine we were only generating code for exported classes, however with Ivy we do it no matter whether the class has been exported or not. These changes add an extra flag that allows consumers to opt into the ViewEngine behavior. The flag works by treating non-exported classes as if they're set to `jit: true`.

Fixes #33724.

PR Close #33921
This commit is contained in:
crisbeto
2019-11-21 21:07:54 +01:00
committed by Matias Niemelä
parent ec495c807f
commit 25dcc7631f
4 changed files with 69 additions and 3 deletions

View File

@ -5181,6 +5181,60 @@ export const Foo = Foo__PRE_R3__;
expect(jsContents).toContain('styles: ["h1[_ngcontent-%COMP%] {font-size: larger}"]');
});
});
describe('non-exported classes', () => {
beforeEach(() => env.tsconfig({compileNonExportedClasses: false}));
it('should not emit directive definitions for non-exported classes if configured', () => {
env.write('test.ts', `
import {Directive} from '@angular/core';
@Directive({
selector: '[test]'
})
class TestDirective {}
`);
env.driveMain();
const jsContents = env.getContents('test.js');
expect(jsContents).not.toContain('defineDirective(');
expect(jsContents).toContain('Directive({');
});
it('should not emit component definitions for non-exported classes if configured', () => {
env.write('test.ts', `
import {Component} from '@angular/core';
@Component({
selector: 'test',
template: 'hello'
})
class TestComponent {}
`);
env.driveMain();
const jsContents = env.getContents('test.js');
expect(jsContents).not.toContain('defineComponent(');
expect(jsContents).toContain('Component({');
});
it('should not emit module definitions for non-exported classes if configured', () => {
env.write('test.ts', `
import {NgModule} from '@angular/core';
@NgModule({
declarations: []
})
class TestModule {}
`);
env.driveMain();
const jsContents = env.getContents('test.js');
expect(jsContents).not.toContain('defineNgModule(');
expect(jsContents).toContain('NgModule({');
});
});
});
function expectTokenAtPosition<T extends ts.Node>(