Skip to content

Commit

Permalink
Remove parsebase functions (#1487)
Browse files Browse the repository at this point in the history
* Remove the parseBase functions

* Add changeset

* Extract documentation

* Extract API

* Fully name tuple

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Jym77 and github-actions[bot] authored Oct 23, 2023
1 parent 2d011f6 commit 2dea20a
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 111 deletions.
9 changes: 9 additions & 0 deletions .changeset/happy-gorillas-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@siteimprove/alfa-css": minor
---

**Breaking:** The various `Value.parseBase` functions are no more available.

These where temporary helpers during migration to calculated values.

Use `filter(Value.parse, value => !value.hasCalculation(), () => "Calculation not allowed")` instead.
10 changes: 0 additions & 10 deletions docs/review/api/alfa-css.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export namespace Angle {
export type Resolver = {};
const // (undocumented)
parse: Parser<Angle>;
const // @internal (undocumented)
parseBase: Parser_2<Slice<Token>, Fixed<Unit.Angle>, string, []>;
{};
}

Expand Down Expand Up @@ -868,8 +866,6 @@ export namespace Integer {
export function of(value: Math_2<"number">): Calculated;
const // (undocumented)
parse: Parser<Integer>;
const // @internal (undocumented)
parseBase: Parser_2<Slice<Token>, Fixed, string, []>;
{};
}

Expand Down Expand Up @@ -992,8 +988,6 @@ export namespace Length {
export function resolver(emBase: Canonical, remBase: Canonical, vwBase: Canonical, vhBase: Canonical): Mapper<Fixed<Unit.Length.Relative>, Canonical>;
const // (undocumented)
parse: Parser<Length>;
const // @internal (undocumented)
parseBase: Parser_2<Slice<Token>, Fixed<Unit.Length>, string, []>;
{};
}

Expand Down Expand Up @@ -1404,8 +1398,6 @@ namespace Number_2 {
parse: Parser<Number_2>;
const // (undocumented)
parseZero: Parser<Fixed>;
const // @internal (undocumented)
parseBase: Parser_2<Slice<Token>, Fixed, string, []>;
{};
}
export { Number_2 as Number }
Expand Down Expand Up @@ -1582,8 +1574,6 @@ export namespace Percentage {
}
const // (undocumented)
parse: Parser<Percentage>;
const // @internal (undocumented)
parseBase: Parser_2<Slice<Token>, Fixed<Numeric_2.Type>, string, []>;
{};
}

Expand Down
25 changes: 13 additions & 12 deletions docs/review/api/alfa-style.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { Transform } from '@siteimprove/alfa-css';
import { Tuple } from '@siteimprove/alfa-css';
import { Unit } from '@siteimprove/alfa-css';
import { URL } from '@siteimprove/alfa-css';
import { Value as Value_2 } from '@siteimprove/alfa-css';

