feat(ivy): add `ngcc` ivy switch (#25238)

Provides a runtime and compile time switch for ivy including
`ApplicationRef.bootstrapModule`.

This is done by naming the symbols such that `ngcc` (angular
Compatibility compiler) can rename symbols in such a way that running
`ngcc` command will switch the `@angular/core` module from `legacy` to
`ivy` mode.

This is done as follows:

```
const someToken__PRE_NGCC__ = ‘legacy mode’;
const someToken__POST_NGCC__ = ‘ivy mode’;

export someSymbol = someToken__PRE_NGCC__;
```

The `ngcc` will search for any token which ends with `__PRE_NGCC__`
and replace it with `__POST_NGCC__`. This allows the `@angular/core`
package to be rewritten to ivy mode post `ngcc` execution.

PR Close #25238
This commit is contained in:
Misko Hevery 2018-07-30 22:34:15 -07:00 committed by Jason Aden
parent cc55d609ce
commit 503905c807
23 changed files with 298 additions and 201 deletions

View File

@ -38,7 +38,9 @@ const MISSING_FROM_CHROME: {[el: string]: string[]} = {
':svg:cursor^:svg:': [],
};
const _G: any = global;
const _G: any = typeof window != 'undefined' && window || typeof global != 'undefined' && global ||
typeof self != 'undefined' && self;
const document: any = typeof _G['document'] == 'object' ? _G['document'] : null;
export function extractSchema(): Map<string, string[]>|null {

View File

@ -9,59 +9,50 @@
import {Observable, Observer, Subscription, merge} from 'rxjs';
import {share} from 'rxjs/operators';
import {ErrorHandler} from '../src/error_handler';
import {scheduleMicroTask, stringify} from '../src/util';
import {isPromise} from '../src/util/lang';
import {ApplicationInitStatus} from './application_init';
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
import {Console} from './console';
import {Injectable, InjectionToken, Injector, StaticProvider} from './di';
import {ErrorHandler} from './error_handler';
import {isDevMode} from './is_dev_mode';
import {CompilerFactory, CompilerOptions} from './linker/compiler';
import {ComponentFactory, ComponentRef} from './linker/component_factory';
import {ComponentFactoryBoundToModule, ComponentFactoryResolver} from './linker/component_factory_resolver';
import {InternalNgModuleRef, NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';
import {InternalViewRef, ViewRef} from './linker/view_ref';
import {WtfScopeFn, wtfCreateScope, wtfLeave} from './profile/profile';
import {assertNgModuleType} from './render3/assert';
import {NgModuleFactory as R3NgModuleFactory} from './render3/ng_module_ref';
import {Testability, TestabilityRegistry} from './testability/testability';
import {Type} from './type';
import {scheduleMicroTask, stringify} from './util';
import {isPromise} from './util/lang';
import {NgZone, NoopNgZone} from './zone/ng_zone';
let _devMode: boolean = true;
let _runModeLocked: boolean = false;
let _platform: PlatformRef;
let compileNgModuleFactory:
<M>(injector: Injector, options: CompilerOptions, moduleType: Type<M>) =>
Promise<NgModuleFactory<M>> = compileNgModuleFactory__PRE_NGCC__;
function compileNgModuleFactory__PRE_NGCC__<M>(
injector: Injector, options: CompilerOptions,
moduleType: Type<M>): Promise<NgModuleFactory<M>> {
const compilerFactory: CompilerFactory = injector.get(CompilerFactory);
const compiler = compilerFactory.createCompiler([options]);
return compiler.compileModuleAsync(moduleType);
}
function compileNgModuleFactory__POST_NGCC__<M>(
injector: Injector, options: CompilerOptions,
moduleType: Type<M>): Promise<NgModuleFactory<M>> {
ngDevMode && assertNgModuleType(moduleType);
return Promise.resolve(new R3NgModuleFactory(moduleType));
}
export const ALLOW_MULTIPLE_PLATFORMS = new InjectionToken<boolean>('AllowMultipleToken');
/**
* Disable Angular's development mode, which turns off assertions and other
* checks within the framework.
*
* One important assertion this disables verifies that a change detection pass
* does not result in additional changes to any bindings (also known as
* unidirectional data flow).
*
*
*/
export function enableProdMode(): void {
if (_runModeLocked) {
throw new Error('Cannot enable prod mode after platform setup.');
}
_devMode = false;
}
/**
* Returns whether Angular is in development mode. After called once,
* the value is locked and won't change any more.
*
* By default, this is true, unless a user calls `enableProdMode` before calling this.
*
* @experimental APIs related to application bootstrap are currently under review.
*/
export function isDevMode(): boolean {
_runModeLocked = true;
return _devMode;
}
/**
* A token for third-party components that can register themselves with NgProbe.
@ -267,12 +258,9 @@ export class PlatformRef {
bootstrapModule<M>(
moduleType: Type<M>, compilerOptions: (CompilerOptions&BootstrapOptions)|
Array<CompilerOptions&BootstrapOptions> = []): Promise<NgModuleRef<M>> {
const compilerFactory: CompilerFactory = this.injector.get(CompilerFactory);
const options = optionsReducer({}, compilerOptions);
const compiler = compilerFactory.createCompiler([options]);
return compiler.compileModuleAsync(moduleType)
.then((moduleFactory) => this.bootstrapModuleFactory(moduleFactory, options));
return compileNgModuleFactory(this.injector, options, moduleType)
.then(moduleFactory => this.bootstrapModuleFactory(moduleFactory, options));
}
private _moduleDoBootstrap(moduleRef: InternalNgModuleRef<any>): void {

View File

@ -15,7 +15,8 @@ export * from './metadata';
export * from './version';
export {TypeDecorator} from './util/decorators';
export * from './di';
export {createPlatform, assertPlatform, destroyPlatform, getPlatform, PlatformRef, ApplicationRef, enableProdMode, isDevMode, createPlatformFactory, NgProbeToken} from './application_ref';
export {createPlatform, assertPlatform, destroyPlatform, getPlatform, PlatformRef, ApplicationRef, createPlatformFactory, NgProbeToken} from './application_ref';
export {enableProdMode, isDevMode} from './is_dev_mode';
export {APP_ID, PACKAGE_ROOT_URL, PLATFORM_INITIALIZER, PLATFORM_ID, APP_BOOTSTRAP_LISTENER} from './application_tokens';
export {APP_INITIALIZER, ApplicationInitStatus} from './application_init';
export * from './zone';

View File

@ -120,9 +120,10 @@ export {
I18nInstruction as ɵI18nInstruction,
I18nExpInstruction as ɵI18nExpInstruction,
WRAP_RENDERER_FACTORY2 as ɵWRAP_RENDERER_FACTORY2,
Render3DebugRendererFactory2 as ɵRender3DebugRendererFactory2,
} from './render3/index';
export { Render3DebugRendererFactory2 as ɵRender3DebugRendererFactory2 } from './render3/debug';
export {
compileNgModuleDefs as ɵcompileNgModuleDefs,

View File

@ -7,18 +7,11 @@
*/
import {R3_COMPILE_INJECTABLE} from '../ivy_switch';
import {ReflectionCapabilities} from '../reflection/reflection_capabilities';
import {Type} from '../type';
import {makeDecorator, makeParamDecorator} from '../util/decorators';
import {getClosureSafeProperty} from '../util/property';
import {makeDecorator} from '../util/decorators';
import {InjectableDef, InjectableType, defineInjectable} from './defs';
import {inject, injectArgs} from './injector';
import {ClassSansProvider, ConstructorProvider, ConstructorSansProvider, ExistingProvider, ExistingSansProvider, FactoryProvider, FactorySansProvider, StaticClassProvider, StaticClassSansProvider, ValueProvider, ValueSansProvider} from './provider';
const GET_PROPERTY_NAME = {} as any;
const USE_VALUE = getClosureSafeProperty<ValueProvider>(
{provide: String, useValue: GET_PROPERTY_NAME}, GET_PROPERTY_NAME);
import {InjectableDef, InjectableType} from './defs';
import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueProvider, ValueSansProvider} from './provider';
/**
* Injectable providers used in `@Injectable` decorator.
@ -61,67 +54,16 @@ export interface InjectableDecorator {
*/
export interface Injectable { providedIn?: Type<any>|'root'|null; }
const EMPTY_ARRAY: any[] = [];
export function convertInjectableProviderToFactory(
type: Type<any>, provider?: InjectableProvider): () => any {
if (!provider) {
const reflectionCapabilities = new ReflectionCapabilities();
const deps = reflectionCapabilities.parameters(type);
// TODO - convert to flags.
return () => new type(...injectArgs(deps as any[]));
}
if (USE_VALUE in provider) {
const valueProvider = (provider as ValueSansProvider);
return () => valueProvider.useValue;
} else if ((provider as ExistingSansProvider).useExisting) {
const existingProvider = (provider as ExistingSansProvider);
return () => inject(existingProvider.useExisting);
} else if ((provider as FactorySansProvider).useFactory) {
const factoryProvider = (provider as FactorySansProvider);
return () => factoryProvider.useFactory(...injectArgs(factoryProvider.deps || EMPTY_ARRAY));
} else if ((provider as StaticClassSansProvider | ClassSansProvider).useClass) {
const classProvider = (provider as StaticClassSansProvider | ClassSansProvider);
let deps = (provider as StaticClassSansProvider).deps;
if (!deps) {
const reflectionCapabilities = new ReflectionCapabilities();
deps = reflectionCapabilities.parameters(type);
}
return () => new classProvider.useClass(...injectArgs(deps));
} else {
let deps = (provider as ConstructorSansProvider).deps;
if (!deps) {
const reflectionCapabilities = new ReflectionCapabilities();
deps = reflectionCapabilities.parameters(type);
}
return () => new type(...injectArgs(deps !));
}
}
/**
* Supports @Injectable() in JIT mode for Render2.
*/
function preR3InjectableCompile(
injectableType: InjectableType<any>,
options: {providedIn?: Type<any>| 'root' | null} & InjectableProvider): void {
if (options && options.providedIn !== undefined && injectableType.ngInjectableDef === undefined) {
injectableType.ngInjectableDef = defineInjectable({
providedIn: options.providedIn,
factory: convertInjectableProviderToFactory(injectableType, options),
});
}
}
/**
* Injectable decorator and metadata.
*
* @Annotation
*/
export const Injectable: InjectableDecorator = makeDecorator(
'Injectable', undefined, undefined, undefined,
(type: Type<any>, meta: Injectable) =>
(R3_COMPILE_INJECTABLE || preR3InjectableCompile)(type, meta));
'Injectable', undefined, undefined, undefined, (type: Type<any>, meta: Injectable) => {
debugger;
return R3_COMPILE_INJECTABLE(type, meta);
});
/**
* Type representing injectable service.

View File

@ -0,0 +1,46 @@
/**
* @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
*/
/**
* This file is used to control if the default rendering pipeline should be `ViewEngine` or `Ivy`.
*
* For more information on how to run and debug tests with either Ivy or View Engine (legacy),
* please see [BAZEL.md](./docs/BAZEL.md).
*/
let _devMode: boolean = true;
let _runModeLocked: boolean = false;
/**
* Returns whether Angular is in development mode. After called once,
* the value is locked and won't change any more.
*
* By default, this is true, unless a user calls `enableProdMode` before calling this.
*
* @experimental APIs related to application bootstrap are currently under review.
*/
export function isDevMode(): boolean {
_runModeLocked = true;
return _devMode;
}
/**
* Disable Angular's development mode, which turns off assertions and other
* checks within the framework.
*
* One important assertion this disables verifies that a change detection pass
* does not result in additional changes to any bindings (also known as
* unidirectional data flow).
*/
export function enableProdMode(): void {
if (_runModeLocked) {
throw new Error('Cannot enable prod mode after platform setup.');
}
_devMode = false;
}

View File

@ -6,9 +6,116 @@
* found in the LICENSE file at https://angular.io/license
*/
export const ivyEnabled = false;
export const R3_COMPILE_COMPONENT: ((type: any, meta: any) => void)|null = null;
export const R3_COMPILE_DIRECTIVE: ((type: any, meta: any) => void)|null = null;
export const R3_COMPILE_INJECTABLE: ((type: any, meta: any) => void)|null = null;
export const R3_COMPILE_NGMODULE: ((type: any, meta: any) => void)|null = null;
export const R3_COMPILE_PIPE: ((type: any, meta: any) => void)|null = null;
import {InjectableType, InjectorType, defineInjectable, defineInjector} from './di/defs';
import {InjectableProvider} from './di/injectable';
import {inject, injectArgs} from './di/injector';
import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueProvider, ValueSansProvider} from './di/provider';
import * as ivyOn from './ivy_switch_on';
import {NgModule} from './metadata';
import {ReflectionCapabilities} from './reflection/reflection_capabilities';
import {Type} from './type';
import {getClosureSafeProperty} from './util/property';
function noop() {}
export interface DirectiveCompiler { (type: any, meta: any): void; }
const R3_COMPILE_COMPONENT__POST_NGCC__ = ivyOn.R3_COMPILE_COMPONENT;
const R3_COMPILE_DIRECTIVE__POST_NGCC__ = ivyOn.R3_COMPILE_DIRECTIVE;
const R3_COMPILE_INJECTABLE__POST_NGCC__ = ivyOn.R3_COMPILE_INJECTABLE;
const R3_COMPILE_NGMODULE__POST_NGCC__ = ivyOn.R3_COMPILE_NGMODULE;
const R3_COMPILE_PIPE__POST_NGCC__ = ivyOn.R3_COMPILE_PIPE;
const ivyEnable__POST_NGCC__ = ivyOn.ivyEnabled;
const compileComponentQueue: any[] = [];
const compileDirectiveQueue: any[] = [];
const compileInjectableQueue: any[] = [];
const compileNgModuleQueue: any[] = [];
const compilePipeQueue: any[] = [];
const R3_COMPILE_COMPONENT__PRE_NGCC__: DirectiveCompiler = noop;
const R3_COMPILE_DIRECTIVE__PRE_NGCC__: DirectiveCompiler = noop;
const R3_COMPILE_INJECTABLE__PRE_NGCC__: DirectiveCompiler = preR3InjectableCompile;
const R3_COMPILE_NGMODULE__PRE_NGCC__: DirectiveCompiler = preR3NgModuleCompile;
const R3_COMPILE_PIPE__PRE_NGCC__: DirectiveCompiler = noop;
const ivyEnable__PRE_NGCC__ = false;
export const ivyEnabled = ivyEnable__PRE_NGCC__;
export let R3_COMPILE_COMPONENT: DirectiveCompiler = R3_COMPILE_COMPONENT__PRE_NGCC__;
export let R3_COMPILE_DIRECTIVE: DirectiveCompiler = R3_COMPILE_DIRECTIVE__PRE_NGCC__;
export let R3_COMPILE_INJECTABLE: DirectiveCompiler = R3_COMPILE_INJECTABLE__PRE_NGCC__;
export let R3_COMPILE_NGMODULE: DirectiveCompiler = R3_COMPILE_NGMODULE__PRE_NGCC__;
export let R3_COMPILE_PIPE: DirectiveCompiler = R3_COMPILE_PIPE__PRE_NGCC__;
////////////////////////////////////////////////////////////
// Glue code which should be removed after Ivy is default //
////////////////////////////////////////////////////////////
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,
});
}
const GET_PROPERTY_NAME = {} as any;
const USE_VALUE = getClosureSafeProperty<ValueProvider>(
{provide: String, useValue: GET_PROPERTY_NAME}, GET_PROPERTY_NAME);
const EMPTY_ARRAY: any[] = [];
function convertInjectableProviderToFactory(type: Type<any>, provider?: InjectableProvider): () =>
any {
if (!provider) {
const reflectionCapabilities = new ReflectionCapabilities();
const deps = reflectionCapabilities.parameters(type);
// TODO - convert to flags.
return () => new type(...injectArgs(deps as any[]));
}
if (USE_VALUE in provider) {
const valueProvider = (provider as ValueSansProvider);
return () => valueProvider.useValue;
} else if ((provider as ExistingSansProvider).useExisting) {
const existingProvider = (provider as ExistingSansProvider);
return () => inject(existingProvider.useExisting);
} else if ((provider as FactorySansProvider).useFactory) {
const factoryProvider = (provider as FactorySansProvider);
return () => factoryProvider.useFactory(...injectArgs(factoryProvider.deps || EMPTY_ARRAY));
} else if ((provider as StaticClassSansProvider | ClassSansProvider).useClass) {
const classProvider = (provider as StaticClassSansProvider | ClassSansProvider);
let deps = (provider as StaticClassSansProvider).deps;
if (!deps) {
const reflectionCapabilities = new ReflectionCapabilities();
deps = reflectionCapabilities.parameters(type);
}
return () => new classProvider.useClass(...injectArgs(deps));
} else {
let deps = (provider as ConstructorSansProvider).deps;
if (!deps) {
const reflectionCapabilities = new ReflectionCapabilities();
deps = reflectionCapabilities.parameters(type);
}
return () => new type(...injectArgs(deps !));
}
}
/**
* Supports @Injectable() in JIT mode for Render2.
*/
function preR3InjectableCompile(
injectableType: InjectableType<any>,
options: {providedIn?: Type<any>| 'root' | null} & InjectableProvider): void {
if (options && options.providedIn !== undefined && injectableType.ngInjectableDef === undefined) {
injectableType.ngInjectableDef = defineInjectable({
providedIn: options.providedIn,
factory: convertInjectableProviderToFactory(injectableType, options),
});
}
}

