refactor(ivy): split the `memory` instruction into `store` and `load` (#22268)

PR Close #22268
This commit is contained in:
Victor Berchet 2018-02-16 16:58:07 -08:00
parent 3ceee99e22
commit 5a14e2238f
19 changed files with 105 additions and 114 deletions

View File

@ -63,7 +63,7 @@ export class Identifiers {
static interpolation8: o.ExternalReference = {name: 'ɵi8', moduleName: CORE}; static interpolation8: o.ExternalReference = {name: 'ɵi8', moduleName: CORE};
static interpolationV: o.ExternalReference = {name: 'ɵiV', moduleName: CORE}; static interpolationV: o.ExternalReference = {name: 'ɵiV', moduleName: CORE};
static memory: o.ExternalReference = {name: 'ɵm', moduleName: CORE}; static load: o.ExternalReference = {name: 'ɵld', moduleName: CORE};
static projection: o.ExternalReference = {name: 'ɵP', moduleName: CORE}; static projection: o.ExternalReference = {name: 'ɵP', moduleName: CORE};
static projectionDef: o.ExternalReference = {name: 'ɵpD', moduleName: CORE}; static projectionDef: o.ExternalReference = {name: 'ɵpD', moduleName: CORE};

View File

@ -408,7 +408,7 @@ class TemplateDefinitionBuilder implements TemplateAstVisitor, LocalResolver {
// Generate the update temporary. // Generate the update temporary.
const variableName = this.bindingScope.freshReferenceName(); const variableName = this.bindingScope.freshReferenceName();
this._bindingMode.push(o.variable(variableName, o.INFERRED_TYPE) this._bindingMode.push(o.variable(variableName, o.INFERRED_TYPE)
.set(o.importExpr(R3.memory).callFn([o.literal(slot)])) .set(o.importExpr(R3.load).callFn([o.literal(slot)]))
.toDeclStmt(o.INFERRED_TYPE, [o.StmtModifier.Final])); .toDeclStmt(o.INFERRED_TYPE, [o.StmtModifier.Final]));
this.bindingScope.set(reference.name, variableName); this.bindingScope.set(reference.name, variableName);
return [reference.name, reference.originalValue]; return [reference.name, reference.originalValue];

View File

@ -293,7 +293,7 @@ describe('r3_view_compiler', () => {
$r3$.ɵC(2, $c2$, MyComponent_IfDirective_Template_2); $r3$.ɵC(2, $c2$, MyComponent_IfDirective_Template_2);
$r3$.ɵe(); $r3$.ɵe();
} }
const $foo$ = $r3$.ɵm(1); const $foo$ = $r3$.ɵld(1);
IfDirective.ngDirectiveDef.h(3,2); IfDirective.ngDirectiveDef.h(3,2);
$r3$.ɵcR(2); $r3$.ɵcR(2);
$r3$.ɵr(3,2); $r3$.ɵr(3,2);
@ -420,7 +420,7 @@ describe('r3_view_compiler', () => {
$r3$.ɵe(); $r3$.ɵe();
$r3$.ɵT(2); $r3$.ɵT(2);
} }
const $user$ = $r3$.ɵm(1); const $user$ = $r3$.ɵld(1);
$r3$.ɵt(2, $r3$.ɵi1('Hello ', $user$.value, '!')); $r3$.ɵt(2, $r3$.ɵi1('Hello ', $user$.value, '!'));
} }
}); });

View File

@ -65,7 +65,8 @@ export {
t as ɵt, t as ɵt,
v as ɵv, v as ɵv,
r as ɵr, r as ɵr,
m as ɵm, st as ɵst,
ld as ɵld,
Pp as ɵPp, Pp as ɵPp,
} from './render3/index'; } from './render3/index';
// clang-format on // clang-format on

View File

