Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Jun 29, 2018
1 parent 65ffed4 commit a9bebd5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/parser/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ export class Parser {
node.addChild(this._parseUnknownAtRuleName());

const isTopLevel = () => curlyDepth === 0 && parensDepth === 0 && bracketsDepth === 0;
let curlyLCount = 0;
let curlyDepth = 0;
let parensDepth = 0;
let bracketsDepth = 0;
Expand All @@ -1024,10 +1025,22 @@ export class Parser {
return this.finish(node);
}
case TokenType.CurlyL:
curlyLCount++;
curlyDepth++;
break;
case TokenType.CurlyR:
curlyDepth--;
// End of at-rule, consume CurlyR and return node
if (curlyLCount > 0 && curlyDepth === 0) {
this.consumeToken();

if (bracketsDepth > 0) {
return this.finish(node, ParseError.RightSquareBracketExpected);
} else if (parensDepth > 0) {
return this.finish(node, ParseError.RightParenthesisExpected);
}
break done;
}
if (curlyDepth < 0) {
// The property value has been terminated without a semicolon, and
// this is the last declaration in the ruleset.
Expand Down
10 changes: 10 additions & 0 deletions src/test/css/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ suite('CSS - Parser', () => {
assertError('@unknown-rule (foo) { .bar {}', parser, parser._parseStylesheet.bind(parser), ParseError.RightCurlyExpected);
});

test('stylesheet - unknown rules node ends properly. Microsoft/vscode#53159', function () {
let parser = new Parser();
const node = assertNode('@unknown-rule (foo) {} .foo {}', parser, parser._parseStylesheet.bind(parser));

const unknownAtRule = node.getChild(0);
assert.equal(unknownAtRule.type, nodes.NodeType.UnknownAtRule);
assert.equal(unknownAtRule.offset, 0);
assert.equal(node.getChild(0).length, 13);
});

test('stylesheet /panic/', function () {
let parser = new Parser();
assertError('#boo, far } \n.far boo {}', parser, parser._parseStylesheet.bind(parser), ParseError.LeftCurlyExpected);
Expand Down

0 comments on commit a9bebd5

Please sign in to comment.