Skip to content

Commit

Permalink
Allow unknown at-rules within CSS rules. Fixes #123
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Oct 29, 2018
1 parent 0bba3ee commit 9686d20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/parser/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ export class Parser {
}

public _parseRuleSetDeclaration(): nodes.Node {
return this._parseAtApply() || this._tryParseCustomPropertyDeclaration() || this._parseDeclaration();
// https://www.w3.org/TR/css-syntax-3/#consume-a-list-of-declarations0
return this._parseAtApply()
|| this._tryParseCustomPropertyDeclaration()
|| this._parseDeclaration()
|| this._parseUnknownAtRule();
}

/**
Expand Down Expand Up @@ -999,6 +1003,10 @@ export class Parser {

// https://www.w3.org/TR/css-syntax-3/#consume-an-at-rule
public _parseUnknownAtRule(): nodes.Node {
if (!this.peek(TokenType.AtKeyword)) {
return null;
}

let node = <nodes.UnknownAtRule>this.create(nodes.UnknownAtRule);
node.addChild(this._parseUnknownAtRuleName());

Expand Down
1 change: 1 addition & 0 deletions src/test/css/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ suite('CSS - Parser', () => {
assertNode('@unknown-rule (foo) {}', parser, parser._parseStylesheet.bind(parser));
assertNode('@unknown-rule (foo) { .bar {} }', parser, parser._parseStylesheet.bind(parser));
assertNode('@mskeyframes darkWordHighlight { from { background-color: inherit; } to { background-color: rgba(83, 83, 83, 0.7); } }', parser, parser._parseStylesheet.bind(parser));
assertNode('foo { @unknown-rule; }', parser, parser._parseStylesheet.bind(parser));

assertError('@unknown-rule (;', parser, parser._parseStylesheet.bind(parser), ParseError.RightParenthesisExpected);
assertError('@unknown-rule [foo', parser, parser._parseStylesheet.bind(parser), ParseError.RightSquareBracketExpected);
Expand Down

0 comments on commit 9686d20

Please sign in to comment.