Skip to content

Commit cb21728

Browse files
committed
rewrite jsx in res, add helper functions
1 parent 229aa0e commit cb21728

File tree

10 files changed

+101
-44
lines changed

10 files changed

+101
-44
lines changed

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

jscomp/others/jsx.ml renamed to jscomp/others/jsx.res

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
1+
/* Copyright (C) 2022- Authors of ReScript
22
*
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU Lesser General Public License as published by
@@ -20,20 +20,39 @@
2020
*
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
23-
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

2525
type element
2626
type ref
2727

28-
external null : element = "null" [@@bs.val]
29-
external float : float -> element = "%identity"
30-
external int : int -> element = "%identity"
31-
external string : string -> element = "%identity"
32-
external array : element array -> element = "%identity"
28+
@val external null: element = "null"
3329

34-
type ('props, 'return) componentLike = 'props -> 'return
35-
type 'props component = ('props, element) componentLike
30+
external float: float => element = "%identity"
31+
external int: int => element = "%identity"
32+
external string: string => element = "%identity"
3633

37-
(* this function exists to prepare for making `component` abstract *)
38-
external component : ('props, element) componentLike -> 'props component
39-
= "%identity"
34+
external array: array<element> => element = "%identity"
35+
36+
type componentLike<'props, 'return> = 'props => 'return
37+
type component<'props> = componentLike<'props, element>
38+
39+
/* this function exists to prepare for making `component` abstract */
40+
external component: componentLike<'props, element> => component<'props> = "%identity"
41+
42+
%%private(
43+
@val
44+
external propsWithKey: (@as(json`{}`) _, 'props, {"key": string}) => 'props = "Object.assign"
45+
46+
@inline
47+
let addKeyProp = (~key: option<string>=?, p: 'props): 'props =>
48+
switch key {
49+
| Some(key) => propsWithKey(p, {"key": key})
50+
| None => p
51+
}
52+
)
53+
54+
let createElementWithKey = (~key=?, createElement, component, props) =>
55+
createElement(component, addKeyProp(~key?, props))
56+
57+
let createElementVariadicWithKey = (~key=?, createElementVariadic, component, props, elements) =>
58+
createElementVariadic(component, addKeyProp(~key?, props), elements)

jscomp/others/release.ninja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ o others/js_vector.cmj : cc_cmi others/js_vector.ml | others/belt_internals.cmi
6464
o others/js_vector.cmi : cc others/js_vector.mli | others/belt_internals.cmi others/js.cmi $bsc
6565
o others/js_weakmap.cmi others/js_weakmap.cmj : cc others/js_weakmap.ml | others/belt_internals.cmi others/js.cmi $bsc
6666
o others/js_weakset.cmi others/js_weakset.cmj : cc others/js_weakset.ml | others/belt_internals.cmi others/js.cmi $bsc
67-
o others/jsx.cmi others/jsx.cmj : cc others/jsx.ml | others/belt_internals.cmi others/js.cmi $bsc
67+
o others/jsx.cmi others/jsx.cmj : cc others/jsx.res | others/belt_internals.cmi others/js.cmi $bsc
6868
o others/jsxDOM.cmi others/jsxDOM.cmj : cc others/jsxDOM.res | others/belt_internals.cmi others/js.cmi others/jsx.cmj others/jsxDOMStyle.cmj others/jsxEvent.cmj $bsc
6969
o others/jsxDOMStyle.cmi others/jsxDOMStyle.cmj : cc others/jsxDOMStyle.ml | others/belt_internals.cmi others/js.cmi $bsc
7070
o others/jsxEvent.cmi others/jsxEvent.cmj : cc others/jsxEvent.ml | others/belt_internals.cmi others/js.cmi $bsc

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

lib/4.06.1/whole_compiler.ml

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

lib/es6/jsx.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
1+
2+
3+
import * as Curry from "./curry.js";
4+
5+
function createElementWithKey(key, createElement, component, props) {
6+
return Curry._2(createElement, component, key !== undefined ? Object.assign({}, props, {
7+
key: key
8+
}) : props);
9+
}
10+
11+
function createElementVariadicWithKey(key, createElementVariadic, component, props, elements) {
12+
return Curry._3(createElementVariadic, component, key !== undefined ? Object.assign({}, props, {
13+
key: key
14+
}) : props, elements);
15+
}
16+
17+
export {
18+
createElementWithKey ,
19+
createElementVariadicWithKey ,
20+
}
21+
/* No side effect */

lib/js/jsx.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
1+
'use strict';
2+
3+
var Curry = require("./curry.js");
4+
5+
function createElementWithKey(key, createElement, component, props) {
6+
return Curry._2(createElement, component, key !== undefined ? Object.assign({}, props, {
7+
key: key
8+
}) : props);
9+
}
10+
11+
function createElementVariadicWithKey(key, createElementVariadic, component, props, elements) {
12+
return Curry._3(createElementVariadic, component, key !== undefined ? Object.assign({}, props, {
13+
key: key
14+
}) : props, elements);
15+
}
16+
17+
exports.createElementWithKey = createElementWithKey;
18+
exports.createElementVariadicWithKey = createElementVariadicWithKey;
19+
/* No side effect */

packages/artifacts.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ lib/ocaml/js_weakset.cmt
794794
lib/ocaml/js_weakset.ml
795795
lib/ocaml/jsx.cmi
796796
lib/ocaml/jsx.cmt
797-
lib/ocaml/jsx.ml
797+
lib/ocaml/jsx.res
798798
lib/ocaml/jsxDOM.cmi
799799
lib/ocaml/jsxDOM.cmt
800800
lib/ocaml/jsxDOM.res

0 commit comments

Comments
 (0)