From b742ed2c6502b94824bff4630fef576ef251f6f5 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 1 Jul 2022 10:26:46 +0300 Subject: [PATCH] parserlib: forbid `default` in custom-ident --- js/csslint/parserlib.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/js/csslint/parserlib.js b/js/csslint/parserlib.js index 3c1fdb17..47848ce5 100644 --- a/js/csslint/parserlib.js +++ b/js/csslint/parserlib.js @@ -33,8 +33,13 @@ self.parserlib = (() => { // Global keywords that can be set for any property are conveniently listed in `all` prop: // https://drafts.csswg.org/css-cascade/#all-shorthand const GlobalKeywords = ['initial', 'inherit', 'revert', 'unset']; - const isGlobalKeyword = RegExp.prototype.test.bind( - new RegExp(`^(${GlobalKeywords.join('|')})$`, 'i')); + const rxGlobalKeyword = new RegExp(`^(${GlobalKeywords.join('|')})$`, 'i'); + /** @param {string} [ex] |-separated exceptions + * @param {RegExp} [re] custom regexp check + * @param {function} [alt] alternative check */ + const customIdentChecker = (ex, re, alt) => + (re = new RegExp(`^(?!(default|${ex ? ex + '|' : ''}${GlobalKeywords.join('|')})$)${re ? re.source : ''}`, 'i')) && + (p => p.tokenType === Tokens.IDENT && re.test(p.value) || (!alt || alt(p))); // eslint-disable-line no-use-before-define const Properties = { 'accent-color': 'auto | ', @@ -56,7 +61,7 @@ self.parserlib = (() => { 'animation-duration': '