From d339d8b81d8b7480b288410eccdab0e7b61d8783 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 25 Jan 2017 22:32:32 -0800 Subject: [PATCH] refactor(abstract): Use abstract keyword where possible to decrease file size. (#14112) PR Close: #14112 --- .../@angular/compiler/src/compile_metadata.ts | 4 ---- modules/@angular/compiler/src/config.ts | 16 ++++++---------- modules/@angular/core/src/application_ref.ts | 19 ++++++++----------- modules/@angular/core/src/di/injector.ts | 6 ++---- .../core/src/di/reflective_injector.ts | 9 ++++----- .../core/src/linker/component_factory.ts | 13 ++++++------- .../core/src/linker/ng_module_factory.ts | 7 +++---- .../@angular/core/src/linker/template_ref.ts | 2 +- .../core/src/linker/view_container_ref.ts | 9 ++++----- modules/@angular/core/src/linker/view_ref.ts | 7 +++---- modules/@angular/core/src/render/api.ts | 13 ++++++------- 11 files changed, 43 insertions(+), 62 deletions(-) diff --git a/modules/@angular/compiler/src/compile_metadata.ts b/modules/@angular/compiler/src/compile_metadata.ts index 7d35b3196a..7045037543 100644 --- a/modules/@angular/compiler/src/compile_metadata.ts +++ b/modules/@angular/compiler/src/compile_metadata.ts @@ -15,10 +15,6 @@ import {LifecycleHooks, reflector} from './private_import_core'; import {CssSelector} from './selector'; import {splitAtColon} from './util'; -function unimplemented(): any { - throw new Error('unimplemented'); -} - // group 0: "[prop] or (event) or @trigger" // group 1: "prop" from "[prop]" // group 2: "event" from "(event)" diff --git a/modules/@angular/compiler/src/config.ts b/modules/@angular/compiler/src/config.ts index a81ec90fa3..c88ebdfb90 100644 --- a/modules/@angular/compiler/src/config.ts +++ b/modules/@angular/compiler/src/config.ts @@ -11,10 +11,6 @@ import {MissingTranslationStrategy, ViewEncapsulation, isDevMode} from '@angular import {CompileIdentifierMetadata} from './compile_metadata'; import {Identifiers, createIdentifier} from './identifiers'; -function unimplemented(): any { - throw new Error('unimplemented'); -} - export class CompilerConfig { public renderTypes: RenderTypes; public defaultEncapsulation: ViewEncapsulation; @@ -55,12 +51,12 @@ export class CompilerConfig { * to help tree shaking. */ export abstract class RenderTypes { - get renderer(): CompileIdentifierMetadata { return unimplemented(); } - get renderText(): CompileIdentifierMetadata { return unimplemented(); } - get renderElement(): CompileIdentifierMetadata { return unimplemented(); } - get renderComment(): CompileIdentifierMetadata { return unimplemented(); } - get renderNode(): CompileIdentifierMetadata { return unimplemented(); } - get renderEvent(): CompileIdentifierMetadata { return unimplemented(); } + abstract get renderer(): CompileIdentifierMetadata; + abstract get renderText(): CompileIdentifierMetadata; + abstract get renderElement(): CompileIdentifierMetadata; + abstract get renderComment(): CompileIdentifierMetadata; + abstract get renderNode(): CompileIdentifierMetadata; + abstract get renderEvent(): CompileIdentifierMetadata; } export class DefaultRenderTypes implements RenderTypes { diff --git a/modules/@angular/core/src/application_ref.ts b/modules/@angular/core/src/application_ref.ts index 802655731a..6c4ea5a649 100644 --- a/modules/@angular/core/src/application_ref.ts +++ b/modules/@angular/core/src/application_ref.ts @@ -8,7 +8,6 @@ import {ErrorHandler} from '../src/error_handler'; import {ListWrapper} from '../src/facade/collection'; -import {unimplemented} from '../src/facade/errors'; import {stringify} from '../src/facade/lang'; import {isPromise} from '../src/util/lang'; @@ -185,9 +184,7 @@ export abstract class PlatformRef { * * @experimental APIs related to application bootstrap are currently under review. */ - bootstrapModuleFactory(moduleFactory: NgModuleFactory): Promise> { - throw unimplemented(); - } + abstract bootstrapModuleFactory(moduleFactory: NgModuleFactory): Promise>; /** * Creates an instance of an `@NgModule` for a given platform using the given runtime compiler. @@ -217,14 +214,14 @@ export abstract class PlatformRef { * Retrieve the platform {@link Injector}, which is the parent injector for * every Angular application on the page and provides singleton providers. */ - get injector(): Injector { throw unimplemented(); }; + abstract get injector(): Injector; /** * Destroy the Angular platform and all Angular applications on the page. */ abstract destroy(): void; - get destroyed(): boolean { throw unimplemented(); } + abstract get destroyed(): boolean; } function _callAndReportToErrorHandler(errorHandler: ErrorHandler, callback: () => any): any { @@ -381,29 +378,29 @@ export abstract class ApplicationRef { * Get a list of component types registered to this application. * This list is populated even before the component is created. */ - get componentTypes(): Type[] { return []>unimplemented(); }; + abstract get componentTypes(): Type[]; /** * Get a list of components registered to this application. */ - get components(): ComponentRef[] { return []>unimplemented(); }; + abstract get components(): ComponentRef[]; /** * Attaches a view so that it will be dirty checked. * The view will be automatically detached when it is destroyed. * This will throw if the view is already attached to a ViewContainer. */ - attachView(view: ViewRef): void { unimplemented(); } + abstract attachView(view: ViewRef): void; /** * Detaches a view from dirty checking again. */ - detachView(view: ViewRef): void { unimplemented(); } + abstract detachView(view: ViewRef): void; /** * Returns the number of attached views. */ - get viewCount() { return unimplemented(); } + abstract get viewCount(): number; } @Injectable() diff --git a/modules/@angular/core/src/di/injector.ts b/modules/@angular/core/src/di/injector.ts index 1b7eeb61f5..a587d5f747 100644 --- a/modules/@angular/core/src/di/injector.ts +++ b/modules/@angular/core/src/di/injector.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {unimplemented} from '../facade/errors'; import {stringify} from '../facade/lang'; import {Type} from '../type'; @@ -55,10 +54,9 @@ export abstract class Injector { * Injector.THROW_IF_NOT_FOUND is given * - Returns the `notFoundValue` otherwise */ - get(token: Type|InjectionToken, notFoundValue?: T): T; + abstract get(token: Type|InjectionToken, notFoundValue?: T): T; /** * @deprecated from v4.0.0 use Type or InjectToken */ - get(token: any, notFoundValue?: any): any; - get(token: any, notFoundValue?: any): any { return unimplemented(); } + abstract get(token: any, notFoundValue?: any): any; } diff --git a/modules/@angular/core/src/di/reflective_injector.ts b/modules/@angular/core/src/di/reflective_injector.ts index cc4f4bf05b..d64fb0f0ca 100644 --- a/modules/@angular/core/src/di/reflective_injector.ts +++ b/modules/@angular/core/src/di/reflective_injector.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {unimplemented} from '../facade/errors'; import {Type} from '../type'; import {Injector, THROW_IF_NOT_FOUND} from './injector'; @@ -467,7 +466,7 @@ export abstract class ReflectiveInjector implements Injector { * expect(child.parent).toBe(parent); * ``` */ - get parent(): Injector { return unimplemented(); } + abstract get parent(): Injector; /** * Resolves an array of providers and creates a child injector from those providers. @@ -496,7 +495,7 @@ export abstract class ReflectiveInjector implements Injector { * because it needs to resolve the passed-in providers first. * See {@link Injector#resolve} and {@link Injector#createChildFromResolved}. */ - resolveAndCreateChild(providers: Provider[]): ReflectiveInjector { return unimplemented(); } + abstract resolveAndCreateChild(providers: Provider[]): ReflectiveInjector; /** * Creates a child injector from previously resolved providers. @@ -549,7 +548,7 @@ export abstract class ReflectiveInjector implements Injector { * expect(car).not.toBe(injector.resolveAndInstantiate(Car)); * ``` */ - resolveAndInstantiate(provider: Provider): any { return unimplemented(); } + abstract resolveAndInstantiate(provider: Provider): any; /** * Instantiates an object using a resolved provider in the context of the injector. @@ -575,7 +574,7 @@ export abstract class ReflectiveInjector implements Injector { * expect(car).not.toBe(injector.instantiateResolved(carProvider)); * ``` */ - instantiateResolved(provider: ResolvedReflectiveProvider): any { return unimplemented(); } + abstract instantiateResolved(provider: ResolvedReflectiveProvider): any; abstract get(token: any, notFoundValue?: any): any; } diff --git a/modules/@angular/core/src/linker/component_factory.ts b/modules/@angular/core/src/linker/component_factory.ts index 8789c40c58..b8ef639bd6 100644 --- a/modules/@angular/core/src/linker/component_factory.ts +++ b/modules/@angular/core/src/linker/component_factory.ts @@ -8,7 +8,6 @@ import {ChangeDetectorRef} from '../change_detection/change_detection'; import {Injector} from '../di/injector'; -import {unimplemented} from '../facade/errors'; import {Type} from '../type'; import {ElementRef} from './element_ref'; @@ -30,32 +29,32 @@ export abstract class ComponentRef { /** * Location of the Host Element of this Component Instance. */ - get location(): ElementRef { return unimplemented(); } + abstract get location(): ElementRef; /** * The injector on which the component instance exists. */ - get injector(): Injector { return unimplemented(); } + abstract get injector(): Injector; /** * The instance of the Component. */ - get instance(): C { return unimplemented(); }; + abstract get instance(): C; /** * The {@link ViewRef} of the Host View of this Component instance. */ - get hostView(): ViewRef { return unimplemented(); }; + abstract get hostView(): ViewRef; /** * The {@link ChangeDetectorRef} of the Component instance. */ - get changeDetectorRef(): ChangeDetectorRef { return unimplemented(); } + abstract get changeDetectorRef(): ChangeDetectorRef; /** * The component type. */ - get componentType(): Type { return unimplemented(); } + abstract get componentType(): Type; /** * Destroys the component instance and all of the data structures associated with it. diff --git a/modules/@angular/core/src/linker/ng_module_factory.ts b/modules/@angular/core/src/linker/ng_module_factory.ts index 3529e58e01..d6700fd67a 100644 --- a/modules/@angular/core/src/linker/ng_module_factory.ts +++ b/modules/@angular/core/src/linker/ng_module_factory.ts @@ -7,7 +7,6 @@ */ import {Injector, THROW_IF_NOT_FOUND} from '../di/injector'; -import {unimplemented} from '../facade/errors'; import {stringify} from '../facade/lang'; import {Type} from '../type'; import {ComponentFactory} from './component_factory'; @@ -27,18 +26,18 @@ export abstract class NgModuleRef { /** * The injector that contains all of the providers of the NgModule. */ - get injector(): Injector { return unimplemented(); } + abstract get injector(): Injector; /** * The ComponentFactoryResolver to get hold of the ComponentFactories * declared in the `entryComponents` property of the module. */ - get componentFactoryResolver(): ComponentFactoryResolver { return unimplemented(); } + abstract get componentFactoryResolver(): ComponentFactoryResolver; /** * The NgModule instance. */ - get instance(): T { return unimplemented(); } + abstract get instance(): T; /** * Destroys the module instance and all of the data structures associated with it. diff --git a/modules/@angular/core/src/linker/template_ref.ts b/modules/@angular/core/src/linker/template_ref.ts index ab5704ae68..cdeb9235da 100644 --- a/modules/@angular/core/src/linker/template_ref.ts +++ b/modules/@angular/core/src/linker/template_ref.ts @@ -37,7 +37,7 @@ export abstract class TemplateRef { * */ // TODO(i): rename to anchor or location - get elementRef(): ElementRef { return null; } + abstract get elementRef(): ElementRef; abstract createEmbeddedView(context: C): EmbeddedViewRef; } diff --git a/modules/@angular/core/src/linker/view_container_ref.ts b/modules/@angular/core/src/linker/view_container_ref.ts index dee90ee245..d21ff0f669 100644 --- a/modules/@angular/core/src/linker/view_container_ref.ts +++ b/modules/@angular/core/src/linker/view_container_ref.ts @@ -7,7 +7,6 @@ */ import {Injector} from '../di/injector'; -import {unimplemented} from '../facade/errors'; import {isPresent} from '../facade/lang'; import {WtfScopeFn, wtfCreateScope, wtfLeave} from '../profile/profile'; @@ -42,11 +41,11 @@ export abstract class ViewContainerRef { * Anchor element that specifies the location of this container in the containing View. * */ - get element(): ElementRef { return unimplemented(); } + abstract get element(): ElementRef; - get injector(): Injector { return unimplemented(); } + abstract get injector(): Injector; - get parentInjector(): Injector { return unimplemented(); } + abstract get parentInjector(): Injector; /** * Destroys all Views in this container. @@ -61,7 +60,7 @@ export abstract class ViewContainerRef { /** * Returns the number of Views currently attached to this container. */ - get length(): number { return unimplemented(); }; + abstract get length(): number; /** * Instantiates an Embedded View based on the {@link TemplateRef `templateRef`} and inserts it diff --git a/modules/@angular/core/src/linker/view_ref.ts b/modules/@angular/core/src/linker/view_ref.ts index 0264627b97..1df1318bf9 100644 --- a/modules/@angular/core/src/linker/view_ref.ts +++ b/modules/@angular/core/src/linker/view_ref.ts @@ -9,7 +9,6 @@ import {AnimationQueue} from '../animation/animation_queue'; import {ChangeDetectorRef} from '../change_detection/change_detector_ref'; import {ChangeDetectorStatus} from '../change_detection/constants'; -import {unimplemented} from '../facade/errors'; import {AppView} from './view'; /** @@ -21,7 +20,7 @@ export abstract class ViewRef extends ChangeDetectorRef { */ abstract destroy(): void; - get destroyed(): boolean { return unimplemented(); } + abstract get destroyed(): boolean; abstract onDestroy(callback: Function): any /** TODO #9100 */; } @@ -81,9 +80,9 @@ export abstract class ViewRef extends ChangeDetectorRef { * @experimental */ export abstract class EmbeddedViewRef extends ViewRef { - get context(): C { return unimplemented(); } + abstract get context(): C; - get rootNodes(): any[] { return unimplemented(); }; + abstract get rootNodes(): any[]; } export class ViewRef_ implements EmbeddedViewRef, ChangeDetectorRef { diff --git a/modules/@angular/core/src/render/api.ts b/modules/@angular/core/src/render/api.ts index cb70bdb3c9..e22de06fe3 100644 --- a/modules/@angular/core/src/render/api.ts +++ b/modules/@angular/core/src/render/api.ts @@ -10,7 +10,6 @@ import {AnimationKeyframe} from '../../src/animation/animation_keyframe'; import {AnimationPlayer} from '../../src/animation/animation_player'; import {AnimationStyles} from '../../src/animation/animation_styles'; import {Injector} from '../di/injector'; -import {unimplemented} from '../facade/errors'; import {ViewEncapsulation} from '../metadata/view'; /** @@ -25,12 +24,12 @@ export class RenderComponentType { } export abstract class RenderDebugInfo { - get injector(): Injector { return unimplemented(); } - get component(): any { return unimplemented(); } - get providerTokens(): any[] { return unimplemented(); } - get references(): {[key: string]: any} { return unimplemented(); } - get context(): any { return unimplemented(); } - get source(): string { return unimplemented(); } + abstract get injector(): Injector; + abstract get component(): any; + abstract get providerTokens(): any[]; + abstract get references(): {[key: string]: any}; + abstract get context(): any; + abstract get source(): string; } export interface DirectRenderer {