Skip to content

Commit

Permalink
fix: Don't permute analyses -- exponents and factorials are bad.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed Nov 22, 2017
1 parent bf9fd78 commit ee93a6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
3 changes: 3 additions & 0 deletions packages/opticss/src/Actions/actions/MergeDeclarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import {
DeclarationInfo
} from '../../optimizations/MergeDeclarations/StyleInfo';
import { isRoot } from 'postcss-selector-parser';

const {
isAttribute,
Expand Down Expand Up @@ -135,6 +136,8 @@ export class MergeDeclarations extends MultiAction {
if (isAtRule(ruleParent)) {
this.removedAtRules.push(ruleParent);
ruleParent.remove();
} else if (isRoot(ruleParent)) {
// Empty stylesheet
} else {
console.warn("this is a weird parent for a rule: ", ruleParent);
}
Expand Down
42 changes: 13 additions & 29 deletions packages/opticss/src/Match/AttributeMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
isStartsAndEndsWith,
isSet,
isChoice,
isFlattenedSet,
} from '@opticss/template-api';
import { Memoize } from 'typescript-memoize';
import * as SelectorParser from 'postcss-selector-parser';
Expand Down Expand Up @@ -110,7 +109,7 @@ export class AttributeMatcher extends Matcher<Attr> {
* @param [value=this.value] the attribute value to match against.
* @returns boolean if it matches or not
*/
matchIdent(attr: Attr, identifier: string, value: AttributeValue = attr.value): Match {
matchIdent(attr: Attr, identifier: string, value: AttributeValue = attr.value, whitespaceDelimited = false): Match {
if (isAbsent(value)) {
return Match.no;
} else if (isUnknown(value)) {
Expand All @@ -131,13 +130,18 @@ export class AttributeMatcher extends Matcher<Attr> {
return boolToMatch(identifier.startsWith(value.startsWith) &&
identifier.endsWith(value.endsWith));
} else if (isSet(value)) {
// This is a tricky case. There really shouldn't be an `allOf` used
// for an identifier match. In theory a regex could be constructed?
// I'm hesitant to throw an error here but maybe I should?
return Match.no;
if (whitespaceDelimited) {
return boolToMatch(value.allOf.some(v =>
matches(this.matchIdent(attr, identifier, v, whitespaceDelimited))));
} else {
// This is a tricky case. There really shouldn't be an `allOf` used
// for an identifier match. In theory a regex could be constructed?
// I'm hesitant to throw an error here but maybe I should?
return Match.no;
}
} else if (isChoice(value)) {
return boolToMatch(value.oneOf.some(v =>
matches(this.matchIdent(attr, identifier, v))));
matches(this.matchIdent(attr, identifier, v, whitespaceDelimited))));
} else {
return assertNever(value);
}
Expand All @@ -153,10 +157,8 @@ export class AttributeMatcher extends Matcher<Attr> {
* @returns boolean if it matches
*/
matchWhitespaceDelimited(attr: Attr, identifier: string, value?: AttributeValue): boolean {
let isTopLevel = false;
if (!value) {
value = attr.value;
isTopLevel = true;
}
if (isAbsent(value)) {
return false;
Expand All @@ -179,28 +181,10 @@ export class AttributeMatcher extends Matcher<Attr> {
return false;
}
return true;
} else if (isTopLevel && (isChoice(value) || isSet(value))) {
let flattenedValues = attr.flattenedValue(value);
for (let flattenedValue of flattenedValues) {
if (isFlattenedSet(flattenedValue)) {
for (let v of flattenedValue.allOf) {
let m = this.matchIdent(attr, identifier, v);
if (m === Match.yes) {
return true;
}
}
} else {
let m = this.matchIdent(attr, identifier, flattenedValue);
if (m === Match.yes) {
return true;
}
}
}
return false;
} else if (isSet(value)) {
return value.allOf.some(v => matches(this.matchIdent(attr, identifier, v)));
return value.allOf.some(v => matches(this.matchIdent(attr, identifier, v, true)));
} else if (isChoice(value)) {
return value.oneOf.some(v => matches(this.matchIdent(attr, identifier, v)));
return value.oneOf.some(v => matches(this.matchIdent(attr, identifier, v, true)));
} else {
return assertNever(value);
}
Expand Down
6 changes: 2 additions & 4 deletions packages/template-api/src/StyleMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,8 @@ export class StyleMapping {
// match the value descriptors -- not to be derived from the analysis for
// our immediate needs this works tho and it's much faster than
// deriving it from the styles.
let names = new Set<string>();
attr.flattenedValue().forEach(v => {
stringsForValue(v).forEach(sv => names.add(sv));
});
// let names = new Set<string>();
let names = attr.constants();
let nameArray = new Array(...names);
nameArray.sort();
return nameArray.map(value => {
Expand Down

0 comments on commit ee93a6c

Please sign in to comment.