Skip to content

Commit 2b69b67

Browse files
authored
Migrate css-support to cram tests (#454)
1 parent cb2bf08 commit 2b69b67

File tree

258 files changed

+7450
-5409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+7450
-5409
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ release-static:
6666

6767
# Testing commands
6868

69-
TEST_TARGETS := ppx_snapshot_reason ppx_snapshot_rescript parser reason_css_parser css_spec_parser css_support css_spec_types string_interpolation emotion emotion_hash native_typecheck ppx_e2e
69+
TEST_TARGETS := ppx_snapshot_reason ppx_snapshot_rescript parser reason_css_parser css_spec_parser css_support css_spec_types string_interpolation emotion emotion_hash native_typecheck
7070

7171
# Create targets with the format "test_{{target_name}}_{{ "watch" | "promote" }}"
7272
define create_test

packages/css/js/Css_Js_Core.ml

Lines changed: 70 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ let join strings separator =
8282
if index = 0 then item else acc ^ separator ^ item)
8383

8484
module Converter = struct
85-
let string_of_time t = Std.Int.toString t ^ {js|ms|js}
85+
let string_of_time = function
86+
| `ms t -> Std.Int.toString t ^ {js|ms|js}
87+
| `s t -> Std.Int.toString t ^ {js|s|js}
8688

8789
let string_of_content x =
8890
match x with
@@ -170,6 +172,7 @@ let alignContent x =
170172
| #AlignContent.t as ac -> AlignContent.toString ac
171173
| #NormalAlignment.t as na -> NormalAlignment.toString na
172174
| #BaselineAlignment.t as ba -> BaselineAlignment.toString ba
175+
| #OverflowAlignment.t as oa -> OverflowAlignment.toString oa
173176
| #DistributedAlignment.t as da -> DistributedAlignment.toString da
174177
| #Var.t as va -> Var.toString va
175178
| #Cascading.t as c -> Cascading.toString c )
@@ -191,6 +194,7 @@ let alignSelf x =
191194
match x with
192195
| #AlignSelf.t as a -> AlignSelf.toString a
193196
| #PositionalAlignment.t as pa -> PositionalAlignment.toString pa
197+
| #OverflowAlignment.t as pa -> OverflowAlignment.toString pa
194198
| #BaselineAlignment.t as ba -> BaselineAlignment.toString ba
195199
| #Var.t as va -> Var.toString va
196200
| #Cascading.t as c -> Cascading.toString c )
@@ -225,9 +229,8 @@ let backfaceVisibility x =
225229
let backdropFilter x =
226230
D
227231
( {js|backdropFilter|js},
228-
x
229-
|. Std.Array.map BackdropFilter.toString
230-
|. Std.Array.joinWith ~sep:{js|, |js} )
232+
x |. Std.Array.map Filter.toString |. Std.Array.joinWith ~sep:{js|, |js}
233+
)
231234

232235
let backgroundAttachment x =
233236
D
@@ -286,25 +289,35 @@ let backgroundOrigin x =
286289
| #Var.t as va -> Var.toString va
287290
| #Cascading.t as c -> Cascading.toString c )
288291

