feat(ivy): ngtsc compiles @Component, @Directive, @NgModule (#24427)
This change supports compilation of components, directives, and modules within ngtsc. Support is not complete, but is enough to compile and test //packages/core/test/bundling/todo in full AOT mode. Code size benefits are not yet achieved as //packages/core itself does not get compiled, and some decorators (e.g. @Input) are not stripped, leading to unwanted code being retained by the tree-shaker. This will be improved in future commits. PR Close #24427
This commit is contained in:

committed by
Miško Hevery

parent
0f7e4fae20
commit
27bc7dcb43
@ -388,6 +388,14 @@ export interface Directive {
|
||||
* ```
|
||||
*/
|
||||
queries?: {[key: string]: any};
|
||||
|
||||
/**
|
||||
* If true, this directive/component will be skipped by the AOT compiler and so will always be
|
||||
* compiled using JIT.
|
||||
*
|
||||
* This exists to support future Ivy work and has no effect currently.
|
||||
*/
|
||||
jit?: true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,11 +27,39 @@ export interface NgModuleTransitiveScopes {
|
||||
exported: {directives: Set<any>; pipes: Set<any>;};
|
||||
}
|
||||
|
||||
export interface NgModuleDef<T> {
|
||||
/**
|
||||
* A version of {@link NgModuleDef} that represents the runtime type shape only, and excludes
|
||||
* metadata parameters.
|
||||
*/
|
||||
export type NgModuleDefInternal<T> = NgModuleDef<T, any, any, any>;
|
||||
|
||||
/**
|
||||
* Runtime link information for NgModules.
|
||||
*
|
||||
* This is the internal data structure used by the runtime to assemble components, directives,
|
||||
* pipes, and injectors.
|
||||
*
|
||||
* NOTE: Always use `defineNgModule` function to create this object,
|
||||
* never create the object directly since the shape of this object
|
||||
* can change between versions.
|
||||
*/
|
||||
export interface NgModuleDef<T, Declarations, Imports, Exports> {
|
||||
/** Token representing the module. Used by DI. */
|
||||
type: T;
|
||||
|
||||
/** List of components to bootstrap. */
|
||||
bootstrap: Type<any>[];
|
||||
|
||||
/** List of components, directives, and pipes declared by this module. */
|
||||
declarations: Type<any>[];
|
||||
|
||||
/** List of modules or `ModuleWithProviders` imported by this module. */
|
||||
imports: Type<any>[];
|
||||
|
||||
/**
|
||||
* List of modules, `ModuleWithProviders`, components, directives, or pipes exported by this
|
||||
* module.
|
||||
*/
|
||||
exports: Type<any>[];
|
||||
|
||||
/**
|
||||
@ -42,18 +70,6 @@ export interface NgModuleDef<T> {
|
||||
transitiveCompileScopes: NgModuleTransitiveScopes|null;
|
||||
}
|
||||
|
||||
export function defineNgModule<T>(def: {type: T} & Partial<NgModuleDef<T>>): never {
|
||||
const res: NgModuleDef<T> = {
|
||||
type: def.type,
|
||||
bootstrap: def.bootstrap || [],
|
||||
declarations: def.declarations || [],
|
||||
imports: def.imports || [],
|
||||
exports: def.exports || [],
|
||||
transitiveCompileScopes: null,
|
||||
};
|
||||
return res as never;
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper around a module that also includes the providers.
|
||||
*
|
||||
@ -226,6 +242,14 @@ export interface NgModule {
|
||||
* `getModuleFactory`.
|
||||
*/
|
||||
id?: string;
|
||||
|
||||
/**
|
||||
* If true, this module will be skipped by the AOT compiler and so will always be compiled
|
||||
* using JIT.
|
||||
*
|
||||
* This exists to support future Ivy work and has no effect currently.
|
||||
*/
|
||||
jit?: true;
|
||||
}
|
||||
|
||||
function preR3NgModuleCompile(moduleType: InjectorType<any>, metadata: NgModule): void {
|
||||
|
Reference in New Issue
Block a user