Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 1.02 KB

File metadata and controls

32 lines (22 loc) · 1.02 KB

gen_js_api: default naming convention

JavaScript names corresponding to bound components can always be specified explicitly (with the use of attributes). When the naming is left implicit, a JavaScript name is automatically derived from the OCaml name by applying the following rules:

  1. uppercasing every character following an underscore;

  2. removing every underscore;

  3. uppercasing the first character when generating object constructor names.

This automatic naming convention can be partially disabled by adding an attribute [@js.verbatim_names] on outer structures. When the attribute [@js.verbatim_names] is inherited from the context, the rule 1 and 2 are disabled.

For instance,

type myType = { x_coord : int; y_coord : int [@js "Y"]}

is mapped to a JS record with two fields named "xCoord" and "Y" whereas

type myType = { x_coord : int; y_coord : int [@js "Y"]} [@@js.verbatim_names]

is mapped to a JS record with two fields named "x_coord" and "y".