From 6995483ec0421143ee105fafd5c6e8d420148945 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 3 Aug 2022 20:29:31 +0300 Subject: [PATCH] parserlib: cosmetics/simplifications --- js/csslint/csslint.js | 5 +- js/csslint/parserlib.js | 108 +++++++++++++++------------------------- 2 files changed, 42 insertions(+), 71 deletions(-) diff --git a/js/csslint/csslint.js b/js/csslint/csslint.js index 4c2d160d..2b25c6b8 100644 --- a/js/csslint/csslint.js +++ b/js/csslint/csslint.js @@ -330,7 +330,7 @@ CSSLint.Util = { /** Gets the lower-cased text without vendor prefix */ getPropName(prop) { return prop._propName || - (prop._propName = prop.text.replace(parserlib.util.rxVendorPrefix, '').toLowerCase()); + (prop._propName = prop.text.match(parserlib.util.rxVendorPrefix)[2].toLowerCase()); }, registerRuleEvents(parser, {start, property, end}) { @@ -1327,14 +1327,13 @@ CSSLint.addRule['known-pseudos'] = [{ const rx = /^(:+)(?:-(\w+)-)?([^(]+)(\()?/i; const allowsFunc = Func + FuncToo; const allowsPrefix = WK + Moz; - const {lower} = parserlib.util; const checkSelector = ({parts}) => { for (const {modifiers} of parts || []) { if (!modifiers) continue; for (const mod of modifiers) { if (mod.type === 'pseudo') { const {text} = mod; - const [all, colons, prefix, name, paren] = rx.exec(lower(text)) || 0; + const [all, colons, prefix, name, paren] = rx.exec(text.toLowerCase()) || 0; const defPrefixed = definitionsPrefixed[name]; const def = definitions[name] || defPrefixed; for (const err of !def ? ['Unknown pseudo'] : [ diff --git a/js/csslint/parserlib.js b/js/csslint/parserlib.js index 64319e32..d3f44db2 100644 --- a/js/csslint/parserlib.js +++ b/js/csslint/parserlib.js @@ -715,9 +715,8 @@ self.parserlib = (() => { const rxNameChar = /[-\\_\da-zA-Z\u00A0-\uFFFF]/u; const rxNameCharNoEsc = /[-_\da-zA-Z\u00A0-\uFFFF]+/yu; // must not match \\ const rxUnquotedUrlCharNoEsc = /[-!#$%&*-[\]-~\u00A0-\uFFFF]+/yu; // must not match \\ - const rxVendorPrefix = /^-(webkit|moz|ms|o)-(.+)/i; + const rxVendorPrefix = /^(?:-(webkit|moz|ms|o)-)?(.+)/i; const rxCalc = /^(?:-(webkit|moz|ms|o)-)?(calc|min|max|clamp)\(/i; - const lowercaseCache = new Map(); //#endregion //#region ValidationTypes - definitions @@ -777,7 +776,7 @@ self.parserlib = (() => { '': 'cielab() | cielch() | cielchab() | icc-color() | icc-named-color()', '': customIdentChecker('span|auto'), '': p => vtIsIdent(p) && !VTSimple[''](p), - '': p => vtIsIdent(p) && !lowerCmp(p.value, 'none'), + '': p => vtIsIdent(p) && !/^none$/i.test(p.value), '': p => p.tokenType === Tokens.IE_FUNCTION, //eslint-disable-line no-use-before-define '': ' | | cross-fade()', '': ' | min-content | max-content | auto', @@ -802,7 +801,7 @@ self.parserlib = (() => { p.expr.parts.every(VTSimple[''], VTSimple) ), //eslint-disable-next-line no-use-before-define - '': p => p.text in Colors || ColorsLC.has(lower(p.text)), + '': p => rxColors.test(p.text), '': p => p.type === 'number' || p.isCalc, '': p => p.value >= 0 && p.type === 'number' || p.isCalc, @@ -830,9 +829,9 @@ self.parserlib = (() => { '