perf: delete pre-view-engine core, compiler, platform-browser, etc code (#14788)

After the introduction of the view engine, we can drop a lot of code that is not used any more.

This should reduce the size of the app bundles because a lot of this code was not being properly tree-shaken by today's tools even though it was dead code.
This commit is contained in:
Tobias Bosch
2017-02-27 23:08:19 -08:00
committed by Igor Minar
parent e58cb7ba08
commit 126fda2613
151 changed files with 1283 additions and 14864 deletions

View File

@ -1,76 +0,0 @@
/**
* @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
*/
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {el} from '@angular/platform-browser/testing/browser_util';
import {ViewAnimationMap} from '../../src/animation/view_animation_map';
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
import {beforeEach, describe, expect, it} from '../../testing/testing_internal';
export function main() {
describe('ActiveAnimationsPlayersMap', function() {
let playersMap: any /** TODO #9100 */;
let elementNode: any /** TODO #9100 */;
const animationName = 'animationName';
beforeEach(() => {
playersMap = new ViewAnimationMap();
elementNode = el('<div></div>');
});
afterEach(() => {
getDOM().remove(elementNode);
elementNode = null;
});
it('should register a player an allow it to be accessed', () => {
const player = new MockAnimationPlayer();
playersMap.set(elementNode, animationName, player);
expect(playersMap.find(elementNode, animationName)).toBe(player);
expect(playersMap.findAllPlayersByElement(elementNode)).toEqual([player]);
expect(playersMap.getAllPlayers()).toEqual([player]);
expect(countPlayers(playersMap)).toEqual(1);
});
it('should remove a registered player when remove() is called', () => {
const player = new MockAnimationPlayer();
playersMap.set(elementNode, animationName, player);
expect(playersMap.find(elementNode, animationName)).toBe(player);
expect(countPlayers(playersMap)).toEqual(1);
playersMap.remove(elementNode, animationName);
expect(playersMap.find(elementNode, animationName)).not.toBe(player);
expect(countPlayers(playersMap)).toEqual(0);
});
it('should allow multiple players to be registered on the same element', () => {
const player1 = new MockAnimationPlayer();
const player2 = new MockAnimationPlayer();
playersMap.set(elementNode, 'myAnimation1', player1);
playersMap.set(elementNode, 'myAnimation2', player2);
expect(countPlayers(playersMap)).toEqual(2);
expect(playersMap.findAllPlayersByElement(elementNode)).toEqual([player1, player2]);
});
it('should only allow one player to be set for a given element/animationName pair', () => {
const player1 = new MockAnimationPlayer();
const player2 = new MockAnimationPlayer();
playersMap.set(elementNode, animationName, player1);
expect(playersMap.find(elementNode, animationName)).toBe(player1);
expect(countPlayers(playersMap)).toEqual(1);
playersMap.set(elementNode, animationName, player2);
expect(playersMap.find(elementNode, animationName)).toBe(player2);
expect(countPlayers(playersMap)).toEqual(1);
});
});
}
function countPlayers(map: ViewAnimationMap): number {
return map.getAllPlayers().length;
}

View File

@ -1,204 +0,0 @@
/**
* @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
*/
import {AnimationGroupPlayer} from '../../src/animation/animation_group_player';
import {fakeAsync, flushMicrotasks} from '../../testing';
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
import {beforeEach, describe, expect, it} from '../../testing/testing_internal';
export function main() {
describe('AnimationGroupPlayer', function() {
let players: any /** TODO #9100 */;
beforeEach(() => {
players = [
new MockAnimationPlayer(),
new MockAnimationPlayer(),
new MockAnimationPlayer(),
];
});
const assertLastStatus =
(player: MockAnimationPlayer, status: string, match: boolean, iOffset: number = 0) => {
const index = player.log.length - 1 + iOffset;
const actual = player.log.length > 0 ? player.log[index] : null;
if (match) {
expect(actual).toEqual(status);
} else {
expect(actual).not.toEqual(status);
}
};
const assertPlaying = (player: MockAnimationPlayer, isPlaying: boolean) => {
assertLastStatus(player, 'play', isPlaying);
};
it('should play and pause all players in parallel', () => {
const group = new AnimationGroupPlayer(players);
assertPlaying(players[0], false);
assertPlaying(players[1], false);
assertPlaying(players[2], false);
group.play();
assertPlaying(players[0], true);
assertPlaying(players[1], true);
assertPlaying(players[2], true);
group.pause();
assertPlaying(players[0], false);
assertPlaying(players[1], false);
assertPlaying(players[2], false);
});
it('should finish when all players have finished', () => {
const group = new AnimationGroupPlayer(players);
let completed = false;
group.onDone(() => completed = true);
group.play();
expect(completed).toBeFalsy();
players[0].finish();
expect(completed).toBeFalsy();
players[1].finish();
expect(completed).toBeFalsy();
players[2].finish();
expect(completed).toBeTruthy();
});
it('should restart all the players', () => {
const group = new AnimationGroupPlayer(players);
group.play();
assertLastStatus(players[0], 'restart', false);
assertLastStatus(players[1], 'restart', false);
assertLastStatus(players[2], 'restart', false);
group.restart();
assertLastStatus(players[0], 'restart', true);
assertLastStatus(players[1], 'restart', true);
assertLastStatus(players[2], 'restart', true);
});
it('should not destroy the inner the players when finished', () => {
const group = new AnimationGroupPlayer(players);
let completed = false;
group.onDone(() => completed = true);
expect(completed).toBeFalsy();
group.play();
assertLastStatus(players[0], 'finish', false);
assertLastStatus(players[1], 'finish', false);
assertLastStatus(players[2], 'finish', false);
expect(completed).toBeFalsy();
group.finish();
assertLastStatus(players[0], 'finish', true);
assertLastStatus(players[1], 'finish', true);
assertLastStatus(players[2], 'finish', true);
expect(completed).toBeTruthy();
});
it('should not call destroy automatically when finished even if a parent player finishes',
() => {
const group = new AnimationGroupPlayer(players);
const parent = new AnimationGroupPlayer([group, new MockAnimationPlayer()]);
group.play();
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
group.finish();
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
parent.finish();
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
});
it('should function without any players', () => {
const group = new AnimationGroupPlayer([]);
group.onDone(() => {});
group.pause();
group.play();
group.finish();
group.restart();
group.destroy();
});
it('should run the onStart method when started but only once', () => {
const player = new AnimationGroupPlayer([]);
let calls = 0;
player.onStart(() => calls++);
expect(calls).toEqual(0);
player.play();
expect(calls).toEqual(1);
player.pause();
player.play();
expect(calls).toEqual(1);
});
it('should call onDone after the next microtask if no players are provided', fakeAsync(() => {
const group = new AnimationGroupPlayer([]);
let completed = false;
group.onDone(() => completed = true);
expect(completed).toEqual(false);
flushMicrotasks();
expect(completed).toEqual(true);
}));
it('should not allow the player to be destroyed if it already has been destroyed unless reset',
fakeAsync(() => {
const p1 = new MockAnimationPlayer();
const p2 = new MockAnimationPlayer();
const innerPlayers = [p1, p2];
const groupPlayer = new AnimationGroupPlayer(innerPlayers);
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');
groupPlayer.destroy();
expect(p1.log[p1.log.length - 1]).toContain('destroy');
expect(p2.log[p2.log.length - 1]).toContain('destroy');
p1.log = p2.log = [];
groupPlayer.destroy();
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');
groupPlayer.reset();
groupPlayer.destroy();
expect(p1.log[p1.log.length - 1]).toContain('destroy');
expect(p2.log[p2.log.length - 1]).toContain('destroy');
}));
});
}

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AUTO_STYLE, AnimationEvent, animate, keyframes, state, style, transition, trigger} from '@angular/animations';
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
import {Component, HostBinding, HostListener, ViewChild} from '@angular/core';
import {AnimationDriver, BrowserAnimationsModule, ɵAnimationEngine} from '@angular/platform-browser/animations';
import {MockAnimationDriver, MockAnimationPlayer} from '@angular/platform-browser/animations/testing';
@ -14,22 +13,6 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {TestBed} from '../../testing';
export function main() {
describe('view engine', () => {
beforeEach(() => {
TestBed.configureCompiler({
useJit: true,
providers: [{
provide: USE_VIEW_ENGINE,
useValue: true,
}],
});
});
declareTests({useJit: true});
});
}
function declareTests({useJit}: {useJit: boolean}) {
// these tests are only mean't to be run within the DOM (for now)
if (typeof Element == 'undefined') return;

View File

@ -1,45 +0,0 @@
/**
* @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
*/
import {NoOpAnimationPlayer} from '../../src/animation/animation_player';
import {fakeAsync, flushMicrotasks} from '../../testing';
import {describe, expect, it} from '../../testing/testing_internal';
export function main() {
describe('NoOpAnimationPlayer', function() {
it('should call onDone after the next microtask when constructed', fakeAsync(() => {
const player = new NoOpAnimationPlayer();
let completed = false;
player.onDone(() => completed = true);
expect(completed).toEqual(false);
flushMicrotasks();
expect(completed).toEqual(true);
}));
it('should be able to run each of the player methods', fakeAsync(() => {
const player = new NoOpAnimationPlayer();
player.pause();
player.play();
player.finish();
player.restart();
player.destroy();
}));
it('should run the onStart method when started but only once', fakeAsync(() => {
const player = new NoOpAnimationPlayer();
let calls = 0;
player.onStart(() => calls++);
expect(calls).toEqual(0);
player.play();
expect(calls).toEqual(1);
player.pause();
player.play();
expect(calls).toEqual(1);
}));
});
}

View File

@ -1,143 +0,0 @@
/**
* @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
*/
import {AnimationQueue} from '@angular/core/src/animation/animation_queue';
import {NgZone} from '../../src/zone/ng_zone';
import {TestBed, fakeAsync, flushMicrotasks} from '../../testing';
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
import {beforeEach, describe, expect, it} from '../../testing/testing_internal';
export function main() {
describe('AnimationQueue', function() {
beforeEach(() => { TestBed.configureTestingModule({declarations: [], imports: []}); });
it('should queue animation players and run when flushed, but only as the next scheduled microtask',
fakeAsync(() => {
const zone = TestBed.get(NgZone);
const queue = new AnimationQueue(zone);
const log: string[] = [];
const p1 = new MockAnimationPlayer();
const p2 = new MockAnimationPlayer();
const p3 = new MockAnimationPlayer();
p1.onStart(() => log.push('1'));
p2.onStart(() => log.push('2'));
p3.onStart(() => log.push('3'));
queue.enqueue(p1);
queue.enqueue(p2);
queue.enqueue(p3);
expect(log).toEqual([]);
queue.flush();
expect(log).toEqual([]);
flushMicrotasks();
expect(log).toEqual(['1', '2', '3']);
}));
it('should always run each of the animation players outside of the angular zone on start',
fakeAsync(() => {
const zone = TestBed.get(NgZone);
const queue = new AnimationQueue(zone);
const player = new MockAnimationPlayer();
let eventHasRun = false;
player.onStart(() => {
NgZone.assertNotInAngularZone();
eventHasRun = true;
});
zone.run(() => {
NgZone.assertInAngularZone();
queue.enqueue(player);
queue.flush();
flushMicrotasks();
});
expect(eventHasRun).toBe(true);
}));
it('should always run each of the animation players outside of the angular zone on done',
fakeAsync(() => {
const zone = TestBed.get(NgZone);
const queue = new AnimationQueue(zone);
const player = new MockAnimationPlayer();
let eventHasRun = false;
player.onDone(() => {
NgZone.assertNotInAngularZone();
eventHasRun = true;
});
zone.run(() => {
NgZone.assertInAngularZone();
queue.enqueue(player);
queue.flush();
flushMicrotasks();
});
expect(eventHasRun).toBe(false);
player.finish();
expect(eventHasRun).toBe(true);
}));
it('should not run animations again incase an animation midway fails', fakeAsync(() => {
const zone = TestBed.get(NgZone);
const queue = new AnimationQueue(zone);
const log: string[] = [];
const p1 = new PlayerThatFails(false);
const p2 = new PlayerThatFails(true);
const p3 = new PlayerThatFails(false);
p1.onStart(() => log.push('1'));
p2.onStart(() => log.push('2'));
p3.onStart(() => log.push('3'));
queue.enqueue(p1);
queue.enqueue(p2);
queue.enqueue(p3);
queue.flush();
expect(() => flushMicrotasks()).toThrowError();
expect(log).toEqual(['1', '2']);
// let's reset this so that it gets triggered again
p2.reset();
p2.onStart(() => log.push('2'));
queue.flush();
expect(() => flushMicrotasks()).not.toThrowError();
expect(log).toEqual(['1', '2', '3']);
}));
});
}
class PlayerThatFails extends MockAnimationPlayer {
private _animationStarted = false;
constructor(public doFail: boolean) { super(); }
play() {
super.play();
this._animationStarted = true;
if (this.doFail) {
throw new Error('Oh nooooo');
}
}
reset() { this._animationStarted = false; }
hasStarted() { return this._animationStarted; }
}

View File

@ -1,226 +0,0 @@
/**
* @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
*/
import {AnimationSequencePlayer} from '../../src/animation/animation_sequence_player';
import {fakeAsync, flushMicrotasks} from '../../testing';
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
import {beforeEach, describe, expect, it} from '../../testing/testing_internal';
export function main() {
describe('AnimationSequencePlayer', function() {
let players: any /** TODO #9100 */;
beforeEach(() => {
players = [
new MockAnimationPlayer(),
new MockAnimationPlayer(),
new MockAnimationPlayer(),
];
});
const assertLastStatus =
(player: MockAnimationPlayer, status: string, match: boolean, iOffset: number = 0) => {
const index = player.log.length - 1 + iOffset;
const actual = player.log.length > 0 ? player.log[index] : null;
if (match) {
expect(actual).toEqual(status);
} else {
expect(actual).not.toEqual(status);
}
};
const assertPlaying = (player: MockAnimationPlayer, isPlaying: boolean) => {
assertLastStatus(player, 'play', isPlaying);
};
it('should pause/play the active player', () => {
const sequence = new AnimationSequencePlayer(players);
assertPlaying(players[0], false);
assertPlaying(players[1], false);
assertPlaying(players[2], false);
sequence.play();
assertPlaying(players[0], true);
assertPlaying(players[1], false);
assertPlaying(players[2], false);
sequence.pause();
assertPlaying(players[0], false);
assertPlaying(players[1], false);
assertPlaying(players[2], false);
sequence.play();
players[0].finish();
assertPlaying(players[0], false);
assertPlaying(players[1], true);
assertPlaying(players[2], false);
players[1].finish();
assertPlaying(players[0], false);
assertPlaying(players[1], false);
assertPlaying(players[2], true);
players[2].finish();
sequence.pause();
assertPlaying(players[0], false);
assertPlaying(players[1], false);
assertPlaying(players[2], false);
});
it('should finish when all players have finished', () => {
const sequence = new AnimationSequencePlayer(players);
let completed = false;
sequence.onDone(() => completed = true);
sequence.play();
expect(completed).toBeFalsy();
players[0].finish();
expect(completed).toBeFalsy();
players[1].finish();
expect(completed).toBeFalsy();
players[2].finish();
expect(completed).toBeTruthy();
});
it('should restart all the players', () => {
const sequence = new AnimationSequencePlayer(players);
sequence.play();
assertPlaying(players[0], true);
assertPlaying(players[1], false);
assertPlaying(players[2], false);
players[0].finish();
assertPlaying(players[0], false);
assertPlaying(players[1], true);
assertPlaying(players[2], false);
sequence.restart();
assertLastStatus(players[0], 'restart', true);
assertLastStatus(players[1], 'reset', true);
assertLastStatus(players[2], 'reset', true);
});
it('should finish all the players', () => {
const sequence = new AnimationSequencePlayer(players);
let completed = false;
sequence.onDone(() => completed = true);
sequence.play();
assertLastStatus(players[0], 'finish', false);
assertLastStatus(players[1], 'finish', false);
assertLastStatus(players[2], 'finish', false);
sequence.finish();
assertLastStatus(players[0], 'finish', true);
assertLastStatus(players[1], 'finish', true);
assertLastStatus(players[2], 'finish', true);
expect(completed).toBeTruthy();
});
it('should not call destroy automatically when finished even if a parent player is present',
() => {
const sequence = new AnimationSequencePlayer(players);
const parent = new AnimationSequencePlayer([sequence, new MockAnimationPlayer()]);
sequence.play();
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
sequence.finish();
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
parent.finish();
assertLastStatus(players[0], 'destroy', false);
assertLastStatus(players[1], 'destroy', false);
assertLastStatus(players[2], 'destroy', false);
});
it('should function without any players', () => {
const sequence = new AnimationSequencePlayer([]);
sequence.onDone(() => {});
sequence.pause();
sequence.play();
sequence.finish();
sequence.restart();
sequence.destroy();
});
it('should run the onStart method when started but only once', () => {
const player = new AnimationSequencePlayer([]);
let calls = 0;
player.onStart(() => calls++);
expect(calls).toEqual(0);
player.play();
expect(calls).toEqual(1);
player.pause();
player.play();
expect(calls).toEqual(1);
});
it('should call onDone after the next microtask if no players are provided', fakeAsync(() => {
const sequence = new AnimationSequencePlayer([]);
let completed = false;
sequence.onDone(() => completed = true);
expect(completed).toEqual(false);
flushMicrotasks();
expect(completed).toEqual(true);
}));
it('should not allow the player to be destroyed if it already has been destroyed unless reset',
fakeAsync(() => {
const p1 = new MockAnimationPlayer();
const p2 = new MockAnimationPlayer();
const innerPlayers = [p1, p2];
const sequencePlayer = new AnimationSequencePlayer(innerPlayers);
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');
sequencePlayer.destroy();
expect(p1.log[p1.log.length - 1]).toContain('destroy');
expect(p2.log[p2.log.length - 1]).toContain('destroy');
p1.log = p2.log = [];
sequencePlayer.destroy();
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');
sequencePlayer.reset();
sequencePlayer.destroy();
expect(p1.log[p1.log.length - 1]).toContain('destroy');
expect(p2.log[p2.log.length - 1]).toContain('destroy');
}));
});
}

View File

@ -1,148 +0,0 @@
/**
* @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
*/
import {FILL_STYLE_FLAG} from '../../src/animation/animation_constants';
import {AnimationKeyframe} from '../../src/animation/animation_keyframe';
import * as animationUtils from '../../src/animation/animation_style_util';
import {AnimationStyles} from '../../src/animation/animation_styles';
import {AUTO_STYLE} from '../../src/animation/metadata';
import {describe, expect, it} from '../../testing/testing_internal';
export function main() {
describe('Animation Style Utils', function() {
describe('prepareFinalAnimationStyles', () => {
it('should set all non-shared styles to the provided null value between the two sets of styles',
() => {
const styles = {opacity: 0, color: 'red'};
const newStyles = {background: 'red'};
const flag = '*';
const result = animationUtils.prepareFinalAnimationStyles(styles, newStyles, flag);
expect(result).toEqual({opacity: flag, color: flag, background: 'red'});
});
it('should handle an empty set of styles', () => {
const value = '*';
expect(animationUtils.prepareFinalAnimationStyles({}, {opacity: '0'}, value)).toEqual({
opacity: '0'
});
expect(animationUtils.prepareFinalAnimationStyles({opacity: '0'}, {}, value)).toEqual({
opacity: value
});
});
it('should set all AUTO styles to the null value', () => {
const styles = {opacity: 0};
const newStyles = {color: '*', border: '*'};
const flag = '*';
const result = animationUtils.prepareFinalAnimationStyles(styles, newStyles, null);
expect(result).toEqual({opacity: null, color: null, border: null});
});
});
describe('balanceAnimationKeyframes', () => {
it('should balance both the starting and final keyframes with thep provided styles', () => {
const collectedStyles = {width: 100, height: 200};
const finalStyles = {background: 'red', border: '1px solid black'};
const keyframes = [
new AnimationKeyframe(0, new AnimationStyles([{height: 100, opacity: 1}])),
new AnimationKeyframe(
1, new AnimationStyles([{background: 'blue', left: '100px', top: '100px'}]))
];
const result =
animationUtils.balanceAnimationKeyframes(collectedStyles, finalStyles, keyframes);
expect(animationUtils.flattenStyles(result[0].styles.styles)).toEqual({
'width': 100,
'height': 100,
'opacity': 1,
'background': '*',
'border': '*',
'left': '*',
'top': '*'
});
expect(animationUtils.flattenStyles(result[1].styles.styles)).toEqual({
'width': '*',
'height': '*',
'opacity': '*',
'background': 'blue',
'border': '1px solid black',
'left': '100px',
'top': '100px'
});
});
it('should perform balancing when no collected and final styles are provided', () => {
const keyframes = [
new AnimationKeyframe(0, new AnimationStyles([{height: 100, opacity: 1}])),
new AnimationKeyframe(1, new AnimationStyles([{width: 100}]))
];
const result = animationUtils.balanceAnimationKeyframes({}, {}, keyframes);
expect(animationUtils.flattenStyles(result[0].styles.styles))
.toEqual({'height': 100, 'opacity': 1, 'width': '*'});
expect(animationUtils.flattenStyles(result[1].styles.styles))
.toEqual({'width': 100, 'height': '*', 'opacity': '*'});
});
});
describe('clearStyles', () => {
it('should set all the style values to "null"', () => {
const styles: {[key: string]:
string | number} = {'opacity': 0, 'width': 100, 'color': 'red'};
const expectedResult: {[key: string]: string |
number} = {'opacity': null, 'width': null, 'color': null};
expect(animationUtils.clearStyles(styles)).toEqual(expectedResult);
});
it('should handle an empty set of styles',
() => { expect(animationUtils.clearStyles({})).toEqual({}); });
});
describe('collectAndResolveStyles', () => {
it('should keep a record of the styles as they are called', () => {
const styles1 = [{'opacity': 0, 'width': 100}];
const styles2 = [{'height': 999, 'opacity': 1}];
const collection: {[key: string]: string | number} = {};
expect(animationUtils.collectAndResolveStyles(collection, styles1)).toEqual(styles1);
expect(collection).toEqual({'opacity': 0, 'width': 100});
expect(animationUtils.collectAndResolveStyles(collection, styles2)).toEqual(styles2);
expect(collection).toEqual({'opacity': 1, 'width': 100, 'height': 999});
});
it('should resolve styles if they contain a FILL_STYLE_FLAG value', () => {
const styles1 = [{'opacity': 0, 'width': FILL_STYLE_FLAG}];
const styles2 = [{'height': 999, 'opacity': FILL_STYLE_FLAG}];
const collection = {};
expect(animationUtils.collectAndResolveStyles(collection, styles1)).toEqual([
{'opacity': 0, 'width': AUTO_STYLE}
]);
expect(animationUtils.collectAndResolveStyles(collection, styles2)).toEqual([
{'opacity': 0, 'height': 999}
]);
});
});
});
}

View File

@ -6,9 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ERROR_DEBUG_CONTEXT} from '@angular/core/src/errors';
import {DebugContext} from '@angular/core/src/linker/debug_context';
import {viewWrappedError} from '@angular/core/src/linker/errors';
import {ERROR_DEBUG_CONTEXT, ERROR_TYPE} from '@angular/core/src/errors';
import {ErrorHandler, wrappedError} from '../src/error_handler';
@ -99,3 +97,10 @@ Context`);
});
});
}
function viewWrappedError(originalError: any, context: any): Error {
const error = wrappedError(`Error in ${context.source}`, originalError);
(error as any)[ERROR_DEBUG_CONTEXT] = context;
(error as any)[ERROR_TYPE] = viewWrappedError;
return error;
}

View File

@ -1,62 +0,0 @@
/**
* @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
*/
import {el} from '@angular/platform-browser/testing/browser_util';
import {NoOpAnimationPlayer} from '../../src/animation/animation_player';
import {AnimationQueue} from '../../src/animation/animation_queue';
import {AnimationViewContext} from '../../src/linker/animation_view_context';
import {TestBed, fakeAsync, flushMicrotasks} from '../../testing';
import {describe, expect, iit, it} from '../../testing/testing_internal';
export function main() {
describe('AnimationViewContext', function() {
let elm: any;
beforeEach(() => { elm = el('<div></div>'); });
function getPlayers(vc: any) { return vc.getAnimationPlayers(elm); }
it('should remove the player from the registry once the animation is complete',
fakeAsync(() => {
const player = new NoOpAnimationPlayer();
const animationQueue = TestBed.get(AnimationQueue) as AnimationQueue;
const vc = new AnimationViewContext(animationQueue);
expect(getPlayers(vc).length).toEqual(0);
vc.queueAnimation(elm, 'someAnimation', player);
expect(getPlayers(vc).length).toEqual(1);
player.finish();
expect(getPlayers(vc).length).toEqual(0);
}));
it('should not remove a follow-up player from the registry if another player is queued',
fakeAsync(() => {
const player1 = new NoOpAnimationPlayer();
const player2 = new NoOpAnimationPlayer();
const animationQueue = TestBed.get(AnimationQueue) as AnimationQueue;
const vc = new AnimationViewContext(animationQueue);
vc.queueAnimation(elm, 'someAnimation', player1);
expect(getPlayers(vc).length).toBe(1);
expect(getPlayers(vc)[0]).toBe(player1);
vc.queueAnimation(elm, 'someAnimation', player2);
expect(getPlayers(vc).length).toBe(1);
expect(getPlayers(vc)[0]).toBe(player2);
player1.finish();
expect(getPlayers(vc).length).toBe(1);
expect(getPlayers(vc)[0]).toBe(player2);
player2.finish();
expect(getPlayers(vc).length).toBe(0);
}));
});
}

View File

@ -6,37 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
import {ElementSchemaRegistry} from '@angular/compiler/src/schema/element_schema_registry';
import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/testing/test_bindings';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, DoCheck, Inject, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, RenderComponentType, Renderer, RendererFactoryV2, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, WrappedValue} from '@angular/core';
import {DebugDomRenderer} from '@angular/core/src/debug/debug_renderer';
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DomRootRenderer} from '@angular/platform-browser/src/dom/dom_renderer';
import {MockSchemaRegistry} from '../../../compiler/testing/index';
import {EventEmitter} from '../../src/facade/async';
export function main() {
describe('Current compiler', () => { createTests({viewEngine: false}); });
describe('View Engine compiler', () => {
beforeEach(() => {
TestBed.configureCompiler({
useJit: true,
providers: [
{provide: USE_VIEW_ENGINE, useValue: true},
]
});
});
createTests({viewEngine: true});
});
}
function createTests({viewEngine}: {viewEngine: boolean}) {
let elSchema: MockSchemaRegistry;
let renderLog: RenderLog;
let directiveLog: DirectiveLog;
@ -123,7 +103,6 @@ function createTests({viewEngine}: {viewEngine: boolean}) {
providers: [
RenderLog,
DirectiveLog,
{provide: RootRenderer, useClass: LoggingRootRenderer},
],
});
});
@ -1286,26 +1265,6 @@ class RenderLog {
}
}
@Injectable()
class LoggingRootRenderer implements RootRenderer {
constructor(private _delegate: DomRootRenderer, private _log: RenderLog) {}
renderComponent(componentProto: RenderComponentType): Renderer {
return new LoggingRenderer(this._delegate.renderComponent(componentProto), this._log);
}
}
class LoggingRenderer extends DebugDomRenderer {
constructor(delegate: Renderer, private _log: RenderLog) { super(delegate); }
setElementProperty(renderElement: any, propertyName: string, propertyValue: any) {
this._log.setElementProperty(renderElement, propertyName, propertyValue);
super.setElementProperty(renderElement, propertyName, propertyValue);
}
setText(renderNode: any, value: string) { this._log.setText(renderNode, value); }
}
class DirectiveLogEntry {
constructor(public directiveName: string, public method: string) {}
}

View File

@ -1,185 +0,0 @@
/**
* @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
*/
import {Component, ContentChild, Injectable, Input, RenderComponentType, Renderer, RootRenderer, TemplateRef} from '@angular/core';
import {DebugDomRenderer} from '@angular/core/src/debug/debug_renderer';
import {DirectRenderer} from '@angular/core/src/render/api';
import {TestBed, inject} from '@angular/core/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DIRECT_DOM_RENDERER, DomRootRenderer} from '@angular/platform-browser/src/dom/dom_renderer';
import {expect} from '@angular/platform-browser/testing/matchers';
let directRenderer: any;
let destroyViewLogs: any[];
export function main() {
// Don't run on server...
if (!getDOM().supportsDOMEvents()) return;
// TODO(tbosch): delete the tests here as they use the old renderer.
xdescribe('direct dom integration tests', function() {
beforeEach(() => {
directRenderer = DIRECT_DOM_RENDERER;
destroyViewLogs = [];
spyOn(directRenderer, 'remove').and.callThrough();
spyOn(directRenderer, 'appendChild').and.callThrough();
spyOn(directRenderer, 'insertBefore').and.callThrough();
TestBed.configureTestingModule(
{providers: [{provide: RootRenderer, useClass: DirectRootRenderer}]});
});
it('should attach views as last nodes in a parent', () => {
@Component({template: '<div *ngIf="true">hello</div>'})
class MyComp {
}
TestBed.configureTestingModule({declarations: [MyComp]});
const fixture = TestBed.createComponent(MyComp);
directRenderer.insertBefore.calls.reset();
directRenderer.appendChild.calls.reset();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('hello');
expect(directRenderer.insertBefore).not.toHaveBeenCalled();
expect(directRenderer.appendChild).toHaveBeenCalled();
});
it('should attach views as non last nodes in a parent', () => {
@Component({template: '<div *ngIf="true">hello</div>after'})
class MyComp {
}
TestBed.configureTestingModule({declarations: [MyComp]});
const fixture = TestBed.createComponent(MyComp);
directRenderer.insertBefore.calls.reset();
directRenderer.appendChild.calls.reset();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('helloafter');
expect(directRenderer.insertBefore).toHaveBeenCalled();
expect(directRenderer.appendChild).not.toHaveBeenCalled();
});
it('should detach views', () => {
@Component({template: '<div *ngIf="shown">hello</div>'})
class MyComp {
shown = true;
}
TestBed.configureTestingModule({declarations: [MyComp]});
const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges();
directRenderer.remove.calls.reset();
fixture.componentInstance.shown = false;
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('');
expect(directRenderer.remove).toHaveBeenCalled();
});
it('should pass null as all nodes to destroyView', () => {
@Component({template: '<div *ngIf="shown">hello</div>'})
class MyComp {
shown = true;
}
TestBed.configureTestingModule({declarations: [MyComp]});
const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges();
destroyViewLogs.length = 0;
fixture.componentInstance.shown = false;
fixture.detectChanges();
expect(destroyViewLogs).toEqual([[null, null]]);
});
it('should project nodes', () => {
@Component({template: '<child>hello</child>'})
class Parent {
}
@Component({selector: 'child', template: '(<ng-content></ng-content>)'})
class Child {
}
TestBed.configureTestingModule({declarations: [Parent, Child]});
const fixture = TestBed.createComponent(Parent);
expect(fixture.nativeElement).toHaveText('(hello)');
const childHostEl = fixture.nativeElement.children[0];
const projectedNode = childHostEl.childNodes[1];
expect(directRenderer.appendChild).toHaveBeenCalledWith(projectedNode, childHostEl);
});
it('should support using structural directives with ngTemplateOutlet', () => {
@Component({
template:
'<child [templateCtx]="templateCtx"><ng-template let-shown="shown" #tpl><span *ngIf="shown">hello</span></ng-template></child>'
})
class Parent {
templateCtx = {shown: false};
}
@Component({
selector: 'child',
template:
'(<ng-container [ngTemplateOutlet]="templateRef" [ngOutletContext]="templateCtx"></ng-container>)'
})
class Child {
@Input()
templateCtx: any;
@ContentChild('tpl')
templateRef: TemplateRef<any>;
}
TestBed.configureTestingModule({declarations: [Parent, Child]});
let fixture = TestBed.createComponent(Parent);
fixture.componentInstance.templateCtx.shown = false;
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('()');
fixture.destroy();
fixture = TestBed.createComponent(Parent);
fixture.componentInstance.templateCtx.shown = true;
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('(hello)');
fixture.componentInstance.templateCtx.shown = false;
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('()');
});
});
}
@Injectable()
class DirectRootRenderer implements RootRenderer {
constructor(private _delegate: DomRootRenderer) {}
renderComponent(componentType: RenderComponentType): Renderer {
const renderer = new DebugDomRenderer(this._delegate.renderComponent(componentType));
(renderer as any).directRenderer = directRenderer;
const originalDestroyView = renderer.destroyView;
renderer.destroyView = function(...args: any[]) {
destroyViewLogs.push(args);
return originalDestroyView.apply(this, args);
};
return renderer;
}
}

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver} from '@angular/core';
import {noComponentFactoryError} from '@angular/core/src/linker/component_factory_resolver';
import {TestBed} from '@angular/core/testing';
@ -15,19 +14,6 @@ import {Console} from '../../src/console';
export function main() {
describe('Current compiler', () => { createTests({viewEngine: false}); });
describe('View Engine compiler', () => {
beforeEach(() => {
TestBed.configureCompiler(
{useJit: true, providers: [{provide: USE_VIEW_ENGINE, useValue: true}]});
});
createTests({viewEngine: true});
});
}
function createTests({viewEngine}: {viewEngine: boolean}) {
describe('jit', () => { declareTests({useJit: true}); });
describe('no jit', () => { declareTests({useJit: false}); });
}

View File

@ -7,14 +7,13 @@
*/
import {CommonModule} from '@angular/common';
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
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';
import {TemplateRef, TemplateRef_} from '@angular/core/src/linker/template_ref';
import {TemplateRef} from '@angular/core/src/linker/template_ref';
import {ViewContainerRef} from '@angular/core/src/linker/view_container_ref';
import {EmbeddedViewRef} from '@angular/core/src/linker/view_ref';
import {Attribute, Component, ContentChildren, Directive, HostBinding, HostListener, Input, Output, Pipe} from '@angular/core/src/metadata';
@ -30,27 +29,13 @@ import {stringify} from '../../src/facade/lang';
const ANCHOR_ELEMENT = new InjectionToken('AnchorElement');
export function main() {
describe('jit', () => { declareTests({useJit: true, viewEngine: false}); });
describe('jit', () => { declareTests({useJit: true}); });
describe('no jit', () => { declareTests({useJit: false, viewEngine: false}); });
describe('view engine', () => {
beforeEach(() => {
TestBed.configureCompiler({
useJit: true,
providers: [{
provide: USE_VIEW_ENGINE,
useValue: true,
}],
});
});
declareTests({useJit: true, viewEngine: true});
});
describe('no jit', () => { declareTests({useJit: false}); });
}
function declareTests({useJit, viewEngine}: {useJit: boolean, viewEngine: boolean}) {
function declareTests({useJit}: {useJit: boolean}) {
describe('integration tests', function() {
beforeEach(() => { TestBed.configureCompiler({useJit}); });
@ -1290,7 +1275,7 @@ function declareTests({useJit, viewEngine}: {useJit: boolean, viewEngine: boolea
});
});
viewEngine || describe('error handling', () => {
describe('error handling', () => {
it('should report a meaningful error when a directive is missing annotation', () => {
TestBed.configureTestingModule({declarations: [MyComp, SomeDirectiveMissingAnnotation]});

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
import {Component, Directive, ElementRef, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by';
@ -14,19 +13,6 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {expect} from '@angular/platform-browser/testing/matchers';
export function main() {
describe('Current compiler', () => { createTests({viewEngine: false}); });
describe('View Engine compiler', () => {
beforeEach(() => {
TestBed.configureCompiler(
{useJit: true, providers: [{provide: USE_VIEW_ENGINE, useValue: true}]});
});
createTests({viewEngine: true});
});
}
function createTests({viewEngine}: {viewEngine: boolean}) {
describe('projection', () => {
beforeEach(() => TestBed.configureTestingModule({declarations: [MainComp, OtherComp, Simple]}));

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, ContentChild, ContentChildren, Directive, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef, asNativeElements} from '@angular/core';
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/matchers';
@ -14,19 +13,6 @@ import {expect} from '@angular/platform-browser/testing/matchers';
import {stringify} from '../../src/facade/lang';
export function main() {
describe('Current compiler', () => { createTests({viewEngine: false}); });
describe('View Engine compiler', () => {
beforeEach(() => {
TestBed.configureCompiler(
{useJit: true, providers: [{provide: USE_VIEW_ENGINE, useValue: true}]});
});
createTests({viewEngine: true});
});
}
function createTests({viewEngine}: {viewEngine: boolean}) {
describe('Query API', () => {
beforeEach(() => TestBed.configureTestingModule({

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, ElementRef, Host, Inject, InjectionToken, Input, Optional, Pipe, PipeTransform, Provider, Self, SkipSelf, TemplateRef, Type, ViewContainerRef} from '@angular/core';
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
@ -184,19 +183,6 @@ class TestComp {
}
export function main() {
describe('Current compiler', () => { createTests({viewEngine: false}); });
describe('View Engine compiler', () => {
beforeEach(() => {
TestBed.configureCompiler(
{useJit: true, providers: [{provide: USE_VIEW_ENGINE, useValue: true}]});
});
createTests({viewEngine: true});
});
}
function createTests({viewEngine}: {viewEngine: boolean}) {
function createComponentFixture<T>(
template: string, providers: Provider[] = null, comp: Type<T> = null): ComponentFixture<T> {
if (!comp) {