View File

@ -6,7 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Injectable, InjectionToken, StaticProvider} from '../di';
import {Injectable} from '../di/injectable';
import {InjectionToken} from '../di/injection_token';
import {StaticProvider} from '../di/provider';
import {MissingTranslationStrategy} from '../i18n/tokens';
import {ViewEncapsulation} from '../metadata';
import {Type} from '../type';
@ -15,6 +17,7 @@ import {ComponentFactory} from './component_factory';
import {NgModuleFactory} from './ng_module_factory';
/**
* Combination of NgModuleFactory and ComponentFactorys.
*

View File

@ -347,7 +347,7 @@ export interface Directive {
*/
export const Directive: DirectiveDecorator = makeDecorator(
'Directive', (dir: Directive = {}) => dir, undefined, undefined,
(type: Type<any>, meta: Directive) => (R3_COMPILE_DIRECTIVE || (() => {}))(type, meta));
(type: Type<any>, meta: Directive) => R3_COMPILE_DIRECTIVE(type, meta));
/**
* Component decorator interface
@ -631,8 +631,7 @@ export interface Component extends Directive {
*/
export const Component: ComponentDecorator = makeDecorator(
'Component', (c: Component = {}) => ({changeDetection: ChangeDetectionStrategy.Default, ...c}),
Directive, undefined,
(type: Type<any>, meta: Component) => (R3_COMPILE_COMPONENT || (() => {}))(type, meta));
Directive, undefined, (type: Type<any>, meta: Component) => R3_COMPILE_COMPONENT(type, meta));
/**
* Type of the Pipe decorator / constructor function.
@ -680,7 +679,7 @@ export interface Pipe {
*/
export const Pipe: PipeDecorator = makeDecorator(
'Pipe', (p: Pipe) => ({pure: true, ...p}), undefined, undefined,
(type: Type<any>, meta: Pipe) => (R3_COMPILE_PIPE || (() => {}))(type, meta));
(type: Type<any>, meta: Pipe) => R3_COMPILE_PIPE(type, meta));
/**

View File

@ -7,8 +7,6 @@
*/
import {ApplicationRef} from '../application_ref';
import {InjectorDef, InjectorType, defineInjector} from '../di/defs';
import {convertInjectableProviderToFactory} from '../di/injectable';
import {Provider} from '../di/provider';
import {R3_COMPILE_NGMODULE} from '../ivy_switch';
import {Type} from '../type';
@ -323,19 +321,6 @@ export interface NgModule {
jit?: true;
}
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,
});
}
/**
* @Annotation
*/
@ -352,7 +337,7 @@ export const NgModule: NgModuleDecorator = makeDecorator(
* * The `imports` and `exports` options bring in members from other modules, and make
* this module's members available to others.
*/
(type: Type<any>, meta: NgModule) => (R3_COMPILE_NGMODULE || preR3NgModuleCompile)(type, meta));
(type: Type<any>, meta: NgModule) => R3_COMPILE_NGMODULE(type, meta));
/**
* @description

View File

@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {InjectionToken, Injector} from '../di';
import {InjectionToken} from '../di/injection_token';
import {Injector} from '../di/injector';
import {ViewEncapsulation} from '../metadata/view';
/**

View File

@ -63,7 +63,15 @@ export function assertComponentType(
msg: string =
'Type passed in is not ComponentType, it does not have \'ngComponentDef\' property.') {
if (!actual.ngComponentDef) {
debugger;
throwError(msg);
}
}
export function assertNgModuleType(
actual: any,
msg: string =
'Type passed in is not NgModuleType, it does not have \'ngModuleDef\' property.') {
if (!actual.ngModuleDef) {
throwError(msg);
}
}

View File

@ -12,7 +12,13 @@
import {ChangeDetectorRef as viewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref';
import {InjectionToken} from '../di/injection_token';
import {InjectFlags, Injector, NullInjector, inject, setCurrentInjector} from '../di/injector';
import * as viewEngine from '../linker';
import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory';
import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver';
import {ElementRef as viewEngine_ElementRef} from '../linker/element_ref';
import {NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory';
import {TemplateRef as viewEngine_TemplateRef} from '../linker/template_ref';
import {ViewContainerRef as viewEngine_ViewContainerRef} from '../linker/view_container_ref';
import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, ViewRef as viewEngine_ViewRef} from '../linker/view_ref';
import {Type} from '../type';
import {assertDefined, assertGreaterThan, assertLessThan} from './assert';
@ -24,7 +30,7 @@ import {LInjector} from './interfaces/injector';
import {AttributeMarker, LContainerNode, LElementContainerNode, LElementNode, LNode, LViewNode, TContainerNode, TElementNode, TNodeFlags, TNodeType} from './interfaces/node';
import {LQueries, QueryReadType} from './interfaces/query';
import {Renderer3} from './interfaces/renderer';
import {DECLARATION_VIEW, DIRECTIVES, HOST_NODE, INJECTOR, LViewData, QUERIES, RENDERER, TVIEW, TView} from './interfaces/view';
import {DIRECTIVES, HOST_NODE, INJECTOR, LViewData, QUERIES, RENDERER, TVIEW, TView} from './interfaces/view';
import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert';
import {addRemoveViewFromContainer, appendChild, detachView, getChildLNode, getParentLNode, insertView, removeView} from './node_manipulation';
import {ViewRef} from './view_ref';
@ -189,7 +195,7 @@ export function directiveInject<T>(
*
* @returns The ElementRef instance to use
*/
export function injectElementRef(): viewEngine.ElementRef {
export function injectElementRef(): viewEngine_ElementRef {
return getOrCreateElementRef(getOrCreateNodeInjector());
}
@ -199,7 +205,7 @@ export function injectElementRef(): viewEngine.ElementRef {
*
* @returns The TemplateRef instance to use
*/
export function injectTemplateRef<T>(): viewEngine.TemplateRef<T> {
export function injectTemplateRef<T>(): viewEngine_TemplateRef<T> {
return getOrCreateTemplateRef<T>(getOrCreateNodeInjector());
}
@ -209,7 +215,7 @@ export function injectTemplateRef<T>(): viewEngine.TemplateRef<T> {
*
* @returns The ViewContainerRef instance to use
*/
export function injectViewContainerRef(): viewEngine.ViewContainerRef {
export function injectViewContainerRef(): viewEngine_ViewContainerRef {
return getOrCreateContainerRef(getOrCreateNodeInjector());
}
@ -225,7 +231,7 @@ export function injectChangeDetectorRef(): viewEngine_ChangeDetectorRef {
*
* @returns The ComponentFactoryResolver instance to use
*/
export function injectComponentFactoryResolver(): viewEngine.ComponentFactoryResolver {
export function injectComponentFactoryResolver(): viewEngine_ComponentFactoryResolver {
return componentFactoryResolver;
}
const componentFactoryResolver: ComponentFactoryResolver = new ComponentFactoryResolver();
@ -533,20 +539,20 @@ export class ReadFromInjectorFn<T> {
* @param di The node injector where we should store a created ElementRef
* @returns The ElementRef instance to use
*/
export function getOrCreateElementRef(di: LInjector): viewEngine.ElementRef {
export function getOrCreateElementRef(di: LInjector): viewEngine_ElementRef {
return di.elementRef || (di.elementRef = new ElementRef(di.node.native));
}
export const QUERY_READ_TEMPLATE_REF = <QueryReadType<viewEngine.TemplateRef<any>>>(
new ReadFromInjectorFn<viewEngine.TemplateRef<any>>(
export const QUERY_READ_TEMPLATE_REF = <QueryReadType<viewEngine_TemplateRef<any>>>(
new ReadFromInjectorFn<viewEngine_TemplateRef<any>>(
(injector: LInjector) => getOrCreateTemplateRef(injector)) as any);
export const QUERY_READ_CONTAINER_REF = <QueryReadType<viewEngine.ViewContainerRef>>(
new ReadFromInjectorFn<viewEngine.ViewContainerRef>(
export const QUERY_READ_CONTAINER_REF = <QueryReadType<viewEngine_ViewContainerRef>>(
new ReadFromInjectorFn<viewEngine_ViewContainerRef>(
(injector: LInjector) => getOrCreateContainerRef(injector)) as any);
export const QUERY_READ_ELEMENT_REF =
<QueryReadType<viewEngine.ElementRef>>(new ReadFromInjectorFn<viewEngine.ElementRef>(
<QueryReadType<viewEngine_ElementRef>>(new ReadFromInjectorFn<viewEngine_ElementRef>(
(injector: LInjector) => getOrCreateElementRef(injector)) as any);
export const QUERY_READ_FROM_NODE =
@ -565,7 +571,7 @@ export const QUERY_READ_FROM_NODE =
}) as any as QueryReadType<any>);
/** A ref to a node's native element. */
class ElementRef implements viewEngine.ElementRef {
class ElementRef implements viewEngine_ElementRef {
readonly nativeElement: any;
constructor(nativeElement: any) { this.nativeElement = nativeElement; }
}
@ -576,7 +582,7 @@ class ElementRef implements viewEngine.ElementRef {
*
* @returns The ViewContainerRef instance to use
*/
export function getOrCreateContainerRef(di: LInjector): viewEngine.ViewContainerRef {
export function getOrCreateContainerRef(di: LInjector): viewEngine_ViewContainerRef {
if (!di.viewContainerRef) {
const vcRefHost = di.node;
@ -609,13 +615,13 @@ export class NodeInjector implements Injector {
constructor(private _lInjector: LInjector) {}
get(token: any): any {
if (token === viewEngine.TemplateRef) {
if (token === viewEngine_TemplateRef) {
return getOrCreateTemplateRef(this._lInjector);
}
if (token === viewEngine.ViewContainerRef) {
if (token === viewEngine_ViewContainerRef) {
return getOrCreateContainerRef(this._lInjector);
}
if (token === viewEngine.ElementRef) {
if (token === viewEngine_ElementRef) {
return getOrCreateElementRef(this._lInjector);
}
if (token === viewEngine_ChangeDetectorRef) {
@ -630,8 +636,8 @@ export class NodeInjector implements Injector {
* A ref to a container that enables adding and removing views from that container
* imperatively.
*/
class ViewContainerRef implements viewEngine.ViewContainerRef {
private _viewRefs: viewEngine.ViewRef[] = [];
class ViewContainerRef implements viewEngine_ViewContainerRef {
private _viewRefs: viewEngine_ViewRef[] = [];
constructor(
private _lContainerNode: LContainerNode,
@ -660,15 +666,15 @@ class ViewContainerRef implements viewEngine.ViewContainerRef {
}
}
get(index: number): viewEngine.ViewRef|null { return this._viewRefs[index] || null; }
get(index: number): viewEngine_ViewRef|null { return this._viewRefs[index] || null; }
get length(): number {
const lContainer = this._lContainerNode.data;
return lContainer[VIEWS].length;
}
createEmbeddedView<C>(templateRef: viewEngine.TemplateRef<C>, context?: C, index?: number):
viewEngine.EmbeddedViewRef<C> {
createEmbeddedView<C>(templateRef: viewEngine_TemplateRef<C>, context?: C, index?: number):
viewEngine_EmbeddedViewRef<C> {
const adjustedIdx = this._adjustIndex(index);
const viewRef = (templateRef as TemplateRef<C>)
.createEmbeddedView(context || <any>{}, this._lContainerNode, adjustedIdx);
@ -678,12 +684,12 @@ class ViewContainerRef implements viewEngine.ViewContainerRef {
}
createComponent<C>(
componentFactory: viewEngine.ComponentFactory<C>, index?: number|undefined,
componentFactory: viewEngine_ComponentFactory<C>, index?: number|undefined,
injector?: Injector|undefined, projectableNodes?: any[][]|undefined,
ngModuleRef?: viewEngine.NgModuleRef<any>|undefined): viewEngine.ComponentRef<C> {
ngModuleRef?: viewEngine_NgModuleRef<any>|undefined): viewEngine_ComponentRef<C> {
const contextInjector = injector || this.parentInjector;
if (!ngModuleRef && contextInjector) {
ngModuleRef = contextInjector.get(viewEngine.NgModuleRef, null);
ngModuleRef = contextInjector.get(viewEngine_NgModuleRef, null);
}
const componentRef =
@ -692,7 +698,7 @@ class ViewContainerRef implements viewEngine.ViewContainerRef {
return componentRef;
}
insert(viewRef: viewEngine.ViewRef, index?: number): viewEngine.ViewRef {
insert(viewRef: viewEngine_ViewRef, index?: number): viewEngine_ViewRef {
if (viewRef.destroyed) {
throw new Error('Cannot insert a destroyed View in a ViewContainer!');
}
@ -712,14 +718,14 @@ class ViewContainerRef implements viewEngine.ViewContainerRef {
return viewRef;
}
move(viewRef: viewEngine.ViewRef, newIndex: number): viewEngine.ViewRef {
move(viewRef: viewEngine_ViewRef, newIndex: number): viewEngine_ViewRef {
const index = this.indexOf(viewRef);
this.detach(index);
this.insert(viewRef, this._adjustIndex(newIndex));
return viewRef;
}
indexOf(viewRef: viewEngine.ViewRef): number { return this._viewRefs.indexOf(viewRef); }
indexOf(viewRef: viewEngine_ViewRef): number { return this._viewRefs.indexOf(viewRef); }
remove(index?: number): void {
const adjustedIdx = this._adjustIndex(index, -1);
@ -727,7 +733,7 @@ class ViewContainerRef implements viewEngine.ViewContainerRef {
this._viewRefs.splice(adjustedIdx, 1);
}
detach(index?: number): viewEngine.ViewRef|null {
detach(index?: number): viewEngine_ViewRef|null {
const adjustedIdx = this._adjustIndex(index, -1);
detachView(this._lContainerNode, adjustedIdx);
return this._viewRefs.splice(adjustedIdx, 1)[0] || null;
@ -753,7 +759,7 @@ class ViewContainerRef implements viewEngine.ViewContainerRef {
* @param di The node injector where we should store a created TemplateRef
* @returns The TemplateRef instance to use
*/
export function getOrCreateTemplateRef<T>(di: LInjector): viewEngine.TemplateRef<T> {
export function getOrCreateTemplateRef<T>(di: LInjector): viewEngine_TemplateRef<T> {
if (!di.templateRef) {
ngDevMode && assertNodeType(di.node, TNodeType.Container);
const hostNode = di.node as LContainerNode;
@ -790,13 +796,13 @@ export function getInheritedFactory<T>(type: Type<any>): (type: Type<T>) => T {
}
}
class TemplateRef<T> implements viewEngine.TemplateRef<T> {
class TemplateRef<T> implements viewEngine_TemplateRef<T> {
constructor(
private _declarationParentView: LViewData, readonly elementRef: viewEngine.ElementRef,
private _declarationParentView: LViewData, readonly elementRef: viewEngine_ElementRef,
private _tView: TView, private _renderer: Renderer3, private _queries: LQueries|null) {}
createEmbeddedView(context: T, containerNode?: LContainerNode, index?: number):
viewEngine.EmbeddedViewRef<T> {
viewEngine_EmbeddedViewRef<T> {
const viewNode = createEmbeddedViewNode(
this._tView, context, this._declarationParentView, this._renderer, this._queries);
if (containerNode) {

View File

@ -14,7 +14,6 @@ import {PublicFeature} from './features/public_feature';
import {BaseDef, ComponentDef, ComponentDefInternal, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFlags, DirectiveDefInternal, DirectiveType, PipeDef} from './interfaces/definition';
export {ComponentFactory, ComponentFactoryResolver, ComponentRef, WRAP_RENDERER_FACTORY2} from './component_ref';
export {Render3DebugRendererFactory2} from './debug';
export {QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF, directiveInject, getFactoryOf, getInheritedFactory, injectAttribute, injectChangeDetectorRef, injectComponentFactoryResolver, injectElementRef, injectTemplateRef, injectViewContainerRef} from './di';
export {RenderFlags} from './interfaces/definition';
export {CssSelectorList} from './interfaces/projection';

View File

@ -5,7 +5,7 @@
* 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
*/
import {devModeEqual} from '../change_detection/change_detection';
import {devModeEqual} from '../change_detection/change_detection_util';
import {assertLessThan} from './assert';
import {LElementNode} from './interfaces/node';
import {HEADER_OFFSET, LViewData} from './interfaces/view';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isDevMode} from '../application_ref';
import {isDevMode} from '../is_dev_mode';
import {InertBodyHelper} from './inert_body';
import {_sanitizeUrl, sanitizeSrcset} from './url_sanitizer';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isDevMode} from '../application_ref';
import {isDevMode} from '../is_dev_mode';
import {_sanitizeUrl} from './url_sanitizer';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isDevMode} from '../application_ref';
import {isDevMode} from '../is_dev_mode';
/**
* A pattern that recognizes a commonly useful subset of URLs that are safe.

View File

@ -6,11 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isDevMode} from '../application_ref';
import {DebugElement, DebugNode, EventListener, getDebugNode, indexDebugNode, removeDebugNodeFromIndex} from '../debug/debug_node';
import {Injector} from '../di';
import {InjectableType} from '../di/injectable';
import {ErrorHandler} from '../error_handler';
import {isDevMode} from '../is_dev_mode';
import {ComponentFactory} from '../linker/component_factory';
import {NgModuleRef} from '../linker/ng_module_factory';
import {Renderer2, RendererFactory2, RendererStyleFlags2, RendererType2} from '../render/api';

View File

@ -27,7 +27,7 @@
"name": "EMPTY$1"
},
{
"name": "EMPTY_ARRAY$2"
"name": "EMPTY_ARRAY"
},
{
"name": "FLAGS"

View File

@ -366,7 +366,7 @@
"name": "CSS_STRIPPABLE_COMMENT_REGEXP"
},
{
"name": "CUSTOM_ELEMENTS_SCHEMA$1"
"name": "CUSTOM_ELEMENTS_SCHEMA"
},
{
"name": "CastExpr"
@ -570,10 +570,10 @@
"name": "EMPTY"
},
{
"name": "EMPTY_ARRAY"
"name": "EMPTY_ARRAY$3"
},
{
"name": "EMPTY_ARRAY$2"
"name": "EMPTY_ARRAY$4"
},
{
"name": "EMPTY_CONTEXT"
@ -711,7 +711,7 @@
"name": "GET_PROPERTY_NAME"
},
{
"name": "GET_PROPERTY_NAME$1"
"name": "GET_PROPERTY_NAME$2"
},
{
"name": "GOOG_GET_MSG"
@ -1020,7 +1020,7 @@
"name": "NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR"
},
{
"name": "NO_ERRORS_SCHEMA$1"
"name": "NO_ERRORS_SCHEMA"
},
{
"name": "NO_NEW_LINE"
@ -1233,11 +1233,14 @@
"name": "QUOTED_KEYS"
},
{
"name": "QueryList"
"name": "QueryList$1"
},
{
"name": "Quote"
},
{
"name": "R3_COMPILE_INJECTABLE$1"
},
{
"name": "ReadKeyExpr"
},
@ -1575,7 +1578,7 @@
"name": "USE_VALUE"
},
{
"name": "USE_VALUE$1"
"name": "USE_VALUE$3"
},
{
"name": "UnsubscriptionError"
@ -1584,7 +1587,7 @@
"name": "UrlResolver"
},
{
"name": "VERSION"
"name": "VERSION$1"
},
{
"name": "VERSION$2"
@ -1599,7 +1602,7 @@
"name": "VariableAst"
},
{
"name": "Version"
"name": "Version$1"
},
{
"name": "ViewAction"
@ -2145,7 +2148,7 @@
"name": "_removeDotSegments"
},
{
"name": "_renderCompCount"
"name": "_renderCompCount$1"
},
{
"name": "_resolveProviders"
@ -2346,7 +2349,7 @@
"name": "camelCaseToDashCase"
},
{
"name": "checkAndUpdateBinding"
"name": "checkAndUpdateBinding$1"
},
{
"name": "checkAndUpdateDirectiveDynamic"
@ -2423,6 +2426,12 @@
{
"name": "compareCharCodeCaseInsensitive"
},
{
"name": "compileNgModuleFactory"
},
{
"name": "compileNgModuleFactory__PRE_NGCC__"
},
{
"name": "componentFactoryName"
},
@ -2568,7 +2577,7 @@
"name": "createOptional"
},
{
"name": "createOutput$1"
"name": "createOutput"
},
{
"name": "createOutputContext"
@ -2601,7 +2610,7 @@
"name": "createPureExpression"
},
{
"name": "createQuery"
"name": "createQuery$1"
},
{
"name": "createRendererType2"
@ -2874,7 +2883,7 @@
"name": "flatten"
},
{
"name": "flatten$2"
"name": "flatten$3"
},
{
"name": "flattenAndDedupeArray"
@ -3063,7 +3072,7 @@
"name": "inlineInterpolate"
},
{
"name": "interpolate"
"name": "interpolate$1"
},
{
"name": "interpretStatements"
@ -3372,10 +3381,10 @@
"name": "nodeValue"
},
{
"name": "noop"
"name": "noop$1"
},
{
"name": "noop$1"
"name": "noop$3"
},
{
"name": "noopScope"
@ -3393,7 +3402,7 @@
"name": "normalizeNgContentSelect"
},
{
"name": "not$1"
"name": "not"
},
{
"name": "nullSafeIsEquivalent"
@ -3663,7 +3672,7 @@
"name": "stringify"
},
{
"name": "stringify$2"
"name": "stringify$1"
},
{
"name": "stringifyType"

View File

@ -3,7 +3,7 @@
"name": "APP_ROOT"
},
{
"name": "CIRCULAR$1"
"name": "CIRCULAR$2"
},
{
"name": "EMPTY_ARRAY$1"
@ -24,7 +24,7 @@
"name": "NOT_YET"
},
{
"name": "NULL_INJECTOR$1"
"name": "NULL_INJECTOR$2"
},
{
"name": "NullInjector"
@ -84,7 +84,7 @@
"name": "forwardRef"
},
{
"name": "getClosureSafeProperty$1"
"name": "getClosureSafeProperty"
},
{
"name": "getNullInjector"

View File

@ -9,7 +9,7 @@
"name": "BLOOM_MASK"
},
{
"name": "CIRCULAR$2"
"name": "CIRCULAR$1"
},
{
"name": "CLEANUP"
@ -45,7 +45,7 @@
"name": "EMPTY$1"
},
{
"name": "EMPTY_ARRAY$2"
"name": "EMPTY_ARRAY"
},
{
"name": "ElementRef"