mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(compiler-cli): Produce diagnostic rather than crash when using invalid hostDirective (#48314)
Because the language service uses the compiler, we try to produce as much useful information as possible rather than throwing hard errors. Hard errors cause the compiler to crash. While this can be acceptable when compiling a program as part of a regular build, this is undesirable for the language service. PR Close #48314
This commit is contained in:
committed by
Andrew Kushnir
parent
38421578a2
commit
27eaded62d
@@ -451,6 +451,24 @@ runInEachFileSystem(() => {
|
||||
expect(messages).toEqual(['Host directive HostDir must be standalone']);
|
||||
});
|
||||
|
||||
it('should produce a diagnostic if a host directive is not a directive', () => {
|
||||
env.write('test.ts', `
|
||||
import {Directive, Pipe, Component, NgModule} from '@angular/core';
|
||||
|
||||
@Pipe({name: 'hostDir'})
|
||||
export class HostDir {}
|
||||
|
||||
@Directive({
|
||||
hostDirectives: [HostDir],
|
||||
})
|
||||
export class Dir {}
|
||||
`);
|
||||
|
||||
const messages = env.driveDiagnostics().map(extractMessage);
|
||||
expect(messages).toEqual(
|
||||
['HostDir must be a standalone directive to be used as a host directive']);
|
||||
});
|
||||
|
||||
it('should produce a diagnostic if a host directive is a component', () => {
|
||||
env.write('test.ts', `
|
||||
import {Directive, Component, NgModule} from '@angular/core';
|
||||
|
||||
Reference in New Issue
Block a user