refactor(compiler-cli): support schemas in standalone components (#45752)

This commit adds support for `@Component.schemas` in both JIT and AOT.

PR Close #45752
This commit is contained in:
Alex Rickabaugh
2022-04-22 14:29:23 -07:00
committed by Andrew Scott
parent 2eb39c0878
commit 3d4548450a
18 changed files with 213 additions and 43 deletions
+3
View File
@@ -13,6 +13,7 @@ import {compileComponent, compileDirective} from '../render3/jit/directive';
import {compilePipe} from '../render3/jit/pipe';
import {makeDecorator, makePropDecorator, TypeDecorator} from '../util/decorators';
import {SchemaMetadata} from './schema';
import {ViewEncapsulation} from './view';
@@ -560,6 +561,8 @@ export interface Component extends Directive {
// TODO: better type here!
imports?: (Type<any>|any[])[];
schemas?: SchemaMetadata[];
}
/**
@@ -167,6 +167,17 @@ export function compileComponent(type: Type<any>, metadata: Component): void {
const scopes = transitiveScopesFor(type.ngSelectorScope);
patchComponentDefWithScope(ngComponentDef, scopes);
}
if (metadata.schemas) {
if (metadata.standalone) {
ngComponentDef.schemas = metadata.schemas;
} else {
throw new Error(`The 'schemas' was specified for the ${
stringifyForError(type)} but is only valid on a component that is standalone.`);
}
} else if (metadata.standalone) {
ngComponentDef.schemas = [];
}
}
return ngComponentDef;
},