2016-06-23 12:47:54 -04: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
|
|
|
|
*/
|
|
|
|
|
2017-03-21 16:36:42 -04:00
|
|
|
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, NgModuleRef, QueryList, Renderer, SecurityContext, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation, ɵCodegenComponentFactoryResolver, ɵEMPTY_ARRAY, ɵEMPTY_MAP, ɵNgModuleInjector, ɵand, ɵccf, ɵcrt, ɵdid, ɵeld, ɵinlineInterpolate, ɵinterpolate, ɵncd, ɵnov, ɵpad, ɵpid, ɵpod, ɵppd, ɵprd, ɵqud, ɵreflector, ɵregisterModuleFactory, ɵted, ɵunv, ɵvid} from '@angular/core';
|
2016-08-22 20:18:25 -04:00
|
|
|
|
2017-01-04 16:59:43 -05:00
|
|
|
import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2017-02-14 16:33:06 -05:00
|
|
|
const CORE = assetUrl('core');
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2016-08-24 20:39:49 -04:00
|
|
|
export interface IdentifierSpec {
|
|
|
|
name: string;
|
|
|
|
moduleUrl: string;
|
|
|
|
runtime: any;
|
|
|
|
}
|
|
|
|
|
2016-01-06 17:13:44 -05:00
|
|
|
export class Identifiers {
|
2016-08-24 20:39:49 -04:00
|
|
|
static ANALYZE_FOR_ENTRY_COMPONENTS: IdentifierSpec = {
|
2016-07-25 03:36:30 -04:00
|
|
|
name: 'ANALYZE_FOR_ENTRY_COMPONENTS',
|
2017-02-14 16:33:06 -05:00
|
|
|
moduleUrl: CORE,
|
2016-07-25 03:36:30 -04:00
|
|
|
runtime: ANALYZE_FOR_ENTRY_COMPONENTS
|
2016-08-24 20:39:49 -04:00
|
|
|
};
|
2017-02-14 16:33:06 -05:00
|
|
|
static ElementRef: IdentifierSpec = {name: 'ElementRef', moduleUrl: CORE, runtime: ElementRef};
|
2017-03-14 19:26:17 -04:00
|
|
|
static NgModuleRef: IdentifierSpec = {name: 'NgModuleRef', moduleUrl: CORE, runtime: NgModuleRef};
|
2017-02-14 16:33:06 -05:00
|
|
|
static ViewContainerRef:
|
|
|
|
IdentifierSpec = {name: 'ViewContainerRef', moduleUrl: CORE, runtime: ViewContainerRef};
|
|
|
|
static ChangeDetectorRef:
|
|
|
|
IdentifierSpec = {name: 'ChangeDetectorRef', moduleUrl: CORE, runtime: ChangeDetectorRef};
|
|
|
|
static QueryList: IdentifierSpec = {name: 'QueryList', moduleUrl: CORE, runtime: QueryList};
|
|
|
|
static TemplateRef: IdentifierSpec = {name: 'TemplateRef', moduleUrl: CORE, runtime: TemplateRef};
|
2016-08-24 20:39:49 -04:00
|
|
|
static CodegenComponentFactoryResolver: IdentifierSpec = {
|
2017-02-14 16:33:06 -05:00
|
|
|
name: 'ɵCodegenComponentFactoryResolver',
|
|
|
|
moduleUrl: CORE,
|
|
|
|
runtime: ɵCodegenComponentFactoryResolver
|
2016-08-24 20:39:49 -04:00
|
|
|
};
|
|
|
|
static ComponentFactoryResolver: IdentifierSpec = {
|
2016-06-22 17:06:23 -04:00
|
|
|
name: 'ComponentFactoryResolver',
|
2017-02-14 16:33:06 -05:00
|
|
|
moduleUrl: CORE,
|
2016-06-22 17:06:23 -04:00
|
|
|
runtime: ComponentFactoryResolver
|
2016-08-24 20:39:49 -04:00
|
|
|
};
|
2017-02-14 16:33:06 -05:00
|
|
|
static ComponentFactory:
|
|
|
|
IdentifierSpec = {name: 'ComponentFactory', moduleUrl: CORE, runtime: ComponentFactory};
|
|
|
|
static ComponentRef:
|
|
|
|
IdentifierSpec = {name: 'ComponentRef', moduleUrl: CORE, runtime: ComponentRef};
|
|
|
|
static NgModuleFactory:
|
|
|
|
IdentifierSpec = {name: 'NgModuleFactory', moduleUrl: CORE, runtime: NgModuleFactory};
|
2016-08-24 20:39:49 -04:00
|
|
|
static NgModuleInjector: IdentifierSpec = {
|
2017-02-14 16:33:06 -05:00
|
|
|
name: 'ɵNgModuleInjector',
|
|
|
|
moduleUrl: CORE,
|
|
|
|
runtime: ɵNgModuleInjector,
|
2016-08-24 20:39:49 -04:00
|
|
|
};
|
2016-09-01 16:46:08 -04:00
|
|
|
static RegisterModuleFactoryFn: IdentifierSpec = {
|
2017-02-14 16:33:06 -05:00
|
|
|
name: 'ɵregisterModuleFactory',
|
|
|
|
moduleUrl: CORE,
|
|
|
|
runtime: ɵregisterModuleFactory,
|
2016-09-01 16:46:08 -04:00
|
|
|
};
|
2017-02-14 16:33:06 -05:00
|
|
|
static Injector: IdentifierSpec = {name: 'Injector', moduleUrl: CORE, runtime: Injector};
|
|
|
|
static ViewEncapsulation:
|
|
|
|
IdentifierSpec = {name: 'ViewEncapsulation', moduleUrl: CORE, runtime: ViewEncapsulation};
|
2016-08-24 20:39:49 -04:00
|
|
|
static ChangeDetectionStrategy: IdentifierSpec = {
|
2016-01-06 17:13:44 -05:00
|
|
|
name: 'ChangeDetectionStrategy',
|
2017-02-14 16:33:06 -05:00
|
|
|
moduleUrl: CORE,
|
2016-08-29 11:52:25 -04:00
|
|
|
runtime: ChangeDetectionStrategy
|
2016-08-24 20:39:49 -04:00
|
|
|
};
|
|
|
|
static SecurityContext: IdentifierSpec = {
|
feat: security implementation in Angular 2.
Summary:
This adds basic security hooks to Angular 2.
* `SecurityContext` is a private API between core, compiler, and
platform-browser. `SecurityContext` communicates what context a value is used
in across template parser, compiler, and sanitization at runtime.
* `SanitizationService` is the bare bones interface to sanitize values for a
particular context.
* `SchemaElementRegistry.securityContext(tagName, attributeOrPropertyName)`
determines the security context for an attribute or property (it turns out
attributes and properties match for the purposes of sanitization).
Based on these hooks:
* `DomSchemaElementRegistry` decides what sanitization applies in a particular
context.
* `DomSanitizationService` implements `SanitizationService` and adds *Safe
Value*s, i.e. the ability to mark a value as safe and not requiring further
sanitization.
* `url_sanitizer` and `style_sanitizer` sanitize URLs and Styles, respectively
(surprise!).
`DomSanitizationService` is the default implementation bound for browser
applications, in the three contexts (browser rendering, web worker rendering,
server side rendering).
BREAKING CHANGES:
*** SECURITY WARNING ***
Angular 2 Release Candidates do not implement proper contextual escaping yet.
Make sure to correctly escape all values that go into the DOM.
*** SECURITY WARNING ***
Reviewers: IgorMinar
Differential Revision: https://reviews.angular.io/D103
2016-04-29 19:04:08 -04:00
|
|
|
name: 'SecurityContext',
|
2017-02-14 16:33:06 -05:00
|
|
|
moduleUrl: CORE,
|
feat: security implementation in Angular 2.
Summary:
This adds basic security hooks to Angular 2.
* `SecurityContext` is a private API between core, compiler, and
platform-browser. `SecurityContext` communicates what context a value is used
in across template parser, compiler, and sanitization at runtime.
* `SanitizationService` is the bare bones interface to sanitize values for a
particular context.
* `SchemaElementRegistry.securityContext(tagName, attributeOrPropertyName)`
determines the security context for an attribute or property (it turns out
attributes and properties match for the purposes of sanitization).
Based on these hooks:
* `DomSchemaElementRegistry` decides what sanitization applies in a particular
context.
* `DomSanitizationService` implements `SanitizationService` and adds *Safe
Value*s, i.e. the ability to mark a value as safe and not requiring further
sanitization.
* `url_sanitizer` and `style_sanitizer` sanitize URLs and Styles, respectively
(surprise!).
`DomSanitizationService` is the default implementation bound for browser
applications, in the three contexts (browser rendering, web worker rendering,
server side rendering).
BREAKING CHANGES:
*** SECURITY WARNING ***
Angular 2 Release Candidates do not implement proper contextual escaping yet.
Make sure to correctly escape all values that go into the DOM.
*** SECURITY WARNING ***
Reviewers: IgorMinar
Differential Revision: https://reviews.angular.io/D103
2016-04-29 19:04:08 -04:00
|
|
|
runtime: SecurityContext,
|
2016-08-24 20:39:49 -04:00
|
|
|
};
|
2017-02-14 16:33:06 -05:00
|
|
|
static LOCALE_ID: IdentifierSpec = {name: 'LOCALE_ID', moduleUrl: CORE, runtime: LOCALE_ID};
|
|
|
|
static TRANSLATIONS_FORMAT:
|
|
|
|
IdentifierSpec = {name: 'TRANSLATIONS_FORMAT', moduleUrl: CORE, runtime: TRANSLATIONS_FORMAT};
|
2017-02-28 02:08:19 -05:00
|
|
|
static inlineInterpolate:
|
|
|
|
IdentifierSpec = {name: 'ɵinlineInterpolate', moduleUrl: CORE, runtime: ɵinlineInterpolate};
|
|
|
|
static interpolate:
|
|
|
|
IdentifierSpec = {name: 'ɵinterpolate', moduleUrl: CORE, runtime: ɵinterpolate};
|
|
|
|
static EMPTY_ARRAY:
|
2017-02-28 17:16:26 -05:00
|
|
|
IdentifierSpec = {name: 'ɵEMPTY_ARRAY', moduleUrl: CORE, runtime: ɵEMPTY_ARRAY};
|
|
|
|
static EMPTY_MAP: IdentifierSpec = {name: 'ɵEMPTY_MAP', moduleUrl: CORE, runtime: ɵEMPTY_MAP};
|
2017-02-28 02:08:19 -05:00
|
|
|
static Renderer: IdentifierSpec = {name: 'Renderer', moduleUrl: CORE, runtime: Renderer};
|
2017-02-27 16:28:41 -05:00
|
|
|
static viewDef: IdentifierSpec = {name: 'ɵvid', moduleUrl: CORE, runtime: ɵvid};
|
|
|
|
static elementDef: IdentifierSpec = {name: 'ɵeld', moduleUrl: CORE, runtime: ɵeld};
|
|
|
|
static anchorDef: IdentifierSpec = {name: 'ɵand', moduleUrl: CORE, runtime: ɵand};
|
|
|
|
static textDef: IdentifierSpec = {name: 'ɵted', moduleUrl: CORE, runtime: ɵted};
|
|
|
|
static directiveDef: IdentifierSpec = {name: 'ɵdid', moduleUrl: CORE, runtime: ɵdid};
|
|
|
|
static providerDef: IdentifierSpec = {name: 'ɵprd', moduleUrl: CORE, runtime: ɵprd};
|
|
|
|
static queryDef: IdentifierSpec = {name: 'ɵqud', moduleUrl: CORE, runtime: ɵqud};
|
|
|
|
static pureArrayDef: IdentifierSpec = {name: 'ɵpad', moduleUrl: CORE, runtime: ɵpad};
|
|
|
|
static pureObjectDef: IdentifierSpec = {name: 'ɵpod', moduleUrl: CORE, runtime: ɵpod};
|
|
|
|
static purePipeDef: IdentifierSpec = {name: 'ɵppd', moduleUrl: CORE, runtime: ɵppd};
|
|
|
|
static pipeDef: IdentifierSpec = {name: 'ɵpid', moduleUrl: CORE, runtime: ɵpid};
|
|
|
|
static nodeValue: IdentifierSpec = {name: 'ɵnov', moduleUrl: CORE, runtime: ɵnov};
|
|
|
|
static ngContentDef: IdentifierSpec = {name: 'ɵncd', moduleUrl: CORE, runtime: ɵncd};
|
|
|
|
static unwrapValue: IdentifierSpec = {name: 'ɵunv', moduleUrl: CORE, runtime: ɵunv};
|
2017-03-07 19:36:12 -05:00
|
|
|
static createRendererType2: IdentifierSpec = {name: 'ɵcrt', moduleUrl: CORE, runtime: ɵcrt};
|
|
|
|
static RendererType2: IdentifierSpec = {
|
|
|
|
name: 'RendererType2',
|
2017-02-17 11:56:49 -05:00
|
|
|
moduleUrl: CORE,
|
|
|
|
// type only
|
|
|
|
runtime: null
|
|
|
|
};
|
|
|
|
static ViewDefinition: IdentifierSpec = {
|
2017-02-19 00:28:27 -05:00
|
|
|
name: 'ɵViewDefinition',
|
2017-02-17 11:56:49 -05:00
|
|
|
moduleUrl: CORE,
|
|
|
|
// type only
|
|
|
|
runtime: null
|
|
|
|
};
|
2017-02-27 16:28:41 -05:00
|
|
|
static createComponentFactory: IdentifierSpec = {name: 'ɵccf', moduleUrl: CORE, runtime: ɵccf};
|
2016-10-19 12:17:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function assetUrl(pkg: string, path: string = null, type: string = 'src'): string {
|
|
|
|
if (path == null) {
|
2017-02-14 16:33:06 -05:00
|
|
|
return `@angular/${pkg}`;
|
2016-10-19 12:17:36 -04:00
|
|
|
} else {
|
2016-11-15 13:14:01 -05:00
|
|
|
return `@angular/${pkg}/${type}/${path}`;
|
2016-10-19 12:17:36 -04:00
|
|
|
}
|
2016-08-24 20:39:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function resolveIdentifier(identifier: IdentifierSpec) {
|
2017-02-14 16:33:06 -05:00
|
|
|
let name = identifier.name;
|
2017-01-27 20:39:48 -05:00
|
|
|
return ɵreflector.resolveIdentifier(name, identifier.moduleUrl, null, identifier.runtime);
|
2016-11-23 12:42:19 -05:00
|
|
|
}
|
|
|
|
|
2016-11-30 13:52:51 -05:00
|
|
|
export function createIdentifier(identifier: IdentifierSpec): CompileIdentifierMetadata {
|
2017-02-14 16:33:06 -05:00
|
|
|
return {reference: resolveIdentifier(identifier)};
|
2016-01-06 17:13:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function identifierToken(identifier: CompileIdentifierMetadata): CompileTokenMetadata {
|
2016-11-30 13:52:51 -05:00
|
|
|
return {identifier: identifier};
|
2016-01-06 17:13:44 -05:00
|
|
|
}
|
2016-08-24 20:39:49 -04:00
|
|
|
|
2016-11-23 12:42:19 -05:00
|
|
|
export function createIdentifierToken(identifier: IdentifierSpec): CompileTokenMetadata {
|
|
|
|
return identifierToken(createIdentifier(identifier));
|
2016-08-24 20:39:49 -04:00
|
|
|
}
|
|
|
|
|
2016-11-23 12:42:19 -05:00
|
|
|
export function createEnumIdentifier(
|
|
|
|
enumType: IdentifierSpec, name: string): CompileIdentifierMetadata {
|
2017-02-14 16:33:06 -05:00
|
|
|
const resolvedEnum = ɵreflector.resolveEnum(resolveIdentifier(enumType), name);
|
2016-11-30 13:52:51 -05:00
|
|
|
return {reference: resolvedEnum};
|
2016-08-30 21:07:40 -04:00
|
|
|
}
|