Skip to content

Commit 2e237ab

Browse files
mheveryalxhub
authored andcommitted
refactor(core): Change TName.tagName to a more generic value name. (angular#39233)
This is a pre-requisite for making the `TNode.value` a generic storage mechanism for attaching data to `TNode`. PR Close angular#39233
1 parent ca11ef2 commit 2e237ab

File tree

12 files changed

+35
-35
lines changed

12 files changed

+35
-35
lines changed

packages/core/src/debug/debug_node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
266266
const lView = context.lView;
267267
const tData = lView[TVIEW].data;
268268
const tNode = tData[context.nodeIndex] as TNode;
269-
return tNode.tagName!;
269+
return tNode.value!;
270270
} catch (e) {
271271
return this.nativeNode.nodeName;
272272
}

packages/core/src/render3/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function throwCyclicDependencyError(token: any): never {
2222

2323
/** Called when there are multiple component selectors that match a given node */
2424
export function throwMultipleComponentError(tNode: TNode): never {
25-
throw new Error(`Multiple components match node with tagname ${tNode.tagName}`);
25+
throw new Error(`Multiple components match node with tagname ${tNode.value}`);
2626
}
2727

2828
export function throwMixedMultiProviderError() {

packages/core/src/render3/i18n/i18n_util.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export function getTIcu(tView: TView, index: number): TIcu|null {
4040
// either TIcu or TIcuContainerNode. This is not ideal, but we still think it is OK because it
4141
// will be just two cases which fits into the browser inline cache (inline cache can take up to
4242
// 4)
43-
const tIcu = value.hasOwnProperty('currentCaseLViewIndex') ?
43+
const tIcu: TIcu = value.hasOwnProperty('currentCaseLViewIndex') ?
4444
value :
45-
(value as TIcuContainerNode).tagName as any;
45+
(value as TIcuContainerNode).value as any;
4646
ngDevMode && assertTIcu(tIcu);
4747
return tIcu;
4848
}
@@ -71,9 +71,7 @@ export function setTIcu(tView: TView, index: number, tIcu: TIcu): void {
7171
tView.data[index] = tIcu;
7272
} else {
7373
ngDevMode && assertNodeType(tNode, TNodeType.IcuContainer);
74-
// FIXME(misko): This is a hack which allows us to associate `TI18n` with `TNode`.
75-
// This should be refactored so that one can attach arbitrary data with `TNode`
76-
tNode.tagName = tIcu as any;
74+
tNode.value = tIcu as any;
7775
}
7876
}
7977

packages/core/src/render3/instructions/element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function logUnknownElementError(
188188
// execute the check below.
189189
if (schemas === null) return;
190190

191-
const tagName = tNode.tagName;
191+
const tagName = tNode.value;
192192

193193
// If the element matches any directive, it's considered as valid.
194194
if (!hasDirectives && tagName !== null) {

packages/core/src/render3/instructions/i18n_icu_container_visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function loadIcuContainerVisitor() {
4343
// FIXME(misko): This is a hack which allows us to associate `TI18n` with `TNode`.
4444
// This should be refactored so that one can attach arbitrary data with `TNode`
4545
ngDevMode && assertTNodeForLView(tIcuContainerNode, lView);
46-
const tIcu: TIcu = tIcuContainerNode.tagName as any;
46+
const tIcu: TIcu = tIcuContainerNode.value as any;
4747
enterIcu(tIcu, lView);
4848
return icuContainerIteratorNext;
4949
}

packages/core/src/render3/instructions/lview_debug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class TNode implements ITNode {
184184
public propertyBindings: number[]|null, //
185185
public flags: TNodeFlags, //
186186
public providerIndexes: TNodeProviderIndexes, //
187-
public tagName: string|null, //
187+
public value: string|null, //
188188
public attrs: (string|AttributeMarker|(string|SelectorFlags)[])[]|null, //
189189
public mergedAttrs: (string|AttributeMarker|(string|SelectorFlags)[])[]|null, //
190190
public localNames: (string|number)[]|null, //
@@ -256,9 +256,9 @@ class TNode implements ITNode {
256256
}
257257

258258
get template_(): string {
259-
if (this.tagName === null && this.type === TNodeType.Element) return '#text';
259+
if (this.value === null && this.type === TNodeType.Element) return '#text';
260260
const buf: string[] = [];
261-
const tagName = typeof this.tagName === 'string' && this.tagName || this.type_;
261+
const tagName = typeof this.value === 'string' && this.value || this.type_;
262262
buf.push('<', tagName);
263263
if (this.flags) {
264264
buf.push(' ', this.flags_);

packages/core/src/render3/instructions/shared.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function getOrCreateTNode(
227227
}
228228
} else if (tNode.type == TNodeType.Placeholder) {
229229
tNode.type = type;
230-
tNode.tagName = name;
230+
tNode.value = name;
231231
tNode.attrs = attrs;
232232
const parent = getCurrentParentTNode();
233233
tNode.injectorIndex = parent === null ? -1 : parent.injectorIndex;
@@ -834,7 +834,7 @@ export function createTNode(
834834
tagName: string|null, attrs: TAttributes|null): TNode;
835835
export function createTNode(
836836
tView: TView, tParent: TElementNode|TContainerNode|null, type: TNodeType, adjustedIndex: number,
837-
tagName: string|null, attrs: TAttributes|null): TNode {
837+
value: string|null, attrs: TAttributes|null): TNode {
838838
ngDevMode && assertNotSame(attrs, undefined, '\'undefined\' is not valid value for \'attrs\'');
839839
ngDevMode && ngDevMode.tNode++;
840840
ngDevMode && tParent && assertTNodeForTView(tParent, tView);
@@ -852,7 +852,7 @@ export function createTNode(
852852
null, // propertyBindings: number[]|null
853853
0, // flags: TNodeFlags
854854
0, // providerIndexes: TNodeProviderIndexes
855-
tagName, // tagName: string|null
855+
value, // value: string|null
856856
attrs, // attrs: (string|AttributeMarker|(string|SelectorFlags)[])[]|null
857857
null, // mergedAttrs
858858
null, // localNames: (string|number)[]|null
@@ -885,7 +885,7 @@ export function createTNode(
885885
propertyBindings: null,
886886
flags: 0,
887887
providerIndexes: 0,
888-
tagName: tagName,
888+
value: value,
889889
attrs: attrs,
890890
mergedAttrs: null,
891891
localNames: null,
@@ -1027,7 +1027,7 @@ export function elementPropertyInternal<T>(
10271027

10281028
// It is assumed that the sanitizer is only added when the compiler determines that the
10291029
// property is risky, so sanitization can be done without further checks.
1030-
value = sanitizer != null ? (sanitizer(value, tNode.tagName || '', propName) as any) : value;
1030+
value = sanitizer != null ? (sanitizer(value, tNode.value || '', propName) as any) : value;
10311031
if (isProceduralRenderer(renderer)) {
10321032
renderer.setProperty(element as RElement, propName, value);
10331033
} else if (!isAnimationProp(propName)) {
@@ -1037,7 +1037,7 @@ export function elementPropertyInternal<T>(
10371037
} else if (tNode.type === TNodeType.Container || tNode.type === TNodeType.ElementContainer) {
10381038
// If the node is a container and the property didn't
10391039
// match any of the inputs or schemas we should throw.
1040-
if (ngDevMode && !matchingSchemas(tView, tNode.tagName)) {
1040+
if (ngDevMode && !matchingSchemas(tView, tNode.value)) {
10411041
logUnknownPropertyError(propName, tNode);
10421042
}
10431043
}
@@ -1104,7 +1104,7 @@ function validateProperty(
11041104

11051105
// The property is considered valid if the element matches the schema, it exists on the element
11061106
// or it is synthetic, and we are in a browser context (web worker nodes should be skipped).
1107-
if (matchingSchemas(tView, tNode.tagName) || propName in element || isAnimationProp(propName)) {
1107+
if (matchingSchemas(tView, tNode.value) || propName in element || isAnimationProp(propName)) {
11081108
return true;
11091109
}
11101110

@@ -1135,8 +1135,7 @@ export function matchingSchemas(tView: TView, tagName: string|null): boolean {
11351135
* @param tNode Node on which we encountered the property.
11361136
*/
11371137
function logUnknownPropertyError(propName: string, tNode: TNode): void {
1138-
console.error(
1139-
`Can't bind to '${propName}' since it isn't a known property of '${tNode.tagName}'.`);
1138+
console.error(`Can't bind to '${propName}' since it isn't a known property of '${tNode.value}'.`);
11401139
}
11411140

11421141
/**
@@ -1404,7 +1403,7 @@ function findDirectiveDefMatches(
14041403
if (ngDevMode) {
14051404
assertNodeOfPossibleTypes(
14061405
tNode, [TNodeType.Element],
1407-
`"${tNode.tagName}" tags cannot be used as component hosts. ` +
1406+
`"${tNode.value}" tags cannot be used as component hosts. ` +
14081407
`Please use a different tag to activate the ${stringify(def.type)} component.`);
14091408

14101409
if (tNode.flags & TNodeFlags.isComponentHost) throwMultipleComponentError(tNode);
@@ -1525,7 +1524,7 @@ export function elementAttributeInternal(
15251524
`Host bindings are not valid on ng-container or ng-template.`);
15261525
}
15271526
const element = getNativeByTNode(tNode, lView) as RElement;
1528-
setElementAttribute(lView[RENDERER], element, namespace, tNode.tagName, name, value, sanitizer);
1527+
setElementAttribute(lView[RENDERER], element, namespace, tNode.value, name, value, sanitizer);
15291528
}
15301529

15311530
export function setElementAttribute(

packages/core/src/render3/interfaces/node.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,14 @@ export interface TNode {
427427
// TODO(misko): break this into actual vars.
428428
providerIndexes: TNodeProviderIndexes;
429429

430-
/** The tag name associated with this node. */
431-
// FIXME(misko): rename to `value` and change the type to `any` so that
432-
// subclasses of `TNode` can use it to link additional payload
433-
tagName: string|null;
430+
/**
431+
* The value name associated with this node.
432+
* if type:
433+
* `TNodeType.Text`: text value
434+
* `TNodeType.Element`: tag name
435+
* `TNodeType.ICUContainer`: `TIcu`
436+
*/
437+
value: string|null;
434438

435439
/**
436440
* Attributes associated with an element. We need to store attributes to support various use-cases

packages/core/src/render3/node_selector_matcher.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function isCssClassMatching(
6262
* @param tNode current TNode
6363
*/
6464
export function isInlineTemplate(tNode: TNode): boolean {
65-
return tNode.type === TNodeType.Container && tNode.tagName !== NG_TEMPLATE_SELECTOR;
65+
return tNode.type === TNodeType.Container && tNode.value !== NG_TEMPLATE_SELECTOR;
6666
}
6767

6868
/**
@@ -78,9 +78,8 @@ export function isInlineTemplate(tNode: TNode): boolean {
7878
*/
7979
function hasTagAndTypeMatch(
8080
tNode: TNode, currentSelector: string, isProjectionMode: boolean): boolean {
81-
const tagNameToCompare = tNode.type === TNodeType.Container && !isProjectionMode ?
82-
NG_TEMPLATE_SELECTOR :
83-
tNode.tagName;
81+
const tagNameToCompare =
82+
tNode.type === TNodeType.Container && !isProjectionMode ? NG_TEMPLATE_SELECTOR : tNode.value;
8483
return currentSelector === tagNameToCompare;
8584
}
8685

packages/core/test/acceptance/debug_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ onlyInIvy('Ivy specific').describe('Debug Representation', () => {
5454
end: HEADER_OFFSET + 2,
5555
length: 2,
5656
content: [
57-
{index: HEADER_OFFSET + 0, t: matchTNode({tagName: 'div'}), l: matchDomElement('div')},
57+
{index: HEADER_OFFSET + 0, t: matchTNode({value: 'div'}), l: matchDomElement('div')},
5858
{index: HEADER_OFFSET + 1, t: matchTI18n(), l: null},
5959
]
6060
});
@@ -70,7 +70,7 @@ onlyInIvy('Ivy specific').describe('Debug Representation', () => {
7070
length: 1,
7171
content: [{
7272
index: HEADER_OFFSET + 3,
73-
t: matchTNode({type: TNodeType.Element, tagName: null}),
73+
t: matchTNode({type: TNodeType.Element, value: null}),
7474
l: matchDomText('Hello World')
7575
}]
7676
});

0 commit comments

Comments
 (0)