csslint: Selectors L4 parts (ED 2020-04-07) (#981)

* add :where(), remove :matches()

* add "s" case-sensitivity flag

* add "||" column combinator
This commit is contained in:
tophf 2020-06-26 19:47:12 +03:00 committed by GitHub
parent 4e146d0e54
commit 429c34ca8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1426,12 +1426,13 @@ self.parserlib = (() => {
GREATER: {text: '>'}, GREATER: {text: '>'},
COMMA: {text: ','}, COMMA: {text: ','},
TILDE: {text: '~'}, TILDE: {text: '~'},
COLUMN: {text: '||'},
// modifier // modifier
NOT: {}, NOT: {},
ANY: {text: ['any', '-webkit-any', '-moz-any']}, ANY: {text: ['any', '-webkit-any', '-moz-any']},
MATCHES: {},
IS: {}, IS: {},
WHERE: {},
/* /*
* Defined in CSS3 Paged Media * Defined in CSS3 Paged Media
@ -1468,7 +1469,6 @@ self.parserlib = (() => {
// part of CSS3 grammar but not the Flex code // part of CSS3 grammar but not the Flex code
CHAR: {}, CHAR: {},
// TODO: Needed?
// Not defined as tokens, but might as well be // Not defined as tokens, but might as well be
PIPE: {text: '|'}, PIPE: {text: '|'},
SLASH: {text: '/'}, SLASH: {text: '/'},
@ -2205,6 +2205,7 @@ self.parserlib = (() => {
value === '>' ? 'child' : value === '>' ? 'child' :
value === '+' ? 'adjacent-sibling' : value === '+' ? 'adjacent-sibling' :
value === '~' ? 'sibling' : value === '~' ? 'sibling' :
value === '||' ? 'column' :
!value.trim() ? 'descendant' : !value.trim() ? 'descendant' :
'unknown'; 'unknown';
} }
@ -2943,6 +2944,7 @@ self.parserlib = (() => {
* - PREFIXMATCH * - PREFIXMATCH
* - SUFFIXMATCH * - SUFFIXMATCH
* - SUBSTRINGMATCH * - SUBSTRINGMATCH
* - COLUMN
* - CHAR * - CHAR
*/ */
case '|': case '|':
@ -2950,10 +2952,11 @@ self.parserlib = (() => {
case '^': case '^':
case '$': case '$':
case '*': case '*':
return reader.peek() === '=' ? return (
this.comparisonToken(c, pos) : reader.peek() === '=' ? this.comparisonToken(c, pos) :
this.charToken(c, pos); reader.readMatch('|') ? this.createToken(Tokens.COLUMN, '||', pos) :
this.charToken(c, pos)
);
/* /*
* Potential tokens: * Potential tokens:
* - STRING * - STRING
@ -3043,8 +3046,8 @@ self.parserlib = (() => {
* Potential tokens: * Potential tokens:
* - ANY * - ANY
* - IS * - IS
* - MATCHES
* - NOT * - NOT
* - WHERE
* - CHAR * - CHAR
*/ */
case ':': case ':':
@ -3258,18 +3261,18 @@ self.parserlib = (() => {
// NOT // NOT
// IS // IS
// ANY // ANY
// MATCHES
// CHAR // CHAR
notOrIsToken(first, pos) { notOrIsToken(first, pos) {
// first is always ':' // first is always ':'
const reader = this._reader; const reader = this._reader;
const func = reader.readMatch(/(not|is|(-(moz|webkit)-)?(any|matches))\(/iy); const func = reader.readMatch(/(not|is|where|(-(moz|webkit)-)?any)\(/iy);
if (func) { if (func) {
const lcase = func[0].toLowerCase(); const lcase = func[0].toLowerCase();
const type = const type =
lcase === 'n' ? Tokens.NOT : lcase === 'n' ? Tokens.NOT :
lcase === 'i' ? Tokens.IS : lcase === 'i' ? Tokens.IS :
lcase === 'm' ? Tokens.MATCHES : Tokens.ANY; lcase === 'w' ? Tokens.WHERE :
Tokens.ANY;
return this.createToken(type, first + func, pos); return this.createToken(type, first + func, pos);
} }
return this.charToken(first, pos); return this.charToken(first, pos);
@ -4369,7 +4372,7 @@ self.parserlib = (() => {
} }
_combinator() { _combinator() {
if (this._tokenStream.match([Tokens.PLUS, Tokens.GREATER, Tokens.TILDE])) { if (this._tokenStream.match([Tokens.PLUS, Tokens.GREATER, Tokens.TILDE, Tokens.COLUMN])) {
const value = new Combinator(this._tokenStream._token); const value = new Combinator(this._tokenStream._token);
this._ws(); this._ws();
return value; return value;
@ -4633,7 +4636,8 @@ self.parserlib = (() => {
this._ws(); this._ws();
if (stream.match([Tokens.IDENT])) { if (stream.match([Tokens.IDENT])) {
if (lower(stream._token.value) === 'i') { const caseMod = lower(stream._token.value);
if (caseMod === 'i' || caseMod === 's') {
value += stream._token.value + value += stream._token.value +
this._ws(); this._ws();
} else { } else {
@ -4713,7 +4717,7 @@ self.parserlib = (() => {
_is() { _is() {
const stream = this._tokenStream; const stream = this._tokenStream;
if (!stream.match([Tokens.IS, Tokens.ANY, Tokens.MATCHES])) return null; if (!stream.match([Tokens.IS, Tokens.ANY, Tokens.WHERE])) return null;
let arg; let arg;
const start = stream._token; const start = stream._token;
@ -5448,7 +5452,7 @@ self.parserlib = (() => {
[Tokens.COLON, Parser.prototype._pseudo], [Tokens.COLON, Parser.prototype._pseudo],
[Tokens.IS, Parser.prototype._is], [Tokens.IS, Parser.prototype._is],
[Tokens.ANY, Parser.prototype._is], [Tokens.ANY, Parser.prototype._is],
[Tokens.MATCHES, Parser.prototype._is], [Tokens.WHERE, Parser.prototype._is],
[Tokens.NOT, Parser.prototype._negation], [Tokens.NOT, Parser.prototype._negation],
]), ]),
}; };