| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 23:02:29 -07:00
										 |  |  | import {InjectorDef, InjectorType, defineInjector} from '../di/defs'; | 
					
						
							| 
									
										
										
										
											2018-02-16 08:45:21 -08:00
										 |  |  | import {convertInjectableProviderToFactory} from '../di/injectable'; | 
					
						
							|  |  |  | import {Provider} from '../di/provider'; | 
					
						
							| 
									
										
										
										
											2018-05-09 08:35:25 -07:00
										 |  |  | import {R3_COMPILE_NGMODULE} from '../ivy_switch'; | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  | import {Type} from '../type'; | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  | import {TypeDecorator, makeDecorator} from '../util/decorators'; | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-06 11:23:38 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Represents the expansion of an `NgModule` into its scopes. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * A scope is a set of directives and pipes that are visible in a particular context. Each | 
					
						
							|  |  |  |  * `NgModule` has two scopes. The `compilation` scope is the set of directives and pipes that will | 
					
						
							|  |  |  |  * be recognized in the templates of components declared by the module. The `exported` scope is the | 
					
						
							|  |  |  |  * set of directives and pipes exported by a module (that is, module B's exported scope gets added | 
					
						
							|  |  |  |  * to module A's compilation scope when module A imports B). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export interface NgModuleTransitiveScopes { | 
					
						
							|  |  |  |   compilation: {directives: Set<any>; pipes: Set<any>;}; | 
					
						
							|  |  |  |   exported: {directives: Set<any>; pipes: Set<any>;}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 08:35:25 -07:00
										 |  |  | export interface NgModuleDef<T> { | 
					
						
							|  |  |  |   type: T; | 
					
						
							|  |  |  |   bootstrap: Type<any>[]; | 
					
						
							|  |  |  |   declarations: Type<any>[]; | 
					
						
							|  |  |  |   imports: Type<any>[]; | 
					
						
							|  |  |  |   exports: Type<any>[]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-06 11:23:38 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Cached value of computed `transitiveCompileScopes` for this module. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * This should never be read directly, but accessed via `transitiveScopesFor`. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   transitiveCompileScopes: NgModuleTransitiveScopes|null; | 
					
						
							| 
									
										
										
										
											2018-05-09 08:35:25 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 || [], | 
					
						
							| 
									
										
										
										
											2018-06-06 11:23:38 -07:00
										 |  |  |     transitiveCompileScopes: null, | 
					
						
							| 
									
										
										
										
											2018-05-09 08:35:25 -07:00
										 |  |  |   }; | 
					
						
							|  |  |  |   return res as never; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-02-16 08:45:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-25 01:39:50 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * A wrapper around a module that also includes the providers. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-04-05 22:31:44 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-07-25 01:39:50 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | export interface ModuleWithProviders { | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |   ngModule: Type<any>; | 
					
						
							| 
									
										
										
										
											2016-08-24 13:39:44 -07:00
										 |  |  |   providers?: Provider[]; | 
					
						
							| 
									
										
										
										
											2016-07-25 01:39:50 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Interface for schema definitions in @NgModules. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export interface SchemaMetadata { name: string; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2016-08-23 10:52:40 -07:00
										 |  |  |  * Defines a schema that will allow: | 
					
						
							| 
									
										
										
										
											2016-10-03 18:19:03 +01:00
										 |  |  |  * - any non-Angular elements with a `-` in their name, | 
					
						
							| 
									
										
										
										
											2016-08-23 10:52:40 -07:00
										 |  |  |  * - any properties on elements with a `-` in their name which is the common rule for custom | 
					
						
							|  |  |  |  * elements. | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-04-05 22:31:44 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | export const CUSTOM_ELEMENTS_SCHEMA: SchemaMetadata = { | 
					
						
							|  |  |  |   name: 'custom-elements' | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 16:05:34 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Defines a schema that will allow any property on any element. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export const NO_ERRORS_SCHEMA: SchemaMetadata = { | 
					
						
							|  |  |  |   name: 'no-errors-schema' | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-29 02:10:30 -07:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |  * Type of the NgModule decorator / constructor function. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-04-05 22:31:44 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-07-29 02:10:30 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-09-12 19:14:17 -07:00
										 |  |  | export interface NgModuleDecorator { | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Defines an NgModule. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   (obj?: NgModule): TypeDecorator; | 
					
						
							|  |  |  |   new (obj?: NgModule): NgModule; | 
					
						
							| 
									
										
										
										
											2016-07-29 02:10:30 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |  * Type of the NgModule metadata. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-04-05 22:31:44 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  | export interface NgModule { | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Defines the set of injectable objects that are available in the injector | 
					
						
							|  |  |  |    * of this module. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * ## Simple Example | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Here is an example of a class that can be injected: | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * ```
 | 
					
						
							|  |  |  |    * class Greeter { | 
					
						
							|  |  |  |    *    greet(name:string) { | 
					
						
							|  |  |  |    *      return 'Hello ' + name + '!'; | 
					
						
							|  |  |  |    *    } | 
					
						
							|  |  |  |    * } | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |    * @NgModule({ | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |    *   providers: [ | 
					
						
							|  |  |  |    *     Greeter | 
					
						
							|  |  |  |    *   ] | 
					
						
							|  |  |  |    * }) | 
					
						
							|  |  |  |    * class HelloWorld { | 
					
						
							|  |  |  |    *   greeter:Greeter; | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    *   constructor(greeter:Greeter) { | 
					
						
							|  |  |  |    *     this.greeter = greeter; | 
					
						
							|  |  |  |    *   } | 
					
						
							|  |  |  |    * } | 
					
						
							|  |  |  |    * ```
 | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   providers?: Provider[]; | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |    * Specifies a list of directives/pipes that belong to this module. | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |    * | 
					
						
							|  |  |  |    * ### Example | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * ```javascript
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |    * @NgModule({ | 
					
						
							|  |  |  |    *   declarations: [NgFor] | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |    * }) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |    * class CommonModule { | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |    * } | 
					
						
							|  |  |  |    * ```
 | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   declarations?: Array<Type<any>|any[]>; | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |    * Specifies a list of modules whose exported directives/pipes | 
					
						
							|  |  |  |    * should be available to templates in this module. | 
					
						
							| 
									
										
										
										
											2016-07-25 01:39:50 -07:00
										 |  |  |    * This can also contain {@link ModuleWithProviders}. | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |    * | 
					
						
							|  |  |  |    * ### Example | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * ```javascript
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |    * @NgModule({ | 
					
						
							|  |  |  |    *   imports: [CommonModule] | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |    * }) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |    * class MainModule { | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |    * } | 
					
						
							|  |  |  |    * ```
 | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   imports?: Array<Type<any>|ModuleWithProviders|any[]>; | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							| 
									
										
										
										
											2016-10-03 18:19:03 +01:00
										 |  |  |    * Specifies a list of directives/pipes/modules that can be used within the template | 
					
						
							|  |  |  |    * of any component that is part of an Angular module | 
					
						
							|  |  |  |    * that imports this Angular module. | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |    * | 
					
						
							|  |  |  |    * ### Example | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * ```javascript
 | 
					
						
							|  |  |  |    * @NgModule({ | 
					
						
							|  |  |  |    *   exports: [NgFor] | 
					
						
							|  |  |  |    * }) | 
					
						
							|  |  |  |    * class CommonModule { | 
					
						
							|  |  |  |    * } | 
					
						
							|  |  |  |    * ```
 | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   exports?: Array<Type<any>|any[]>; | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							| 
									
										
										
										
											2016-10-03 18:19:03 +01:00
										 |  |  |    * Specifies a list of components that should be compiled when this module is defined. | 
					
						
							|  |  |  |    * For each component listed here, Angular will create a {@link ComponentFactory} | 
					
						
							|  |  |  |    * and store it in the {@link ComponentFactoryResolver}. | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   entryComponents?: Array<Type<any>|any[]>; | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 06:54:08 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Defines the components that should be bootstrapped when | 
					
						
							|  |  |  |    * this module is bootstrapped. The components listed here | 
					
						
							|  |  |  |    * will automatically be added to `entryComponents`. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   bootstrap?: Array<Type<any>|any[]>; | 
					
						
							| 
									
										
										
										
											2016-08-02 06:54:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-23 10:52:40 -07:00
										 |  |  |   /** | 
					
						
							| 
									
										
										
										
											2016-10-03 18:19:03 +01:00
										 |  |  |    * Elements and properties that are not Angular components nor directives have to be declared in | 
					
						
							| 
									
										
										
										
											2016-08-23 10:52:40 -07:00
										 |  |  |    * the schema. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Available schemas: | 
					
						
							|  |  |  |    * - `NO_ERRORS_SCHEMA`: any elements and properties are allowed, | 
					
						
							|  |  |  |    * - `CUSTOM_ELEMENTS_SCHEMA`: any custom elements (tag name has "-") with any properties are | 
					
						
							|  |  |  |    *   allowed. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @security When using one of `NO_ERRORS_SCHEMA` or `CUSTOM_ELEMENTS_SCHEMA` we're trusting that | 
					
						
							|  |  |  |    * allowed elements (and its properties) securely escape inputs. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   schemas?: Array<SchemaMetadata|any[]>; | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-01 13:46:08 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * An opaque ID for this module, e.g. a name or a path. Used to identify modules in | 
					
						
							|  |  |  |    * `getModuleFactory`. If left `undefined`, the `NgModule` will not be registered with | 
					
						
							|  |  |  |    * `getModuleFactory`. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   id?: string; | 
					
						
							| 
									
										
										
										
											2016-06-28 09:54:42 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 08:35:25 -07:00
										 |  |  | function preR3NgModuleCompile(moduleType: InjectorType<any>, metadata: NgModule): void { | 
					
						
							|  |  |  |   let imports = (metadata && metadata.imports) || []; | 
					
						
							|  |  |  |   if (metadata && metadata.exports) { | 
					
						
							|  |  |  |     imports = [...imports, metadata.exports]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   moduleType.ngInjectorDef = defineInjector({ | 
					
						
							|  |  |  |     factory: convertInjectableProviderToFactory(moduleType, {useClass: moduleType}), | 
					
						
							|  |  |  |     providers: metadata && metadata.providers, | 
					
						
							|  |  |  |     imports: imports, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2016-10-03 18:19:03 +01:00
										 |  |  |  * NgModule decorator and metadata. | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-04-05 22:31:44 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |  * @Annotation | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-02-16 08:45:21 -08:00
										 |  |  | export const NgModule: NgModuleDecorator = makeDecorator( | 
					
						
							|  |  |  |     'NgModule', (ngModule: NgModule) => ngModule, undefined, undefined, | 
					
						
							| 
									
										
										
										
											2018-05-09 08:35:25 -07:00
										 |  |  |     (type: Type<any>, meta: NgModule) => (R3_COMPILE_NGMODULE || preR3NgModuleCompile)(type, meta)); |