Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/lib/sort.js

Issue 800513006: Added vulcanize under third_party/npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/lib/sort.js
diff --git a/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/lib/sort.js b/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/lib/sort.js
new file mode 100644
index 0000000000000000000000000000000000000000..c97c7c77aa605184566d67529fb7a729edc2d102
--- /dev/null
+++ b/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/lib/sort.js
@@ -0,0 +1,59 @@
+module.exports = sortByProcedure;
+
+/*
+ sort the parts of the passed selector,
+ as there is potential for optimization
+ (some types of selectors are faster than others)
+*/
+
+var ATTRIBUTE = 1;
+
+var procedure = {
+ __proto__: null,
+ universal: 5, //should be last so that it can be ignored
+ tag: 3, //very quick test
+ attribute: ATTRIBUTE,
+ pseudo: 0, //can be pretty expensive (especially :has)
+
+ //everything else shouldn't be moved
+ descendant: -1,
+ child: -1,
+ parent: -1,
+ sibling: -1,
+ adjacent: -1
+};
+
+var attributes = {
+ __proto__: null,
+ exists: 8,
+ equals: 7,
+ not: 6,
+ start: 5,
+ end: 4,
+ any: 3,
+ hyphen: 2,
+ element: 1
+};
+
+function sortByProcedure(arr){
+ for(var i = 1; i < arr.length; i++){
+ var procNew = procedure[arr[i].type];
+
+ if(procNew < 0) continue;
+
+ for(var j = i - 1; j >= 0; j--){
+ if(
+ procNew > procedure[arr[j].type] || !(
+ procNew === ATTRIBUTE &&
+ procedure[arr[j].type] === ATTRIBUTE &&
+ attributes[arr[i].action] <= attributes[arr[j].action]
+ )
+ ) break;
+
+ var tmp = arr[j + 1];
+ arr[j + 1] = arr[j];
+ arr[j] = tmp;
+ }
+ }
+ return arr;
+}

Powered by Google App Engine
This is Rietveld 408576698