perf: Don’t subclass Error; resulting in smaller binary (#14160)

Subclassing errors is problematic since Error returns a
new instance. All of the patching which we do than prevent
proper application of source maps.

PR Close #14160
This commit is contained in:
Miško Hevery
2017-01-27 13:19:00 -08:00
committed by Miško Hevery
parent 3c2842be96
commit c33fda2607
51 changed files with 407 additions and 500 deletions

View File

@ -7,7 +7,7 @@
*/
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver} from '@angular/core';
import {NoComponentFactoryError} from '@angular/core/src/linker/component_factory_resolver';
import {noComponentFactoryError} from '@angular/core/src/linker/component_factory_resolver';
import {TestBed} from '@angular/core/testing';
import {Console} from '../../src/console';
@ -77,7 +77,7 @@ function declareTests({useJit}: {useJit: boolean}) {
const nestedChildComp: NestedChildComp = nestedChildCompEl.componentInstance;
expect(nestedChildComp.cfr.resolveComponentFactory(ChildComp).componentType).toBe(ChildComp);
expect(() => nestedChildComp.cfr.resolveComponentFactory(NestedChildComp))
.toThrow(new NoComponentFactoryError(NestedChildComp));
.toThrow(noComponentFactoryError(NestedChildComp));
});
});

View File

@ -9,6 +9,7 @@
import {CommonModule} from '@angular/common';
import {ComponentFactory, Host, Inject, Injectable, InjectionToken, Injector, NO_ERRORS_SCHEMA, NgModule, OnDestroy, ReflectiveInjector, SkipSelf} from '@angular/core';
import {ChangeDetectionStrategy, ChangeDetectorRef, PipeTransform} from '@angular/core/src/change_detection/change_detection';
import {getDebugContext} from '@angular/core/src/errors';
import {ComponentFactoryResolver} from '@angular/core/src/linker/component_factory_resolver';
import {ElementRef} from '@angular/core/src/linker/element_ref';
import {QueryList} from '@angular/core/src/linker/query_list';
@ -1295,7 +1296,7 @@ function declareTests({useJit}: {useJit: boolean}) {
TestBed.createComponent(MyComp);
throw 'Should throw';
} catch (e) {
const c = e.context;
const c = getDebugContext(e);
expect(getDOM().nodeName(c.componentRenderElement).toUpperCase()).toEqual('DIV');
expect((<Injector>c.injector).get).toBeTruthy();
}
@ -1310,7 +1311,7 @@ function declareTests({useJit}: {useJit: boolean}) {
fixture.detectChanges();
throw 'Should throw';
} catch (e) {
const c = e.context;
const c = getDebugContext(e);
expect(getDOM().nodeName(c.renderNode).toUpperCase()).toEqual('INPUT');
expect(getDOM().nodeName(c.componentRenderElement).toUpperCase()).toEqual('DIV');
expect((<Injector>c.injector).get).toBeTruthy();
@ -1330,7 +1331,7 @@ function declareTests({useJit}: {useJit: boolean}) {
fixture.detectChanges();
throw 'Should throw';
} catch (e) {
const c = e.context;
const c = getDebugContext(e);
expect(c.renderNode).toBeTruthy();
expect(c.source).toContain(':0:5');
}
@ -1353,7 +1354,7 @@ function declareTests({useJit}: {useJit: boolean}) {
try {
tc.injector.get(DirectiveEmittingEvent).fireEvent('boom');
} catch (e) {
const c = e.context;
const c = getDebugContext(e);
expect(getDOM().nodeName(c.renderNode).toUpperCase()).toEqual('SPAN');
expect(getDOM().nodeName(c.componentRenderElement).toUpperCase()).toEqual('DIV');
expect((<Injector>c.injector).get).toBeTruthy();