// Warning: (ae-internal-missing-underscore) The name "Longhand" should be prefixed with an underscore because the declaration is marked as @internal
//
Expand Down Expand Up @@ -136,8 +137,8 @@ export namespace Longhands {
readonly "border-image-outset": Longhand<Specified_2, Tuple<[top: Length | Number_2, right: Length | Number_2, bottom: Length | Number_2, left: Length | Number_2], boolean>>;
readonly "border-image-repeat": Longhand<Specified_4, Specified_4>;
readonly "border-image-slice": Longhand<Specified_6, Specified_6>;
readonly "border-image-source": Longhand<Specified_8, Image.PartiallyResolved | Keyword<"none">>;
readonly "border-image-width": Longhand<Specified_9, Tuple<[top: Percentage.Canonical | Length | Number_2.Fixed | Keyword<"auto">, right: Percentage.Canonical | Length | Number_2.Fixed | Keyword<"auto">, bottom: Percentage.Canonical | Length | Number_2.Fixed | Keyword<"auto">, left: Percentage.Canonical | Length | Number_2.Fixed | Keyword<"auto">], boolean>>;
readonly "border-image-source": Longhand<Specified_7, Image.PartiallyResolved | Keyword<"none">>;
readonly "border-image-width": Longhand<Specified_8, Tuple<[top: Percentage.Canonical | Length | Number_2.Fixed | Keyword<"auto">, right: Percentage.Canonical | Length | Number_2.Fixed | Keyword<"auto">, bottom: Percentage.Canonical | Length | Number_2.Fixed | Keyword<"auto">, left: Percentage.Canonical | Length | Number_2.Fixed | Keyword<"auto">], boolean>>;
readonly "border-inline-end-color": Longhand<Color, Color.Canonical>;
readonly "border-inline-end-style": Longhand<Keyword.ToKeywords<"none" | "hidden" | "inset" | "dotted" | "dashed" | "solid" | "double" | "groove" | "ridge" | "outset">, Keyword.ToKeywords<"none" | "hidden" | "inset" | "dotted" | "dashed" | "solid" | "double" | "groove" | "ridge" | "outset">>;
readonly "border-inline-end-width": Longhand<Specified, Length>;
Expand Down Expand Up @@ -169,12 +170,12 @@ export namespace Longhands {
readonly float: Longhand<Keyword.ToKeywords<"none" | "left" | "right">, Keyword.ToKeywords<"none" | "left" | "right">>;
readonly "font-family": Longhand<List<String_2 | Keyword<"serif"> | Keyword<"sans-serif"> | Keyword<"cursive"> | Keyword<"fantasy"> | Keyword<"monospace">, boolean>, List<String_2 | Keyword<"serif"> | Keyword<"sans-serif"> | Keyword<"cursive"> | Keyword<"fantasy"> | Keyword<"monospace">, boolean>>;
readonly "font-size": Longhand<LengthPercentage | Keyword<"medium"> | Keyword<"xx-small"> | Keyword<"x-small"> | Keyword<"small"> | Keyword<"large"> | Keyword<"x-large"> | Keyword<"xx-large"> | Keyword<"xxx-large"> | Keyword<"larger"> | Keyword<"smaller">, Length>;
readonly "font-stretch": Longhand<Specified_11, Percentage>;
readonly "font-stretch": Longhand<Specified_10, Percentage>;
readonly "font-style": Longhand<Keyword.ToKeywords<"normal" | "italic" | "oblique">, Keyword.ToKeywords<"normal" | "italic" | "oblique">>;
readonly "font-variant-caps": Longhand<Keyword.ToKeywords<"normal" | "small-caps" | "all-small-caps" | "petite-caps" | "all-petite-caps" | "unicase" | "titling-caps">, Keyword.ToKeywords<"normal" | "small-caps" | "all-small-caps" | "petite-caps" | "all-petite-caps" | "unicase" | "titling-caps">>;
readonly "font-variant-east-asian": Longhand<Specified_12, Specified_12>;
readonly "font-variant-ligatures": Longhand<Specified_13, Specified_13>;
readonly "font-variant-numeric": Longhand<Specified_14, Specified_14>;
readonly "font-variant-east-asian": Longhand<Specified_11, Specified_11>;
readonly "font-variant-ligatures": Longhand<Specified_12, Specified_12>;
readonly "font-variant-numeric": Longhand<Specified_13, Specified_13>;
readonly "font-variant-position": Longhand<Keyword.ToKeywords<"sub" | "normal" | "super">, Keyword.ToKeywords<"sub" | "normal" | "super">>;
readonly "font-weight": Longhand<Number_2 | Keyword<"normal"> | Keyword<"bold"> | Keyword<"bolder"> | Keyword<"lighter">, Number_2.Fixed>;
readonly height: Longhand<Percentage | Length | Keyword<"auto">, Percentage.Canonical | Length | Keyword<"auto">>;
Expand Down Expand Up @@ -484,9 +485,9 @@ export namespace Value {
// src/longhands.ts:203:7 - (ae-incompatible-release-tags) The symbol ""border-image-repeat"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:204:7 - (ae-forgotten-export) The symbol "Specified_6" needs to be exported by the entry point index.d.ts
// src/longhands.ts:204:7 - (ae-incompatible-release-tags) The symbol ""border-image-slice"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:205:7 - (ae-forgotten-export) The symbol "Specified_8" needs to be exported by the entry point index.d.ts
// src/longhands.ts:205:7 - (ae-forgotten-export) The symbol "Specified_7" needs to be exported by the entry point index.d.ts
// src/longhands.ts:205:7 - (ae-incompatible-release-tags) The symbol ""border-image-source"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:206:7 - (ae-forgotten-export) The symbol "Specified_9" needs to be exported by the entry point index.d.ts
// src/longhands.ts:206:7 - (ae-forgotten-export) The symbol "Specified_8" needs to be exported by the entry point index.d.ts
// src/longhands.ts:206:7 - (ae-incompatible-release-tags) The symbol ""border-image-width"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:207:7 - (ae-incompatible-release-tags) The symbol ""border-inline-end-color"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:208:7 - (ae-incompatible-release-tags) The symbol ""border-inline-end-style"" is marked as @public, but its signature references "Longhand" which is marked as @internal
Expand Down Expand Up @@ -519,15 +520,15 @@ export namespace Value {
// src/longhands.ts:235:7 - (ae-incompatible-release-tags) The symbol "float" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:236:7 - (ae-incompatible-release-tags) The symbol ""font-family"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:237:7 - (ae-incompatible-release-tags) The symbol ""font-size"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:238:7 - (ae-forgotten-export) The symbol "Specified_11" needs to be exported by the entry point index.d.ts
// src/longhands.ts:238:7 - (ae-forgotten-export) The symbol "Specified_10" needs to be exported by the entry point index.d.ts
// src/longhands.ts:238:7 - (ae-incompatible-release-tags) The symbol ""font-stretch"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:239:7 - (ae-incompatible-release-tags) The symbol ""font-style"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:240:7 - (ae-incompatible-release-tags) The symbol ""font-variant-caps"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:241:7 - (ae-forgotten-export) The symbol "Specified_12" needs to be exported by the entry point index.d.ts
// src/longhands.ts:241:7 - (ae-forgotten-export) The symbol "Specified_11" needs to be exported by the entry point index.d.ts
// src/longhands.ts:241:7 - (ae-incompatible-release-tags) The symbol ""font-variant-east-asian"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:242:7 - (ae-forgotten-export) The symbol "Specified_13" needs to be exported by the entry point index.d.ts
// src/longhands.ts:242:7 - (ae-forgotten-export) The symbol "Specified_12" needs to be exported by the entry point index.d.ts
// src/longhands.ts:242:7 - (ae-incompatible-release-tags) The symbol ""font-variant-ligatures"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:243:7 - (ae-forgotten-export) The symbol "Specified_14" needs to be exported by the entry point index.d.ts
// src/longhands.ts:243:7 - (ae-forgotten-export) The symbol "Specified_13" needs to be exported by the entry point index.d.ts
// src/longhands.ts:243:7 - (ae-incompatible-release-tags) The symbol ""font-variant-numeric"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:244:7 - (ae-incompatible-release-tags) The symbol ""font-variant-position"" is marked as @public, but its signature references "Longhand" which is marked as @internal
// src/longhands.ts:245:7 - (ae-incompatible-release-tags) The symbol ""font-weight"" is marked as @public, but its signature references "Longhand" which is marked as @internal
Expand Down
9 changes: 0 additions & 9 deletions packages/alfa-css/src/value/numeric/angle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,4 @@ export namespace Angle {
map<Slice<Token>, BaseAngle, Fixed, string>(BaseAngle.parse, of),
map(Math.parseAngle, of)
);

// TODO: temporary helper needed during migration
/**
* @internal
*/
export const parseBase = map<Slice<Token>, BaseAngle, Fixed, string>(
BaseAngle.parse,
of
);
}
9 changes: 0 additions & 9 deletions packages/alfa-css/src/value/numeric/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,4 @@ export namespace Integer {
map<Slice<Token>, BaseInteger, Fixed, string>(BaseInteger.parse, of),
map(Calculation.parseNumber, of)
);

// TODO: temporary helper needed during migration
/**
* @internal
*/
export const parseBase = map<Slice<Token>, BaseInteger, Fixed, string>(
BaseInteger.parse,
of
);
}
9 changes: 0 additions & 9 deletions packages/alfa-css/src/value/numeric/length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,4 @@ export namespace Length {
map<Slice<Token>, BaseLength, Fixed, string>(BaseLength.parse, of),
map(Math.parseLength, of)
);

// TODO: temporary helper needed during migration to calculated values.
/**
* @internal
*/
export const parseBase = map<Slice<Token>, BaseLength, Fixed, string>(
BaseLength.parse,
of
);
}
9 changes: 0 additions & 9 deletions packages/alfa-css/src/value/numeric/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,4 @@ export namespace Number {
Fixed,
string
>(BaseNumber.parseZero, of);

// TODO: temporary helper needed during migration
/**
* @internal
*/
export const parseBase = map<Slice<Token>, BaseNumber, Fixed, string>(
BaseNumber.parse,
of
);
}
9 changes: 0 additions & 9 deletions packages/alfa-css/src/value/numeric/percentage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,4 @@ export namespace Percentage {
map<Slice<Token>, BasePercentage, Fixed, string>(BasePercentage.parse, of),
map(Math.parsePercentage, of)
);

// TODO: temporary helper needed during migration
/**
* @internal
*/
export const parseBase = map<Slice<Token>, BasePercentage, Fixed, string>(
BasePercentage.parse,
of
);
}
26 changes: 19 additions & 7 deletions packages/alfa-media/src/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ import * as json from "@siteimprove/alfa-json";
import { Resolver } from "./resolver";

