mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Andrew Scott
parent
2eb39c0878
commit
3d4548450a
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user