Skip to content

Commit 5912a52

Browse files
authored
Merge pull request #6610 from cknitt/11-to-master
Take over changes from v11 to master
2 parents 1d4910a + 5aa8014 commit 5912a52

File tree

10 files changed

+81
-69
lines changed

10 files changed

+81
-69
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
runs-on: ${{matrix.os}}
3535

3636
container:
37-
image: ghcr.io/rescript-lang/rescript-ci-build:v1.1.0
37+
image: ghcr.io/rescript-lang/rescript-ci-build:alpine-3.19-ocaml-4.14.1-02
3838

3939
steps:
4040
# See https://github.com/actions/runner/issues/801#issuecomment-1374967227.
@@ -115,7 +115,7 @@ jobs:
115115
ubuntu-latest,
116116
windows-latest,
117117
]
118-
ocaml_compiler: [4.14.0]
118+
ocaml_compiler: [4.14.1]
119119

120120
runs-on: ${{matrix.os}}
121121

@@ -147,15 +147,15 @@ jobs:
147147
chmod +x _build/install/default/bin/*
148148
149149
- name: Use OCaml ${{matrix.ocaml_compiler}}
150-
uses: ocaml/setup-ocaml@v2.1.7
150+
uses: ocaml/setup-ocaml@v2
151151
if: matrix.os != 'windows-latest'
152152
with:
153153
ocaml-compiler: ${{matrix.ocaml_compiler}}
154154
opam-pin: false
155155
opam-depext: false
156156

157157
- name: Use OCaml ${{matrix.ocaml_compiler}} (Win)
158-
uses: ocaml/setup-ocaml@v2.1.7
158+
uses: ocaml/setup-ocaml@v2
159159
if: matrix.os == 'windows-latest'
160160
with:
161161
ocaml-compiler: ${{matrix.ocaml_compiler}}

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
1313
# 12.0.0-alpha.1 (Unreleased)
1414

15+
# 11.1.0-rc.2 (Unreleased)
16+
17+
#### :bug: Bug Fix
18+
19+
- Fix issue with async and newtype in uncurried mode. https://github.com/rescript-lang/rescript-compiler/pull/6601
20+
- Generic JSX transform: Rename expected module name for lowercase JSX to `Elements` from `DOM`. https://github.com/rescript-lang/rescript-compiler/pull/6606
21+
- Generic JSX transform: Set default config params for `jsxConfig`. https://github.com/rescript-lang/rescript-compiler/pull/6606
22+
- Generic JSX transform: Handle namespaced names. https://github.com/rescript-lang/rescript-compiler/pull/6606
23+
24+
#### :house: Internal
25+
26+
- Use OCaml 4.14.1 (+ Alpine 3.19 container) for CI build. https://github.com/rescript-lang/rescript-compiler/pull/6600
27+
1528
# 11.1.0-rc.1
1629

1730
#### :rocket: New Feature

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Make sure you have [opam](https://opam.ocaml.org/doc/Install.html) installed on
4141
opam init
4242

4343
# Any recent OCaml version works as a development compiler
44-
opam switch create 4.14.0 # can also create local switch with opam switch create . 4.14.0
44+
opam switch create 4.14.1 # can also create local switch with opam switch create . 4.14.1
4545

4646
# Install dev dependencies from OPAM
4747
opam install . --deps-only

jscomp/bsc/rescript_compiler_main.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,14 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
251251
"*internal* Set jsx version";
252252

253253
"-bs-jsx-module", string_call (fun i ->
254-
Js_config.jsx_module := Js_config.jsx_module_of_string i),
254+
let isGeneric = match i |> String.lowercase_ascii with
255+
| "react" -> false
256+
| _ -> true in
257+
Js_config.jsx_module := Js_config.jsx_module_of_string i;
258+
if isGeneric then (
259+
Js_config.jsx_mode := Automatic;
260+
Js_config.jsx_version := Some Jsx_v4
261+
)),
255262
"*internal* Set jsx module";
256263

257264
"-bs-jsx-mode", string_call (fun i ->

jscomp/gentype_tests/typescript-react-example/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/ml/ast_async.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ let add_promise_type ?(loc = Location.none) ~async
1313

1414
let add_async_attribute ~async (body : Parsetree.expression) =
1515
if async then
16-
{
17-
body with
18-
pexp_attributes =
19-
({txt = "res.async"; loc = Location.none}, PStr [])
20-
:: body.pexp_attributes;
21-
}
16+
(
17+
match body.pexp_desc with
18+
| Pexp_construct (x, Some e) when Ast_uncurried.exprIsUncurriedFun body ->
19+
{body with pexp_desc = Pexp_construct (x, Some {e with pexp_attributes =
20+
({txt = "res.async"; loc = Location.none}, PStr []) :: e.pexp_attributes} )}
21+
| _ ->
22+
{
23+
body with
24+
pexp_attributes =
25+
({txt = "res.async"; loc = Location.none}, PStr [])
26+
:: body.pexp_attributes;
27+
})
2228
else body
2329

2430
let rec add_promise_to_result ~loc (e : Parsetree.expression) =

jscomp/syntax/src/jsx_ppx.ml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,23 @@ let getString ~key fields = fields |> getJsxConfigByKey ~key ~type_:String
4848

4949
let updateConfig config payload =
5050
let fields = getPayloadFields payload in
51-
(match getInt ~key:"version" fields with
52-
| None -> ()
53-
| Some i -> config.Jsx_common.version <- i);
54-
(match getString ~key:"module_" fields with
51+
let moduleRaw = getString ~key:"module_" fields in
52+
let isGeneric =
53+
match moduleRaw |> Option.map (fun m -> String.lowercase_ascii m) with
54+
| Some "react" | None -> false
55+
| Some _ -> true
56+
in
57+
(match (isGeneric, getInt ~key:"version" fields) with
58+
| true, _ -> config.Jsx_common.version <- 4
59+
| false, Some i -> config.Jsx_common.version <- i
60+
| _ -> ());
61+
(match moduleRaw with
5562
| None -> ()
5663
| Some s -> config.module_ <- s);
57-
match getString ~key:"mode" fields with
58-
| None -> ()
59-
| Some s -> config.mode <- s
64+
match (isGeneric, getString ~key:"mode" fields) with
65+
| true, _ -> config.mode <- "automatic"
66+
| false, Some s -> config.mode <- s
67+
| _ -> ()
6068

6169
let isJsxConfigAttr ((loc, _) : attribute) = loc.txt = "jsxConfig"
6270

jscomp/syntax/src/jsx_v4.ml

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ open Asttypes
44
open Parsetree
55
open Longident
66

7-
let moduleAccessName config = String.capitalize_ascii config.Jsx_common.module_
7+
let moduleAccessName config value =
8+
String.capitalize_ascii config.Jsx_common.module_ ^ "." ^ value
9+
|> Longident.parse
810

911
let nolabel = Nolabel
1012

@@ -384,10 +386,7 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
384386
( labelled "children",
385387
Exp.apply
386388
(Exp.ident
387-
{
388-
txt = Ldot (Lident (moduleAccessName config), "array");
389-
loc = Location.none;
390-
})
389+
{txt = moduleAccessName config "array"; loc = Location.none})
391390
[(Nolabel, expression)] );
392391
]
393392
| _ ->
@@ -431,31 +430,17 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
431430
match (!childrenArg, keyProp) with
432431
| None, key :: _ ->
433432
( Exp.ident
434-
{
435-
loc = Location.none;
436-
txt = Ldot (Lident (moduleAccessName config), "jsxKeyed");
437-
},
433+
{loc = Location.none; txt = moduleAccessName config "jsxKeyed"},
438434
[key; (nolabel, unitExpr ~loc:Location.none)] )
439435
| None, [] ->
440-
( Exp.ident
441-
{
442-
loc = Location.none;
443-
txt = Ldot (Lident (moduleAccessName config), "jsx");
444-
},
436+
( Exp.ident {loc = Location.none; txt = moduleAccessName config "jsx"},
445437
[] )
446438
| Some _, key :: _ ->
447439
( Exp.ident
448-
{
449-
loc = Location.none;
450-
txt = Ldot (Lident (moduleAccessName config), "jsxsKeyed");
451-
},
440+
{loc = Location.none; txt = moduleAccessName config "jsxsKeyed"},
452441
[key; (nolabel, unitExpr ~loc:Location.none)] )
453442
| Some _, [] ->
454-
( Exp.ident
455-
{
456-
loc = Location.none;
457-
txt = Ldot (Lident (moduleAccessName config), "jsxs");
458-
},
443+
( Exp.ident {loc = Location.none; txt = moduleAccessName config "jsxs"},
459444
[] )
460445
in
461446
Exp.apply ~loc:jsxExprLoc ~attrs jsxExpr
@@ -500,9 +485,9 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
500485
(* the new jsx transform *)
501486
| "automatic" ->
502487
let elementBinding =
503-
match moduleAccessName config with
504-
| "React" -> Lident "ReactDOM"
505-
| generic -> Ldot (Lident generic, "DOM")
488+
match config.module_ |> String.lowercase_ascii with
489+
| "react" -> Lident "ReactDOM"
490+
| _generic -> moduleAccessName config "Elements"
506491
in
507492

508493
let children, nonChildrenProps =
@@ -539,10 +524,7 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
539524
( labelled "children",
540525
Exp.apply
541526
(Exp.ident
542-
{
543-
txt = Ldot (Lident (moduleAccessName config), "array");
544-
loc = Location.none;
545-
})
527+
{txt = moduleAccessName config "array"; loc = Location.none})
546528
[(Nolabel, expression)] );
547529
]
548530
in
@@ -1203,10 +1185,7 @@ let transformStructureItem ~config item =
12031185
(* can't be an arrow because it will defensively uncurry *)
12041186
let newExternalType =
12051187
Ptyp_constr
1206-
( {
1207-
loc = pstr_loc;
1208-
txt = Ldot (Lident (moduleAccessName config), "componentLike");
1209-
},
1188+
( {loc = pstr_loc; txt = moduleAccessName config "componentLike"},
12101189
[retPropsType; innerType] )
12111190
in
12121191
let newStructure =
@@ -1321,10 +1300,7 @@ let transformSignatureItem ~config item =
13211300
(* can't be an arrow because it will defensively uncurry *)
13221301
let newExternalType =
13231302
Ptyp_constr
1324-
( {
1325-
loc = psig_loc;
1326-
txt = Ldot (Lident (moduleAccessName config), "componentLike");
1327-
},
1303+
( {loc = psig_loc; txt = moduleAccessName config "componentLike"},
13281304
[retPropsType; innerType] )
13291305
in
13301306
let newStructure =
@@ -1419,8 +1395,7 @@ let expr ~config mapper expression =
14191395
let fragment =
14201396
match config.mode with
14211397
| "automatic" ->
1422-
Exp.ident ~loc
1423-
{loc; txt = Ldot (Lident (moduleAccessName config), "jsxFragment")}
1398+
Exp.ident ~loc {loc; txt = moduleAccessName config "jsxFragment"}
14241399
| "classic" | _ ->
14251400
Exp.ident ~loc {loc; txt = Ldot (Lident "React", "fragment")}
14261401
in
@@ -1431,10 +1406,7 @@ let expr ~config mapper expression =
14311406
let applyJsxArray expr =
14321407
Exp.apply
14331408
(Exp.ident
1434-
{
1435-
txt = Ldot (Lident (moduleAccessName config), "array");
1436-
loc = Location.none;
1437-
})
1409+
{txt = moduleAccessName config "array"; loc = Location.none})
14381410
[(Nolabel, expr)]
14391411
in
14401412
let countOfChildren = function
@@ -1472,11 +1444,8 @@ let expr ~config mapper expression =
14721444
(match config.mode with
14731445
| "automatic" ->
14741446
if countOfChildren childrenExpr > 1 then
1475-
Exp.ident ~loc
1476-
{loc; txt = Ldot (Lident (moduleAccessName config), "jsxs")}
1477-
else
1478-
Exp.ident ~loc
1479-
{loc; txt = Ldot (Lident (moduleAccessName config), "jsx")}
1447+
Exp.ident ~loc {loc; txt = moduleAccessName config "jsxs"}
1448+
else Exp.ident ~loc {loc; txt = moduleAccessName config "jsx"}
14801449
| "classic" | _ ->
14811450
if countOfChildren childrenExpr > 1 then
14821451
Exp.ident ~loc

jscomp/test/async_await.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/async_await.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ let arr = [1, 2, 3]
1616

1717
let toplevelAwait = await topFoo()
1818
let toplevelAwait2 = arr[await topFoo()]
19+
20+
let f = async (type input, value: input) => {
21+
await Js.Promise.resolve(. 1)
22+
}

0 commit comments

Comments
 (0)