Skip to content

Commit

Permalink
Remove atRuleBody error and follow simple block spec for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Jun 18, 2018
1 parent c81075f commit e284752
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/parser/cssErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export let ParseError = {
CommaExpected: new CSSIssueType('css-commaexpected', localize('expected.comma', "comma expected")),
PageDirectiveOrDeclarationExpected: new CSSIssueType('css-pagedirordeclexpected', localize('expected.pagedirordecl', "page directive or declaraton expected")),
UnknownAtRule: new CSSIssueType('css-unknownatrule', localize('unknown.atrule', "at-rule unknown")),
AtRuleBodyExpected: new CSSIssueType('css-atrulebodyexpected', localize('expected.atrulebody', 'at rule body expected')),
UnknownKeyword: new CSSIssueType('css-unknownkeyword', localize('unknown.keyword', "unknown keyword")),
SelectorExpected: new CSSIssueType('css-selectorexpected', localize('expected.selector', "selector expected")),
StringLiteralExpected: new CSSIssueType('css-stringliteralexpected', localize('expected.stringliteral', "string literal expected")),
Expand Down
10 changes: 0 additions & 10 deletions src/parser/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,16 +1060,6 @@ export class Parser {
this.consumeToken();
}

this.resync([], [TokenType.SemiColon, TokenType.EOF, TokenType.CurlyL]); // ignore all the rules
if (this.peek(TokenType.SemiColon)) {
this.consumeToken();
return node;
} else if (this.peek(TokenType.CurlyL)) {
return this._parseBody(node, this._parseStylesheetStatement.bind(this));
} else if (this.peek(TokenType.EOF)) {
return this.finish(node, ParseError.AtRuleBodyExpected);
}

return node;
}

Expand Down
7 changes: 4 additions & 3 deletions src/test/css/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ suite('CSS - Parser', () => {
test('stylesheet - graceful handling of unknown rules', function () {
let parser = new Parser();
assertNode('@unknown-rule;', parser, parser._parseStylesheet.bind(parser));
assertNode('@unknown-rule (;', parser, parser._parseStylesheet.bind(parser));
assertNode(`@unknown-rule 'foo';`, parser, parser._parseStylesheet.bind(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));

assertError('@unknown-rule', parser, parser._parseStylesheet.bind(parser), ParseError.AtRuleBodyExpected);
assertError('@unknown-rule foo', parser, parser._parseStylesheet.bind(parser), ParseError.AtRuleBodyExpected);
assertError('@unknown-rule (;', parser, parser._parseStylesheet.bind(parser), ParseError.RightParenthesisExpected);
assertError('@unknown-rule [foo', parser, parser._parseStylesheet.bind(parser), ParseError.RightSquareBracketExpected);
assertError('@unknown-rule { [foo }', parser, parser._parseStylesheet.bind(parser), ParseError.RightSquareBracketExpected);
assertError('@unknown-rule (foo) {', parser, parser._parseStylesheet.bind(parser), ParseError.RightCurlyExpected);
assertError('@unknown-rule (foo) { .bar {}', parser, parser._parseStylesheet.bind(parser), ParseError.RightCurlyExpected);
});

Expand Down

0 comments on commit e284752

Please sign in to comment.