Skip to content

Commit

Permalink
Fix regression causing failure to parse characters like "•" (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubegasimon authored Dec 3, 2023
1 parent 14390eb commit 753e4f1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
59 changes: 29 additions & 30 deletions packages/css/native/shared/Css_Js_Core.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Css_AtomicTypes

module Std = Kloth

type rule =
Expand Down Expand Up @@ -79,10 +78,10 @@ module Make (CssImpl : Css_Core.CssImplementationIntf) :

let framesToDict frames =
Std.Array.reduceU frames (Js.Dict.empty ()) (fun [@u] dict (stop, rules) ->
let _ =
Js.Dict.set dict (Std.Int.toString stop ^ {js|%|js}) (toJson rules)
in
dict)
let _ =
Js.Dict.set dict (Std.Int.toString stop ^ {js|%|js}) (toJson rules)
in
dict)

let keyframes =
fun [@u] frames -> (CssImpl.makeKeyframes (framesToDict frames) [@u])
Expand All @@ -94,7 +93,7 @@ end

let join strings separator =
Std.Array.reduceWithIndexU strings {js||js} (fun [@u] acc item index ->
if index = 0 then item else acc ^ separator ^ item)
if index = 0 then item else acc ^ separator ^ item)

module Converter = struct
let string_of_time t = Std.Int.toString t ^ {js|ms|js}
Expand Down Expand Up @@ -1866,11 +1865,11 @@ let backgrounds x =
( {js|background|js},
x
|. Std.Array.map (fun item ->
match item with
| #Color.t as c -> Color.toString c
| #Url.t as u -> Url.toString u
| #Gradient.t as g -> Gradient.toString g
| `none -> {js|none|js})
match item with
| #Color.t as c -> Color.toString c
| #Url.t as u -> Url.toString u
| #Gradient.t as g -> Gradient.toString g
| `none -> {js|none|js})
|. Std.Array.joinWith {js|, |js} )

let backgroundSize x =
Expand All @@ -1890,38 +1889,38 @@ let fontFace ~fontFamily ~src ?fontStyle ?fontWeight ?fontDisplay ?sizeAdjust ()
let src =
src
|. Std.Array.map (fun x ->
match x with
| `localUrl value ->
((({js|local("|js} [@res.template]) ^ value) [@res.template]
^ ({js|")|js} [@res.template]))
[@res.template]
| `url value ->
((({js|url("|js} [@res.template]) ^ value) [@res.template]
^ ({js|")|js} [@res.template]))
[@res.template])
match x with
| `localUrl value ->
((({js|local("|js} [@res.template]) ^ value) [@res.template]
^ ({js|")|js} [@res.template]))
[@res.template]
| `url value ->
((({js|url("|js} [@res.template]) ^ value) [@res.template]
^ ({js|")|js} [@res.template]))
[@res.template])
|. Std.Array.joinWith {js|, |js}
in
let fontStyle =
Belt.Option.mapWithDefault fontStyle {js||js} (fun s ->
({js|font-style: |js} ^ s) ^ {js|;|js})
({js|font-style: |js} ^ s) ^ {js|;|js})
in
let fontWeight =
Belt.Option.mapWithDefault fontWeight {js||js} (fun w ->
({js|font-weight: |js}
^
match w with
| #FontWeight.t as f -> FontWeight.toString f
| #Var.t as va -> Var.toString va
| #Cascading.t as c -> Cascading.toString c)
^ {js|;|js})
({js|font-weight: |js}
^
match w with
| #FontWeight.t as f -> FontWeight.toString f
| #Var.t as va -> Var.toString va
| #Cascading.t as c -> Cascading.toString c)
^ {js|;|js})
in
let fontDisplay =
Belt.Option.mapWithDefault fontDisplay {js||js} (fun f ->
({js|font-display: |js} ^ FontDisplay.toString f) ^ {js|;|js})
({js|font-display: |js} ^ FontDisplay.toString f) ^ {js|;|js})
in
let sizeAdjust =
Belt.Option.mapWithDefault sizeAdjust {js||js} (fun s ->
({js|size-adjust: |js} ^ Percentage.toString s) ^ {js|;|js})
({js|size-adjust: |js} ^ Percentage.toString s) ^ {js|;|js})
in
((((((((((((({js|@font-face {
font-family: |js} [@res.template])
Expand Down
3 changes: 1 addition & 2 deletions packages/emotion-hash/test/native_hash.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let () =
if Array.length Sys.argv <> 2 then (
Printf.eprintf "Usage: %s <input_string>\n" Sys.argv.(0);
exit 1
);
exit 1);

let input_string = Sys.argv.(1) in
let result = Emotion_hash.Hash.default input_string in
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/lib/driver.re
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let from_string = (~pos: option(Lexing.position)=?, string) => {
let last_buffer = ref(None);

let parse_string = (~skip_whitespace, ~pos, parser, string) => {
let buffer = Sedlexing.Utf8.from_string(string);
let buffer = Sedlexing.Latin1.from_string(string);

last_buffer := Some(from_string(~pos?, string));

Expand Down
24 changes: 24 additions & 0 deletions packages/ppx/test/native/Selector_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ open Ppxlib;
let loc = Location.none;

let simple_tests = [
(
":before { content: '点'; }",
[%expr [%cx ":before { content: '点'; }"]],
[%expr
CssJs.style([|
CssJs.selector(
{js|:before|js},
[|CssJs.unsafe({js|content|js}, {js|'点'|js})|],
),
|])
],
),
(
":before { content: '•'; }",
[%expr [%cx ":before { content: '•'; }"]],
[%expr
CssJs.style([|
CssJs.selector(
{js|:before|js},
[|CssJs.unsafe({js|content|js}, {js|'•'|js})|],
),
|])
],
),
(
".a",
[%expr [%cx ".a {}"]],
Expand Down

0 comments on commit 753e4f1

Please sign in to comment.