Skip to content

Add Jsx.addKeyProp function #5664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions jscomp/main/builtin_cmi_datasets.ml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions jscomp/main/builtin_cmj_datasets.ml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions jscomp/others/jsx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ type 'props component = ('props, element) componentLike
(* this function exists to prepare for making `component` abstract *)
external component : ('props, element) componentLike -> 'props component
= "%identity"

let addKeyProp (o : 't) (k : string) =
Obj.magic (Js.Obj.assign (Obj.magic o) [%obj { key = k }])
[@@inline]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether [@@inline] is correct or not. I'm wondering [@@bs.inline] is current, but it fails to be compiled. Unused attribute ... error is thrown.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Js output seems incorrect either.

// generated
Jsx.addKeyProp({ x: "x" }, { key: "k1"})

// expected
Object.assign({ x: "x" }, { key: "k1"})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same:

let is_inline : attr -> bool =
 fun ({ txt }, _) -> txt = "bs.inline" || txt = "inline"

I think it's more like inline is not so well specified. Not even sure it works across files.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume a bundler would inline it anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume a bundler would inline it anyway?

Worth checking. The current output is working fine without any issues in the example project anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to merge?

2 changes: 1 addition & 1 deletion jscomp/others/release.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ o others/js_vector.cmj : cc_cmi others/js_vector.ml | others/belt_internals.cmi
o others/js_vector.cmi : cc others/js_vector.mli | others/belt_internals.cmi others/js.cmi $bsc
o others/js_weakmap.cmi others/js_weakmap.cmj : cc others/js_weakmap.ml | others/belt_internals.cmi others/js.cmi $bsc
o others/js_weakset.cmi others/js_weakset.cmj : cc others/js_weakset.ml | others/belt_internals.cmi others/js.cmi $bsc
o others/jsx.cmi others/jsx.cmj : cc others/jsx.ml | others/belt_internals.cmi others/js.cmi $bsc
o others/jsx.cmi others/jsx.cmj : cc others/jsx.ml | others/belt_internals.cmi others/js.cmi others/js.cmj $bsc
o others/jsxDOM.cmi others/jsxDOM.cmj : cc others/jsxDOM.ml | others/belt_internals.cmi others/js.cmi others/jsx.cmj others/jsxDOMStyle.cmj others/jsxEvent.cmj $bsc
o others/jsxDOMStyle.cmi others/jsxDOMStyle.cmj : cc others/jsxDOMStyle.ml | others/belt_internals.cmi others/js.cmi $bsc
o others/jsxEvent.cmi others/jsxEvent.cmj : cc others/jsxEvent.ml | others/belt_internals.cmi others/js.cmi $bsc
Expand Down
16 changes: 8 additions & 8 deletions lib/4.06.1/unstable/js_compiler.ml

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions lib/4.06.1/unstable/js_playground_compiler.ml

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions lib/4.06.1/whole_compiler.ml

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion lib/es6/jsx.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */



function addKeyProp(o, k) {
return Object.assign(o, {
key: k
});
}

export {
addKeyProp ,
}
/* No side effect */
12 changes: 11 additions & 1 deletion lib/js/jsx.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
'use strict';


function addKeyProp(o, k) {
return Object.assign(o, {
key: k
});
}

exports.addKeyProp = addKeyProp;
/* No side effect */