css-what
Advanced tools
Comparing version 6.0.1 to 6.1.0
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -108,2 +108,23 @@ "use strict"; | ||
} | ||
function readValueWithParenthesis() { | ||
selectorIndex += 1; | ||
var start = selectorIndex; | ||
var counter = 1; | ||
for (; counter > 0 && selectorIndex < selector.length; selectorIndex++) { | ||
if (selector.charCodeAt(selectorIndex) === | ||
40 /* LeftParenthesis */ && | ||
!isEscaped(selectorIndex)) { | ||
counter++; | ||
} | ||
else if (selector.charCodeAt(selectorIndex) === | ||
41 /* RightParenthesis */ && | ||
!isEscaped(selectorIndex)) { | ||
counter--; | ||
} | ||
} | ||
if (counter) { | ||
throw new Error("Parenthesis not matched"); | ||
} | ||
return unescapeCSS(selector.slice(start, selectorIndex - 1)); | ||
} | ||
function isEscaped(pos) { | ||
@@ -308,2 +329,6 @@ var slashCount = 0; | ||
name: getName(2).toLowerCase(), | ||
data: selector.charCodeAt(selectorIndex) === | ||
40 /* LeftParenthesis */ | ||
? readValueWithParenthesis() | ||
: null, | ||
}); | ||
@@ -329,21 +354,3 @@ continue; | ||
else { | ||
selectorIndex += 1; | ||
var start = selectorIndex; | ||
var counter = 1; | ||
for (; counter > 0 && selectorIndex < selector.length; selectorIndex++) { | ||
if (selector.charCodeAt(selectorIndex) === | ||
40 /* LeftParenthesis */ && | ||
!isEscaped(selectorIndex)) { | ||
counter++; | ||
} | ||
else if (selector.charCodeAt(selectorIndex) === | ||
41 /* RightParenthesis */ && | ||
!isEscaped(selectorIndex)) { | ||
counter--; | ||
} | ||
} | ||
if (counter) { | ||
throw new Error("Parenthesis not matched"); | ||
} | ||
data = selector.slice(start, selectorIndex - 1); | ||
data = readValueWithParenthesis(); | ||
if (stripQuotesFromPseudos.has(name_2)) { | ||
@@ -413,8 +420,5 @@ var quot = data.charCodeAt(0); | ||
} | ||
if (name_3 === "*") { | ||
tokens.push({ type: types_1.SelectorType.Universal, namespace: namespace }); | ||
} | ||
else { | ||
tokens.push({ type: types_1.SelectorType.Tag, name: name_3, namespace: namespace }); | ||
} | ||
tokens.push(name_3 === "*" | ||
? { type: types_1.SelectorType.Universal, namespace: namespace } | ||
: { type: types_1.SelectorType.Tag, name: name_3, namespace: namespace }); | ||
} | ||
@@ -421,0 +425,0 @@ } |
@@ -68,10 +68,11 @@ "use strict"; | ||
case types_1.SelectorType.PseudoElement: | ||
return "::".concat(escapeName(token.name, charsToEscapeInName)); | ||
return "::".concat(escapeName(token.name, charsToEscapeInName)).concat(token.data === null | ||
? "" | ||
: "(".concat(escapeName(token.data, charsToEscapeInPseudoValue), ")")); | ||
case types_1.SelectorType.Pseudo: | ||
if (token.data === null) | ||
return ":".concat(escapeName(token.name, charsToEscapeInName)); | ||
if (typeof token.data === "string") { | ||
return ":".concat(escapeName(token.name, charsToEscapeInName), "(").concat(escapeName(token.data, charsToEscapeInPseudoValue), ")"); | ||
} | ||
return ":".concat(escapeName(token.name, charsToEscapeInName), "(").concat(stringify(token.data), ")"); | ||
return ":".concat(escapeName(token.name, charsToEscapeInName)).concat(token.data === null | ||
? "" | ||
: "(".concat(typeof token.data === "string" | ||
? escapeName(token.data, charsToEscapeInPseudoValue) | ||
: stringify(token.data), ")")); | ||
case types_1.SelectorType.Attribute: { | ||
@@ -78,0 +79,0 @@ if (token.name === "id" && |
@@ -45,2 +45,3 @@ export declare type Selector = PseudoSelector | PseudoElement | AttributeSelector | TagSelector | UniversalSelector | Traversal; | ||
name: string; | ||
data: string | null; | ||
} | ||
@@ -47,0 +48,0 @@ export interface TagSelector { |
@@ -103,2 +103,23 @@ import { SelectorType, AttributeAction, } from "./types"; | ||
} | ||
function readValueWithParenthesis() { | ||
selectorIndex += 1; | ||
const start = selectorIndex; | ||
let counter = 1; | ||
for (; counter > 0 && selectorIndex < selector.length; selectorIndex++) { | ||
if (selector.charCodeAt(selectorIndex) === | ||
40 /* LeftParenthesis */ && | ||
!isEscaped(selectorIndex)) { | ||
counter++; | ||
} | ||
else if (selector.charCodeAt(selectorIndex) === | ||
41 /* RightParenthesis */ && | ||
!isEscaped(selectorIndex)) { | ||
counter--; | ||
} | ||
} | ||
if (counter) { | ||
throw new Error("Parenthesis not matched"); | ||
} | ||
return unescapeCSS(selector.slice(start, selectorIndex - 1)); | ||
} | ||
function isEscaped(pos) { | ||
@@ -303,2 +324,6 @@ let slashCount = 0; | ||
name: getName(2).toLowerCase(), | ||
data: selector.charCodeAt(selectorIndex) === | ||
40 /* LeftParenthesis */ | ||
? readValueWithParenthesis() | ||
: null, | ||
}); | ||
@@ -324,21 +349,3 @@ continue; | ||
else { | ||
selectorIndex += 1; | ||
const start = selectorIndex; | ||
let counter = 1; | ||
for (; counter > 0 && selectorIndex < selector.length; selectorIndex++) { | ||
if (selector.charCodeAt(selectorIndex) === | ||
40 /* LeftParenthesis */ && | ||
!isEscaped(selectorIndex)) { | ||
counter++; | ||
} | ||
else if (selector.charCodeAt(selectorIndex) === | ||
41 /* RightParenthesis */ && | ||
!isEscaped(selectorIndex)) { | ||
counter--; | ||
} | ||
} | ||
if (counter) { | ||
throw new Error("Parenthesis not matched"); | ||
} | ||
data = selector.slice(start, selectorIndex - 1); | ||
data = readValueWithParenthesis(); | ||
if (stripQuotesFromPseudos.has(name)) { | ||
@@ -408,8 +415,5 @@ const quot = data.charCodeAt(0); | ||
} | ||
if (name === "*") { | ||
tokens.push({ type: SelectorType.Universal, namespace }); | ||
} | ||
else { | ||
tokens.push({ type: SelectorType.Tag, name, namespace }); | ||
} | ||
tokens.push(name === "*" | ||
? { type: SelectorType.Universal, namespace } | ||
: { type: SelectorType.Tag, name, namespace }); | ||
} | ||
@@ -416,0 +420,0 @@ } |
@@ -56,10 +56,11 @@ import { SelectorType, AttributeAction } from "./types"; | ||
case SelectorType.PseudoElement: | ||
return `::${escapeName(token.name, charsToEscapeInName)}`; | ||
return `::${escapeName(token.name, charsToEscapeInName)}${token.data === null | ||
? "" | ||
: `(${escapeName(token.data, charsToEscapeInPseudoValue)})`}`; | ||
case SelectorType.Pseudo: | ||
if (token.data === null) | ||
return `:${escapeName(token.name, charsToEscapeInName)}`; | ||
if (typeof token.data === "string") { | ||
return `:${escapeName(token.name, charsToEscapeInName)}(${escapeName(token.data, charsToEscapeInPseudoValue)})`; | ||
} | ||
return `:${escapeName(token.name, charsToEscapeInName)}(${stringify(token.data)})`; | ||
return `:${escapeName(token.name, charsToEscapeInName)}${token.data === null | ||
? "" | ||
: `(${typeof token.data === "string" | ||
? escapeName(token.data, charsToEscapeInPseudoValue) | ||
: stringify(token.data)})`}`; | ||
case SelectorType.Attribute: { | ||
@@ -66,0 +67,0 @@ if (token.name === "id" && |
@@ -45,2 +45,3 @@ export declare type Selector = PseudoSelector | PseudoElement | AttributeSelector | TagSelector | UniversalSelector | Traversal; | ||
name: string; | ||
data: string | null; | ||
} | ||
@@ -47,0 +48,0 @@ export interface TagSelector { |
@@ -5,3 +5,3 @@ { | ||
"description": "a CSS selector parser", | ||
"version": "6.0.1", | ||
"version": "6.1.0", | ||
"funding": { | ||
@@ -35,13 +35,13 @@ "url": "https://github.com/sponsors/fb55" | ||
"devDependencies": { | ||
"@types/jest": "^27.0.3", | ||
"@types/node": "^17.0.5", | ||
"@typescript-eslint/eslint-plugin": "^5.8.0", | ||
"@typescript-eslint/parser": "^5.8.0", | ||
"eslint": "^8.5.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^17.0.23", | ||
"@typescript-eslint/eslint-plugin": "^5.17.0", | ||
"@typescript-eslint/parser": "^5.17.0", | ||
"eslint": "^8.12.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"jest": "^27.4.5", | ||
"prettier": "^2.5.1", | ||
"ts-jest": "^27.1.2", | ||
"typescript": "^4.5.4" | ||
"jest": "^27.5.1", | ||
"prettier": "^2.6.1", | ||
"ts-jest": "^27.1.4", | ||
"typescript": "^4.6.3" | ||
}, | ||
@@ -48,0 +48,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
66038
1412