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:
Alex Rickabaugh
2018-05-31 15:50:02 -07:00
committed by Miško Hevery
parent 0f7e4fae20
commit 27bc7dcb43
69 changed files with 1884 additions and 607 deletions

View File

@ -54,6 +54,12 @@ export const enum DirectiveDefFlags {ContentQuery = 0b10}
*/
export interface PipeType<T> extends Type<T> { ngPipeDef: never; }
/**
* A version of {@link DirectiveDef} that represents the runtime type shape only, and excludes
* metadata parameters.
*/
export type DirectiveDefInternal<T> = DirectiveDef<T, string>;
/**
* Runtime link information for Directives.
*
@ -64,14 +70,16 @@ export interface PipeType<T> extends Type<T> { ngPipeDef: never; }
* never create the object directly since the shape of this object
* can change between versions.
*
* @param Selector type metadata specifying the selector of the directive or component
*
* See: {@link defineDirective}
*/
export interface DirectiveDef<T> {
export interface DirectiveDef<T, Selector extends string> {
/** Token representing the directive. Used by DI. */
type: Type<T>;
/** Function that makes a directive public to the DI system. */
diPublic: ((def: DirectiveDef<any>) => void)|null;
diPublic: ((def: DirectiveDef<any, string>) => void)|null;
/** The selectors that will be used to match nodes to this directive. */
selectors: CssSelectorList;
@ -124,6 +132,12 @@ export interface DirectiveDef<T> {
onDestroy: (() => void)|null;
}
/**
* A version of {@link ComponentDef} that represents the runtime type shape only, and excludes
* metadata parameters.
*/
export type ComponentDefInternal<T> = ComponentDef<T, string>;
/**
* Runtime link information for Components.
*
@ -136,7 +150,7 @@ export interface DirectiveDef<T> {
*
* See: {@link defineComponent}
*/
export interface ComponentDef<T> extends DirectiveDef<T> {
export interface ComponentDef<T, Selector extends string> extends DirectiveDef<T, Selector> {
/**
* The View template of the component.
*
@ -220,8 +234,8 @@ export interface PipeDef<T> {
onDestroy: (() => void)|null;
}
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T, string>) => void;
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T, string>) => void;
/**
* Type used for directiveDefs on component definition.
@ -230,12 +244,12 @@ export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
*/
export type DirectiveDefListOrFactory = (() => DirectiveDefList) | DirectiveDefList;
export type DirectiveDefList = (DirectiveDef<any>| ComponentDef<any>)[];
export type DirectiveDefList = (DirectiveDef<any, string>| ComponentDef<any, string>)[];
export type DirectiveTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
export type DirectiveTypeList =
(DirectiveDef<any>| ComponentDef<any>|
(DirectiveDef<any, string>| ComponentDef<any, string>|
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
/**

View File

@ -10,7 +10,7 @@ import {Injector} from '../../di/injector';
import {Sanitizer} from '../../sanitization/security';
import {LContainer} from './container';
import {ComponentTemplate, DirectiveDef, DirectiveDefList, PipeDef, PipeDefList} from './definition';
import {ComponentTemplate, DirectiveDefInternal, DirectiveDefList, PipeDef, PipeDefList} from './definition';
import {LElementNode, LViewNode, TNode} from './node';
import {LQueries} from './query';
import {Renderer3} from './renderer';
@ -443,7 +443,7 @@ export type HookData = (number | (() => void))[];
export type TData = (TNode | PipeDef<any>| null)[];
/** Type for TView.currentMatches */
export type CurrentMatchesList = [DirectiveDef<any>, (string | number | null)];
export type CurrentMatchesList = [DirectiveDefInternal<any>, (string | number | null)];
// Note: This hack is necessary so we don't erroneously get a circular dependency
// failure based on types.