Skip to content

Commit

Permalink
Use CSSParser where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Jym77 committed Jul 11, 2023
1 parent ba3325f commit f3d91ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/alfa-css/src/value/color/color.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Parser } from "@siteimprove/alfa-parser";
import { Slice } from "@siteimprove/alfa-slice";

import { type Parser as CSSParser } from "../../syntax";
import { Token } from "../../syntax";

import { Keyword } from "../keyword";
import { Angle, Number, Percentage } from "../numeric";
Expand Down Expand Up @@ -64,7 +64,7 @@ export namespace Color {
/**
* {@link https://drafts.csswg.org/css-color/#typedef-color}
*/
export const parse: CSSParser<Color> = either(
export const parse = either<Slice<Token>, Color, string>(
Hex.parse,
Named.parse,
RGB.parse,
Expand Down
13 changes: 7 additions & 6 deletions packages/alfa-css/src/value/color/rgb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Hash } from "@siteimprove/alfa-hash";
import { Parser } from "@siteimprove/alfa-parser";
import { Err } from "@siteimprove/alfa-result";
import { Slice } from "@siteimprove/alfa-slice";

import { Function, type Parser as CSSParser, Token } from "../../syntax";
import { Keyword } from "../keyword";
Expand Down Expand Up @@ -174,7 +175,7 @@ export namespace RGB {
* the correct type, or fails if it is not allowed.
*/
const parseItem = <C extends Number | Percentage>(
parser: Parser<Slice<Token>, C, string>,
parser: CSSParser<C>,
ifNone?: C
) =>
either(
Expand All @@ -190,8 +191,8 @@ export namespace RGB {
* whitespace.
*/
const parseTriplet = <C extends Number | Percentage>(
parser: Parser<Slice<Token>, C, string>,
separator: Parser<Slice<Token>, any, string>,
parser: CSSParser<C>,
separator: CSSParser<any>,
ifNone?: C
) =>
map(
Expand All @@ -203,7 +204,7 @@ export namespace RGB {
);

const parseLegacyTriplet = <C extends Number | Percentage>(
parser: Parser<Slice<Token>, C, string>
parser: CSSParser<C>
) =>
parseTriplet(
parser,
Expand All @@ -224,7 +225,7 @@ export namespace RGB {
);

const parseModernTriplet = <C extends Number | Percentage>(
parser: Parser<Slice<Token>, C, string>,
parser: CSSParser<C>,
ifNone: C
) => parseTriplet(parser, option(Token.parseWhitespace), ifNone);

Expand All @@ -244,7 +245,7 @@ export namespace RGB {
/**
* {@link https://drafts.csswg.org/css-color/#funcdef-rgb}
*/
export const parse: Parser<Slice<Token>, RGB, string> = map(
export const parse: CSSParser<RGB> = map(
Function.parse(
(fn) => fn.value === "rgb" || fn.value === "rgba",
either(parseLegacy, parseModern)
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ __metadata:
minimist: ^1.2.6
package-dependency-graph: ^1.14.4
prettier: ^2.7.1
typescript: ^5.0.4
typescript: ^5.1.6
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -6065,23 +6065,23 @@ resolve@~1.19.0:
languageName: node
linkType: hard

"typescript@npm:^5.0.2, typescript@npm:^5.0.4":
version: 5.1.5
resolution: "typescript@npm:5.1.5"
"typescript@npm:^5.0.2, typescript@npm:^5.1.6":
version: 5.1.6
resolution: "typescript@npm:5.1.6"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 0eef8699e05ae767096924dbed633c340b4d36e953bb8ed87fb12e9dd9dcea5055ceac7182c614a556dbd346a8a82df799d330e1e286ae66e17c84e1710f6a6f
checksum: b2f2c35096035fe1f5facd1e38922ccb8558996331405eb00a5111cc948b2e733163cc22fab5db46992aba7dd520fff637f2c1df4996ff0e134e77d3249a7350
languageName: node
linkType: hard

"typescript@patch:typescript@^5.0.2#~builtin<compat/typescript>, typescript@patch:typescript@^5.0.4#~builtin<compat/typescript>":
version: 5.1.5
resolution: "typescript@patch:typescript@npm%3A5.1.5#~builtin<compat/typescript>::version=5.1.5&hash=85af82"
"typescript@patch:typescript@^5.0.2#~builtin<compat/typescript>, typescript@patch:typescript@^5.1.6#~builtin<compat/typescript>":
version: 5.1.6
resolution: "typescript@patch:typescript@npm%3A5.1.6#~builtin<compat/typescript>::version=5.1.6&hash=85af82"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 33020c886b1aa2e948b557aad4986cf6448b30c58915b12cac873bd35dc2260d93f71af8a661d2c9f352b5d099d9df13a59688e222e79276099b9c5d86d847be
checksum: 21e88b0a0c0226f9cb9fd25b9626fb05b4c0f3fddac521844a13e1f30beb8f14e90bd409a9ac43c812c5946d714d6e0dee12d5d02dfc1c562c5aacfa1f49b606
languageName: node
linkType: hard

Expand Down

0 comments on commit f3d91ef

Please sign in to comment.