parserlib: implement @supports selector()

This commit is contained in:
tophf 2020-10-14 20:17:57 +03:00
parent a71b621bf9
commit 492b75d84e

View File

@ -4020,24 +4020,19 @@ self.parserlib = (() => {
_supportsCondition() { _supportsCondition() {
const stream = this._tokenStream; const stream = this._tokenStream;
if (stream.match(Tokens.IDENT)) { const next = stream.LT(1);
const ident = lower(stream._token.value); if (next.type === Tokens.IDENT && lower(next.value) === 'not') {
if (ident === 'not') { stream.get();
stream.mustMatch(Tokens.S); stream.mustMatch(Tokens.S);
this._supportsConditionInParens(); this._supportsConditionInParens();
} else {
stream.unget();
}
} else { } else {
this._supportsConditionInParens(); this._supportsConditionInParens();
this._ws();
while (stream.peek() === Tokens.IDENT) { while (stream.peek() === Tokens.IDENT) {
const ident = lower(stream.LT(1).value); const ident = lower(stream.LT(1).value);
if (ident === 'and' || ident === 'or') { if (ident === 'and' || ident === 'or') {
stream.mustMatch(Tokens.IDENT); stream.get();
this._ws(); this._ws();
this._supportsConditionInParens(); this._supportsConditionInParens();
this._ws();
} }
} }
} }
@ -4045,36 +4040,41 @@ self.parserlib = (() => {
_supportsConditionInParens() { _supportsConditionInParens() {
const stream = this._tokenStream; const stream = this._tokenStream;
if (stream.match(Tokens.LPAREN)) { const next = stream.LT(1);
this._ws(); if (next.type === Tokens.LPAREN) {
if (stream.match([Tokens.IDENT, Tokens.CUSTOM_PROP])) { stream.get();
// look ahead for not keyword,
// if not given, continue with declaration condition.
const ident = lower(stream._token.value);
if (ident === 'not') {
this._ws(); this._ws();
const {type, value} = stream.LT(1);
if (type === Tokens.IDENT || type === Tokens.CUSTOM_PROP) {
if (lower(value) === 'not') {
this._supportsCondition(); this._supportsCondition();
stream.mustMatch(Tokens.RPAREN); stream.mustMatch(Tokens.RPAREN);
} else { } else {
stream.unget(); this._supportsDecl(false);
this._supportsDeclarationCondition(false);
} }
} else { } else {
this._supportsCondition(); this._supportsCondition();
stream.mustMatch(Tokens.RPAREN); stream.mustMatch(Tokens.RPAREN);
} }
} else if (next.type === Tokens.FUNCTION && lower(next.value) === 'selector(') {
stream.get();
this._ws();
this._selector();
stream.mustMatch(Tokens.RPAREN);
} else { } else {
this._supportsDeclarationCondition(); this._supportsDecl();
} }
this._ws();
} }
_supportsDeclarationCondition(requireStartParen = true) { _supportsDecl(requireStartParen = true) {
const stream = this._tokenStream;
if (requireStartParen) { if (requireStartParen) {
this._tokenStream.mustMatch(Tokens.LPAREN); stream.mustMatch(Tokens.LPAREN);
} }
this._ws(); this._ws();
this._declaration(); this._declaration();
this._tokenStream.mustMatch(Tokens.RPAREN); stream.mustMatch(Tokens.RPAREN);
} }
_media() { _media() {