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

Added --allow-duplicate-declarations flag #75

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
3 changes: 3 additions & 0 deletions src/com/google/common/css/JobDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class JobDescription {
public final boolean eliminateDeadStyles;
public final boolean allowDefPropagation;
public final boolean allowUnrecognizedFunctions;
public final boolean allowDuplicateDeclarations;
public final Set<String> allowedNonStandardFunctions;
public final boolean allowUnrecognizedProperties;
public final Set<String> allowedUnrecognizedProperties;
Expand Down Expand Up @@ -125,6 +126,7 @@ public enum SourceMapDetailLevel { ALL, DEFAULT }
boolean swapLeftRightInUrl, boolean simplifyCss,
boolean eliminateDeadStyles, boolean allowDefPropagation,
boolean allowUnrecognizedFunctions,
boolean allowDuplicateDeclarations,
Set<String> allowedNonStandardFunctions,
boolean allowUnrecognizedProperties,
Set<String> allowedUnrecognizedProperties, boolean allowUndefinedConstants,
Expand Down Expand Up @@ -163,6 +165,7 @@ public enum SourceMapDetailLevel { ALL, DEFAULT }
this.eliminateDeadStyles = eliminateDeadStyles;
this.allowDefPropagation = allowDefPropagation;
this.allowUnrecognizedFunctions = allowUnrecognizedFunctions;
this.allowDuplicateDeclarations = allowDuplicateDeclarations;
this.allowedNonStandardFunctions = ImmutableSet.copyOf(
allowedNonStandardFunctions);
this.allowUnrecognizedProperties = allowUnrecognizedProperties;
Expand Down
15 changes: 14 additions & 1 deletion src/com/google/common/css/JobDescriptionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class JobDescriptionBuilder {
boolean eliminateDeadStyles;
boolean allowDefPropagation;
boolean allowUnrecognizedFunctions;
boolean allowDuplicateDeclarations;
Set<String> allowedNonStandardFunctions;
boolean allowUnrecognizedProperties;
Set<String> allowedUnrecognizedProperties;
Expand Down Expand Up @@ -89,6 +90,7 @@ public JobDescriptionBuilder() {
this.eliminateDeadStyles = false;
this.allowDefPropagation = false;
this.allowUnrecognizedFunctions = false;
this.allowDuplicateDeclarations = false;
this.allowedNonStandardFunctions = Sets.newHashSet();
this.allowUnrecognizedProperties = false;
this.allowedUnrecognizedProperties = Sets.newHashSet();
Expand Down Expand Up @@ -125,6 +127,7 @@ public JobDescriptionBuilder copyFrom(JobDescription jobToCopy) {
this.eliminateDeadStyles = jobToCopy.eliminateDeadStyles;
this.allowDefPropagation = jobToCopy.allowDefPropagation;
this.allowUnrecognizedFunctions = jobToCopy.allowUnrecognizedFunctions;
this.allowDuplicateDeclarations = jobToCopy.allowDuplicateDeclarations;
this.allowedNonStandardFunctions =
ImmutableSet.copyOf(jobToCopy.allowedNonStandardFunctions);
this.allowUnrecognizedProperties = jobToCopy.allowUnrecognizedProperties;
Expand Down Expand Up @@ -324,10 +327,20 @@ public JobDescriptionBuilder setAllowUnrecognizedFunctions(boolean allow) {
return this;
}

public JobDescriptionBuilder setAllowDuplicateDeclarations(boolean allow) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go just before allowDuplicateDeclarations. Somehow allowUnrecognizedFunctions managed to slip between the two.

checkJobIsNotAlreadyCreated();
this.allowDuplicateDeclarations = allow;
return this;
}

public JobDescriptionBuilder allowUnrecognizedFunctions() {
return setAllowUnrecognizedFunctions(true);
}

public JobDescriptionBuilder allowDuplicateDeclarations() {
return setAllowDuplicateDeclarations(true);
}

public JobDescriptionBuilder setAllowedNonStandardFunctions(
List<String> functionNames) {
checkJobIsNotAlreadyCreated();
Expand Down Expand Up @@ -464,7 +477,7 @@ public JobDescription getJobDescription() {
copyrightNotice, outputFormat, inputOrientation, outputOrientation,
optimize, trueConditionNames, useInternalBidiFlipper, swapLtrRtlInUrl,
swapLeftRightInUrl, simplifyCss, eliminateDeadStyles,
allowDefPropagation, allowUnrecognizedFunctions, allowedNonStandardFunctions,
allowDefPropagation, allowUnrecognizedFunctions, allowDuplicateDeclarations, allowedNonStandardFunctions,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap at 100 columns.

allowUnrecognizedProperties, allowedUnrecognizedProperties, allowUndefinedConstants,
allowMozDocument, vendor,
allowKeyframes, allowWebkitKeyframes, processDependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ static class Flags {
"Allow unrecognized functions.")
private boolean allowUnrecognizedFunctions = false;

@Option(name = "--allow-duplicate-declarations", usage =
"Allow duplicate declarations.")
private boolean allowDuplicateDeclarations = false;

@Option(name = "--allowed-non-standard-function", usage =
"Specify a non-standard function to whitelist, like alpha()")
private List<String> allowedNonStandardFunctions = Lists.newArrayList();
Expand Down Expand Up @@ -224,6 +228,7 @@ JobDescription createJobDescription() {
builder.setTrueConditionNames(trueConditions);
builder.setAllowDefPropagation(allowDefPropagation);
builder.setAllowUnrecognizedFunctions(allowUnrecognizedFunctions);
builder.setAllowDuplicateDeclarations(allowDuplicateDeclarations);
builder.setAllowedNonStandardFunctions(allowedNonStandardFunctions);
builder.setAllowedUnrecognizedProperties(allowedUnrecognizedProperties);
builder.setAllowUnrecognizedProperties(allowUnrecognizedProperties);
Expand Down
7 changes: 5 additions & 2 deletions src/com/google/common/css/compiler/passes/PassRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ public void runPasses(CssTree cssTree) {
new AbbreviatePositionalValues(
cssTree.getMutatingVisitController()).runPass();
}
if (job.eliminateDeadStyles) {
// Report errors for duplicate declarations
// Report errors for duplicate declarations
if (!job.allowDuplicateDeclarations) {
new DisallowDuplicateDeclarations(
cssTree.getVisitController(), errorManager).runPass();
}

if (job.eliminateDeadStyles) {
// Split rules by selector and declaration.
new SplitRulesetNodes(cssTree.getMutatingVisitController()).runPass();
// Dead code elimination.
Expand Down