Browse Source

kernel: Fix missed exclusion in `TFoo @ {#bar->#baz} - #(bar)`.

Plus optimize to `if` not to call `Object.keys` and `forEach` for empty cases.
Herbert Vojčík 7 years ago
parent
commit
0ceac7a118
1 changed files with 18 additions and 12 deletions
  1. 18 12
      support/kernel-fundamentals.js

+ 18 - 12
support/kernel-fundamentals.js

@@ -372,16 +372,20 @@ define(['./compatibility'], function () {
             Object.keys(traitMethods).forEach(function (selector) {
                 obj[selector] = traitMethods[selector];
             });
-            var traitAliases = traitTransformation.aliases || {};
-            Object.keys(traitAliases).forEach(function (aliasSelector) {
-                var aliasedMethod = traitMethods[traitAliases[aliasSelector]];
-                if (aliasedMethod) obj[aliasSelector] = aliased(aliasSelector, aliasedMethod);
-                // else delete obj[aliasSelector]; // semantically correct; optimized away
-            });
-            var traitExclusions = traitTransformation.exclusions || [];
-            traitExclusions.forEach(function (selector) {
-                delete obj[selector];
-            });
+            var traitAliases = traitTransformation.aliases;
+            if (traitAliases) {
+                Object.keys(traitAliases).forEach(function (aliasSelector) {
+                    var aliasedMethod = traitMethods[traitAliases[aliasSelector]];
+                    if (aliasedMethod) obj[aliasSelector] = aliased(aliasSelector, aliasedMethod);
+                    // else delete obj[aliasSelector]; // semantically correct; optimized away
+                });
+            }
+            var traitExclusions = traitTransformation.exclusions;
+            if (traitExclusions) {
+                traitExclusions.forEach(function (selector) {
+                    delete obj[selector];
+                });
+            }
             return obj;
         }
 
@@ -442,8 +446,10 @@ define(['./compatibility'], function () {
                 obj[aliasSelector] = aliased(aliasSelector, method);
             });
             var traitExclusions = traitTransformation.exclusions;
-            if (traitExclusions && traitExclusions.indexOf(selector) !== -1) {
-                delete obj[selector];
+            if (traitExclusions) {
+                traitExclusions.forEach(function (selector) {
+                    delete obj[selector];
+                });
             }
             return changes;
         }