@ -53,7 +53,8 @@ export {
elementStyle as s, elementStyle as s,
listener as L, listener as L,
memory as m, store as st,
load as ld,
projection as P, projection as P,
projectionDef as pD, projectionDef as pD,

View File

@ -1306,8 +1306,7 @@ export function projection(
const componentNode = findComponentHost(currentView); const componentNode = findComponentHost(currentView);
// make sure that nodes to project were memorized // make sure that nodes to project were memorized
const nodesForSelector = const nodesForSelector = componentNode.data !.data ![localIndex][selectorIndex];
valueInData<LNode[][]>(componentNode.data !.data !, localIndex)[selectorIndex];
// build the linked list of projected nodes: // build the linked list of projected nodes:
for (let i = 0; i < nodesForSelector.length; i++) { for (let i = 0; i < nodesForSelector.length; i++) {
@ -1744,23 +1743,20 @@ export function interpolation8(
NO_CHANGE; NO_CHANGE;
} }
export function memory<T>(index: number, value?: T): T { /** Store a value in the `data` at a given `index`. */
return valueInData<T>(data, index, value); export function store<T>(index: number, value: T): void {
// We don't store any static data for local variables, so the first time
// we see the template, we should store as null to avoid a sparse array
if (index >= tData.length) {
tData[index] = null;
}
data[index] = value;
} }
function valueInData<T>(data: any[], index: number, value?: T): T { /** Retrieves a value from the `data`. */
if (value === undefined) { export function load<T>(index: number): T {
ngDevMode && assertDataInRange(index, data); ngDevMode && assertDataInRange(index, data);
value = data[index]; return data[index];
} else {
// We don't store any static data for local variables, so the first time
// we see the template, we should store as null to avoid a sparse array
if (index >= tData.length) {
tData[index] = null;
}
data[index] = value;
}
return value !;
} }
export function getCurrentQueries(QueryType: {new (): LQueries}): LQueries { export function getCurrentQueries(QueryType: {new (): LQueries}): LQueries {

View File

@ -17,7 +17,7 @@ import {getSymbolIterator} from '../util';
import {assertEqual, assertNotNull} from './assert'; import {assertEqual, assertNotNull} from './assert';
import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di'; import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di';
import {assertPreviousIsParent, getCurrentQueries, memory} from './instructions'; import {assertPreviousIsParent, getCurrentQueries, store} from './instructions';
import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition'; import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector'; import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
import {LContainerNode, LElementNode, LNode, LNodeFlags, TNode, unusedValueExportToPlacateAjd as unused3} from './interfaces/node'; import {LContainerNode, LElementNode, LNode, LNodeFlags, TNode, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
@ -389,7 +389,7 @@ export function query<T>(
queries.track(queryList, predicate, descend, read); queries.track(queryList, predicate, descend, read);
if (memoryIndex != null) { if (memoryIndex != null) {
memory(memoryIndex, queryList); store(memoryIndex, queryList);
} }
return queryList; return queryList;
} }

View File

@ -11,7 +11,6 @@ import {IterableDiffers} from '@angular/core';
import {defaultIterableDiffers} from '../../src/change_detection/change_detection'; import {defaultIterableDiffers} from '../../src/change_detection/change_detection';
import {DirectiveType, InjectFlags, NgOnChangesFeature, defineDirective, inject, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index'; import {DirectiveType, InjectFlags, NgOnChangesFeature, defineDirective, inject, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index';
import {memory} from '../../src/render3/instructions';
export const NgForOf: DirectiveType<NgForOfDef<any>> = NgForOfDef as any; export const NgForOf: DirectiveType<NgForOfDef<any>> = NgForOfDef as any;

View File

@ -354,7 +354,7 @@ describe('compiler specification', () => {
$r3$.ɵC(2, $c1_dirs$, C1); $r3$.ɵC(2, $c1_dirs$, C1);
$r3$.ɵe(); $r3$.ɵe();
} }
let $foo$ = $r3$.ɵm<any>(1); let $foo$ = $r3$.ɵld<any>(1);
$r3$.ɵcR(2); $r3$.ɵcR(2);
$r3$.ɵr(3, 2); $r3$.ɵr(3, 2);
$r3$.ɵcr(); $r3$.ɵcr();
@ -951,8 +951,8 @@ describe('compiler specification', () => {
$r3$.ɵe(); $r3$.ɵe();
} }
$r3$.ɵqR($tmp$ = $r3$.ɵm<QueryList<any>>(0)) && (ctx.someDir = $tmp$.first); $r3$.ɵqR($tmp$ = $r3$.ɵld<QueryList<any>>(0)) && (ctx.someDir = $tmp$.first);
$r3$.ɵqR($tmp$ = $r3$.ɵm<QueryList<any>>(1)) && $r3$.ɵqR($tmp$ = $r3$.ɵld<QueryList<any>>(1)) &&
(ctx.someDirList = $tmp$ as QueryList<any>); (ctx.someDirList = $tmp$ as QueryList<any>);
SomeDirective.ngDirectiveDef.h(3, 2); SomeDirective.ngDirectiveDef.h(3, 2);
$r3$.ɵr(3, 2); $r3$.ɵr(3, 2);
@ -998,9 +998,9 @@ describe('compiler specification', () => {
hostBindings: function ContentQueryComponent_HostBindings( hostBindings: function ContentQueryComponent_HostBindings(
dirIndex: $number$, elIndex: $number$) { dirIndex: $number$, elIndex: $number$) {
let $tmp$: any; let $tmp$: any;
const $instance$ = $r3$.ɵm<any[]>(dirIndex)[0]; const $instance$ = $r3$.ɵld<any[]>(dirIndex)[0];
$r3$.ɵqR($tmp$ = $r3$.ɵm<any[]>(dirIndex)[1]) && ($instance$.someDir = $tmp$.first); $r3$.ɵqR($tmp$ = $r3$.ɵld<any[]>(dirIndex)[1]) && ($instance$.someDir = $tmp$.first);
$r3$.ɵqR($tmp$ = $r3$.ɵm<any[]>(dirIndex)[2]) && ($instance$.someDirList = $tmp$); $r3$.ɵqR($tmp$ = $r3$.ɵld<any[]>(dirIndex)[2]) && ($instance$.someDirList = $tmp$);
}, },
template: function ContentQueryComponent_Template( template: function ContentQueryComponent_Template(
ctx: $ContentQueryComponent$, cm: $boolean$) { ctx: $ContentQueryComponent$, cm: $boolean$) {
@ -1035,7 +1035,7 @@ describe('compiler specification', () => {
template: function MyApp_Template(ctx: $MyApp$, cm: $boolean$) { template: function MyApp_Template(ctx: $MyApp$, cm: $boolean$) {
if (cm) { if (cm) {
$r3$.ɵE(0, ContentQueryComponent); $r3$.ɵE(0, ContentQueryComponent);
contentQueryComp = $r3$.ɵm<any[]>(1)[0]; contentQueryComp = $r3$.ɵld<any[]>(1)[0];
$r3$.ɵE(2, 'div', $e2_attrs$, $e2_dirs$); $r3$.ɵE(2, 'div', $e2_attrs$, $e2_dirs$);
$r3$.ɵe(); $r3$.ɵe();
$r3$.ɵe(); $r3$.ɵe();
@ -1148,7 +1148,7 @@ describe('compiler specification', () => {
$r3$.ɵe(); $r3$.ɵe();
$r3$.ɵT(2); $r3$.ɵT(2);
} }
const l1_user = $r3$.ɵm<any>(1); const l1_user = $r3$.ɵld<any>(1);
$r3$.ɵt(2, $r3$.ɵi1('Hello ', l1_user.value, '!')); $r3$.ɵt(2, $r3$.ɵi1('Hello ', l1_user.value, '!'));
} }
}); });

View File

@ -7,7 +7,7 @@
*/ */
import {detectChanges} from '../../src/render3/index'; import {detectChanges} from '../../src/render3/index';
import {componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, memory, projection, projectionDef, text} from '../../src/render3/instructions'; import {componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, load, projection, projectionDef, text} from '../../src/render3/instructions';
import {createComponent, renderComponent, toHtml} from './render_util'; import {createComponent, renderComponent, toHtml} from './render_util';
@ -309,7 +309,7 @@ describe('content projection', () => {
if (cm) { if (cm) {
elementStart(0, Child); elementStart(0, Child);
{ {
childCmptInstance = memory(1); childCmptInstance = load(1);
text(2, 'content'); text(2, 'content');
} }
elementEnd(); elementEnd();
@ -362,7 +362,7 @@ describe('content projection', () => {
if (cm) { if (cm) {
elementStart(0, Child); elementStart(0, Child);
{ {
childCmptInstance = memory(1); childCmptInstance = load(1);
text(2, 'content'); text(2, 'content');
} }
elementEnd(); elementEnd();
@ -417,7 +417,7 @@ describe('content projection', () => {
if (cm) { if (cm) {
elementStart(0, Child); elementStart(0, Child);
{ {
childCmptInstance = memory(1); childCmptInstance = load(1);
text(2, 'content'); text(2, 'content');
} }
elementEnd(); elementEnd();
@ -512,7 +512,7 @@ describe('content projection', () => {
if (cm) { if (cm) {
elementStart(0, Child); elementStart(0, Child);
{ {
childCmptInstance = memory(1); childCmptInstance = load(1);
text(2, 'content'); text(2, 'content');
} }
elementEnd(); elementEnd();

View File

@ -11,7 +11,7 @@ import {ElementRef, TemplateRef, ViewContainerRef} from '@angular/core';
import {defineComponent} from '../../src/render3/definition'; import {defineComponent} from '../../src/render3/definition';
import {InjectFlags, bloomAdd, bloomFindPossibleInjector, getOrCreateNodeInjector} from '../../src/render3/di'; import {InjectFlags, bloomAdd, bloomFindPossibleInjector, getOrCreateNodeInjector} from '../../src/render3/di';
import {PublicFeature, defineDirective, inject, injectElementRef, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index'; import {PublicFeature, defineDirective, inject, injectElementRef, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index';
import {bind, container, containerRefreshEnd, containerRefreshStart, createLNode, createLView, createTView, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, enterView, interpolation2, leaveView, memory, text, textBinding} from '../../src/render3/instructions'; import {bind, container, containerRefreshEnd, containerRefreshStart, createLNode, createLView, createTView, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, enterView, interpolation2, leaveView, load, text, textBinding} from '../../src/render3/instructions';
import {LInjector} from '../../src/render3/interfaces/injector'; import {LInjector} from '../../src/render3/interfaces/injector';
import {LNodeFlags} from '../../src/render3/interfaces/node'; import {LNodeFlags} from '../../src/render3/interfaces/node';
@ -31,7 +31,7 @@ describe('di', () => {
{ text(2); } { text(2); }
elementEnd(); elementEnd();
} }
textBinding(2, bind(memory<Directive>(1).value)); textBinding(2, bind(load<Directive>(1).value));
} }
expect(renderToHtml(Template, {})).toEqual('<div>Created</div>'); expect(renderToHtml(Template, {})).toEqual('<div>Created</div>');
@ -71,7 +71,7 @@ describe('di', () => {
} }
elementEnd(); elementEnd();
} }
textBinding(5, bind(memory<DirectiveC>(4).value)); textBinding(5, bind(load<DirectiveC>(4).value));
} }
expect(renderToHtml(Template, {})).toEqual('<div><span>AB</span></div>'); expect(renderToHtml(Template, {})).toEqual('<div><span>AB</span></div>');
@ -110,9 +110,8 @@ describe('di', () => {
elementEnd(); elementEnd();
} }
textBinding( textBinding(
3, 3, interpolation2(
interpolation2( '', load<Directive>(1).value, '-', load<DirectiveSameInstance>(2).value, ''));
'', memory<Directive>(1).value, '-', memory<DirectiveSameInstance>(2).value, ''));
} }
expect(renderToHtml(Template, {})).toEqual('<div>ElementRef-true</div>'); expect(renderToHtml(Template, {})).toEqual('<div>ElementRef-true</div>');
@ -151,9 +150,8 @@ describe('di', () => {
text(3); text(3);
} }
textBinding( textBinding(
3, 3, interpolation2(
interpolation2( '', load<Directive>(1).value, '-', load<DirectiveSameInstance>(2).value, ''));
'', memory<Directive>(1).value, '-', memory<DirectiveSameInstance>(2).value, ''));
} }
expect(renderToHtml(Template, {})).toEqual('TemplateRef-true'); expect(renderToHtml(Template, {})).toEqual('TemplateRef-true');
@ -192,9 +190,8 @@ describe('di', () => {
elementEnd(); elementEnd();
} }
textBinding( textBinding(
3, 3, interpolation2(
interpolation2( '', load<Directive>(1).value, '-', load<DirectiveSameInstance>(2).value, ''));
'', memory<Directive>(1).value, '-', memory<DirectiveSameInstance>(2).value, ''));
} }
expect(renderToHtml(Template, {})).toEqual('<div>ViewContainerRef-true</div>'); expect(renderToHtml(Template, {})).toEqual('<div>ViewContainerRef-true</div>');
@ -306,9 +303,8 @@ describe('di', () => {
elementEnd(); elementEnd();
} }
textBinding( textBinding(
3, 3, interpolation2(
interpolation2( '', load<ChildDirective>(1).value, '-', load<Child2Directive>(2).value, ''));
'', memory<ChildDirective>(1).value, '-', memory<Child2Directive>(2).value, ''));
embeddedViewEnd(); embeddedViewEnd();
} }
containerRefreshEnd(); containerRefreshEnd();

View File

@ -7,7 +7,7 @@
*/ */
import {defineDirective} from '../../src/render3/index'; import {defineDirective} from '../../src/render3/index';
import {bind, componentRefresh, elementEnd, elementProperty, elementStart, memory} from '../../src/render3/instructions'; import {bind, componentRefresh, elementEnd, elementProperty, elementStart, load} from '../../src/render3/instructions';
import {renderToHtml} from './render_util'; import {renderToHtml} from './render_util';
@ -24,8 +24,7 @@ describe('directive', () => {
type: Directive, type: Directive,
factory: () => directiveInstance = new Directive, factory: () => directiveInstance = new Directive,
hostBindings: (directiveIndex: number, elementIndex: number) => { hostBindings: (directiveIndex: number, elementIndex: number) => {
elementProperty( elementProperty(elementIndex, 'className', bind(load<Directive>(directiveIndex).klass));
elementIndex, 'className', bind(memory<Directive>(directiveIndex).klass));
} }
}); });
} }

View File

@ -7,7 +7,7 @@
*/ */
import {defineComponent, defineDirective} from '../../src/render3/index'; import {defineComponent, defineDirective} from '../../src/render3/index';
import {bind, container, containerRefreshEnd, containerRefreshStart, elementAttribute, elementClass, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, memory, text, textBinding} from '../../src/render3/instructions'; import {bind, container, containerRefreshEnd, containerRefreshStart, elementAttribute, elementClass, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, load, text, textBinding} from '../../src/render3/instructions';
import {renderToHtml} from './render_util'; import {renderToHtml} from './render_util';
@ -37,7 +37,7 @@ describe('exports', () => {
elementEnd(); elementEnd();
text(2); text(2);
} }
textBinding(2, memory<MyComponent>(1).name); textBinding(2, load<MyComponent>(1).name);
} }
class MyComponent { class MyComponent {
@ -83,7 +83,7 @@ describe('exports', () => {
elementStart(2, 'div', null, [MyDir]); elementStart(2, 'div', null, [MyDir]);
elementEnd(); elementEnd();
} }
elementProperty(2, 'myDir', bind(memory<MyComponent>(1))); elementProperty(2, 'myDir', bind(load<MyComponent>(1)));
} }
renderToHtml(Template, {}); renderToHtml(Template, {});
@ -99,7 +99,7 @@ describe('exports', () => {
elementEnd(); elementEnd();
text(2); text(2);
} }
textBinding(2, memory<SomeDir>(1).name); textBinding(2, load<SomeDir>(1).name);
} }
class SomeDir { class SomeDir {
@ -209,7 +209,7 @@ describe('exports', () => {
elementStart(2, MyComponent); elementStart(2, MyComponent);
elementEnd(); elementEnd();
} }
elementProperty(0, 'myDir', bind(memory<MyComponent>(3))); elementProperty(0, 'myDir', bind(load<MyComponent>(3)));
} }
renderToHtml(Template, {}); renderToHtml(Template, {});
@ -229,7 +229,7 @@ describe('exports', () => {
elementEnd(); elementEnd();
} }
let myInput = elementStart(4); let myInput = elementStart(4);
let myComp = memory(3) as MyComponent; let myComp = load<MyComponent>(3);
textBinding(0, bind(myInput && (myInput as any).value)); textBinding(0, bind(myInput && (myInput as any).value));
textBinding(1, bind(myComp && myComp.name)); textBinding(1, bind(myComp && myComp.name));
} }

View File

@ -7,7 +7,7 @@
*/ */
import {defineComponent, defineDirective} from '../../src/render3/index'; import {defineComponent, defineDirective} from '../../src/render3/index';
import {NO_CHANGE, bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementAttribute, elementClass, elementEnd, elementProperty, elementStart, elementStyle, embeddedViewEnd, embeddedViewStart, interpolation1, interpolation2, interpolation3, interpolation4, interpolation5, interpolation6, interpolation7, interpolation8, interpolationV, memory, projection, projectionDef, text, textBinding} from '../../src/render3/instructions'; import {NO_CHANGE, bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementAttribute, elementClass, elementEnd, elementProperty, elementStart, elementStyle, embeddedViewEnd, embeddedViewStart, interpolation1, interpolation2, interpolation3, interpolation4, interpolation5, interpolation6, interpolation7, interpolation8, interpolationV, load, projection, projectionDef, text, textBinding} from '../../src/render3/instructions';
import {containerEl, renderToHtml} from './render_util'; import {containerEl, renderToHtml} from './render_util';
@ -300,8 +300,7 @@ describe('render3 integration test', () => {
hostBindings: function(directiveIndex: number, elementIndex: number): void { hostBindings: function(directiveIndex: number, elementIndex: number): void {
// host bindings // host bindings
elementProperty( elementProperty(
elementIndex, 'title', elementIndex, 'title', bind(load<TodoComponentHostBinding>(directiveIndex).title));
bind(memory<TodoComponentHostBinding>(directiveIndex).title));
} }
}); });
} }