289-
let string_of_backgroundposition x =
290-
match x with
291-
| #BackgroundPosition.t as bp -> BackgroundPosition.toString bp
292-
| `hv (h, v) ->
293-
(match h with
292+
let string_of_backgroundposition2 (x, y) =
293+
match x, y with
294+
| x, Some y ->
295+
(match x with
294296
| #BackgroundPosition.X.t as h -> BackgroundPosition.X.toString h
295297
| #Length.t as l -> Length.toString l)
296298
^ {js| |js}
297299
^
298-
(match v with
300+
(match y with
299301
| #BackgroundPosition.Y.t as v -> BackgroundPosition.Y.toString v
300302
| #Length.t as l -> Length.toString l)
303+
| x, None ->
304+
(match x with
305+
| #BackgroundPosition.t as bp -> BackgroundPosition.toString bp
306+
| #Length.t as l -> Length.toString l)
307+
308+
let string_of_backgroundposition x =
309+
match x with
310+
| #BackgroundPosition.t as bp -> BackgroundPosition.toString bp
301311
| #Length.t as l -> Length.toString l
302312
| #Var.t as va -> Var.toString va
303313
| #Cascading.t as c -> Cascading.toString c
304314

305315
let backgroundPosition x =
306316
D ({js|backgroundPosition|js}, string_of_backgroundposition x)
307317

318+
let backgroundPosition2 x =
319+
D ({js|backgroundPosition|js}, string_of_backgroundposition2 x)
320+
308321
let backgroundPositions bp =
309322
D
310323
( {js|backgroundPosition|js},
@@ -727,6 +740,7 @@ let justifyItems x =
727740
D
728741
( {js|justifyItems|js},
729742
match x with
743+
| `stretch -> {js|stretch|js}
730744
| #PositionalAlignment.t as pa -> PositionalAlignment.toString pa
731745
| #NormalAlignment.t as na -> NormalAlignment.toString na
732746
| #BaselineAlignment.t as ba -> BaselineAlignment.toString ba
@@ -957,17 +971,24 @@ let perspective x =
957971
| #Var.t as va -> Var.toString va
958972
| #Cascading.t as c -> Cascading.toString c )
959973

