Skip to content

Commit

Permalink
drop CompoundSelector customer
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jan 30, 2017
1 parent a3ef27f commit 5cb04ed
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 95 deletions.
4 changes: 1 addition & 3 deletions lib/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var getAtrule = require('./nodes/Atrule');
var getRule = require('./nodes/Rule');
var getSelectorList = require('./nodes/SelectorList');
var getSelector = require('./nodes/Selector');
var getCompoundSelector = require('./nodes/_CompoundSelector');
var getBlock = require('./nodes/Block');
var getDeclarationList = require('./nodes/DeclarationList');
var getDeclaration = require('./nodes/Declaration');
Expand Down Expand Up @@ -122,7 +121,6 @@ Parser.prototype = {
Rule: getRule,
SelectorList: getSelectorList,
Selector: getSelector,
CompoundSelector: getCompoundSelector,
Block: getBlock,
DeclarationList: getDeclarationList,
Declaration: getDeclaration,
Expand Down Expand Up @@ -205,6 +203,6 @@ var parser = new Parser();

// warm up parse to elimitate code branches that never execute
// fix soft deoptimizations (insufficient type feedback)
parser.parse('a.b#c:e:Not(a):Nth-child(2n+1)::g,* b >c+d~e/deep/f,100%{v:1 2em t a(2%, var(--a)) url(..) -foo-bar !important}');
parser.parse('a.b#c:e:Not(a/**/):Nth-child(2n+1)::g::slotted(a/**/),* b >c+d~e/deep/f,100%{v:1 2em t a(2%, var(--a)) url(..) -foo-bar !important}');

module.exports = parser.parse.bind(parser);
4 changes: 3 additions & 1 deletion lib/parser/nodes/PseudoElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var TYPE = require('../../scanner').TYPE;
var COLON = TYPE.Colon;
var LEFTPARENTHESIS = TYPE.LeftParenthesis;
var RIGHTPARENTHESIS = TYPE.RightParenthesis;
var ABSOLUTE = false;
var DISALLOW_COMBINATORS = true;

// :: ident
module.exports = function PseudoElement() {
Expand All @@ -18,7 +20,7 @@ module.exports = function PseudoElement() {
if (this.scanner.lookupValue(0, 'slotted')) {
name = this.readIdent(false);
this.scanner.eat(LEFTPARENTHESIS);
children = new List().appendData(this.CompoundSelector());
children = new List().appendData(this.Selector(ABSOLUTE, DISALLOW_COMBINATORS));
this.scanner.eat(RIGHTPARENTHESIS);
} else {
name = this.readIdent(false);
Expand Down
18 changes: 16 additions & 2 deletions lib/parser/nodes/Selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var LEFTSQUAREBRACKET = TYPE.LeftSquareBracket;
var VERTICALLINE = TYPE.VerticalLine;
var TILDE = TYPE.Tilde;

module.exports = function Selector(relative) {
module.exports = function Selector(relative, disallowCombinators) {
this.readSC();

var start = this.scanner.tokenStart;
Expand All @@ -27,14 +27,27 @@ module.exports = function Selector(relative) {
var combinatorOffset = -1;
var child = null;

relative = relative || false;
disallowCombinators = disallowCombinators || false;

scan:
while (!this.scanner.eof) {
switch (this.scanner.tokenType) {
case COMMENT:
if (disallowCombinators) {
this.readSC();
break scan;
}

this.scanner.next();
continue;

case WHITESPACE:
if (disallowCombinators) {
this.readSC();
break scan;
}

if (combinator === null && children.head !== null) {
combinatorOffset = this.scanner.tokenStart;
combinator = DESCENDANT_COMBINATOR;
Expand All @@ -47,7 +60,8 @@ module.exports = function Selector(relative) {
case GREATERTHANSIGN:
case TILDE:
case SOLIDUS:
if ((children.head === null && !relative) || // combinator in the beginning
if (disallowCombinators ||
(children.head === null && !relative) || // combinator in the beginning
(combinator !== null && combinator !== DESCENDANT_COMBINATOR)) {
this.scanner.error('Unexpected combinator');
}
Expand Down
88 changes: 0 additions & 88 deletions lib/parser/nodes/_CompoundSelector.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/fixture/parse/selector/pseudo-slotted.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"error #6": {
"source": "::slotted(> test)",
"offset": " ^",
"error": "Selector is expected"
"error": "Unexpected combinator"
},
"error #7": {
"source": "::slotted(foo,bar)",
Expand Down

0 comments on commit 5cb04ed

Please sign in to comment.