feat(ivy): add element instruction (#23899)
Adds a simplified element instruction that can be used if an element has no children. PR Close #23899
This commit is contained in:
@ -28,6 +28,7 @@ export {
|
||||
NC as ɵNC,
|
||||
C as ɵC,
|
||||
E as ɵE,
|
||||
Ee as ɵEe,
|
||||
L as ɵL,
|
||||
T as ɵT,
|
||||
V as ɵV,
|
||||
|
@ -50,6 +50,7 @@ export {
|
||||
elementEnd as e,
|
||||
elementProperty as p,
|
||||
elementStart as E,
|
||||
element as Ee,
|
||||
elementStyle as s,
|
||||
elementStyleNamed as sn,
|
||||
|
||||
|
@ -1032,6 +1032,15 @@ export function elementEnd() {
|
||||
queueLifecycleHooks(previousOrParentNode.tNode.flags, currentView);
|
||||
}
|
||||
|
||||
/** Marks the beginning and end of an element in one call. */
|
||||
export function element(
|
||||
index: number, name: string, attrs?: TAttributes | null | undefined,
|
||||
localRefs?: string[] | null | undefined): RElement {
|
||||
const relement = elementStart(index, name, attrs, localRefs);
|
||||
elementEnd();
|
||||
return relement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the value of removes an attribute on an Element.
|
||||
*
|
||||
|
@ -12,6 +12,7 @@ import {assertNotNull} from './assert';
|
||||
import {AttributeMarker, TAttributes, TNode, unusedValueExportToPlacateAjd as unused1} from './interfaces/node';
|
||||
import {CssSelector, CssSelectorList, NG_PROJECT_AS_ATTR_NAME, SelectorFlags, unusedValueExportToPlacateAjd as unused2} from './interfaces/projection';
|
||||
|
||||
|
||||
const unusedValueToPlacateAjd = unused1 + unused2;
|
||||
|
||||
function isCssClassMatching(nodeClassAttrVal: string, cssClassToMatch: string): boolean {
|
||||
|
@ -69,8 +69,7 @@ describe('components & directives', () => {
|
||||
factory: () => new MyComponent(),
|
||||
template: function(rf: $RenderFlags$, ctx: $MyComponent$) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'child', $e0_attrs$);
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵEe(0, 'child', $e0_attrs$);
|
||||
$r3$.ɵT(1, '!');
|
||||
}
|
||||
}
|
||||
@ -455,8 +454,7 @@ describe('components & directives', () => {
|
||||
factory: function MyApp_Factory() { return new MyApp(); },
|
||||
template: function MyApp_Template(rf: $RenderFlags$, ctx: $MyApp$) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'my-array-comp');
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵEe(0, 'my-array-comp');
|
||||
}
|
||||
if (rf & 2) {
|
||||
$r3$.ɵp(0, 'names', rf & 1 ? $e0_arr$ : $r3$.ɵNC);
|
||||
@ -500,8 +498,7 @@ describe('components & directives', () => {
|
||||
factory: function MyApp_Factory() { return new MyApp(); },
|
||||
template: function MyApp_Template(rf: $RenderFlags$, ctx: $MyApp$) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'my-array-comp');
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵEe(0, 'my-array-comp');
|
||||
$r3$.ɵrS(1);
|
||||
}
|
||||
if (rf & 2) {
|
||||
@ -606,8 +603,7 @@ describe('components & directives', () => {
|
||||
factory: function MyApp_Factory() { return new MyApp(); },
|
||||
template: function MyApp_Template(rf: $RenderFlags$, ctx: $MyApp$) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'my-array-comp');
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵEe(0, 'my-array-comp');
|
||||
$r3$.ɵrS(2);
|
||||
}
|
||||
if (rf & 2) {
|
||||
@ -717,8 +713,7 @@ describe('components & directives', () => {
|
||||
factory: function MyApp_Factory() { return new MyApp(); },
|
||||
template: function MyApp_Template(rf: $RenderFlags$, c: $any$) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'my-comp');
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵEe(0, 'my-comp');
|
||||
$r3$.ɵrS(10);
|
||||
}
|
||||
if (rf & 2) {
|
||||
|
@ -58,8 +58,7 @@ describe('queries', () => {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵQ(0, SomeDirective, false);
|
||||
$r3$.ɵQ(1, SomeDirective, false);
|
||||
$r3$.ɵE(2, 'div', $e1_attrs$);
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵEe(2, 'div', $e1_attrs$);
|
||||
}
|
||||
if (rf & 2) {
|
||||
$r3$.ɵqR($tmp$ = $r3$.ɵld<QueryList<any>>(0)) && (ctx.someDir = $tmp$.first);
|
||||
|
@ -10,14 +10,14 @@ import {NgForOfContext} from '@angular/common';
|
||||
|
||||
import {RenderFlags, directiveInject} from '../../src/render3';
|
||||
import {defineComponent} from '../../src/render3/definition';
|
||||
import {bind, container, elementAttribute, elementClass, elementEnd, elementProperty, elementStart, elementStyle, elementStyleNamed, interpolation1, renderTemplate, setHtmlNS, setSvgNS, text, textBinding} from '../../src/render3/instructions';
|
||||
import {bind, container, element, elementAttribute, elementClass, elementEnd, elementProperty, elementStart, elementStyle, elementStyleNamed, interpolation1, renderTemplate, setHtmlNS, setSvgNS, text, textBinding} from '../../src/render3/instructions';
|
||||
import {LElementNode, LNode, NS} from '../../src/render3/interfaces/node';
|
||||
import {RElement, domRendererFactory3} from '../../src/render3/interfaces/renderer';
|
||||
import {TrustedString, bypassSanitizationTrustHtml, bypassSanitizationTrustResourceUrl, bypassSanitizationTrustScript, bypassSanitizationTrustStyle, bypassSanitizationTrustUrl, sanitizeHtml, sanitizeResourceUrl, sanitizeScript, sanitizeStyle, sanitizeUrl} from '../../src/sanitization/sanitization';
|
||||
import {Sanitizer, SecurityContext} from '../../src/sanitization/security';
|
||||
|
||||
import {NgForOf} from './common_with_def';
|
||||
import {ComponentFixture, TemplateFixture} from './render_util';
|
||||
import {ComponentFixture, TemplateFixture, toHtml} from './render_util';
|
||||
|
||||
describe('instructions', () => {
|
||||
function createAnchor() {
|
||||
@ -94,13 +94,12 @@ describe('instructions', () => {
|
||||
|
||||
it('should use sanitizer function even on elements with namespaced attributes', () => {
|
||||
const t = new TemplateFixture(() => {
|
||||
elementStart(0, 'div', [
|
||||
element(0, 'div', [
|
||||
NS.FULL,
|
||||
'http://www.example.com/2004/test',
|
||||
'whatever',
|
||||
'abc',
|
||||
]);
|
||||
elementEnd();
|
||||
});
|
||||
|
||||
t.update(() => elementAttribute(0, 'title', 'javascript:true', sanitizeUrl));
|
||||
@ -451,8 +450,7 @@ describe('instructions', () => {
|
||||
'title',
|
||||
'abc',
|
||||
]);
|
||||
elementStart(2, 'circle', ['cx', '200', 'cy', '150', 'fill', '#0000ff']);
|
||||
elementEnd();
|
||||
element(2, 'circle', ['cx', '200', 'cy', '150', 'fill', '#0000ff']);
|
||||
elementEnd();
|
||||
setHtmlNS();
|
||||
elementEnd();
|
||||
@ -470,7 +468,7 @@ describe('instructions', () => {
|
||||
|
||||
it('should set an attribute with a namespace', () => {
|
||||
const t = new TemplateFixture(() => {
|
||||
elementStart(0, 'div', [
|
||||
element(0, 'div', [
|
||||
'id',
|
||||
'container',
|
||||
// test:title="abc"
|
||||
@ -479,7 +477,6 @@ describe('instructions', () => {
|
||||
'title',
|
||||
'abc',
|
||||
]);
|
||||
elementEnd();
|
||||
});
|
||||
|
||||
const standardHTML = '<div id="container" title="abc"></div>';
|
||||
@ -490,7 +487,7 @@ describe('instructions', () => {
|
||||
|
||||
it('should set attributes including more than one namespaced attribute', () => {
|
||||
const t = new TemplateFixture(() => {
|
||||
elementStart(0, 'div', [
|
||||
element(0, 'div', [
|
||||
'id',
|
||||
'container',
|
||||
|
||||
@ -516,7 +513,6 @@ describe('instructions', () => {
|
||||
'shazbot',
|
||||
'wocka wocka',
|
||||
]);
|
||||
elementEnd();
|
||||
});
|
||||
|
||||
const standardHTML =
|
||||
|
Reference in New Issue
Block a user