From 1208a35373f1ebf58f7512948c6f58d7d1a03570 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Wed, 30 May 2018 15:57:09 -0700 Subject: [PATCH] refactor(ivy): Use AttributeMarker instead of NS (#23899) - Removes NS enum - Uses existing AttributeMarker - Adds enum value NAMESPACE_URI PR Close #23899 --- packages/core/src/render3/di.ts | 2 +- packages/core/src/render3/instructions.ts | 5 ++--- packages/core/src/render3/interfaces/node.ts | 20 ++++++------------- .../core/src/render3/node_selector_matcher.ts | 3 +-- .../core/test/render3/instructions_spec.ts | 14 ++++++------- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 4cc09c5b2d..168507bdb5 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -262,7 +262,7 @@ export function injectAttribute(attrNameToInject: string): string|undefined { for (let i = 0; i < attrs.length; i = i + 2) { let attrName = attrs[i]; if (attrName === AttributeMarker.SELECT_ONLY) break; - if (attrName === 0) { // NS.FULL + if (attrName === AttributeMarker.NAMESPACE_URI) { attrName = attrs[i += 2]; } if (attrName == attrNameToInject) { diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index 30fcc1fe80..f6fad80f48 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -843,8 +843,7 @@ function setUpAttributes(native: RElement, attrs: TAttributes): void { const isProc = isProceduralRenderer(renderer); for (let i = 0; i < attrs.length; i += 2) { let attrName = attrs[i]; - if (attrName === 0) { // NS.FULL - // Namespaced attribute + if (attrName === AttributeMarker.NAMESPACE_URI) { const attrNS = attrs[i + 1] as string; attrName = attrs[i + 2] as string; const attrVal = attrs[i + 3] as string; @@ -1516,7 +1515,7 @@ function generateInitialInputs( const attrs = tNode.attrs !; for (let i = 0; i < attrs.length; i += 2) { const first = attrs[i]; - const attrName = first === 0 ? attrs[i += 2] : first; // 0 = NS.FULL + const attrName = first === AttributeMarker.NAMESPACE_URI ? attrs[i += 2] : first; const minifiedInputName = inputs[attrName]; const attrValue = attrs[i + 1]; diff --git a/packages/core/src/render3/interfaces/node.ts b/packages/core/src/render3/interfaces/node.ts index 00ea8220a7..2f3ac9585a 100644 --- a/packages/core/src/render3/interfaces/node.ts +++ b/packages/core/src/render3/interfaces/node.ts @@ -12,18 +12,6 @@ import {LQueries} from './query'; import {RElement, RNode, RText} from './renderer'; import {LView, TData, TView} from './view'; - -/** - * Namespace attribute flags. - */ -export const enum NS { - /** - * Use the next value as the full namespaces URI, the values after that - * are then the name and the value, respectively. - */ - FULL = 0, -} - /** * TNodeType corresponds to the TNode.type property. It contains information * on how to map a particular set of bits in LNode.flags to the node type. @@ -172,7 +160,11 @@ export interface LProjectionNode extends LNode { * items are not regular attributes and the processing should be adapted accordingly. */ export const enum AttributeMarker { - NS = 0, // namespace. Has to be repeated. + /** + * Use the next value as the full namespaces URI, the values after that + * are then the name and the value, respectively. + */ + NAMESPACE_URI = 0, // namespace. Has to be repeated. /** * This marker indicates that the following attribute names were extracted from bindings (ex.: @@ -188,7 +180,7 @@ export const enum AttributeMarker { * - attribute names and values * - special markers acting as flags to alter attributes processing. */ -export type TAttributes = (string | AttributeMarker | NS)[]; +export type TAttributes = (string | AttributeMarker)[]; /** * LNode binding data (flyweight) for a particular node that is shared between all templates diff --git a/packages/core/src/render3/node_selector_matcher.ts b/packages/core/src/render3/node_selector_matcher.ts index efba0295ee..354ff7317f 100644 --- a/packages/core/src/render3/node_selector_matcher.ts +++ b/packages/core/src/render3/node_selector_matcher.ts @@ -107,8 +107,7 @@ function findAttrIndexInNode(name: string, attrs: TAttributes | null): number { if (attrs === null) return -1; for (let i = 0; i < attrs.length; i += step) { const attrName = attrs[i]; - if (attrName === 0) { - // NS.FULL + if (attrName === AttributeMarker.NAMESPACE_URI) { step = 2; } else if (attrName === name) { return i; diff --git a/packages/core/test/render3/instructions_spec.ts b/packages/core/test/render3/instructions_spec.ts index 237744cee4..b7e79be99d 100644 --- a/packages/core/test/render3/instructions_spec.ts +++ b/packages/core/test/render3/instructions_spec.ts @@ -11,7 +11,7 @@ import {NgForOfContext} from '@angular/common'; import {RenderFlags, directiveInject} from '../../src/render3'; import {defineComponent} from '../../src/render3/definition'; 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 {AttributeMarker, LElementNode, LNode} 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'; @@ -95,7 +95,7 @@ describe('instructions', () => { it('should use sanitizer function even on elements with namespaced attributes', () => { const t = new TemplateFixture(() => { element(0, 'div', [ - NS.FULL, + AttributeMarker.NAMESPACE_URI, 'http://www.example.com/2004/test', 'whatever', 'abc', @@ -445,7 +445,7 @@ describe('instructions', () => { 'height', '300', // test:title="abc" - NS.FULL, + AttributeMarker.NAMESPACE_URI, 'http://www.example.com/2014/test', 'title', 'abc', @@ -472,7 +472,7 @@ describe('instructions', () => { 'id', 'container', // test:title="abc" - NS.FULL, + AttributeMarker.NAMESPACE_URI, 'http://www.example.com/2014/test', 'title', 'abc', @@ -492,7 +492,7 @@ describe('instructions', () => { 'container', // NS1:title="abc" - NS.FULL, + AttributeMarker.NAMESPACE_URI, 'http://www.example.com/2014/test', 'title', 'abc', @@ -502,13 +502,13 @@ describe('instructions', () => { 'background: #dead11', // NS1:whatever="wee" - NS.FULL, + AttributeMarker.NAMESPACE_URI, 'http://www.example.com/2014/test', 'whatever', 'wee', // NS2:shazbot="wocka wocka" - NS.FULL, + AttributeMarker.NAMESPACE_URI, 'http://www.whatever.com/2016/blah', 'shazbot', 'wocka wocka',