refactor: rename AttributeMarker.ProjectOnly
to AttributeMarker.Bindings
(#29041)
PR Close #29041
This commit is contained in:

committed by
Kara Erickson

parent
c7e4931f32
commit
423ac01dcf
@ -272,7 +272,9 @@ export function injectAttributeImpl(tNode: TNode, attrNameToInject: string): str
|
||||
if (attrs) {
|
||||
for (let i = 0; i < attrs.length; i = i + 2) {
|
||||
const attrName = attrs[i];
|
||||
if (attrName === AttributeMarker.SelectOnly) break;
|
||||
if (attrName === AttributeMarker.Bindings) break;
|
||||
// TODO: What happens here if an attribute has a namespace?
|
||||
// TODO: What happens here if the attribute name happens to match a CSS class or style?
|
||||
if (attrName == attrNameToInject) {
|
||||
return attrs[i + 1] as string;
|
||||
}
|
||||
|
@ -2126,15 +2126,15 @@ function generateInitialInputs(
|
||||
let i = 0;
|
||||
while (i < attrs.length) {
|
||||
const attrName = attrs[i];
|
||||
// If we hit Select-Only, Classes or Styles, we're done anyway. None of those are valid inputs.
|
||||
if (attrName === AttributeMarker.SelectOnly || attrName === AttributeMarker.Classes ||
|
||||
attrName === AttributeMarker.Styles)
|
||||
break;
|
||||
if (attrName === AttributeMarker.NamespaceURI) {
|
||||
// We do not allow inputs on namespaced attributes.
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we hit any other attribute markers, we're done anyway. None of those are valid inputs.
|
||||
if (typeof attrName === 'number') break;
|
||||
|
||||
const minifiedInputName = inputs[attrName];
|
||||
const attrValue = attrs[i + 1];
|
||||
|
||||
|
@ -107,12 +107,21 @@ export const enum AttributeMarker {
|
||||
Styles = 2,
|
||||
|
||||
/**
|
||||
* This marker indicates that the following attribute names were extracted from bindings (ex.:
|
||||
* [foo]="exp") and / or event handlers (ex. (bar)="doSth()").
|
||||
* Taking the above bindings and outputs as an example an attributes array could look as follows:
|
||||
* ['class', 'fade in', AttributeMarker.SelectOnly, 'foo', 'bar']
|
||||
* Signals that the following attribute names were extracted from input or output bindings.
|
||||
*
|
||||
* For example, given the following HTML:
|
||||
*
|
||||
* ```
|
||||
* <div moo="car" [foo]="exp" (bar)="doSth()">
|
||||
* ```
|
||||
*
|
||||
* the generated code is:
|
||||
*
|
||||
* ```
|
||||
* var _c1 = ['moo', 'car', AttributeMarker.Bindings, 'foo', 'bar'];
|
||||
* ```
|
||||
*/
|
||||
SelectOnly = 3,
|
||||
Bindings = 3,
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,8 +60,8 @@ export function isNodeMatchingSelector(
|
||||
tNode: TNode, selector: CssSelector, isProjectionMode: boolean): boolean {
|
||||
ngDevMode && assertDefined(selector[0], 'Selector should have a tag name');
|
||||
let mode: SelectorFlags = SelectorFlags.ELEMENT;
|
||||
const nodeAttrs = tNode.attrs !;
|
||||
const selectOnlyMarkerIdx = nodeAttrs ? nodeAttrs.indexOf(AttributeMarker.SelectOnly) : -1;
|
||||
const nodeAttrs = tNode.attrs || [];
|
||||
const nameOnlyMarkerIdx = nodeAttrs.indexOf(AttributeMarker.Bindings);
|
||||
|
||||
// When processing ":not" selectors, we skip to the next ":not" if the
|
||||
// current one doesn't match
|
||||
@ -116,7 +116,7 @@ export function isNodeMatchingSelector(
|
||||
if (selectorAttrValue !== '') {
|
||||
let nodeAttrValue: string;
|
||||
const maybeAttrName = nodeAttrs[attrIndexInNode];
|
||||
if (selectOnlyMarkerIdx > -1 && attrIndexInNode > selectOnlyMarkerIdx) {
|
||||
if (attrIndexInNode > nameOnlyMarkerIdx) {
|
||||
nodeAttrValue = '';
|
||||
} else {
|
||||
ngDevMode && assertNotEqual(
|
||||
@ -154,7 +154,7 @@ function readClassValueFromTNode(tNode: TNode): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Examines an attributes definition array from a node to find the index of the
|
||||
* Examines an attribute's definition array from a node to find the index of the
|
||||
* attribute with the specified name.
|
||||
*
|
||||
* NOTE: Will not find namespaced attributes.
|
||||
@ -164,7 +164,7 @@ function readClassValueFromTNode(tNode: TNode): string {
|
||||
*/
|
||||
function findAttrIndexInNode(name: string, attrs: TAttributes | null): number {
|
||||
if (attrs === null) return -1;
|
||||
let selectOnlyMode = false;
|
||||
let nameOnlyMode = false;
|
||||
let i = 0;
|
||||
while (i < attrs.length) {
|
||||
const maybeAttrName = attrs[i];
|
||||
@ -174,10 +174,10 @@ function findAttrIndexInNode(name: string, attrs: TAttributes | null): number {
|
||||
// NOTE(benlesh): will not find namespaced attributes. This is by design.
|
||||
i += 4;
|
||||
} else {
|
||||
if (maybeAttrName === AttributeMarker.SelectOnly) {
|
||||
selectOnlyMode = true;
|
||||
if (maybeAttrName === AttributeMarker.Bindings) {
|
||||
nameOnlyMode = true;
|
||||
}
|
||||
i += selectOnlyMode ? 1 : 2;
|
||||
i += nameOnlyMode ? 1 : 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user