Skip to content

Commit

Permalink
Use res.optional
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Mar 21, 2023
1 parent 49faa85 commit 7600e95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/ppx/src/generate.re
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ let styledDynamic =
let variableMakeProps =
variableList
|> List.map(((arg, optional, _, type_)) =>
customPropLabel(~loc, getLabel(arg), type_, optional)
customPropLabel(~loc, ~optional, getLabel(arg), type_)
);

/* (~arg1=props.arg1, ~arg2=props.arg2, ...) */
Expand Down
8 changes: 5 additions & 3 deletions packages/ppx/src/generate_lib.re
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module BuckleScriptAttributes = {
};

let optional = (~loc) =>
Helper.Attr.mk(withLoc("optional", ~loc), PStr([]));
Helper.Attr.mk(withLoc("res.optional", ~loc), PStr([]));

/* [@bs.deriving abstract] */
let derivingAbstract = (~loc) =>
Expand Down Expand Up @@ -207,12 +207,13 @@ let variadicElement = (~loc, ~htmlTag) => {
);
};

let propItem = (~loc, name) =>
let propItem = (~loc, name) => {
Helper.Exp.field(
~loc,
Helper.Exp.ident(~loc, withLoc(Lident("props"), ~loc)),
withLoc(Lident(name), ~loc),
);
};

/* let stylesObject = { "className": className, "ref": props.ref }; */
let stylesAndRefObject = (~loc) => {
Expand Down Expand Up @@ -358,9 +359,10 @@ let component =
};

/* color: string */
let customPropLabel = (~loc, name, type_, _isOptional) => {
let customPropLabel = (~loc, ~optional, name, type_) => {
Helper.Type.field(
~loc,
~attrs=optional ? [BuckleScriptAttributes.optional(~loc)] : [],
withLoc(name, ~loc),
type_,
);
Expand Down

0 comments on commit 7600e95

Please sign in to comment.