Skip to content

chore: camelCase to snake_case 🐍 #6702

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 6 commits into from
May 27, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

- Allow `@directive` on functions for emitting function level directive code (`let serverAction = @directive("'use server'") (~name) => {...}`). https://github.com/rescript-lang/rescript-compiler/pull/6756

#### :house: Internal

- Convert OCaml codebase to snake case style. https://github.com/rescript-lang/rescript-compiler/pull/6702

#### :boom: Breaking Change

- `lazy` syntax is no longer supported. If you're using it, use `Lazy` module or `React.lazy_` instead. https://github.com/rescript-lang/rescript-compiler/pull/6342
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ make test-syntax-roundtrip
make artifacts
```

## Coding Style

- OCaml Code: snake case format is used, e.g, `to_string`
- ReScript Code: the camel case format is used, e.g `toString`

## Adding new Files to the Npm Package

To make sure that no files are added to or removed from the npm package inadvertently, an artifact list is kept at `packages/artifacts.txt`. During CI build, it is verified that only the files that are listed there are actually included in the npm package.
Expand Down
34 changes: 17 additions & 17 deletions jscomp/bsc/rescript_compiler_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ let process_file sourcefile ?(kind ) ppf =
let sourcefile = set_abs_input_name sourcefile in
setup_compiler_printer `rescript;
Js_implementation.implementation
~parser:(Res_driver.parse_implementation ~ignoreParseErrors:!Clflags.ignore_parse_errors)
~parser:(Res_driver.parse_implementation ~ignore_parse_errors:!Clflags.ignore_parse_errors)
ppf sourcefile
| Resi ->
let sourcefile = set_abs_input_name sourcefile in
setup_compiler_printer `rescript;
Js_implementation.interface
~parser:(Res_driver.parse_interface ~ignoreParseErrors:!Clflags.ignore_parse_errors)
~parser:(Res_driver.parse_interface ~ignore_parse_errors:!Clflags.ignore_parse_errors)
ppf sourcefile
| Intf_ast
->
Expand Down Expand Up @@ -113,32 +113,32 @@ let reprint_source_file sourcefile =
let sourcefile = set_abs_input_name sourcefile in
let res = match kind with
| Res ->
let parseResult =
Res_driver.parsingEngine.parseImplementation ~forPrinter:true ~filename:sourcefile
let parse_result =
Res_driver.parsing_engine.parse_implementation ~for_printer:true ~filename:sourcefile
in
if parseResult.invalid then (
Res_diagnostics.printReport parseResult.diagnostics parseResult.source;
if parse_result.invalid then (
Res_diagnostics.print_report parse_result.diagnostics parse_result.source;
exit 1
);
Res_compmisc.init_path ();
parseResult.parsetree
parse_result.parsetree
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Ml
|> Ppx_entry.rewrite_implementation
|> Res_printer.printImplementation ~width:100 ~comments:parseResult.comments
|> Res_printer.print_implementation ~width:100 ~comments:parse_result.comments
|> print_endline
| Resi ->
let parseResult =
Res_driver.parsingEngine.parseInterface ~forPrinter:true ~filename:sourcefile
let parse_result =
Res_driver.parsing_engine.parse_interface ~for_printer:true ~filename:sourcefile
in
if parseResult.invalid then (
Res_diagnostics.printReport parseResult.diagnostics parseResult.source;
if parse_result.invalid then (
Res_diagnostics.print_report parse_result.diagnostics parse_result.source;
exit 1
);
Res_compmisc.init_path ();
parseResult.parsetree
parse_result.parsetree
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Mli
|> Ppx_entry.rewrite_signature
|> Res_printer.printInterface ~width:100 ~comments:parseResult.comments
|> Res_printer.print_interface ~width:100 ~comments:parse_result.comments
|> print_endline
| _
->
Expand Down Expand Up @@ -198,7 +198,7 @@ let format_file input =
| Ml | Mli -> `ml
| Res | Resi -> `res
| _ -> Bsc_args.bad_arg ("don't know what to do with " ^ input) in
let formatted = Res_multi_printer.print ~ignoreParseErrors:!Clflags.ignore_parse_errors syntax ~input in
let formatted = Res_multi_printer.print ~ignore_parse_errors:!Clflags.ignore_parse_errors syntax ~input in
match !Clflags.output_name with
| None ->
output_string stdout formatted
Expand Down Expand Up @@ -293,11 +293,11 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
"*internal* Set jsx version";

"-bs-jsx-module", string_call (fun i ->
let isGeneric = match i |> String.lowercase_ascii with
let is_generic = match i |> String.lowercase_ascii with
| "react" -> false
| _ -> true in
Js_config.jsx_module := Js_config.jsx_module_of_string i;
if isGeneric then (
if is_generic then (
Js_config.jsx_mode := Automatic;
Js_config.jsx_version := Some Jsx_v4
)),
Expand Down
6 changes: 3 additions & 3 deletions jscomp/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(** Browser is not set via command line only for internal use *)

type jsx_version = Jsx_v3 | Jsx_v4
type jsx_module = React | Generic of {moduleName: string}
type jsx_module = React | Generic of {module_name: string}
type jsx_mode = Classic | Automatic

let no_version_header = ref false
Expand Down Expand Up @@ -63,7 +63,7 @@ let int_of_jsx_version = function

let string_of_jsx_module = function
| React -> "react"
| Generic {moduleName} -> moduleName
| Generic {module_name} -> module_name

let string_of_jsx_mode = function
| Classic -> "classic"
Expand All @@ -76,7 +76,7 @@ let jsx_version_of_int = function

let jsx_module_of_string = function
| "react" -> React
| moduleName -> Generic {moduleName}
| module_name -> Generic {module_name}

let jsx_mode_of_string = function
| "classic" -> Classic
Expand Down
2 changes: 1 addition & 1 deletion jscomp/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

type jsx_version = Jsx_v3 | Jsx_v4
type jsx_module = React | Generic of {moduleName: string}
type jsx_module = React | Generic of {module_name: string}
type jsx_mode = Classic | Automatic

(* val get_packages_info :
Expand Down
12 changes: 6 additions & 6 deletions jscomp/common/pattern_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ let mkpat desc = Ast_helper.Pat.mk desc
let untype typed =
let rec loop pat =
match pat.pat_desc with
| Tpat_or (p1, { pat_desc = Tpat_or (p2, p3, rI) }, rO) ->
| Tpat_or (p1, { pat_desc = Tpat_or (p2, p3, r_i) }, r_o) ->
(* Turn A | (B | C) into (A | B) | C for pretty printing without parens *)
let newInner = { pat with pat_desc = Tpat_or (p1, p2, rI) } in
let newOuter = { pat with pat_desc = Tpat_or (newInner, p3, rO) } in
loop newOuter
let new_inner = { pat with pat_desc = Tpat_or (p1, p2, r_i) } in
let new_outer = { pat with pat_desc = Tpat_or (new_inner, p3, r_o) } in
loop new_outer
| Tpat_or (pa, pb, _) -> mkpat (Ppat_or (loop pa, loop pb))
| Tpat_any | Tpat_var _ -> mkpat Ppat_any
| Tpat_constant c -> mkpat (Ppat_constant (Untypeast.constant c))
Expand Down Expand Up @@ -44,5 +44,5 @@ let untype typed =

let print_pattern typed =
let pat = untype typed in
let doc = Res_printer.printPattern pat Res_comments_table.empty in
Res_doc.toString ~width:80 doc
let doc = Res_printer.print_pattern pat Res_comments_table.empty in
Res_doc.to_string ~width:80 doc
2 changes: 1 addition & 1 deletion jscomp/core/bs_conditional_initial.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let setup_env () =

Rescript_cpp.replace_directive_bool "BS" true;
Rescript_cpp.replace_directive_bool "JS" true;
Printtyp.print_res_poly_identifier := Res_printer.polyVarIdentToString;
Printtyp.print_res_poly_identifier := Res_printer.polyvar_ident_to_string;
Rescript_cpp.replace_directive_string "BS_VERSION" Bs_version.version
(*; Switch.cut := 100*) (* tweakable but not very useful *)

Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/j.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ and expression_desc =
*)
| Number of number
| Object of property_map
| Undefined of {isUnit: bool}
| Undefined of {is_unit: bool}
| Null
| Await of expression

Expand Down
42 changes: 21 additions & 21 deletions jscomp/core/js_cmj_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,57 +104,57 @@ let to_file name ~check_exists (v : t) =
output_string oc s;
close_out oc)

let keyComp (a : string) b = Map_string.compare_key a b.name
let key_comp (a : string) b = Map_string.compare_key a b.name

let not_found key =
{ name = key; arity = single_na; persistent_closed_lambda = None }

let get_result midVal =
match midVal.persistent_closed_lambda with
let get_result mid_val =
match mid_val.persistent_closed_lambda with
| Some
(Lconst
(Const_js_null | Const_js_undefined _ | Const_js_true | Const_js_false))
| None ->
midVal
mid_val
| Some _ ->
if !Js_config.cross_module_inline then midVal
else { midVal with persistent_closed_lambda = None }
if !Js_config.cross_module_inline then mid_val
else { mid_val with persistent_closed_lambda = None }

let rec binarySearchAux arr lo hi (key : string) =
let rec binary_search_aux arr lo hi (key : string) =
let mid = (lo + hi) / 2 in
let midVal = Array.unsafe_get arr mid in
let c = keyComp key midVal in
if c = 0 then get_result midVal
let mid_val = Array.unsafe_get arr mid in
let c = key_comp key mid_val in
if c = 0 then get_result mid_val
else if c < 0 then
(* a[lo] =< key < a[mid] <= a[hi] *)
if hi = mid then
let loVal = Array.unsafe_get arr lo in
if loVal.name = key then get_result loVal else not_found key
else binarySearchAux arr lo mid key
let lo_val = Array.unsafe_get arr lo in
if lo_val.name = key then get_result lo_val else not_found key
else binary_search_aux arr lo mid key
else if (* a[lo] =< a[mid] < key <= a[hi] *)
lo = mid then
let hiVal = Array.unsafe_get arr hi in
if hiVal.name = key then get_result hiVal else not_found key
else binarySearchAux arr mid hi key
let hi_val = Array.unsafe_get arr hi in
if hi_val.name = key then get_result hi_val else not_found key
else binary_search_aux arr mid hi key

let binarySearch (sorted : keyed_cmj_values) (key : string) : keyed_cmj_value =
let binary_search (sorted : keyed_cmj_values) (key : string) : keyed_cmj_value =
let len = Array.length sorted in
if len = 0 then not_found key
else
let lo = Array.unsafe_get sorted 0 in
let c = keyComp key lo in
let c = key_comp key lo in
if c < 0 then not_found key
else
let hi = Array.unsafe_get sorted (len - 1) in
let c2 = keyComp key hi in
if c2 > 0 then not_found key else binarySearchAux sorted 0 (len - 1) key
let c2 = key_comp key hi in
if c2 > 0 then not_found key else binary_search_aux sorted 0 (len - 1) key

(* FIXME: better error message when ocamldep
get self-cycle
*)
let query_by_name (cmj_table : t) name : keyed_cmj_value =
let values = cmj_table.values in
binarySearch values name
binary_search values name

type path = string

Expand Down
10 changes: 5 additions & 5 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
params body env
| _ ->
let el = match el with
| [e] when e.expression_desc = Undefined {isUnit = true} ->
| [e] when e.expression_desc = Undefined {is_unit = true} ->
(* omit passing undefined when the call is f() *)
[]
| _ ->
Expand All @@ -548,8 +548,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
P.string f L.null;
comma_sp f;
expression ~level:1 cxt f el))
| Tagged_template (callExpr, stringArgs, valueArgs) ->
let cxt = expression cxt ~level f callExpr in
| Tagged_template (call_expr, string_args, value_args) ->
let cxt = expression cxt ~level f call_expr in
P.string f "`";
let rec aux cxt xs ys = match xs, ys with
| [], [] -> ()
Expand All @@ -563,14 +563,14 @@ and expression_desc cxt ~(level : int) f x : cxt =
aux cxt x_rest y_rest
| _ -> assert false
in
aux cxt stringArgs valueArgs;
aux cxt string_args value_args;
P.string f "`";
cxt
| String_index (a, b) ->
P.group f 1 (fun _ ->
let cxt = expression ~level:15 cxt f a in
P.string f L.dot;
P.string f L.codePointAt;
P.string f L.code_point_at;
(* FIXME: use code_point_at *)
P.paren_group f 1 (fun _ -> expression ~level:0 cxt f b))
| Str { delim; txt } ->
Expand Down
22 changes: 11 additions & 11 deletions jscomp/core/js_dump_import_export.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module L = Js_dump_lit

