refactor(ivy): clean of #34804 from previous merge (#35022)

This is a follow up for https://github.com/angular/angular/pull/34804

PR Close #35022
This commit is contained in:
Miško Hevery
2020-01-28 16:26:56 -08:00
committed by Andrew Kushnir
parent 19c489524f
commit 36b8c0320b
19 changed files with 249 additions and 314 deletions

View File

@ -93,7 +93,7 @@ describe('host bindings', () => {
* - That executes a **different template**, that has host bindings
* - this executes `setHostBindings`
* - Inside of `setHostBindings` we are currently updating the selected index **global
* state** via `setActiveHostElement`.
* state** via `setSelectedIndex`.
* 3. We attempt to update the next property in the **original template**.
* - But the selected index has been altered, and we get errors.
*/

View File

@ -3,7 +3,7 @@
## `js_expected_symbol_test`
This folder contains tests which assert that most of the code is tree shaken away.
This is asserted by keeping gold files of all symbols which are expected to be retained.
When doing renaming it is often necessary to update the gold files, to do so use this commands:
When doing renaming it is often necessary to update the gold files, to do so use these commands:
```
yarn bazel run --config=ivy //packages/core/test/bundling/cyclic_import:symbol_test.accept

View File

@ -185,9 +185,6 @@
{
"name": "classIndexOf"
},
{
"name": "clearActiveHostElement"
},
{
"name": "computeStaticStyling"
},
@ -572,9 +569,6 @@
{
"name": "selectIndexInternal"
},
{
"name": "setActiveHostElement"
},
{
"name": "setBindingIndex"
},

View File

@ -164,9 +164,6 @@
{
"name": "callHooks"
},
{
"name": "clearActiveHostElement"
},
{
"name": "computeStaticStyling"
},
@ -446,9 +443,6 @@
{
"name": "selectIndexInternal"
},
{
"name": "setActiveHostElement"
},
{
"name": "setBindingIndex"
},

View File

@ -344,15 +344,6 @@
{
"name": "arrayInsert2"
},
{
"name": "arrayMapGet"
},
{
"name": "arrayMapIndexOf"
},
{
"name": "arrayMapSet"
},
{
"name": "assertTemplate"
},
@ -395,9 +386,6 @@
{
"name": "cleanUpView"
},
{
"name": "clearActiveHostElement"
},
{
"name": "collectNativeNodes"
},
@ -902,6 +890,15 @@
{
"name": "iterateListLike"
},
{
"name": "keyValueArrayGet"
},
{
"name": "keyValueArrayIndexOf"
},
{
"name": "keyValueArraySet"
},
{
"name": "leaveDI"
},
@ -1079,9 +1076,6 @@
{
"name": "selectIndexInternal"
},
{
"name": "setActiveHostElement"
},
{
"name": "setBindingIndex"
},
@ -1155,7 +1149,7 @@
"name": "stringifyForError"
},
{
"name": "stylingPropertyFirstUpdatePass"
"name": "stylingFirstUpdatePass"
},
{
"name": "syncViewWithBlueprint"

View File

@ -12,7 +12,7 @@ import {TNodeType} from '@angular/core/src/render3/interfaces/node';
import {LView, TView, TViewType} from '@angular/core/src/render3/interfaces/view';
import {enterView, leaveView} from '@angular/core/src/render3/state';
import {insertTStylingBinding} from '@angular/core/src/render3/styling/style_binding_list';
import {ArrayMap} from '@angular/core/src/util/array_utils';
import {KeyValueArray} from '@angular/core/src/util/array_utils';
describe('lView_debug', () => {
@ -36,14 +36,14 @@ describe('lView_debug', () => {
});
it('should decode static styling', () => {
tNode.residualStyles = ['color', 'blue'] as ArrayMap<any>;
tNode.residualClasses = ['STATIC', true] as ArrayMap<any>;
expect(tNode.styleBindings_).toEqual([['color', 'blue'] as ArrayMap<any>]);
expect(tNode.classBindings_).toEqual([['STATIC', true] as ArrayMap<any>]);
tNode.residualStyles = ['color', 'blue'] as KeyValueArray<any>;
tNode.residualClasses = ['STATIC', true] as KeyValueArray<any>;
expect(tNode.styleBindings_).toEqual([['color', 'blue'] as KeyValueArray<any>]);
expect(tNode.classBindings_).toEqual([['STATIC', true] as KeyValueArray<any>]);
});
it('should decode no-template property binding', () => {
tNode.residualClasses = ['STATIC', true] as ArrayMap<any>;
tNode.residualClasses = ['STATIC', true] as KeyValueArray<any>;
insertTStylingBinding(tView.data, tNode, 'CLASS', 2, true, true);
insertTStylingBinding(tView.data, tNode, 'color', 4, true, false);
@ -69,12 +69,12 @@ describe('lView_debug', () => {
prevIndex: 0,
nextIndex: 0,
},
['STATIC', true] as ArrayMap<any>
['STATIC', true] as KeyValueArray<any>
]);
});
it('should decode template and directive property binding', () => {
tNode.residualClasses = ['STATIC', true] as ArrayMap<any>;
tNode.residualClasses = ['STATIC', true] as KeyValueArray<any>;
insertTStylingBinding(tView.data, tNode, 'CLASS', 2, false, true);
insertTStylingBinding(tView.data, tNode, 'color', 4, false, false);
@ -100,7 +100,7 @@ describe('lView_debug', () => {
prevIndex: 0,
nextIndex: 0,
},
['STATIC', true] as ArrayMap<any>
['STATIC', true] as KeyValueArray<any>
]);
insertTStylingBinding(tView.data, tNode, null, 6, true, true);
@ -146,7 +146,7 @@ describe('lView_debug', () => {
prevIndex: 6,
nextIndex: 0,
},
['STATIC', true] as ArrayMap<any>
['STATIC', true] as KeyValueArray<any>
]);
});
});

View File

@ -8,7 +8,7 @@
import {DirectiveDef} from '@angular/core/src/render3';
import {ɵɵdefineDirective} from '@angular/core/src/render3/definition';
import {classStringParser, initializeStylingStaticArrayMap, styleStringParser, toStylingArrayMap, ɵɵclassProp, ɵɵstyleMap, ɵɵstyleProp, ɵɵstyleSanitizer} from '@angular/core/src/render3/instructions/styling';
import {classStringParser, styleStringParser, toStylingKeyValueArray, ɵɵclassProp, ɵɵstyleMap, ɵɵstyleProp, ɵɵstyleSanitizer} from '@angular/core/src/render3/instructions/styling';
import {AttributeMarker, TAttributes, TDirectiveDefs} from '@angular/core/src/render3/interfaces/node';
import {StylingRange, TStylingKey, TStylingRange, getTStylingRangeNext, getTStylingRangeNextDuplicate, getTStylingRangePrev, getTStylingRangePrevDuplicate, setTStylingRangeNext, setTStylingRangePrev, toTStylingRange} from '@angular/core/src/render3/interfaces/styling';
import {HEADER_OFFSET, TVIEW} from '@angular/core/src/render3/interfaces/view';
@ -16,7 +16,7 @@ import {getLView, leaveView, setBindingRootForHostBindings} from '@angular/core/
import {getNativeByIndex} from '@angular/core/src/render3/util/view_utils';
import {bypassSanitizationTrustStyle} from '@angular/core/src/sanitization/bypass';
import {ɵɵsanitizeStyle} from '@angular/core/src/sanitization/sanitization';
import {arrayMapSet} from '@angular/core/src/util/array_utils';
import {keyValueArraySet} from '@angular/core/src/util/array_utils';
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
import {getElementClasses, getElementStyles} from '@angular/core/testing/src/styling';
import {expect} from '@angular/core/testing/src/testing_internal';
@ -268,31 +268,6 @@ describe('styling', () => {
expect(div.style.getPropertyValue('background')).toContain('url("javascript:/trusted")');
});
});
describe('populateStylingStaticArrayMap', () => {
it('should initialize to null if no mergedAttrs', () => {
const tNode = getLView()[TVIEW].firstChild !;
expect(tNode.residualStyles).toEqual(undefined);
expect(tNode.residualClasses).toEqual(undefined);
initializeStylingStaticArrayMap(tNode);
expect(tNode.residualStyles).toEqual(null);
expect(tNode.residualClasses).toEqual(null);
});
it('should initialize from mergeAttrs', () => {
const tNode = getLView()[TVIEW].firstChild !;
expect(tNode.residualStyles).toEqual(undefined);
expect(tNode.residualClasses).toEqual(undefined);
tNode.mergedAttrs = [
'ignore', 'value', //
AttributeMarker.Classes, 'foo', 'bar', //
AttributeMarker.Styles, 'width', '0', 'color', 'red', //
];
initializeStylingStaticArrayMap(tNode);
expect(tNode.residualClasses).toEqual(['bar', true, 'foo', true] as any);
expect(tNode.residualStyles).toEqual(['color', 'red', 'width', '0'] as any);
});
});
});
describe('static', () => {
@ -428,53 +403,54 @@ describe('styling', () => {
describe('toStylingArray', () => {
describe('falsy', () => {
it('should return empty ArrayMap', () => {
expect(toStylingArrayMap(arrayMapSet, null !, '')).toEqual([] as any);
expect(toStylingArrayMap(arrayMapSet, null !, null)).toEqual([] as any);
expect(toStylingArrayMap(arrayMapSet, null !, undefined)).toEqual([] as any);
expect(toStylingArrayMap(arrayMapSet, null !, [])).toEqual([] as any);
expect(toStylingArrayMap(arrayMapSet, null !, {})).toEqual([] as any);
it('should return empty KeyValueArray', () => {
expect(toStylingKeyValueArray(keyValueArraySet, null !, '')).toEqual([] as any);
expect(toStylingKeyValueArray(keyValueArraySet, null !, null)).toEqual([] as any);
expect(toStylingKeyValueArray(keyValueArraySet, null !, undefined)).toEqual([] as any);
expect(toStylingKeyValueArray(keyValueArraySet, null !, [])).toEqual([] as any);
expect(toStylingKeyValueArray(keyValueArraySet, null !, {})).toEqual([] as any);
});
describe('string', () => {
it('should parse classes', () => {
expect(toStylingArrayMap(arrayMapSet, classStringParser, ' ')).toEqual([] as any);
expect(toStylingArrayMap(arrayMapSet, classStringParser, ' X A ')).toEqual([
expect(toStylingKeyValueArray(keyValueArraySet, classStringParser, ' ')).toEqual([
] as any);
expect(toStylingKeyValueArray(keyValueArraySet, classStringParser, ' X A ')).toEqual([
'A', true, 'X', true
] as any);
});
it('should parse styles', () => {
expect(toStylingArrayMap(arrayMapSet, styleStringParser, ' ')).toEqual([] as any);
expect(toStylingArrayMap(arrayMapSet, styleStringParser, 'B:b;A:a')).toEqual([
expect(toStylingKeyValueArray(keyValueArraySet, styleStringParser, ' ')).toEqual([
] as any);
expect(toStylingKeyValueArray(keyValueArraySet, styleStringParser, 'B:b;A:a')).toEqual([
'A', 'a', 'B', 'b'
] as any);
});
});
describe('array', () => {
it('should parse', () => {
expect(toStylingArrayMap(arrayMapSet, null !, ['X', 'A'])).toEqual([
expect(toStylingKeyValueArray(keyValueArraySet, null !, ['X', 'A'])).toEqual([
'A', true, 'X', true
] as any);
});
});
describe('object', () => {
it('should parse', () => {
expect(toStylingArrayMap(arrayMapSet, null !, {X: 'x', A: 'a'})).toEqual([
expect(toStylingKeyValueArray(keyValueArraySet, null !, {X: 'x', A: 'a'})).toEqual([
'A', 'a', 'X', 'x'
] as any);
});
});
describe('Map', () => {
it('should parse', () => {
expect(toStylingArrayMap(
arrayMapSet, null !, new Map<string, string>([['X', 'x'], ['A', 'a']])))
expect(toStylingKeyValueArray(
keyValueArraySet, null !, new Map<string, string>([['X', 'x'], ['A', 'a']])))
.toEqual(['A', 'a', 'X', 'x'] as any);
});
});
describe('Iterable', () => {
it('should parse', () => {
expect(toStylingArrayMap(arrayMapSet, null !, new Set<string>(['X', 'A']))).toEqual([
'A', true, 'X', true
] as any);
expect(toStylingKeyValueArray(keyValueArraySet, null !, new Set<string>(['X', 'A'])))
.toEqual(['A', true, 'X', true] as any);
});
});
});

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ArrayMap, arrayIndexOfSorted, arrayInsert, arrayInsert2, arrayInsertSorted, arrayMapDelete, arrayMapGet, arrayMapIndexOf, arrayMapSet, arrayRemoveSorted, arraySplice, flatten} from '../../src/util/array_utils';
import {KeyValueArray, arrayIndexOfSorted, arrayInsert, arrayInsert2, arrayInsertSorted, arrayRemoveSorted, arraySplice, flatten, keyValueArrayDelete, keyValueArrayGet, keyValueArrayIndexOf, keyValueArraySet} from '../../src/util/array_utils';
describe('array_utils', () => {
@ -140,38 +140,38 @@ describe('array_utils', () => {
});
});
describe('ArrayMap', () => {
describe('KeyValueArray', () => {
it('should support basic operations', () => {
const map: ArrayMap<number> = [] as any;
const map: KeyValueArray<number> = [] as any;
expect(arrayMapIndexOf(map, 'A')).toEqual(~0);
expect(keyValueArrayIndexOf(map, 'A')).toEqual(~0);
expect(arrayMapSet(map, 'B', 1)).toEqual(0);
expect(keyValueArraySet(map, 'B', 1)).toEqual(0);
expect(map).toEqual(['B', 1]);
expect(arrayMapIndexOf(map, 'B')).toEqual(0);
expect(keyValueArrayIndexOf(map, 'B')).toEqual(0);
expect(arrayMapSet(map, 'A', 0)).toEqual(0);
expect(keyValueArraySet(map, 'A', 0)).toEqual(0);
expect(map).toEqual(['A', 0, 'B', 1]);
expect(arrayMapIndexOf(map, 'B')).toEqual(2);
expect(arrayMapIndexOf(map, 'AA')).toEqual(~2);
expect(keyValueArrayIndexOf(map, 'B')).toEqual(2);
expect(keyValueArrayIndexOf(map, 'AA')).toEqual(~2);
expect(arrayMapSet(map, 'C', 2)).toEqual(4);
expect(keyValueArraySet(map, 'C', 2)).toEqual(4);
expect(map).toEqual(['A', 0, 'B', 1, 'C', 2]);
expect(arrayMapGet(map, 'A')).toEqual(0);
expect(arrayMapGet(map, 'B')).toEqual(1);
expect(arrayMapGet(map, 'C')).toEqual(2);
expect(arrayMapGet(map, 'AA')).toEqual(undefined);
expect(keyValueArrayGet(map, 'A')).toEqual(0);
expect(keyValueArrayGet(map, 'B')).toEqual(1);
expect(keyValueArrayGet(map, 'C')).toEqual(2);
expect(keyValueArrayGet(map, 'AA')).toEqual(undefined);
expect(arrayMapSet(map, 'B', -1)).toEqual(2);
expect(keyValueArraySet(map, 'B', -1)).toEqual(2);
expect(map).toEqual(['A', 0, 'B', -1, 'C', 2]);
expect(arrayMapDelete(map, 'AA')).toEqual(~2);
expect(arrayMapDelete(map, 'B')).toEqual(2);
expect(keyValueArrayDelete(map, 'AA')).toEqual(~2);
expect(keyValueArrayDelete(map, 'B')).toEqual(2);
expect(map).toEqual(['A', 0, 'C', 2]);
expect(arrayMapDelete(map, 'A')).toEqual(0);
expect(keyValueArrayDelete(map, 'A')).toEqual(0);
expect(map).toEqual(['C', 2]);
expect(arrayMapDelete(map, 'C')).toEqual(0);
expect(keyValueArrayDelete(map, 'C')).toEqual(0);
expect(map).toEqual([]);
});
});