const {
either,
delimited,
either,
end,
filter,
left,
right,
map,
mapResult,
oneOrMore,
option,
pair,
oneOrMore,
zeroOrMore,
takeUntil,
right,
separated,
separatedList,
takeUntil,
zeroOrMore,
} = Parser;

const { property, equals } = Predicate;
Expand Down Expand Up @@ -485,10 +486,17 @@ export namespace Media {

/**
* {@link https://drafts.csswg.org/mediaqueries/#typedef-mf-value}
*
* @remarks
* We currently do not support calculations in media queries
*/
const parseFeatureValue = either(
either(
Number.parseBase,
filter(
Number.parse,
(number) => !number.hasCalculation(),
() => "Calculations no supported in media queries"
),
map(Token.parseIdent(), (ident) => Keyword.of(ident.value.toLowerCase()))
),
either(
Expand All @@ -500,7 +508,11 @@ export namespace Media {
),
([left, right]) => Percentage.of(left.value / right.value)
),
Length.parseBase
filter(
Length.parse,
(length) => !length.hasCalculation(),
() => "Calculations no supported in media queries"
)
)
);

Expand Down
42 changes: 14 additions & 28 deletions packages/alfa-style/src/property/border-image-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Percentage,
Token,
Tuple,
Value,
} from "@siteimprove/alfa-css";
import { Parser } from "@siteimprove/alfa-parser";
import { Err, Result } from "@siteimprove/alfa-result";
Expand All @@ -13,37 +14,22 @@ import { Longhand } from "../longhand";