let default_export = "default"

let esModule = ("__esModule", "true")
let es_module = ("__esModule", "true")
(* Exports printer *)

let rev_iter_inter lst f inter =
Expand All @@ -50,7 +50,7 @@ let exports cxt f (idents : Ident.t list) =
( cxt,
if id_name = default_export then
(* TODO check how it will affect AMDJS*)
esModule :: (default_export, str) :: acc
es_module :: (default_export, str) :: acc
else (s, str) :: acc ))
in
P.at_least_two_lines f;
Expand Down Expand Up @@ -124,23 +124,23 @@ let requires require_lit cxt f (modules : (Ident.t * string * bool) list) =
P.newline f);
outer_cxt

let dumpImportAttributes f (importAttributes : External_ffi_types.import_attributes option) =
match importAttributes with
let dump_import_attributes f (import_attributes : External_ffi_types.import_attributes option) =
match import_attributes with
| None -> ()
| Some importAttributes ->
| Some import_attributes ->
P.space f;
P.string f "with";
P.space f;
let total = Hashtbl.length importAttributes in
let total = Hashtbl.length import_attributes in
let idx = ref 1 in
P.brace_group f 0 (
fun _ ->
importAttributes |> Hashtbl.iter(fun key value ->
import_attributes |> Hashtbl.iter(fun key value ->
Js_dump_string.pp_string f key;
P.string f L.colon_space;
Js_dump_string.pp_string f value;
let shouldAddComma = !idx < total in
if shouldAddComma then (
let should_add_comma = !idx < total in
if should_add_comma then (
P.string f L.comma;
P.space f
);
Expand All @@ -166,7 +166,7 @@ let imports cxt f (modules : (Ident.t * string * bool * External_ffi_types.impor
P.string f L.from;
P.space f;
Js_dump_string.pp_string f file;
dumpImportAttributes f import_attributes)
dump_import_attributes f import_attributes)
else (
P.string f L.star;
P.space f;
Expand All @@ -178,7 +178,7 @@ let imports cxt f (modules : (Ident.t * string * bool * External_ffi_types.impor
P.string f L.from;
P.space f;
Js_dump_string.pp_string f file;
dumpImportAttributes f import_attributes);
dump_import_attributes f import_attributes);
P.string f L.semi;
P.newline f);
outer_cxt
4 changes: 2 additions & 2 deletions jscomp/core/js_dump_lit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let default = "default"

let length = "length"

let codePointAt = "codePointAt"
let code_point_at = "codePointAt"

let new_ = "new"

Expand Down Expand Up @@ -136,7 +136,7 @@ let undefined = "undefined"

let string_cap = "String"

let fromCharcode = "fromCharCode"
let from_charcode = "fromCharCode"

let eq = "="

Expand Down
Loading
Loading