Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 557c063

Browse files
Fix parsing of poly-var typexpr consisting of one tag-spec-first (#254)
* Fix parsing of poly-var typexpr consisting of only tag-spec-first `[s]` or `[ListStyleType.t]` should parse without more tag-spec's * Add bs-css to roundtrip tests * Add changelog entry
1 parent f613227 commit 557c063

26 files changed

+15816
-23
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unreleased
22

3-
* Implement new syntax for guards on pattern match cases in [3248](https://github.com/rescript-lang/syntax/pull/248)
3+
* Fix parsing of poly-var typexpr consisting of one tag-spec-first in [254](https://github.com/rescript-lang/syntax/pull/254)
4+
* Implement new syntax for guards on pattern match cases in [#248](https://github.com/rescript-lang/syntax/pull/248)
45
* Implement intelligent breaking for poly-var type expressions in [#246](https://github.com/rescript-lang/syntax/pull/246)
56
* Improve indentation of fast pipe chain in let binding in [#244](https://github.com/rescript-lang/syntax/pull/244)
67
* Improve printing of non-callback arguments in call expressions with callback in [#241](https://github.com/rescript-lang/syntax/pull/241/files)

src/res_core.ml

+8-2
Original file line numberDiff line numberDiff line change
@@ -4827,8 +4827,14 @@ and parseTagSpecFirst p =
48274827
[parsePolymorphicVariantTypeSpecHash ~attrs ~full:false p]
48284828
| _ ->
48294829
let typ = parseTypExpr ~attrs p in
4830-
Parser.expect Bar p;
4831-
[Parsetree.Rinherit typ; parseTagSpec p]
4830+
begin match p.token with
4831+
| Rbracket ->
4832+
(* example: [ListStyleType.t] *)
4833+
[Parsetree.Rinherit typ;]
4834+
| _ ->
4835+
Parser.expect Bar p;
4836+
[Parsetree.Rinherit typ; parseTagSpec p]
4837+
end
48324838

48334839
and parsePolymorphicVariantTypeSpecHash ~attrs ~full p : Parsetree.row_field =
48344840
let startPos = p.Parser.startPos in

tests/idempotency/bs-css/Css.re

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include Css_Legacy_Core;
2+
include Css_Colors;
3+
4+
include Css_Legacy_Core.Make({
5+
exception NotImplemented;
6+
7+
let make = (. _) => raise(NotImplemented);
8+
let mergeStyles = (. _) => raise(NotImplemented);
9+
let injectRule = (. _) => ();
10+
let injectRaw = (. _) => ();
11+
let makeKeyFrames = (. _) => raise(NotImplemented);
12+
});
13+
14+
external unsafeJsonToStyles: Js.Json.t => ReactDOMRe.Style.t = "%identity";
15+
16+
let style = rules => rules->toJson->unsafeJsonToStyles;
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
include Css_Legacy_Core;
2+
include Css_Colors;
3+
4+
include Css_Legacy_Core.Make({
5+
[@bs.module "emotion"]
6+
external mergeStyles: (. array(string)) => string = "cx";
7+
8+
[@bs.module "emotion"] external make: (. Js.Json.t) => string = "css";
9+
10+
[@bs.module "emotion"]
11+
external injectRule: (. Js.Json.t) => unit = "injectGlobal";
12+
13+
[@bs.module "emotion"]
14+
external injectRaw: (. string) => unit = "injectGlobal";
15+
16+
[@bs.module "emotion"]
17+
external makeKeyFrames: (. Js.Dict.t(Js.Json.t)) => string = "keyframes";
18+
});
19+
20+
type cache;
21+
22+
[@bs.module "emotion"] external cache: cache = "cache";
23+
24+
let fontFace =
25+
(~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?, ()) => {
26+
let asString =
27+
Css_Legacy_Core.fontFace(
28+
~fontFamily,
29+
~src,
30+
~fontStyle?,
31+
~fontWeight?,
32+
~fontDisplay?,
33+
(),
34+
);
35+
insertRule(asString);
36+
fontFamily;
37+
};
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
include Css_Js_Core;
2+
include Css_Colors;
3+
4+
include Css_Js_Core.Make({
5+
[@bs.module "emotion"]
6+
external mergeStyles: (. array(string)) => string = "cx";
7+
8+
[@bs.module "emotion"] external make: (. Js.Json.t) => string = "css";
9+
10+
[@bs.module "emotion"]
11+
external injectRule: (. Js.Json.t) => unit = "injectGlobal";
12+
13+
[@bs.module "emotion"]
14+
external injectRaw: (. string) => unit = "injectGlobal";
15+
16+
[@bs.module "emotion"]
17+
external makeKeyFrames: (. Js.Dict.t(Js.Json.t)) => string = "keyframes";
18+
});
19+
20+
type cache;
21+
22+
[@bs.module "emotion"] external cache: cache = "cache";
23+
24+
let fontFace =
25+
(~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?, ()) => {
26+
insertRule(.
27+
Css_Js_Core.fontFace(
28+
~fontFamily,
29+
~src,
30+
~fontStyle?,
31+
~fontWeight?,
32+
~fontDisplay?,
33+
(),
34+
),
35+
);
36+
fontFamily;
37+
};

tests/idempotency/bs-css/CssJs.re

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include Css_Js_Core;
2+
include Css_Colors;
3+
4+
include Css_Js_Core.Make({
5+
exception NotImplemented;
6+
7+
let make = (. _) => raise(NotImplemented);
8+
let mergeStyles = (. _) => raise(NotImplemented);
9+
let injectRule = (. _) => ();
10+
let injectRaw = (. _) => ();
11+
let makeKeyFrames = (. _) => raise(NotImplemented);
12+
});
13+
14+
external unsafeJsonToStyles: Js.Json.t => ReactDOMRe.Style.t = "%identity";
15+
16+
let style = (. rules) => rules->toJson->unsafeJsonToStyles;

0 commit comments

Comments
 (0)