fix(ivy): Support selector-less directive as base classes (#32125)
Following #31379, this adds support for directives without a selector to Ivy. PR Close #32125
This commit is contained in:
@ -669,44 +669,6 @@ describe('compiler compliance', () => {
|
||||
source, EmptyOutletComponentDefinition, 'Incorrect EmptyOutletComponent.ngComponentDef');
|
||||
});
|
||||
|
||||
it('should not support directives without selector', () => {
|
||||
const files = {
|
||||
app: {
|
||||
'spec.ts': `
|
||||
import {Component, Directive, NgModule} from '@angular/core';
|
||||
|
||||
@Directive({})
|
||||
export class EmptyOutletDirective {}
|
||||
|
||||
@NgModule({declarations: [EmptyOutletDirective]})
|
||||
export class MyModule{}
|
||||
`
|
||||
}
|
||||
};
|
||||
|
||||
expect(() => compile(files, angularFiles))
|
||||
.toThrowError('Directive EmptyOutletDirective has no selector, please add it!');
|
||||
});
|
||||
|
||||
it('should not support directives with empty selector', () => {
|
||||
const files = {
|
||||
app: {
|
||||
'spec.ts': `
|
||||
import {Component, Directive, NgModule} from '@angular/core';
|
||||
|
||||
@Directive({selector: ''})
|
||||
export class EmptyOutletDirective {}
|
||||
|
||||
@NgModule({declarations: [EmptyOutletDirective]})
|
||||
export class MyModule{}
|
||||
`
|
||||
}
|
||||
};
|
||||
|
||||
expect(() => compile(files, angularFiles))
|
||||
.toThrowError('Directive EmptyOutletDirective has no selector, please add it!');
|
||||
});
|
||||
|
||||
it('should not treat ElementRef, ViewContainerRef, or ChangeDetectorRef specially when injecting',
|
||||
() => {
|
||||
const files = {
|
||||
|
@ -1008,19 +1008,43 @@ runInEachFileSystem(os => {
|
||||
expect(jsContents).toContain('selectors: [["ng-component"]]');
|
||||
});
|
||||
|
||||
it('should throw if selector is missing in Directive decorator params', () => {
|
||||
env.write('test.ts', `
|
||||
import {Directive} from '@angular/core';
|
||||
it('should allow directives with no selector that are not in NgModules', () => {
|
||||
env.write('main.ts', `
|
||||
import {Directive} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
inputs: ['a', 'b']
|
||||
})
|
||||
export class TestDir {}
|
||||
`);
|
||||
@Directive({})
|
||||
export class BaseDir {}
|
||||
|
||||
@Directive({})
|
||||
export abstract class AbstractBaseDir {}
|
||||
|
||||
@Directive()
|
||||
export abstract class EmptyDir {}
|
||||
|
||||
@Directive({
|
||||
inputs: ['a', 'b']
|
||||
})
|
||||
export class TestDirWithInputs {}
|
||||
`);
|
||||
const errors = env.driveDiagnostics();
|
||||
expect(errors.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should not allow directives with no selector that are in NgModules', () => {
|
||||
env.write('main.ts', `
|
||||
import {Directive, NgModule} from '@angular/core';
|
||||
|
||||
@Directive({})
|
||||
export class BaseDir {}
|
||||
|
||||
@NgModule({
|
||||
declarations: [BaseDir],
|
||||
})
|
||||
export class MyModule {}
|
||||
`);
|
||||
const errors = env.driveDiagnostics();
|
||||
expect(trim(errors[0].messageText as string))
|
||||
.toContain('Directive TestDir has no selector, please add it!');
|
||||
.toContain('Directive BaseDir has no selector, please add it!');
|
||||
});
|
||||
|
||||
it('should throw if Directive selector is an empty string', () => {
|
||||
|
Reference in New Issue
Block a user