Skip to content

Commit f4009dd

Browse files
committed
Remove redundant functions from compile
1 parent 0100eea commit f4009dd

File tree

1 file changed

+20
-42
lines changed

1 file changed

+20
-42
lines changed

src/core/compile/compile.js

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -972,31 +972,20 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
972972
}
973973

974974
// iterate over the attributes
975-
for (
976-
var attr,
977-
name,
978-
nName,
979-
value,
980-
ngPrefixMatch,
981-
nAttrs = node.attributes,
982-
j = 0,
983-
jj = nAttrs && nAttrs.length;
984-
j < jj;
985-
j++
986-
) {
975+
for (let j = 0; j < node.attributes?.length; j++) {
987976
let isNgAttr = false;
988977
let isNgProp = false;
989978
let isNgEvent = false;
990979
let isNgObserve = false;
991980

992-
attr = nAttrs[j];
993-
name = attr.name;
994-
value = attr.value;
995-
996-
nName = directiveNormalize(name.toLowerCase());
981+
let attr = node.attributes[j];
982+
let name = attr.name;
983+
let value = attr.value;
984+
let nName = directiveNormalize(name.toLowerCase());
997985

998986
// Support ng-attr-*, ng-prop-* and ng-on-*
999-
if ((ngPrefixMatch = nName.match(NG_PREFIX_BINDING))) {
987+
const ngPrefixMatch = nName.match(NG_PREFIX_BINDING);
988+
if (ngPrefixMatch) {
1000989
isNgAttr = ngPrefixMatch[1] === "Attr";
1001990
isNgProp = ngPrefixMatch[1] === "Prop";
1002991
isNgEvent = ngPrefixMatch[1] === "On";
@@ -1017,10 +1006,19 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
10171006
if (isNgProp) {
10181007
addPropertyDirective(node, directives, nName, name);
10191008
} else {
1020-
addEventDirective(directives, nName, name);
1009+
directives.push(
1010+
createEventDirective(
1011+
$parse,
1012+
$rootScope,
1013+
$exceptionHandler,
1014+
nName,
1015+
name,
1016+
/* forceAsync= */ false,
1017+
),
1018+
);
10211019
}
10221020
} else if (isNgObserve) {
1023-
addObserveDirective(directives, name, value);
1021+
directives.push(ngObserveDirective(name, value));
10241022
} else {
10251023
// Update nName for cases where a prefix was removed
10261024
// NOTE: the .toLowerCase() is unnecessary and causes https://github.com/angular/angular.js/issues/16624 for ng-attr-*
@@ -2400,10 +2398,6 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
24002398
);
24012399
}
24022400

2403-
function sanitizeSrcsetPropertyValue(value) {
2404-
return sanitizeSrcset($sce.valueOf(value), "ng-prop-srcset");
2405-
}
2406-
24072401
function sanitizeSrcset(value, invokeType) {
24082402
if (!value) {
24092403
return value;
@@ -2476,7 +2470,8 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
24762470
propName === "srcset" &&
24772471
(nodeName === "img" || nodeName === "source")
24782472
) {
2479-
sanitizer = sanitizeSrcsetPropertyValue;
2473+
sanitizer = (value) =>
2474+
sanitizeSrcset($sce.valueOf(value), "ng-prop-srcset");
24802475
} else if (trustedContext) {
24812476
sanitizer = $sce.getTrusted.bind($sce, trustedContext);
24822477
}
@@ -2505,23 +2500,6 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
25052500
});
25062501
}
25072502

2508-
function addEventDirective(directives, attrName, eventName) {
2509-
directives.push(
2510-
createEventDirective(
2511-
$parse,
2512-
$rootScope,
2513-
$exceptionHandler,
2514-
attrName,
2515-
eventName,
2516-
/* forceAsync= */ false,
2517-
),
2518-
);
2519-
}
2520-
2521-
function addObserveDirective(directives, source, prop) {
2522-
directives.push(ngObserveDirective(source, prop));
2523-
}
2524-
25252503
function addAttrInterpolateDirective(
25262504
node,
25272505
directives,

0 commit comments

Comments
 (0)