diff --git a/packages/compiler/test/schema/schema_extractor.ts b/packages/compiler/test/schema/schema_extractor.ts index 533ca59a6a..ec25bda11b 100644 --- a/packages/compiler/test/schema/schema_extractor.ts +++ b/packages/compiler/test/schema/schema_extractor.ts @@ -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|null { diff --git a/packages/core/src/application_ref.ts b/packages/core/src/application_ref.ts index 9ec754f3ab..c6979b8a03 100644 --- a/packages/core/src/application_ref.ts +++ b/packages/core/src/application_ref.ts @@ -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: + (injector: Injector, options: CompilerOptions, moduleType: Type) => + Promise> = compileNgModuleFactory__PRE_NGCC__; + +function compileNgModuleFactory__PRE_NGCC__( + injector: Injector, options: CompilerOptions, + moduleType: Type): Promise> { + const compilerFactory: CompilerFactory = injector.get(CompilerFactory); + const compiler = compilerFactory.createCompiler([options]); + return compiler.compileModuleAsync(moduleType); +} + +function compileNgModuleFactory__POST_NGCC__( + injector: Injector, options: CompilerOptions, + moduleType: Type): Promise> { + ngDevMode && assertNgModuleType(moduleType); + return Promise.resolve(new R3NgModuleFactory(moduleType)); +} + export const ALLOW_MULTIPLE_PLATFORMS = new InjectionToken('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( moduleType: Type, compilerOptions: (CompilerOptions&BootstrapOptions)| Array = []): Promise> { - 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): void { diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 0444eea601..ee0b21204c 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -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'; diff --git a/packages/core/src/core_render3_private_export.ts b/packages/core/src/core_render3_private_export.ts index 6d908bf655..8bb2cb5c2c 100644 --- a/packages/core/src/core_render3_private_export.ts +++ b/packages/core/src/core_render3_private_export.ts @@ -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, diff --git a/packages/core/src/di/injectable.ts b/packages/core/src/di/injectable.ts index d1dacf1033..5d60296260 100644 --- a/packages/core/src/di/injectable.ts +++ b/packages/core/src/di/injectable.ts @@ -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( - {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|'root'|null; } -const EMPTY_ARRAY: any[] = []; - -export function convertInjectableProviderToFactory( - type: Type, 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, - options: {providedIn?: Type| '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, meta: Injectable) => - (R3_COMPILE_INJECTABLE || preR3InjectableCompile)(type, meta)); + 'Injectable', undefined, undefined, undefined, (type: Type, meta: Injectable) => { + debugger; + return R3_COMPILE_INJECTABLE(type, meta); + }); /** * Type representing injectable service. diff --git a/packages/core/src/is_dev_mode.ts b/packages/core/src/is_dev_mode.ts new file mode 100644 index 0000000000..dc0c9cc268 --- /dev/null +++ b/packages/core/src/is_dev_mode.ts @@ -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; +} \ No newline at end of file diff --git a/packages/core/src/ivy_switch_legacy.ts b/packages/core/src/ivy_switch_legacy.ts index 3b50412715..e6b5c3cbf4 100644 --- a/packages/core/src/ivy_switch_legacy.ts +++ b/packages/core/src/ivy_switch_legacy.ts @@ -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, 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( + {provide: String, useValue: GET_PROPERTY_NAME}, GET_PROPERTY_NAME); +const EMPTY_ARRAY: any[] = []; + +function convertInjectableProviderToFactory(type: Type, 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, + options: {providedIn?: Type| 'root' | null} & InjectableProvider): void { + if (options && options.providedIn !== undefined && injectableType.ngInjectableDef === undefined) { + injectableType.ngInjectableDef = defineInjectable({ + providedIn: options.providedIn, + factory: convertInjectableProviderToFactory(injectableType, options), + }); + } +} \ No newline at end of file diff --git a/packages/core/src/linker/compiler.ts b/packages/core/src/linker/compiler.ts index 86446a9eae..3d035b589f 100644 --- a/packages/core/src/linker/compiler.ts +++ b/packages/core/src/linker/compiler.ts @@ -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. * diff --git a/packages/core/src/metadata/directives.ts b/packages/core/src/metadata/directives.ts index 360cee307e..c63d1a20e4 100644 --- a/packages/core/src/metadata/directives.ts +++ b/packages/core/src/metadata/directives.ts @@ -347,7 +347,7 @@ export interface Directive { */ export const Directive: DirectiveDecorator = makeDecorator( 'Directive', (dir: Directive = {}) => dir, undefined, undefined, - (type: Type, meta: Directive) => (R3_COMPILE_DIRECTIVE || (() => {}))(type, meta)); + (type: Type, 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, meta: Component) => (R3_COMPILE_COMPONENT || (() => {}))(type, meta)); + Directive, undefined, (type: Type, 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, meta: Pipe) => (R3_COMPILE_PIPE || (() => {}))(type, meta)); + (type: Type, meta: Pipe) => R3_COMPILE_PIPE(type, meta)); /** diff --git a/packages/core/src/metadata/ng_module.ts b/packages/core/src/metadata/ng_module.ts index 6bab5807d6..1ce2ad1467 100644 --- a/packages/core/src/metadata/ng_module.ts +++ b/packages/core/src/metadata/ng_module.ts @@ -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, 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, meta: NgModule) => (R3_COMPILE_NGMODULE || preR3NgModuleCompile)(type, meta)); + (type: Type, meta: NgModule) => R3_COMPILE_NGMODULE(type, meta)); /** * @description diff --git a/packages/core/src/render/api.ts b/packages/core/src/render/api.ts index ab442b419b..22daa2332d 100644 --- a/packages/core/src/render/api.ts +++ b/packages/core/src/render/api.ts @@ -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'; /** diff --git a/packages/core/src/render3/assert.ts b/packages/core/src/render3/assert.ts index dc3d97311d..d75978c7d4 100644 --- a/packages/core/src/render3/assert.ts +++ b/packages/core/src/render3/assert.ts @@ -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); } } diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 28eced1bda..13d550cadb 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -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( * * @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(): viewEngine.TemplateRef { +export function injectTemplateRef(): viewEngine_TemplateRef { return getOrCreateTemplateRef(getOrCreateNodeInjector()); } @@ -209,7 +215,7 @@ export function injectTemplateRef(): viewEngine.TemplateRef { * * @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 { * @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 = >>( - new ReadFromInjectorFn>( +export const QUERY_READ_TEMPLATE_REF = >>( + new ReadFromInjectorFn>( (injector: LInjector) => getOrCreateTemplateRef(injector)) as any); -export const QUERY_READ_CONTAINER_REF = >( - new ReadFromInjectorFn( +export const QUERY_READ_CONTAINER_REF = >( + new ReadFromInjectorFn( (injector: LInjector) => getOrCreateContainerRef(injector)) as any); export const QUERY_READ_ELEMENT_REF = - >(new ReadFromInjectorFn( + >(new ReadFromInjectorFn( (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); /** 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(templateRef: viewEngine.TemplateRef, context?: C, index?: number): - viewEngine.EmbeddedViewRef { + createEmbeddedView(templateRef: viewEngine_TemplateRef, context?: C, index?: number): + viewEngine_EmbeddedViewRef { const adjustedIdx = this._adjustIndex(index); const viewRef = (templateRef as TemplateRef) .createEmbeddedView(context || {}, this._lContainerNode, adjustedIdx); @@ -678,12 +684,12 @@ class ViewContainerRef implements viewEngine.ViewContainerRef { } createComponent( - componentFactory: viewEngine.ComponentFactory, index?: number|undefined, + componentFactory: viewEngine_ComponentFactory, index?: number|undefined, injector?: Injector|undefined, projectableNodes?: any[][]|undefined, - ngModuleRef?: viewEngine.NgModuleRef|undefined): viewEngine.ComponentRef { + ngModuleRef?: viewEngine_NgModuleRef|undefined): viewEngine_ComponentRef { 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(di: LInjector): viewEngine.TemplateRef { +export function getOrCreateTemplateRef(di: LInjector): viewEngine_TemplateRef { if (!di.templateRef) { ngDevMode && assertNodeType(di.node, TNodeType.Container); const hostNode = di.node as LContainerNode; @@ -790,13 +796,13 @@ export function getInheritedFactory(type: Type): (type: Type) => T { } } -class TemplateRef implements viewEngine.TemplateRef { +class TemplateRef implements viewEngine_TemplateRef { 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 { + viewEngine_EmbeddedViewRef { const viewNode = createEmbeddedViewNode( this._tView, context, this._declarationParentView, this._renderer, this._queries); if (containerNode) { diff --git a/packages/core/src/render3/index.ts b/packages/core/src/render3/index.ts index edc85ec25e..5b4e068c57 100644 --- a/packages/core/src/render3/index.ts +++ b/packages/core/src/render3/index.ts @@ -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'; diff --git a/packages/core/src/render3/util.ts b/packages/core/src/render3/util.ts index 784cc69dc4..338ccf2d20 100644 --- a/packages/core/src/render3/util.ts +++ b/packages/core/src/render3/util.ts @@ -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'; diff --git a/packages/core/src/sanitization/html_sanitizer.ts b/packages/core/src/sanitization/html_sanitizer.ts index cfa7e58035..2c45e72693 100644 --- a/packages/core/src/sanitization/html_sanitizer.ts +++ b/packages/core/src/sanitization/html_sanitizer.ts @@ -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'; diff --git a/packages/core/src/sanitization/style_sanitizer.ts b/packages/core/src/sanitization/style_sanitizer.ts index 88a03e8e98..aef692fa89 100644 --- a/packages/core/src/sanitization/style_sanitizer.ts +++ b/packages/core/src/sanitization/style_sanitizer.ts @@ -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'; diff --git a/packages/core/src/sanitization/url_sanitizer.ts b/packages/core/src/sanitization/url_sanitizer.ts index 6fe9056016..205443d91b 100644 --- a/packages/core/src/sanitization/url_sanitizer.ts +++ b/packages/core/src/sanitization/url_sanitizer.ts @@ -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. diff --git a/packages/core/src/view/services.ts b/packages/core/src/view/services.ts index c3eabf9ee7..32bb76e13e 100644 --- a/packages/core/src/view/services.ts +++ b/packages/core/src/view/services.ts @@ -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'; diff --git a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json index ce331251be..fe2a6d0643 100644 --- a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json @@ -27,7 +27,7 @@ "name": "EMPTY$1" }, { - "name": "EMPTY_ARRAY$2" + "name": "EMPTY_ARRAY" }, { "name": "FLAGS" diff --git a/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json b/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json index 96fd910e84..fcccc10fc6 100644 --- a/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json @@ -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" @@ -3842,4 +3851,4 @@ { "name": "wtfLeave" } -] +] \ No newline at end of file diff --git a/packages/core/test/bundling/injection/bundle.golden_symbols.json b/packages/core/test/bundling/injection/bundle.golden_symbols.json index fa888017ba..9abb429794 100644 --- a/packages/core/test/bundling/injection/bundle.golden_symbols.json +++ b/packages/core/test/bundling/injection/bundle.golden_symbols.json @@ -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" diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index 1664cce75d..2ebf4e57eb 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -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"