Skip to content

Commit 43482f9

Browse files
authored
Merge pull request #2 from MicrosoftEdge/master
Update from fork
2 parents 25291af + 4578920 commit 43482f9

File tree

4 files changed

+114
-282
lines changed

4 files changed

+114
-282
lines changed

Recipe.min.js

Lines changed: 37 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -824,84 +824,36 @@ void function() { try {
824824
atrulesUsage[selectorText] = Object.create(null);
825825
atrulesUsage[selectorText] = {"count": 1,
826826
"props": {},
827-
"nested": {},
828827
"conditions": {}}
829828
} else {
830829
var count = atrulesUsage[selectorText].count;
831-
count = count++;
830+
atrulesUsage[selectorText].count = count + 1;
832831
}
833832

834833
var selectedAtruleUsage = atrulesUsage[selectorText];
835834

836835
if(rule.cssRules) {
837836
CSSUsage.PropertyValuesAnalyzer.anaylzeStyleOfRulePropCount(rule, selectedAtruleUsage);
838-
processNestedRules(rule, selectedAtruleUsage.nested);
839837
}
840838

841839
processConditionText(rule.conditionText, selectedAtruleUsage.conditions);
842840
}
843841

844-
/**
845-
* Analyzes the given @atrules, such as @supports, and counts the usage of the nested rules
846-
* according to their type. NOTE: must pass in the current usage of nested rules for the
847-
* given @atrule.
848-
*/
849-
function processNestedRules(rule, nestedRulesUsage) {
850-
// find the rule count for nested rules
851-
for(let index in rule.cssRules) {
852-
let ruleBody = rule.cssRules[index];
853-
854-
if(!ruleBody.cssText) {
855-
continue;
856-
}
857-
858-
var nestRuleSelector;
859-
860-
if(isRuleAnAtRule(ruleBody)) {
861-
nestRuleSelector = '@atrule:' + ruleBody.type;
862-
863-
} else if(ruleBody.style) {
864-
if(ruleBody.selectorText) {
865-
try {
866-
var selectorText = CSSUsage.PropertyValuesAnalyzer.cleanSelectorText(ruleBody.selectorText);
867-
var matchedElements = [].slice.call(document.querySelectorAll(selectorText));
868-
869-
if(matchedElements.length == 0) {
870-
continue;
871-
}
872-
873-
var cleanedSelector = CSSUsage.PropertyValuesAnalyzer.generalizedSelectorsOf(selectorText);
874-
nestRuleSelector = cleanedSelector[0]; // only passed in one selector to a function that returns many
875-
} catch (ex) {
876-
continue;
877-
}
878-
}
879-
}
880-
881-
if(nestRuleSelector) {
882-
if(!nestedRulesUsage[nestRuleSelector]) {
883-
nestedRulesUsage[nestRuleSelector] = Object.create(null);
884-
nestedRulesUsage[nestRuleSelector] = {"count": 1}
885-
} else {
886-
var nestedCount = nestedRulesUsage[nestRuleSelector].count;
887-
nestedCount = nestedCount++;
888-
}
889-
}
890-
}
891-
}
892-
893842
/**
894843
* This processes the usage of conditions of conditional @atrules like @media.
895844
* Requires the condition of the rule to process and the current recorded usage
896845
* of the @atrule in question.
897846
*/
898847
function processConditionText(conditionText, selectedAtruleConditionalUsage) {
848+
// replace numeric specific information from condition statements
849+
conditionText = conditionText.replace(/[0-9]+.*[0-9]+/g, '');
850+
899851
if(!selectedAtruleConditionalUsage[conditionText]) {
900852
selectedAtruleConditionalUsage[conditionText] = Object.create(null);
901853
selectedAtruleConditionalUsage[conditionText] = {"count": 1}
902854
} else {
903855
var count = selectedAtruleConditionalUsage[conditionText].count;
904-
count = count++;
856+
selectedAtruleConditionalUsage[conditionText].count = count + 1;
905857
}
906858
}
907859

@@ -920,48 +872,18 @@ void function() { try {
920872
"props": {}}
921873
} else {
922874
var count = atrulesUsage[selectorText].count;
923-
count = count++;
875+
atrulesUsage[selectorText].count = count + 1;
924876
}
925877

926878
// @keyframes rule type is 7
927879
if(rule.type == 7) {
928880
processKeyframeAtRules(rule);
929881
} else if(CSSUsageResults.rules[selectorText].props) {
930882
atrulesUsage[selectorText].props = CSSUsageResults.rules[selectorText].props;
931-
}
932-
933-
if(rule.pseudoClass) {
934-
processPseudoClassesOfAtrules(rule);
883+
delete atrulesUsage[selectorText].props.values;
935884
}
936885
}
937886