960-
let perspectiveOrigin x y =
974+
let perspectiveOrigin x =
975+
D
976+
( {js|perspectiveOrigin|js},
977+
match x with
978+
| #Perspective.t as p -> Perspective.toString p
979+
| #TransformOrigin.t as t -> TransformOrigin.toString t )
980+
981+
let perspectiveOrigin2 x y =
961982
D
962983
( {js|perspectiveOrigin|js},
963984
(match x with
964985
| #Perspective.t as p -> Perspective.toString p
965-
| #Length.t as l -> Length.toString l)
986+
| #TransformOrigin.t as t -> TransformOrigin.toString t)
966987
^ {js| |js}
967988
^
968989
match y with
969990
| #Perspective.t as p -> Perspective.toString p
970-
| #Length.t as l -> Length.toString l )
991+
| #TransformOrigin.t as t -> TransformOrigin.toString t )
971992

972993
let pointerEvents x =
973994
D
@@ -998,6 +1019,7 @@ let justifySelf x =
9981019
match x with
9991020
| #JustifySelf.t as j -> JustifySelf.toString j
10001021
| #PositionalAlignment.t as pa -> PositionalAlignment.toString pa
1022+
| #OverflowAlignment.t as oa -> OverflowAlignment.toString oa
10011023
| #BaselineAlignment.t as ba -> BaselineAlignment.toString ba
10021024
| #Var.t as va -> Var.toString va
10031025
| #Cascading.t as c -> Cascading.toString c )
@@ -1142,8 +1164,12 @@ let transforms x =
11421164
x |. Std.Array.map Transform.toString |. Std.Array.joinWith ~sep:{js| |js}
11431165
)
11441166

1145-
let transformOrigin x y =
1146-
D ({js|transformOrigin|js}, Length.toString x ^ {js| |js} ^ Length.toString y)
1167+
let transformOrigin x = D ({js|transformOrigin|js}, TransformOrigin.toString x)
1168+
1169+
let transformOrigin2 x y =
1170+
D
1171+
( {js|transformOrigin|js},
1172+
TransformOrigin.toString x ^ {js| |js} ^ TransformOrigin.toString y )
11471173

11481174
let transformOrigin3d x y z =
11491175
D
@@ -1367,7 +1393,7 @@ type listStyleType = ListStyleType.t
13671393
type repeatValue = RepeatValue.t
13681394
type outlineStyle = OutlineStyle.t
13691395
type transform = Transform.t
1370-
type 'colorOrVar gradient = 'colorOrVar Gradient.t
1396+
type gradient = Gradient.t
13711397

13721398
let initial = Cascading.initial
13731399
let inherit_ = Cascading.inherit_
@@ -1632,61 +1658,20 @@ let flexBasis x =
16321658

16331659
let order x = D ({js|order|js}, Std.Int.toString x)
16341660

1635-
let string_of_calc x fn =
1636-
match x with
1637-
| `one a -> {js|calc(|js} ^ fn a ^ {js|)|js}
1638-
| `add (a, b) -> {js|calc(|js} ^ fn a ^ {js| + |js} ^ fn b ^ {js|)|js}
1639-
| `sub (a, b) -> {js|calc(|js} ^ fn a ^ {js| - |js} ^ fn b ^ {js|)|js}
1640-
| `mult (a, b) -> {js|calc(|js} ^ fn a ^ {js| * |js} ^ fn b ^ {js|)|js}
1641-
16421661
let string_of_minmax x =
16431662
match x with
16441663
| `auto -> {js|auto|js}
1645-
| `calc c -> string_of_calc c Length.toString
1646-
| `ch x -> Std.Float.toString x ^ {js|ch|js}
1647-
| `cm x -> Std.Float.toString x ^ {js|cm|js}
1648-
| `em x -> Std.Float.toString x ^ {js|em|js}
1649-
| `ex x -> Std.Float.toString x ^ {js|ex|js}
1650-
| `mm x -> Std.Float.toString x ^ {js|mm|js}
1651-
| `percent x -> Std.Float.toString x ^ {js|%|js}
1652-
| `pt x -> Std.Int.toString x ^ {js|pt|js}
1653-
| `px x -> Std.Int.toString x ^ {js|px|js}
1654-
| `pxFloat x -> Std.Float.toString x ^ {js|px|js}
1655-
| `rem x -> Std.Float.toString x ^ {js|rem|js}
1656-
| `vh x -> Std.Float.toString x ^ {js|vh|js}
1657-
| `vmax x -> Std.Float.toString x ^ {js|vmax|js}
1658-
| `vmin x -> Std.Float.toString x ^ {js|vmin|js}
1659-
| `vw x -> Std.Float.toString x ^ {js|vw|js}
1664+
| #Length.t as l -> Length.toString l
16601665
| `fr x -> Std.Float.toString x ^ {js|fr|js}
1661-
| `inch x -> Std.Float.toString x ^ {js|in|js}
1662-
| `pc x -> Std.Float.toString x ^ {js|pc|js}
1663-
| `zero -> {js|0|js}
16641666
| `minContent -> {js|min-content|js}
16651667
| `maxContent -> {js|max-content|js}
16661668

16671669
let string_of_dimension x =
16681670
match x with
16691671
| `auto -> {js|auto|js}
16701672
| `none -> {js|none|js}
1671-
| `calc c -> string_of_calc c Length.toString
1672-
| `ch x -> Std.Float.toString x ^ {js|ch|js}
1673-
| `cm x -> Std.Float.toString x ^ {js|cm|js}
1674-
| `em x -> Std.Float.toString x ^ {js|em|js}
1675-
| `ex x -> Std.Float.toString x ^ {js|ex|js}
1676-
| `mm x -> Std.Float.toString x ^ {js|mm|js}
1677-
| `percent x -> Std.Float.toString x ^ {js|%|js}
1678-
| `pt x -> Std.Int.toString x ^ {js|pt|js}
1679-
| `px x -> Std.Int.toString x ^ {js|px|js}
1680-
| `pxFloat x -> Std.Float.toString x ^ {js|px|js}
1681-
| `rem x -> Std.Float.toString x ^ {js|rem|js}
1682-
| `vh x -> Std.Float.toString x ^ {js|vh|js}
1683-
| `vmax x -> Std.Float.toString x ^ {js|vmax|js}
1684-
| `vmin x -> Std.Float.toString x ^ {js|vmin|js}
1685-
| `vw x -> Std.Float.toString x ^ {js|vw|js}
1673+
| #Length.t as l -> Length.toString l
16861674
| `fr x -> Std.Float.toString x ^ {js|fr|js}
1687-
| `inch x -> Std.Float.toString x ^ {js|in|js}
1688-
| `pc x -> Std.Float.toString x ^ {js|pc|js}
1689-
| `zero -> {js|0|js}
16901675
| `fitContent -> {js|fit-content|js}
16911676
| `minContent -> {js|min-content|js}
16921677
| `maxContent -> {js|max-content|js}
@@ -1724,25 +1709,8 @@ let rec gridLengthToJs x =
17241709
| `name name -> name
17251710
| `none -> {js|none|js}
17261711
| `auto -> {js|auto|js}
1727-
| `calc c -> string_of_calc c Length.toString
1728-
| `ch x -> Std.Float.toString x ^ {js|ch|js}
1729-
| `cm x -> Std.Float.toString x ^ {js|cm|js}
1730-
| `em x -> Std.Float.toString x ^ {js|em|js}
1731-
| `ex x -> Std.Float.toString x ^ {js|ex|js}
1732-
| `mm x -> Std.Float.toString x ^ {js|mm|js}
1733-
| `percent x -> Std.Float.toString x ^ {js|%|js}
1734-
| `pt x -> Std.Int.toString x ^ {js|pt|js}
1735-
| `px x -> Std.Int.toString x ^ {js|px|js}
1736-
| `pxFloat x -> Std.Float.toString x ^ {js|px|js}
1737-
| `rem x -> Std.Float.toString x ^ {js|rem|js}
1738-
| `vh x -> Std.Float.toString x ^ {js|vh|js}
1739-
| `inch x -> Std.Float.toString x ^ {js|in|js}
1740-
| `pc x -> Std.Float.toString x ^ {js|pc|js}
1741-
| `vmax x -> Std.Float.toString x ^ {js|vmax|js}
1742-
| `vmin x -> Std.Float.toString x ^ {js|vmin|js}
1743-
| `vw x -> Std.Float.toString x ^ {js|vw|js}
1712+
| #Length.t as l -> Length.toString l
17441713
| `fr x -> Std.Float.toString x ^ {js|fr|js}
1745-
| `zero -> {js|0|js}
17461714
| `minContent -> {js|min-content|js}
17471715
| `maxContent -> {js|max-content|js}
17481716
| `fitContent x ->
@@ -1820,26 +1788,31 @@ let gridTemplateAreas l =
18201788

18211789
type filter =
18221790
[ `blur of Length.t
1823-
| `brightness of float
1824-
| `contrast of float
1791+
| `brightness of [ `percent of float | `num of float ]
1792+
| `contrast of [ `percent of float | `num of float ]
18251793
| `dropShadow of Length.t * Length.t * Length.t * [ Color.t | Var.t ]
1826-
| `grayscale of float
1794+
| `grayscale of [ `percent of float | `num of float ]
18271795
| `hueRotate of angle
1828-
| `invert of float
1829-
| `opacity of float
1830-
| `saturate of float
1831-
| `sepia of float
1796+
| `invert of [ `percent of float | `num of float ]
1797+
| `opacity of [ `percent of float | `num of float ]
1798+
| `saturate of [ `percent of float | `num of float ]
1799+
| `sepia of [ `percent of float | `num of float ]
18321800
| `url of string
18331801
| `none
18341802
| Var.t
18351803
| Cascading.t
18361804
]
18371805

1806+
let string_of_amount x =
1807+
match x with
1808+
| `percent v -> Std.Float.toString v ^ {js|%|js}
1809+
| `num v -> Std.Float.toString v
1810+
18381811
let string_of_filter x =
18391812
match x with
1840-
| `blur v -> ({js|blur(|js} ^ Length.toString v) ^ {js|)|js}
1841-
| `brightness v -> ({js|brightness(|js} ^ Std.Float.toString v) ^ {js|%)|js}
1842-
| `contrast v -> ({js|contrast(|js} ^ Std.Float.toString v) ^ {js|%)|js}
1813+
| `blur v -> {js|blur(|js} ^ Length.toString v ^ {js|)|js}
1814+
| `brightness v -> {js|brightness(|js} ^ string_of_amount v ^ {js|%)|js}
1815+
| `contrast v -> {js|contrast(|js} ^ string_of_amount v ^ {js|%)|js}
18431816
| `dropShadow (a, b, c, d) ->
18441817
{js|drop-shadow(|js}
18451818
^ Length.toString a
@@ -1848,16 +1821,16 @@ let string_of_filter x =
18481821
^ {js| |js}
18491822
^ Length.toString c
18501823
^ {js| |js}
1851-
^ (match d with
1824+
^ (match (d : [ Color.t | Var.t ]) with
18521825
| #Color.t as c -> Color.toString c
18531826
| #Var.t as v -> Var.toString v)
18541827
^ {js|)|js}
1855-
| `grayscale v -> ({js|grayscale(|js} ^ Std.Float.toString v) ^ {js|%)|js}
1856-
| `hueRotate v -> ({js|hue-rotate(|js} ^ Angle.toString v) ^ {js|)|js}
1857-
| `invert v -> ({js|invert(|js} ^ Std.Float.toString v) ^ {js|%)|js}
1858-
| `opacity v -> ({js|opacity(|js} ^ Std.Float.toString v) ^ {js|%)|js}
1859-
| `saturate v -> ({js|saturate(|js} ^ Std.Float.toString v) ^ {js|%)|js}
1860-
| `sepia v -> ({js|sepia(|js} ^ Std.Float.toString v) ^ {js|%)|js}
1828+
| `grayscale v -> {js|grayscale(|js} ^ string_of_amount v ^ {js|%)|js}
1829+
| `hueRotate v -> {js|hue-rotate(|js} ^ Angle.toString v ^ {js|)|js}
1830+
| `invert v -> {js|invert(|js} ^ string_of_amount v ^ {js|%)|js}
1831+
| `opacity v -> {js|opacity(|js} ^ string_of_amount v ^ {js|%)|js}
1832+
| `saturate v -> {js|saturate(|js} ^ string_of_amount v ^ {js|%)|js}
1833+
| `sepia v -> {js|sepia(|js} ^ string_of_amount v ^ {js|%)|js}
18611834
| `none -> {js|none|js}
18621835
| #Url.t as u -> Url.toString u
18631836
| #Var.t as va -> Var.toString va
@@ -2092,8 +2065,8 @@ let transformStyle x =
20922065
module Transition = struct
20932066
type t = [ `value of string ]
20942067

2095-
let shorthand ?(duration = 0) ?(delay = 0) ?(timingFunction = `ease) property
2096-
=
2068+
let shorthand ?(duration = `ms 0) ?(delay = `ms 0) ?(timingFunction = `ease)
2069+
property =
20972070
`value
20982071
(string_of_time duration
20992072
^ {js| |js}
@@ -2133,7 +2106,7 @@ let transitionProperty x = D ({js|transitionProperty|js}, x)
21332106
module Animation = struct
21342107
type t = [ `value of string ]
21352108

2136-
let shorthand ?(duration = 0) ?(delay = 0) ?(direction = `normal)
2109+
let shorthand ?(duration = `ms 0) ?(delay = `ms 0) ?(direction = `normal)
21372110
?(timingFunction = `ease) ?(fillMode = `none) ?(playState = `running)
21382111
?(iterationCount = `count 1.) name =
21392112
`value

0 commit comments

Comments
 (0)