css-selector-tokenizer
Advanced tools
Comparing version 0.5.4 to 0.6.0
@@ -0,0 +0,0 @@ exports.parse = require("./parse"); |
"use strict"; | ||
var Parser = require("fastparse"); | ||
var regexpu = require("regexpu-core"); | ||
@@ -167,7 +168,15 @@ function unescape(str) { | ||
var parser = new Parser({ | ||
selector: { | ||
"/\\*([\\s\\S]*?)\\*/": commentMatch, | ||
"\\.((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": typeMatch("class"), | ||
"#((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": typeMatch("id"), | ||
function getSelectors() { | ||
// The assignment here is split to preserve the property enumeration order. | ||
var selectors = { | ||
"/\\*([\\s\\S]*?)\\*/": commentMatch | ||
}; | ||
// https://www.w3.org/TR/CSS21/syndata.html#characters | ||
// 4.1.3: identifiers (...) can contain only the characters [a-zA-Z0-9] and | ||
// ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_) | ||
// | ||
// 10ffff is the maximum allowed in current Unicode | ||
selectors[regexpu("\\.((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)", "u")] = typeMatch("class"); | ||
selectors[regexpu("#((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)", "u")] = typeMatch("id"); | ||
var selectorsSecondHalf = { | ||
":(not|matches|has|local|global)\\((\\s*)": nestedPseudoClassStartMatch, | ||
@@ -189,3 +198,14 @@ ":((?:\\\\.|[A-Za-z_\\-0-9])+)\\(": pseudoClassStartMatch, | ||
".": invalidMatch | ||
}, | ||
}; | ||
var selector; | ||
for (selector in selectorsSecondHalf) { | ||
if (Object.prototype.hasOwnProperty.call(selectorsSecondHalf, selector)) { | ||
selectors[selector] = selectorsSecondHalf[selector]; | ||
} | ||
} | ||
return selectors; | ||
} | ||
var parser = new Parser({ | ||
selector: getSelectors(), | ||
inBrackets: { | ||
@@ -192,0 +212,0 @@ "/\\*[\\s\\S]*?\\*/": addToCurrent, |
@@ -26,13 +26,13 @@ "use strict"; | ||
function unescapeString(content) { | ||
return content.replace(/\\([a-fA-F0-9]{2,5}|.)/g, function(escaped) { | ||
if(escaped.length > 2) { | ||
var C = parseInt(escaped.substr(1), 16); | ||
if(C < 0x10000) { | ||
return String.fromCharCode(C); | ||
} else { | ||
return String.fromCharCode(Math.floor((C - 0x10000) / 0x400) + 0xD800) + | ||
String.fromCharCode((C - 0x10000) % 0x400 + 0xDC00); | ||
} | ||
return content.replace(/\\(?:([a-fA-F0-9]{1,6})|(.))/g, function(all, unicode, otherCharacter) { | ||
if (otherCharacter) { | ||
return otherCharacter; | ||
} | ||
var C = parseInt(unicode, 16); | ||
if(C < 0x10000) { | ||
return String.fromCharCode(C); | ||
} else { | ||
return escaped.substr(1); | ||
return String.fromCharCode(Math.floor((C - 0x10000) / 0x400) + 0xD800) + | ||
String.fromCharCode((C - 0x10000) % 0x400 + 0xDC00); | ||
} | ||
@@ -39,0 +39,0 @@ }); |
@@ -5,7 +5,17 @@ "use strict"; | ||
function escape(str) { | ||
var regexpu = require("regexpu-core"); | ||
var identifierEscapeRegexp = new RegExp( | ||
regexpu("(^[^A-Za-z_\\-\\u{00a0}-\\u{10ffff}]|^\\-\\-|[^A-Za-z_0-9\\-\\u{00a0}-\\u{10ffff}])", "ug"), | ||
"g" | ||
); | ||
function escape(str, identifier) { | ||
if(str === "*") { | ||
return "*"; | ||
} | ||
return str.replace(/(^[^A-Za-z_\\-]|^\-\-|[^A-Za-z_0-9\\-])/g, "\\$1"); | ||
if (identifier) { | ||
return str.replace(identifierEscapeRegexp, "\\$1"); | ||
} else { | ||
return str.replace(/(^[^A-Za-z_\\-]|^\-\-|[^A-Za-z_0-9\\-])/g, "\\$1"); | ||
} | ||
} | ||
@@ -22,5 +32,5 @@ | ||
case "class": | ||
return "." + escape(tree.name); | ||
return "." + escape(tree.name, true); | ||
case "id": | ||
return "#" + escape(tree.name); | ||
return "#" + escape(tree.name, true); | ||
case "attribute": | ||
@@ -27,0 +37,0 @@ return "[" + tree.content + "]"; |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "css-selector-tokenizer", | ||
"version": "0.5.4", | ||
"version": "0.6.0", | ||
"description": "Parses and stringifies CSS selectors", | ||
@@ -35,3 +35,4 @@ "main": "lib/index.js", | ||
"cssesc": "^0.1.0", | ||
"fastparse": "^1.1.1" | ||
"fastparse": "^1.1.1", | ||
"regexpu-core": "^1.0.0" | ||
}, | ||
@@ -38,0 +39,0 @@ "devDependencies": { |
@@ -0,0 +0,0 @@ # CSS Modules: CSS selector Tokenizer |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15998
485
3
1
+ Addedregexpu-core@^1.0.0
+ Addedjsesc@0.5.0(transitive)
+ Addedregenerate@1.4.2(transitive)
+ Addedregexpu-core@1.0.0(transitive)
+ Addedregjsgen@0.2.0(transitive)
+ Addedregjsparser@0.1.5(transitive)