Skip to content

Commit

Permalink
Backport fix for matching CSS wide keywords in atrule's prelude and d…
Browse files Browse the repository at this point in the history
…escriptors
  • Loading branch information
lahmatiy committed Dec 17, 2020
1 parent 1ece839 commit 125a013
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/lexer/Lexer.js
Expand Up @@ -292,7 +292,7 @@ module.exports = class Lexer {
return buildMatchResult(null, null);
}

return matchSyntax(this, this.getAtrule(atruleName).prelude, prelude, true);
return matchSyntax(this, this.getAtrule(atruleName).prelude, prelude, false);
}
matchAtruleDescriptor(atruleName, descriptorName, value) {
const error = this.checkAtruleDescriptorName(atruleName, descriptorName);
Expand All @@ -304,7 +304,7 @@ module.exports = class Lexer {
const atrule = this.getAtrule(atruleName);
const descriptor = names.keyword(descriptorName);

return matchSyntax(this, atrule.descriptors[descriptor.name] || atrule.descriptors[descriptor.basename], value, true);
return matchSyntax(this, atrule.descriptors[descriptor.name] || atrule.descriptors[descriptor.basename], value, false);
}
matchDeclaration(node) {
if (node.type !== 'Declaration') {
Expand Down
8 changes: 8 additions & 0 deletions test/lexer-match-atrule-descriptor.js
Expand Up @@ -5,6 +5,7 @@ const fixture = require('./fixture/definition-syntax');
const values = lazyValues({
swapValue: () => parse('swap', { context: 'value' }),
xxxValue: () => parse('xxx', { context: 'value' }),
inherit: () => parse('inherit', { context: 'value' }),
fontDisplaySyntax: () => 'auto | block | swap | fallback | optional',
customSyntax: () => fork(prev => ({
...prev,
Expand Down Expand Up @@ -88,6 +89,13 @@ describe('Lexer#matchAtruleDescriptor()', () => {
assert.equal(match.error.message, 'At-rule `@keyframes` has no known descriptors');
});

it('should not match css wide keywords', function() {
var match = lexer.matchAtruleDescriptor('font-face', 'font-display', values.inherit);

assert.equal(match.matched, null);
assert.equal(match.error.rawMessage, 'Mismatch');
});

fixture.forEachAtruleDescriptorTest((testType, testState, name, lexer, atruleName, descriptorName, value) => {
switch (testType) {
case 'valid':
Expand Down
7 changes: 7 additions & 0 deletions test/lexer-match-atrule-prelude.js
Expand Up @@ -69,6 +69,13 @@ describe('Lexer#matchAtrulePrelude()', () => {
});
});

it('should not match css wide keywords', function() {
var match = lexer.matchAtrulePrelude('import', parse('inherit', { context: 'atrulePrelude', positions: true }));

assert.equal(match.matched, null);
assert.equal(match.error.rawMessage, 'Mismatch');
});

describe('should not be matched to at-rules with no prelude', () => {
it('regular name', () => {
const match = lexer.matchAtrulePrelude('font-face', values.animationName);
Expand Down
8 changes: 8 additions & 0 deletions test/lexer-match-property.js
Expand Up @@ -5,6 +5,7 @@ const fixture = require('./fixture/definition-syntax');
const values = lazyValues({
bar: () => parse('bar', { context: 'value' }),
qux: () => parse('qux', { context: 'value' }),
inherit: () => parse('inherit', { context: 'value' }),
customSyntax: () => fork(function(prev, assign) {
return assign(prev, {
properties: {
Expand Down Expand Up @@ -84,6 +85,13 @@ describe('Lexer#matchProperty()', () => {
assert.equal(match.error.message, 'Lexer matching doesn\'t applicable for custom properties');
});

it('should match css wide keywords', function() {
var match = lexer.matchProperty('color', values.inherit);

assert(match.matched);
assert.equal(match.error, null);
});

it('should not be matched to empty value', () => {
const match = lexer.matchProperty('color', parse('', { context: 'value', positions: true }));

Expand Down

0 comments on commit 125a013

Please sign in to comment.