From 06bed7e59a5814d2898d5133ded1e53ca9fcc4d4 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Mon, 15 Jan 2024 11:36:51 +0100 Subject: [PATCH] Clean up --- .changeset/kind-singers-teach.md | 8 ++++++++ packages/alfa-cascade/src/block.ts | 2 +- packages/alfa-cascade/src/precedence/origin.ts | 2 +- packages/alfa-cascade/test/rule-tree.spec.ts | 12 ++++-------- packages/alfa-style/src/variable.ts | 8 +------- packages/alfa-style/test/style.spec.tsx | 2 +- 6 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 .changeset/kind-singers-teach.md diff --git a/.changeset/kind-singers-teach.md b/.changeset/kind-singers-teach.md new file mode 100644 index 0000000000..83f6799101 --- /dev/null +++ b/.changeset/kind-singers-teach.md @@ -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`. diff --git a/packages/alfa-cascade/src/block.ts b/packages/alfa-cascade/src/block.ts index dc01ef663b..e524c8f863 100644 --- a/packages/alfa-cascade/src/block.ts +++ b/packages/alfa-cascade/src/block.ts @@ -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 { diff --git a/packages/alfa-cascade/src/precedence/origin.ts b/packages/alfa-cascade/src/precedence/origin.ts index da8e3ff31f..564c523d15 100644 --- a/packages/alfa-cascade/src/precedence/origin.ts +++ b/packages/alfa-cascade/src/precedence/origin.ts @@ -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. diff --git a/packages/alfa-cascade/test/rule-tree.spec.ts b/packages/alfa-cascade/test/rule-tree.spec.ts index a398b33d09..d57f6457af 100644 --- a/packages/alfa-cascade/test/rule-tree.spec.ts +++ b/packages/alfa-cascade/test/rule-tree.spec.ts @@ -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., `
` // and inserted in increasing specificity. const div = fakeBlock("div"); diff --git a/packages/alfa-style/src/variable.ts b/packages/alfa-style/src/variable.ts index 9a8db46602..01c691f26c 100644 --- a/packages/alfa-style/src/variable.ts +++ b/packages/alfa-style/src/variable.ts @@ -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, - // shouldOverride: ( - // previous: Option>, - // next: Declaration, - // ) => boolean, - ): DefinitionMap { + export function gather(declarations: Array): DefinitionMap { let currentVariables: DefinitionMap = Map.empty(); for (const declaration of declarations.filter((declaration) => diff --git a/packages/alfa-style/test/style.spec.tsx b/packages/alfa-style/test/style.spec.tsx index 54010841af..e45cf42f7c 100644 --- a/packages/alfa-style/test/style.spec.tsx +++ b/packages/alfa-style/test/style.spec.tsx @@ -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 =
; h.document(