fix(ivy): directives without selector should not be supported (#28021)
PR Close #28021
This commit is contained in:

committed by
Andrew Kushnir

parent
7374dfd1fa
commit
76ed13bffe
@ -640,9 +640,6 @@ describe('compiler compliance', () => {
|
||||
'spec.ts': `
|
||||
import {Component, Directive, NgModule} from '@angular/core';
|
||||
|
||||
@Directive({})
|
||||
export class EmptyOutletDirective {}
|
||||
|
||||
@Component({template: '<router-outlet></router-outlet>'})
|
||||
export class EmptyOutletComponent {}
|
||||
|
||||
@ -652,16 +649,6 @@ describe('compiler compliance', () => {
|
||||
}
|
||||
};
|
||||
|
||||
// EmptyOutletDirective definition should be:
|
||||
const EmptyOutletDirectiveDefinition = `
|
||||
…
|
||||
EmptyOutletDirective.ngDirectiveDef = $r3$.ɵdefineDirective({
|
||||
type: EmptyOutletDirective,
|
||||
selectors: [],
|
||||
factory: function EmptyOutletDirective_Factory(t) { return new (t || EmptyOutletDirective)(); }
|
||||
});
|
||||
`;
|
||||
|
||||
// EmptyOutletComponent definition should be:
|
||||
const EmptyOutletComponentDefinition = `
|
||||
…
|
||||
@ -683,13 +670,48 @@ describe('compiler compliance', () => {
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(
|
||||
source, EmptyOutletDirectiveDefinition,
|
||||
'Incorrect EmptyOutletDirective.ngDirectiveDefDef');
|
||||
expectEmit(
|
||||
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 = {
|
||||
|
Reference in New Issue
Block a user