css-what
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -10,9 +10,13 @@ "use strict"; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringify = exports.parse = void 0; | ||
__exportStar(require("./parse"), exports); | ||
var parse_1 = require("./parse"); | ||
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.default; } }); | ||
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return __importDefault(parse_1).default; } }); | ||
var stringify_1 = require("./stringify"); | ||
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return stringify_1.default; } }); | ||
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return __importDefault(stringify_1).default; } }); |
@@ -6,3 +6,3 @@ "use strict"; | ||
var reEscape = /\\([\da-f]{1,6}\s?|(\s)|.)/gi; | ||
//modified version of https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L87 | ||
// Modified version of https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L87 | ||
var reAttr = /^\s*((?:\\.|[\w\u00b0-\uFFFF-])+)\s*(?:(\S?)=\s*(?:(['"])([^]*?)\3|(#?(?:\\.|[\w\u00b0-\uFFFF-])*)|)|)\s*(i)?\]/; | ||
@@ -29,7 +29,14 @@ var actionTypes = { | ||
}; | ||
//pseudos, whose data-property is parsed as well | ||
var unpackPseudos = new Set(["has", "not", "matches"]); | ||
// Pseudos, whose data property is parsed as well. | ||
var unpackPseudos = new Set([ | ||
"has", | ||
"not", | ||
"matches", | ||
"is", | ||
"host", | ||
"host-context", | ||
]); | ||
var stripQuotesFromPseudos = new Set(["contains", "icontains"]); | ||
var quotes = new Set(['"', "'"]); | ||
//unescape function taken from https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L152 | ||
// Unescape function taken from https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L152 | ||
function funescape(_, escaped, escapedWhitespace) { | ||
@@ -61,2 +68,4 @@ var high = parseInt(escaped, 16) - 0x10000; | ||
function parseSelector(subselects, selector, options) { | ||
var _a, _b; | ||
if (options === void 0) { options = {}; } | ||
var tokens = []; | ||
@@ -117,3 +126,3 @@ var sawWS = false; | ||
else if (firstChar in attribSelectors) { | ||
var _a = attribSelectors[firstChar], name_1 = _a[0], action = _a[1]; | ||
var _c = attribSelectors[firstChar], name_1 = _c[0], action = _c[1]; | ||
selector = selector.substr(1); | ||
@@ -130,12 +139,10 @@ tokens.push({ | ||
selector = selector.substr(1); | ||
var data = selector.match(reAttr); | ||
if (!data) { | ||
var attributeMatch = selector.match(reAttr); | ||
if (!attributeMatch) { | ||
throw new Error("Malformed attribute selector: " + selector); | ||
} | ||
selector = selector.substr(data[0].length); | ||
var name_2 = unescapeCSS(data[1]); | ||
if (!options || | ||
("lowerCaseAttributeNames" in options | ||
? options.lowerCaseAttributeNames | ||
: !options.xmlMode)) { | ||
var completeSelector = attributeMatch[0], baseName = attributeMatch[1], actionType = attributeMatch[2], _d = attributeMatch[4], quotedValue = _d === void 0 ? "" : _d, _e = attributeMatch[5], value = _e === void 0 ? quotedValue : _e, ignoreCase = attributeMatch[6]; | ||
selector = selector.substr(completeSelector.length); | ||
var name_2 = unescapeCSS(baseName); | ||
if ((_a = options.lowerCaseAttributeNames) !== null && _a !== void 0 ? _a : !options.xmlMode) { | ||
name_2 = name_2.toLowerCase(); | ||
@@ -146,5 +153,5 @@ } | ||
name: name_2, | ||
action: actionTypes[data[2]], | ||
value: unescapeCSS(data[4] || data[5] || ""), | ||
ignoreCase: !!data[6], | ||
action: actionTypes[actionType], | ||
value: unescapeCSS(value), | ||
ignoreCase: !!ignoreCase, | ||
}); | ||
@@ -164,3 +171,3 @@ } | ||
var data = null; | ||
if (selector.charAt(0) === "(") { | ||
if (selector.startsWith("(")) { | ||
if (unpackPseudos.has(name_3)) { | ||
@@ -173,3 +180,3 @@ var quot = selector.charAt(1); | ||
if (quoted) { | ||
if (selector.charAt(0) !== quot) { | ||
if (!selector.startsWith(quot)) { | ||
throw new Error("Unmatched quotes in :" + name_3); | ||
@@ -181,3 +188,3 @@ } | ||
} | ||
if (selector.charAt(0) !== ")") { | ||
if (!selector.startsWith(")")) { | ||
throw new Error("Missing closing parenthesis in :" + name_3 + " (" + selector + ")"); | ||
@@ -191,7 +198,10 @@ } | ||
for (; counter > 0 && pos < selector.length; pos++) { | ||
if (selector.charAt(pos) === "(" && !isEscaped(pos)) | ||
if (selector.charAt(pos) === "(" && | ||
!isEscaped(pos)) { | ||
counter++; | ||
} | ||
else if (selector.charAt(pos) === ")" && | ||
!isEscaped(pos)) | ||
!isEscaped(pos)) { | ||
counter--; | ||
} | ||
} | ||
@@ -216,6 +226,3 @@ if (counter) { | ||
var name_4 = getName(); | ||
if (!options || | ||
("lowerCaseTags" in options | ||
? options.lowerCaseTags | ||
: !options.xmlMode)) { | ||
if ((_b = options.lowerCaseTags) !== null && _b !== void 0 ? _b : !options.xmlMode) { | ||
name_4 = name_4.toLowerCase(); | ||
@@ -222,0 +229,0 @@ } |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -12,2 +19,8 @@ var actionTypes = { | ||
}; | ||
var charsToEscape = new Set(__spreadArrays(Object.values(actionTypes).filter(Boolean), [ | ||
":", | ||
"[", | ||
"]", | ||
" ", | ||
])); | ||
function stringify(token) { | ||
@@ -61,9 +74,9 @@ return token.map(stringifySubselector).join(", "); | ||
return "[" + escapeName(token.name) + actionTypes[token.action] + "='" + escapeName(token.value) + "'" + (token.ignoreCase ? "i" : "") + "]"; | ||
default: | ||
throw new Error("Unknown type"); | ||
} | ||
} | ||
function escapeName(str) { | ||
//TODO | ||
return str; | ||
return str | ||
.split("") | ||
.map(function (c) { return (charsToEscape.has(c) ? "\\" + c : c); }) | ||
.join(""); | ||
} |
@@ -5,3 +5,3 @@ { | ||
"description": "a CSS selector parser", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"repository": { | ||
@@ -18,4 +18,9 @@ "url": "https://github.com/fb55/css-what" | ||
"coverage": "cat coverage/lcov.info | coveralls", | ||
"lint": "eslint src", | ||
"format": "prettier --write '**/*.{ts,md,json}'", | ||
"lint": "npm run lint:es && npm run lint:prettier", | ||
"lint:es": "eslint src", | ||
"lint:prettier": "npm run prettier -- --check", | ||
"format": "npm run format:es && npm run format:prettier", | ||
"format:es": "npm run lint:es -- --fix", | ||
"format:prettier": "npm run prettier -- --write", | ||
"prettier": "prettier '**/*.{ts,md,json,yml}'", | ||
"build": "tsc", | ||
@@ -26,6 +31,6 @@ "prepare": "npm run build" | ||
"devDependencies": { | ||
"@types/jest": "^25.1.4", | ||
"@types/jest": "^26.0.3", | ||
"@types/node": "^14.0.5", | ||
"@typescript-eslint/eslint-plugin": "^2.31.0", | ||
"@typescript-eslint/parser": "^2.31.0", | ||
"@typescript-eslint/eslint-plugin": "^4.1.0", | ||
"@typescript-eslint/parser": "^4.1.0", | ||
"coveralls": "^3.0.5", | ||
@@ -37,3 +42,3 @@ "eslint": "^7.0.0", | ||
"ts-jest": "^26.0.0", | ||
"typescript": "^3.5.3" | ||
"typescript": "^4.0.2" | ||
}, | ||
@@ -40,0 +45,0 @@ "optionalDependencies": {}, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23485
382