938-
939-
/**
940-
* If an atrule as has a pseudo class such as @page, process the pseudo class and
941-
* add it to the atrule usage.
942-
*/
943-
function processPseudoClassesOfAtrules(rule) {
944-
var selectorText = '@atrule:' + rule.type;
945-
var selectorAtruleUsage = CSSUsageResults.atrules[selectorText];
946-
947-
if(!selectorAtruleUsage["pseudos"]) {
948-
selectorAtruleUsage["pseudos"] = Object.create(null);
949-
selectorAtruleUsage["pseudos"] = {};
950-
}
951-
952-
var pseudosUsageForSelector = selectorAtruleUsage["pseudos"];
953-
let pseudoClass = rule.pseudoClass;
954-
955-
if(!pseudosUsageForSelector[pseudoClass]) {
956-
pseudosUsageForSelector[pseudoClass] = Object.create(null);
957-
pseudosUsageForSelector[pseudoClass] = {"count": 1};
958-
} else {
959-
var pseudoCount = pseudosUsageForSelector[pseudoClass].count;
960-
pseudoCount = pseudoCount++;
961-
}
962-
}
963-
964-
965887
/**
966888
* Processes on @keyframe to add the appropriate props from the frame and a counter of which
967889
* frames are used throughout the document.
@@ -980,18 +902,23 @@ void function() { try {
980902
* WARN: tightly coupled with previous processing of rules.
981903
*/
982904
atrulesUsageForSelector.props = CSSUsageResults.rules["@atrule:8"].props;
905+
delete atrulesUsageForSelector.props.values;
983906

984907
for(let index in rule.cssRules) {
985908
let keyframe = rule.cssRules[index];
986909
var atrulesUsageForKeyframeOfSelector = atrulesUsageForSelector.keyframes;
987910

988-
if(keyframe.keyText) {
989-
if(!atrulesUsageForKeyframeOfSelector[keyframe.keyText]) {
990-
atrulesUsageForKeyframeOfSelector[keyframe.keyText] = {"count": 1};
991-
} else {
992-
var keyframeCount = atrulesUsageForKeyframeOfSelector[keyframe.keyText].count;
993-
keyframeCount = keyframeCount++;
994-
}
911+
if(!keyframe.keyText) {
912+
continue;
913+
}
914+
915+
var frame = keyframe.keyText;
916+
917+
if(!atrulesUsageForKeyframeOfSelector[frame]) {
918+
atrulesUsageForKeyframeOfSelector[frame] = { "count" : 1 };
919+
} else {
920+
var keyframeCount = atrulesUsageForKeyframeOfSelector[frame].count;
921+
atrulesUsageForKeyframeOfSelector[frame].count = keyframeCount + 1;
995922
}
996923
}
997924
}
@@ -1505,6 +1432,20 @@ void function() { try {
15051432
continue;
15061433
}
15071434

1435+
if(ruleBody.selector) {
1436+
try {
1437+
var selectorText = CssPropertyValuesAnalyzer.cleanSelectorText(ruleBody.selectorText);
1438+
var matchedElements = [].slice.call(document.querySelectorAll(selectorText));
1439+
1440+
if (matchedElements.length == 0) {
1441+
continue;
1442+
}
1443+
} catch (ex) {
1444+
console.warn(ex.stack||("Invalid selector: "+selectorText+" -- via "+ruleBody.selectorText));
1445+
continue;
1446+
}
1447+
}
1448+
15081449
let cssText = ' ' + style.cssText.toLowerCase();
15091450

15101451
for (var i = style.length; i--;) {
@@ -1532,7 +1473,7 @@ void function() { try {
15321473
propsForSelectedAtrule[normalizedKey] = {"count": 1};
15331474
} else {
15341475
var propCount = propsForSelectedAtrule[normalizedKey].count;
1535-
propCount = propCount++;
1476+
propsForSelectedAtrule[normalizedKey].count = propCount + 1;
15361477
}
15371478
}
15381479
}
@@ -1812,7 +1753,7 @@ void function() { try {
18121753

18131754
CSSUsageResults.usages = results;
18141755
deleteDuplicatedAtRules(); // TODO: issue #52
1815-
1756+
18161757
if(window.debugCSSUsage) if(window.debugCSSUsage) console.log(CSSUsageResults.usages);
18171758
}
18181759

@@ -1830,6 +1771,8 @@ void function() { try {
18301771
delete cssUsageRules[key];
18311772
}
18321773
}
1774+
1775+
delete CSSUsageResults.atrules["@atrule:8"]; // delete duplicated data from atrule:7, keyframe
18331776
}
18341777
}();
18351778

0 commit comments

Comments
 (0)