Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Jym77 committed Jan 15, 2024
1 parent 1017b31 commit 06bed7e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
8 changes: 8 additions & 0 deletions .changeset/kind-singers-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@siteimprove/alfa-cascade": minor
---

**Added:** Cascade now handle importance of declarations, and `style` attribute.

This should have no impact on regular usage of `Style.from()` but may affect code trying to use the cascade directly.
Most notably, the internal rule tree `Block` can now come either from a rule or an element. Therefore, `Block.rule` and `Bolkc.selector` may now be `null`.
2 changes: 1 addition & 1 deletion packages/alfa-cascade/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export namespace Block {

/**
* Turns the style attribute of an element into blocks (one for important
* declaration, one for normal declarations).
* declarations, one for normal declarations).
* @param element
*/
export function fromStyle(element: Element): Iterable<Block> {
Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-cascade/src/precedence/origin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Comparable, type Comparer } from "@siteimprove/alfa-comparable";
* Mixing both here allows for the comparison to be simple number comparison,
* which should be faster than looking at more than one field.
*
* Cascading origins defined in ascending order; origins defined first have
* Cascading origins are defined in ascending order; origins defined first have
* lower precedence than origins defined later. Thus, an origin with higher
* value takes precedence over an origin with lower value. This means that
* comparing origins is the same as comparing numbers.
Expand Down
12 changes: 4 additions & 8 deletions packages/alfa-cascade/test/rule-tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ import { Block } from "../src/block";
import { Origin } from "../src/precedence";

function fakeBlock(
selector: string,
selectorText: string,
origin: Origin = Origin.NormalUserAgent,
): Block {
const sel = parse(selector) as Compound | Complex | Simple;
const selector = parse(selectorText) as Compound | Complex | Simple;

return Block.of({ rule: h.rule.style(selector, []), selector: sel }, [], {
return Block.of({ rule: h.rule.style(selectorText, []), selector }, [], {
origin,
isElementAttached: false,
specificity: sel.specificity,
specificity: selector.specificity,
order: -1,
});
}

// function fakeJSON(selector: string, origin?: Origin): Block.JSON {
// return fakeBlock(selector, origin).toJSON();
// }

// Selectors `div`, `.foo`, `#bar`, matching, e.g., `<div class="foo" id="bar">`
// and inserted in increasing specificity.
const div = fakeBlock("div");
Expand Down
8 changes: 1 addition & 7 deletions packages/alfa-style/src/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ export namespace Variable {
* This builds a map from variable names to their lexed value
* i.e. "--foo: lorem ipsum" becomes "foo => [lorem, ipsum]"
**/
export function gather(
declarations: Array<Declaration>,
// shouldOverride: <T>(
// previous: Option<Value<T>>,
// next: Declaration,
// ) => boolean,
): DefinitionMap {
export function gather(declarations: Array<Declaration>): DefinitionMap {
let currentVariables: DefinitionMap = Map.empty();

for (const declaration of declarations.filter((declaration) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-style/test/style.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ test(`#cascaded() expands a var() function`, (t) => {
});
});

test("#cascaded() prefer important var() declarations", (t) => {
test("#cascaded() prefers important var() declarations", (t) => {
const element = <div class="foo" id="foo" />;

h.document(
Expand Down

0 comments on commit 06bed7e

Please sign in to comment.