diff --git a/packages/core/src/debug/debug_node.ts b/packages/core/src/debug/debug_node.ts index 78fbdd0d77..0f4ba3ae31 100644 --- a/packages/core/src/debug/debug_node.ts +++ b/packages/core/src/debug/debug_node.ts @@ -17,19 +17,13 @@ export class EventListener { * @experimental All debugging apis are currently experimental. */ export class DebugNode { - nativeNode: any; - listeners: EventListener[]; - // TODO(issue/24571): remove '!'. - parent !: DebugElement | null; + listeners: EventListener[] = []; + parent: DebugElement|null = null; - constructor(nativeNode: any, parent: DebugNode|null, private _debugContext: DebugContext) { - this.nativeNode = nativeNode; + constructor(public nativeNode: any, parent: DebugNode|null, private _debugContext: DebugContext) { if (parent && parent instanceof DebugElement) { parent.addChild(this); - } else { - this.parent = null; } - this.listeners = []; } get injector(): Injector { return this._debugContext.injector; } @@ -47,22 +41,16 @@ export class DebugNode { * @experimental All debugging apis are currently experimental. */ export class DebugElement extends DebugNode { - // TODO(issue/24571): remove '!'. name !: string; - properties: {[key: string]: any}; - attributes: {[key: string]: string | null}; - classes: {[key: string]: boolean}; - styles: {[key: string]: string | null}; - childNodes: DebugNode[]; + properties: {[key: string]: any} = {}; + attributes: {[key: string]: string | null} = {}; + classes: {[key: string]: boolean} = {}; + styles: {[key: string]: string | null} = {}; + childNodes: DebugNode[] = []; nativeElement: any; constructor(nativeNode: any, parent: any, _debugContext: DebugContext) { super(nativeNode, parent, _debugContext); - this.properties = {}; - this.attributes = {}; - this.classes = {}; - this.styles = {}; - this.childNodes = []; this.nativeElement = nativeNode; } diff --git a/packages/core/src/di/r3_injector.ts b/packages/core/src/di/r3_injector.ts index e8dcdf42ef..9696aa1e82 100644 --- a/packages/core/src/di/r3_injector.ts +++ b/packages/core/src/di/r3_injector.ts @@ -394,10 +394,6 @@ function isFactoryProvider(value: SingleProvider): value is FactoryProvider { return !!(value as FactoryProvider).useFactory; } -function isClassProvider(value: SingleProvider): value is ClassProvider { - return !!(value as ClassProvider).useClass; -} - function isTypeProvider(value: SingleProvider): value is TypeProvider { return typeof value === 'function'; } diff --git a/packages/core/src/render3/component.ts b/packages/core/src/render3/component.ts index c82b66aa1f..42af53fbba 100644 --- a/packages/core/src/render3/component.ts +++ b/packages/core/src/render3/component.ts @@ -99,7 +99,7 @@ export function renderComponent( const componentDef = (componentType as ComponentType).ngComponentDef as ComponentDefInternal; if (componentDef.type != componentType) componentDef.type = componentType; - let component: T; + // The first index of the first selector is the tag name. const componentTag = componentDef.selectors ![0] ![0] as string; const hostNode = locateHostElement(rendererFactory, opts.host || componentTag); @@ -113,6 +113,7 @@ export function renderComponent( const oldView = enterView(rootView, null !); let elementNode: LElementNode; + let component: T; try { if (rendererFactory.begin) rendererFactory.begin(); @@ -120,8 +121,8 @@ export function renderComponent( elementNode = hostElement(componentTag, hostNode, componentDef, sanitizer); // Create directive instance with factory() and store at index 0 in directives array - rootContext.components.push( - component = baseDirectiveCreate(0, componentDef.factory(), componentDef) as T); + component = baseDirectiveCreate(0, componentDef.factory() as T, componentDef); + rootContext.components.push(component); (elementNode.data as LViewData)[CONTEXT] = component; initChangeDetectorIfExisting(elementNode.nodeInjector, component, elementNode.data !); diff --git a/packages/core/src/render3/definition.ts b/packages/core/src/render3/definition.ts index 392052d52d..92e0601fa8 100644 --- a/packages/core/src/render3/definition.ts +++ b/packages/core/src/render3/definition.ts @@ -6,17 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ -import {SimpleChange} from '../change_detection/change_detection_util'; import {ChangeDetectionStrategy} from '../change_detection/constants'; import {Provider} from '../core'; -import {OnChanges, SimpleChanges} from '../metadata/lifecycle_hooks'; import {NgModuleDef, NgModuleDefInternal} from '../metadata/ng_module'; import {RendererType2} from '../render/api'; import {Type} from '../type'; import {resolveRendererType2} from '../view/util'; -import {diPublic} from './di'; -import {BaseDef, ComponentDefFeature, ComponentDefInternal, ComponentQuery, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDefInternal, PipeType, PipeTypesOrFactory} from './interfaces/definition'; +import {BaseDef, ComponentDefFeature, ComponentDefInternal, ComponentQuery, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveType, DirectiveTypesOrFactory, PipeDefInternal, PipeType, PipeTypesOrFactory} from './interfaces/definition'; import {CssSelectorList, SelectorFlags} from './interfaces/projection'; diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 0a2b24ceda..c0ac484353 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -772,13 +772,9 @@ export function getOrCreateTemplateRef(di: LInjector): viewEngine.TemplateRef } class TemplateRef implements viewEngine.TemplateRef { - readonly elementRef: viewEngine.ElementRef; - constructor( - private _declarationParentView: LViewData, elementRef: viewEngine.ElementRef, - private _tView: TView, private _renderer: Renderer3, private _queries: LQueries|null) { - this.elementRef = 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 { diff --git a/packages/core/src/render3/index.ts b/packages/core/src/render3/index.ts index 46d4eedcce..5f12ea33bb 100644 --- a/packages/core/src/render3/index.ts +++ b/packages/core/src/render3/index.ts @@ -11,7 +11,6 @@ import {defineBase, defineComponent, defineDirective, defineNgModule, definePipe import {InheritDefinitionFeature} from './features/inherit_definition_feature'; import {NgOnChangesFeature} from './features/ng_onchanges_feature'; import {PublicFeature} from './features/public_feature'; -import {I18nExpInstruction, I18nInstruction, i18nExpMapping, i18nInterpolation1, i18nInterpolation2, i18nInterpolation3, i18nInterpolation4, i18nInterpolation5, i18nInterpolation6, i18nInterpolation7, i18nInterpolation8, i18nInterpolationV} from './i18n'; import {ComponentDef, ComponentDefInternal, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFlags, DirectiveDefInternal, DirectiveType, PipeDef} from './interfaces/definition'; export {ComponentFactory, ComponentFactoryResolver, ComponentRef} from './component_ref'; diff --git a/packages/core/src/render3/interfaces/view.ts b/packages/core/src/render3/interfaces/view.ts index 5f3d62fc30..bf3f2aeb6d 100644 --- a/packages/core/src/render3/interfaces/view.ts +++ b/packages/core/src/render3/interfaces/view.ts @@ -12,7 +12,7 @@ import {Sanitizer} from '../../sanitization/security'; import {LContainer} from './container'; import {ComponentQuery, ComponentTemplate, DirectiveDefInternal, DirectiveDefList, PipeDefInternal, PipeDefList} from './definition'; -import {LContainerNode, LElementNode, LViewNode, TNode} from './node'; +import {LElementNode, LViewNode, TNode} from './node'; import {LQueries} from './query'; import {Renderer3} from './renderer'; diff --git a/packages/core/src/render3/jit/injectable.ts b/packages/core/src/render3/jit/injectable.ts index 4fc86832e1..6c714b29f1 100644 --- a/packages/core/src/render3/jit/injectable.ts +++ b/packages/core/src/render3/jit/injectable.ts @@ -22,11 +22,9 @@ import {convertDependencies, reflectDependencies} from './util'; * Compile an Angular injectable according to its `Injectable` metadata, and patch the resulting * `ngInjectableDef` onto the injectable type. */ -export function compileInjectable(type: Type, meta?: Injectable): void { - // TODO(alxhub): handle JIT of bare @Injectable(). - if (!meta) { - return; - } +export function compileInjectable(type: Type, srcMeta?: Injectable): void { + // Allow the compilation of a class with a `@Injectable()` decorator without parameters + const meta: Injectable = srcMeta || {providedIn: null}; let def: any = null; Object.defineProperty(type, NG_INJECTABLE_DEF, { diff --git a/packages/platform-browser-dynamic/src/compiler_reflector.ts b/packages/platform-browser-dynamic/src/compiler_reflector.ts index a7744a2a68..fbb0b4b11b 100644 --- a/packages/platform-browser-dynamic/src/compiler_reflector.ts +++ b/packages/platform-browser-dynamic/src/compiler_reflector.ts @@ -13,9 +13,8 @@ export const MODULE_SUFFIX = ''; const builtinExternalReferences = createBuiltinExternalReferencesMap(); export class JitReflector implements CompileReflector { - private reflectionCapabilities: ReflectionCapabilities; - private builtinExternalReferences = new Map(); - constructor() { this.reflectionCapabilities = new ReflectionCapabilities(); } + private reflectionCapabilities: ReflectionCapabilities = new ReflectionCapabilities(); + componentModuleUrl(type: any, cmpMetadata: Component): string { const moduleId = cmpMetadata.moduleId; diff --git a/packages/platform-browser-dynamic/testing/src/platform_core_dynamic_testing.ts b/packages/platform-browser-dynamic/testing/src/platform_core_dynamic_testing.ts index 528770c750..0f2202bca9 100644 --- a/packages/platform-browser-dynamic/testing/src/platform_core_dynamic_testing.ts +++ b/packages/platform-browser-dynamic/testing/src/platform_core_dynamic_testing.ts @@ -6,8 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {COMPILER_OPTIONS, CompilerFactory, Injector, PlatformRef, StaticProvider, createPlatformFactory} from '@angular/core'; -import {TestComponentRenderer, ɵTestingCompilerFactory as TestingCompilerFactory} from '@angular/core/testing'; +import {COMPILER_OPTIONS, CompilerFactory, Injector, PlatformRef, createPlatformFactory} from '@angular/core'; +import {ɵTestingCompilerFactory as TestingCompilerFactory} from '@angular/core/testing'; import {ɵplatformCoreDynamic as platformCoreDynamic} from '@angular/platform-browser-dynamic'; import {COMPILER_PROVIDERS, TestingCompilerFactoryImpl} from './compiler_factory'; diff --git a/packages/platform-browser/src/browser.ts b/packages/platform-browser/src/browser.ts index be4821570b..6da3936936 100644 --- a/packages/platform-browser/src/browser.ts +++ b/packages/platform-browser/src/browser.ts @@ -7,20 +7,17 @@ */ import {CommonModule, PlatformLocation, ɵPLATFORM_BROWSER_ID as PLATFORM_BROWSER_ID} from '@angular/common'; -import {APP_ID, ApplicationModule, ClassProvider, ConstructorSansProvider, ErrorHandler, ExistingProvider, FactoryProvider, Inject, InjectionToken, ModuleWithProviders, NgModule, NgZone, Optional, PLATFORM_ID, PLATFORM_INITIALIZER, PlatformRef, RendererFactory2, RootRenderer, Sanitizer, SkipSelf, StaticProvider, Testability, TypeProvider, ValueProvider, createPlatformFactory, platformCore, ɵAPP_ROOT as APP_ROOT, ɵConsole as Console} from '@angular/core'; +import {APP_ID, ApplicationModule, ErrorHandler, Inject, ModuleWithProviders, NgModule, NgZone, Optional, PLATFORM_ID, PLATFORM_INITIALIZER, PlatformRef, RendererFactory2, Sanitizer, SkipSelf, StaticProvider, Testability, createPlatformFactory, platformCore, ɵAPP_ROOT as APP_ROOT, ɵConsole as Console} from '@angular/core'; import {BrowserDomAdapter} from './browser/browser_adapter'; import {BrowserPlatformLocation} from './browser/location/browser_platform_location'; -import {Meta} from './browser/meta'; import {SERVER_TRANSITION_PROVIDERS, TRANSITION_ID} from './browser/server-transition'; import {BrowserGetTestability} from './browser/testability'; -import {Title} from './browser/title'; import {ELEMENT_PROBE_PROVIDERS} from './dom/debug/ng_probe'; -import {getDOM} from './dom/dom_adapter'; import {DomRendererFactory2} from './dom/dom_renderer'; import {DOCUMENT} from './dom/dom_tokens'; import {DomEventsPlugin} from './dom/events/dom_events'; -import {EVENT_MANAGER_PLUGINS, EventManager, EventManagerPlugin} from './dom/events/event_manager'; +import {EVENT_MANAGER_PLUGINS, EventManager} from './dom/events/event_manager'; import {HAMMER_GESTURE_CONFIG, HAMMER_LOADER, HammerGestureConfig, HammerGesturesPlugin} from './dom/events/hammer_gestures'; import {KeyEventsPlugin} from './dom/events/key_events'; import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';