Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Don't componentize classes inside :not()
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=110167491
  • Loading branch information
SLaks authored and iflan committed Mar 9, 2016
1 parent 00809a9 commit 0b446fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/com/google/common/css/compiler/passes/ProcessComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.common.css.compiler.ast.CssLiteralNode;
import com.google.common.css.compiler.ast.CssNode;
import com.google.common.css.compiler.ast.CssProvideNode;
import com.google.common.css.compiler.ast.CssPseudoClassNode;
import com.google.common.css.compiler.ast.CssRootNode;
import com.google.common.css.compiler.ast.CssRulesetNode;
import com.google.common.css.compiler.ast.CssSelectorNode;
Expand Down Expand Up @@ -273,8 +274,9 @@ private static class TransformNodes extends DefaultTreeVisitor
private final String defPrefix;
private final String parentName;
private final SourceCodeLocation sourceCodeLocation;
private int inCombinator;
private boolean firstClassSelector;
/** If non-zero, we won't process the first classname in the current selector. */
private int nestedSelectorDepth;

public TransformNodes(Set<String> constants, CssComponentNode current, boolean inAncestorBlock,
MutatingVisitController visitController, ErrorManager errorManager,
Expand Down Expand Up @@ -320,21 +322,21 @@ public boolean enterRuleset(CssRulesetNode node) {

@Override
public boolean enterCombinator(CssCombinatorNode combinator) {
inCombinator++;
nestedSelectorDepth++;
return true;
}

@Override
public void leaveCombinator(CssCombinatorNode combinator) {
inCombinator--;
nestedSelectorDepth--;
}

@Override
public boolean enterSelector(CssSelectorNode selector) {
// Only reset the 'first selector' flag if we're not in a combinator.
// Otherwise, keep the same flag value (which may or may not have been set
// depending on whether we saw a class selector in an earlier refiner list.)
if (inCombinator == 0) {
if (nestedSelectorDepth == 0) {
firstClassSelector = true;
}
return true;
Expand All @@ -345,6 +347,18 @@ public void leaveSelector(CssSelectorNode selector) {
firstClassSelector = false;
}

// Don't reset firstClassSelector for classes in :not().
@Override
public boolean enterPseudoClass(CssPseudoClassNode pseudoClass) {
nestedSelectorDepth++;
return true;
}

@Override
public void leavePseudoClass(CssPseudoClassNode pseudoClass) {
nestedSelectorDepth--;
}

@Override
public boolean enterClassSelector(CssClassSelectorNode node) {
Preconditions.checkState(!isAbstract);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ public class ProcessComponentsTest extends PassesTestBase {
// in the output.
private final ImmutableList<String> prefixingTestInputRules = ImmutableList.of(
" .PREFIX_A1.NO_PREFIX_A2,", // Complex selector
" .PREFIX_A1:not(.NO_PREFIX_A2),", // :not() selector
" .PREFIX_A1:not(.%PREFIX_A2),", // :not() selector
" .PREFIX_A1 .NO_PREFIX_B2:not(.NO_PREFIX_B3),", // :not() selector
" .PREFIX_A1 .NO_PREFIX_B2:not(.%PREFIX_B3),", // :not() selector
" :not(.PREFIX_A1).NO_PREFIX_A2,", // :not() selector as first class selector
" :not(.PREFIX_A1).%PREFIX_A2,", // :not() selector as first class selector
" .PREFIX_B1 .NO_PREFIX_B2,", // Descendant combinator
" .PREFIX_C1 > .NO_PREFIX_C2,", // Child combinator
" TD.PREFIX_D1.NO_PREFIX_D2,", // Element refiner before class refiner
Expand Down Expand Up @@ -272,6 +278,12 @@ public class ProcessComponentsTest extends PassesTestBase {
// errors easier to diagnose.
private final String prefixingTestComponentOutput =
"[.someExamplePackagePREFIX_A1.NO_PREFIX_A2," +
".someExamplePackagePREFIX_A1:not(.NO_PREFIX_A2)," +
".someExamplePackagePREFIX_A1:not(.someExamplePackagePREFIX_A2)," +
".someExamplePackagePREFIX_A1 .NO_PREFIX_B2:not(.NO_PREFIX_B3)," +
".someExamplePackagePREFIX_A1 .NO_PREFIX_B2:not(.someExamplePackagePREFIX_B3)," +
":not(.someExamplePackagePREFIX_A1).NO_PREFIX_A2," +
":not(.someExamplePackagePREFIX_A1).someExamplePackagePREFIX_A2," +
".someExamplePackagePREFIX_B1 .NO_PREFIX_B2," +
".someExamplePackagePREFIX_C1>.NO_PREFIX_C2," +
"TD.someExamplePackagePREFIX_D1.NO_PREFIX_D2," +
Expand Down

0 comments on commit 0b446fd

Please sign in to comment.