Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

Adding ability for children to directly reference other children #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/checkCSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ function walkChildSelectors(callback, remainder, isParentConstrained) {
var continueParsing = callback(childElement, childClass, isConstrained);

while(/^\S/.test(trailer)) {
var modifierMatch = /^(?:\.-[a-z0-9-]+|::?[a-z-]+(?:\([^)]*\))?|\[[^\]]+\])(.*)$/.exec(trailer);
var modifierRegex = /^(?:\.-[a-z0-9-]+|::?[a-z-]+(?:\([^)]*\))?|\[[^\]]+\])(.*)$/,
directSemanticTagRegex = /^(?:\>(?!div)(?!span)[a-z0-9]+)(.*)$/;
var trailerMatch = modifierRegex.exec(trailer) || directSemanticTagRegex.exec(trailer);

if (!modifierMatch) {
throw new Error('invalid modifier: "' + trailer + '"');
if (!trailerMatch) {
throw new Error('invalid modifier or non-semantic tag: "' + trailer + '"');
}

trailer = modifierMatch[1];
trailer = trailerMatch[1];
}

if (continueParsing && trailer !== '') {
Expand Down
4 changes: 4 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ t.same(run('testtag {}'), [], 'global tag');
t.same(run('.top-level-class {}'), [], 'top-level class');

t.same(run('.-dangling-top-modifier {}'), [[1, 1, 'cannot recognize top-level selector match']], 'dangling top-level modifier');

// child element direct child references
t.same(run('.top-level ._child > h1 {}'), [], 'allow child classes to directly refer to element tags');
t.same(run('.top-level ._child > div {}'), [[1, 1, 'do not use non-semantic tag name: "div"']], 'child classes can\'t directly refer to non-semantic element tags');