View File

@ -7,7 +7,7 @@
*/ */
import {ComponentTemplate, defineComponent, defineDirective} from '../../src/render3/index'; import {ComponentTemplate, defineComponent, defineDirective} from '../../src/render3/index';
import {bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, listener, memory, projection, projectionDef, text} from '../../src/render3/instructions'; import {bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, listener, projection, projectionDef, store, text} from '../../src/render3/instructions';
import {containerEl, renderToHtml} from './render_util'; import {containerEl, renderToHtml} from './render_util';

View File

@ -9,7 +9,7 @@
import {EventEmitter} from '@angular/core'; import {EventEmitter} from '@angular/core';
import {defineComponent, defineDirective} from '../../src/render3/index'; import {defineComponent, defineDirective} from '../../src/render3/index';
import {NO_CHANGE, bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, interpolation1, listener, memory, text, textBinding} from '../../src/render3/instructions'; import {NO_CHANGE, bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, interpolation1, listener, load, text, textBinding} from '../../src/render3/instructions';
import {renderToHtml} from './render_util'; import {renderToHtml} from './render_util';
@ -479,7 +479,7 @@ describe('elementProperty', () => {
elementEnd(); elementEnd();
text(2); text(2);
} }
textBinding(2, bind(memory<MyDir>(1).role)); textBinding(2, bind(load<MyDir>(1).role));
}, },
factory: () => new Comp() factory: () => new Comp()
}); });

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {defineComponent} from '../../src/render3/index'; import {defineComponent} from '../../src/render3/index';
import {bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, memory} from '../../src/render3/instructions'; import {bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, load} from '../../src/render3/instructions';
import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunction5, pureFunction6, pureFunction7, pureFunction8, pureFunctionV} from '../../src/render3/pure_function'; import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunction5, pureFunction6, pureFunction7, pureFunction8, pureFunctionV} from '../../src/render3/pure_function';
import {renderToHtml} from '../../test/render3/render_util'; import {renderToHtml} from '../../test/render3/render_util';
@ -124,7 +124,7 @@ describe('array literals', () => {
template: function(ctx: any, cm: boolean) { template: function(ctx: any, cm: boolean) {
if (cm) { if (cm) {
elementStart(0, MyComp); elementStart(0, MyComp);
myComps.push(memory(1)); myComps.push(load(1));
elementEnd(); elementEnd();
} }
elementProperty(0, 'names', bind(ctx.someFn(pureFunction1(e0_ff, ctx.customName)))); elementProperty(0, 'names', bind(ctx.someFn(pureFunction1(e0_ff, ctx.customName))));
@ -223,22 +223,22 @@ describe('array literals', () => {
function Template(c: any, cm: boolean) { function Template(c: any, cm: boolean) {
if (cm) { if (cm) {
elementStart(0, MyComp); elementStart(0, MyComp);
f3Comp = memory(1); f3Comp = load(1);
elementEnd(); elementEnd();
elementStart(2, MyComp); elementStart(2, MyComp);
f4Comp = memory(3); f4Comp = load(3);
elementEnd(); elementEnd();
elementStart(4, MyComp); elementStart(4, MyComp);
f5Comp = memory(5); f5Comp = load(5);
elementEnd(); elementEnd();
elementStart(6, MyComp); elementStart(6, MyComp);
f6Comp = memory(7); f6Comp = load(7);
elementEnd(); elementEnd();
elementStart(8, MyComp); elementStart(8, MyComp);
f7Comp = memory(9); f7Comp = load(9);
elementEnd(); elementEnd();
elementStart(10, MyComp); elementStart(10, MyComp);
f8Comp = memory(11); f8Comp = load(11);
elementEnd(); elementEnd();
} }
elementProperty(0, 'names', bind(pureFunction3(e0_ff, c[5], c[6], c[7]))); elementProperty(0, 'names', bind(pureFunction3(e0_ff, c[5], c[6], c[7])));
@ -444,7 +444,7 @@ describe('object literals', () => {
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
if (embeddedViewStart(0)) { if (embeddedViewStart(0)) {
elementStart(0, ObjectComp); elementStart(0, ObjectComp);
objectComps.push(memory(1)); objectComps.push(load(1));
elementEnd(); elementEnd();
} }
elementProperty( elementProperty(

View File

@ -7,7 +7,7 @@
*/ */
import {QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF} from '../../src/render3/di'; import {QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF} from '../../src/render3/di';
import {QueryList, detectChanges} from '../../src/render3/index'; import {QueryList, detectChanges} from '../../src/render3/index';
import {container, containerRefreshEnd, containerRefreshStart, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, memory} from '../../src/render3/instructions'; import {container, containerRefreshEnd, containerRefreshStart, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, load} from '../../src/render3/instructions';
import {query, queryRefresh} from '../../src/render3/query'; import {query, queryRefresh} from '../../src/render3/query';
import {createComponent, createDirective, renderComponent} from './render_util'; import {createComponent, createDirective, renderComponent} from './render_util';
@ -64,15 +64,15 @@ describe('query', () => {
query(1, Child, true); query(1, Child, true);
elementStart(2, Child); elementStart(2, Child);
{ {
child1 = memory(3); child1 = load(3);
elementStart(4, Child); elementStart(4, Child);
{ child2 = memory(5); } { child2 = load(5); }
elementEnd(); elementEnd();
} }
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query0 = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query0 = tmp as QueryList<any>);
queryRefresh(tmp = memory<QueryList<any>>(1)) && (ctx.query1 = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(1)) && (ctx.query1 = tmp as QueryList<any>);
}); });
const parent = renderComponent(Cmp); const parent = renderComponent(Cmp);
@ -98,7 +98,7 @@ describe('query', () => {
elToQuery = elementStart(1, 'div', null, [Child]); elToQuery = elementStart(1, 'div', null, [Child]);
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -124,10 +124,10 @@ describe('query', () => {
if (cm) { if (cm) {
query(0, Child, false, OtherChild); query(0, Child, false, OtherChild);
elementStart(1, 'div', null, [Child, OtherChild]); elementStart(1, 'div', null, [Child, OtherChild]);
{ otherChildInstance = memory(3); } { otherChildInstance = load(3); }
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -152,7 +152,7 @@ describe('query', () => {
elementStart(1, 'div', null, [Child]); elementStart(1, 'div', null, [Child]);
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -182,7 +182,7 @@ describe('query', () => {
elementStart(2, 'div'); elementStart(2, 'div');
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -214,7 +214,7 @@ describe('query', () => {
el2ToQuery = elementStart(3, 'div', null, null, ['bar', '']); el2ToQuery = elementStart(3, 'div', null, null, ['bar', '']);
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -243,7 +243,7 @@ describe('query', () => {
elementStart(2, 'div'); elementStart(2, 'div');
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -267,7 +267,7 @@ describe('query', () => {
elementStart(1, 'div', null, null, ['foo', '']); elementStart(1, 'div', null, null, ['foo', '']);
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -289,7 +289,7 @@ describe('query', () => {
query(0, ['foo'], false, QUERY_READ_CONTAINER_REF); query(0, ['foo'], false, QUERY_READ_CONTAINER_REF);
container(1, undefined, undefined, undefined, undefined, ['foo', '']); container(1, undefined, undefined, undefined, undefined, ['foo', '']);
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -312,7 +312,7 @@ describe('query', () => {
query(0, ['foo'], false, QUERY_READ_ELEMENT_REF); query(0, ['foo'], false, QUERY_READ_ELEMENT_REF);
container(1, undefined, undefined, undefined, undefined, ['foo', '']); container(1, undefined, undefined, undefined, undefined, ['foo', '']);
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -335,7 +335,7 @@ describe('query', () => {
query(0, ['foo'], undefined, QUERY_READ_FROM_NODE); query(0, ['foo'], undefined, QUERY_READ_FROM_NODE);
container(1, undefined, undefined, undefined, undefined, ['foo', '']); container(1, undefined, undefined, undefined, undefined, ['foo', '']);
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -358,7 +358,7 @@ describe('query', () => {
query(0, ['foo'], false, QUERY_READ_TEMPLATE_REF); query(0, ['foo'], false, QUERY_READ_TEMPLATE_REF);
container(1, undefined, undefined, undefined, undefined, ['foo', '']); container(1, undefined, undefined, undefined, undefined, ['foo', '']);
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -382,10 +382,10 @@ describe('query', () => {
if (cm) { if (cm) {
query(0, ['foo'], true, QUERY_READ_FROM_NODE); query(0, ['foo'], true, QUERY_READ_FROM_NODE);
elementStart(1, Child, null, null, ['foo', '']); elementStart(1, Child, null, null, ['foo', '']);
{ childInstance = memory(2); } { childInstance = load(2); }
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -410,10 +410,10 @@ describe('query', () => {
if (cm) { if (cm) {
query(0, ['foo'], true, QUERY_READ_FROM_NODE); query(0, ['foo'], true, QUERY_READ_FROM_NODE);
elementStart(1, 'div', null, [Child], ['foo', 'child']); elementStart(1, 'div', null, [Child], ['foo', 'child']);
childInstance = memory(2); childInstance = load(2);
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -439,12 +439,12 @@ describe('query', () => {
query(0, ['foo', 'bar'], true, QUERY_READ_FROM_NODE); query(0, ['foo', 'bar'], true, QUERY_READ_FROM_NODE);
elementStart(1, 'div', null, [Child1, Child2], ['foo', 'child1', 'bar', 'child2']); elementStart(1, 'div', null, [Child1, Child2], ['foo', 'child1', 'bar', 'child2']);
{ {
child1Instance = memory(2); child1Instance = load(2);
child2Instance = memory(3); child2Instance = load(3);
} }
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -471,7 +471,7 @@ describe('query', () => {
div = elementStart(1, 'div', null, [Child], ['foo', 'child']); div = elementStart(1, 'div', null, [Child], ['foo', 'child']);
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -495,10 +495,10 @@ describe('query', () => {
if (cm) { if (cm) {
query(0, ['foo', 'bar'], undefined, QUERY_READ_FROM_NODE); query(0, ['foo', 'bar'], undefined, QUERY_READ_FROM_NODE);
div = elementStart(1, 'div', null, [Child], ['foo', '', 'bar', 'child']); div = elementStart(1, 'div', null, [Child], ['foo', '', 'bar', 'child']);
{ childInstance = memory(2); } { childInstance = load(2); }
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -524,7 +524,7 @@ describe('query', () => {
elementStart(1, 'div', null, null, ['foo', '']); elementStart(1, 'div', null, null, ['foo', '']);
elementEnd(); elementEnd();
} }
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -566,7 +566,7 @@ describe('query', () => {
} }
} }
containerRefreshEnd(); containerRefreshEnd();
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -620,7 +620,7 @@ describe('query', () => {
} }
} }
containerRefreshEnd(); containerRefreshEnd();
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -686,7 +686,7 @@ describe('query', () => {
} }
} }
containerRefreshEnd(); containerRefreshEnd();
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -753,7 +753,7 @@ describe('query', () => {
} }
} }
containerRefreshEnd(); containerRefreshEnd();
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);
@ -805,8 +805,8 @@ describe('query', () => {
} }
} }
containerRefreshEnd(); containerRefreshEnd();
queryRefresh(tmp = memory<QueryList<any>>(0)) && (ctx.deep = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.deep = tmp as QueryList<any>);
queryRefresh(tmp = memory<QueryList<any>>(1)) && (ctx.shallow = tmp as QueryList<any>); queryRefresh(tmp = load<QueryList<any>>(1)) && (ctx.shallow = tmp as QueryList<any>);
}); });
const cmptInstance = renderComponent(Cmpt); const cmptInstance = renderComponent(Cmpt);

View File

@ -8,7 +8,7 @@
import {TemplateRef, ViewContainerRef} from '../../src/core'; import {TemplateRef, ViewContainerRef} from '../../src/core';
import {defineComponent, defineDirective, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index'; import {defineComponent, defineDirective, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index';
import {bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, memory, text, textBinding} from '../../src/render3/instructions'; import {bind, componentRefresh, container, containerRefreshEnd, containerRefreshStart, load, text, textBinding} from '../../src/render3/instructions';
import {renderComponent, toHtml} from './render_util'; import {renderComponent, toHtml} from './render_util';
@ -40,7 +40,7 @@ describe('ViewContainerRef', () => {
container(0, [TestDirective], subTemplate); container(0, [TestDirective], subTemplate);
} }
containerRefreshStart(0); containerRefreshStart(0);
cmp.testDir = memory(1) as TestDirective; cmp.testDir = load<TestDirective>(1);
TestDirective.ngDirectiveDef.h(1, 0); TestDirective.ngDirectiveDef.h(1, 0);
componentRefresh(1, 0); componentRefresh(1, 0);
containerRefreshEnd(); containerRefreshEnd();