const { either, filter } = Parser;

type NoFill<T extends Value> = Tuple<[top: T, right: T, bottom: T, left: T]>;
type WithFill<T extends Value> = Tuple<
[top: T, right: T, bottom: T, left: T, fill: Keyword<"fill">]
>;
type ImageSlice<T extends Value> = NoFill<T> | WithFill<T>;

/**
* @internal
*/
export type Specified =
| Tuple<
[
top: Specified.Item,
right: Specified.Item,
bottom: Specified.Item,
left: Specified.Item
]
>
| Tuple<
[
top: Specified.Item,
right: Specified.Item,
bottom: Specified.Item,
left: Specified.Item,
fill: Keyword<"fill">
]
>;

namespace Specified {
export type Item = Number.Fixed | Percentage.Fixed;
}
export type Specified = ImageSlice<Number | Percentage>;

type Computed = Specified;

const parseItem = filter(
either(Number.parseBase, Percentage.parseBase),
(size) => size.value >= 0,
either(Number.parse, Percentage.parse),
(size) => size.hasCalculation() || size.value >= 0,
() => `Negative sizes are not allowed`
);

Expand All @@ -53,10 +39,10 @@ const parseFill = Keyword.parse("fill");
* @internal
*/
export const parse: Parser<Slice<Token>, Specified, string> = (input) => {
let top: Specified.Item | undefined;
let right: Specified.Item | undefined;
let bottom: Specified.Item | undefined;
let left: Specified.Item | undefined;
let top: Number | Percentage | undefined;
let right: Number | Percentage | undefined;
let bottom: Number | Percentage | undefined;
let left: Number | Percentage | undefined;
let fill: Keyword<"fill"> | undefined;

while (true) {
Expand Down
12 changes: 3 additions & 9 deletions packages/alfa-style/src/property/border-radius.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Length, Percentage, Token, Tuple } from "@siteimprove/alfa-css";
import { LengthPercentage, Token, Tuple } from "@siteimprove/alfa-css";
import { Parser } from "@siteimprove/alfa-parser";

import { Shorthand } from "../shorthand";
Expand All @@ -11,21 +11,15 @@ const { delimited, either, map, option, pair, right, takeBetween } = Parser;
const parse = map(
pair(
takeBetween(
delimited(
option(Token.parseWhitespace),
either(Length.parse, Percentage.parseBase)
),
delimited(option(Token.parseWhitespace), LengthPercentage.parse),
1,
4
),
option(
right(
Token.parseDelim("/"),
takeBetween(
delimited(
option(Token.parseWhitespace),
either(Length.parse, Percentage.parseBase)
),
delimited(option(Token.parseWhitespace), LengthPercentage.parse),
1,
4
)
Expand Down

0 comments on commit 2dea20a

Please sign in to comment.