Skip to content

Commit 5e5c65c

Browse files
author
Hongbo Zhang
committed
clean up and 0 length fix
1 parent 97b257f commit 5e5c65c

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

jscomp/lam_compile_external_call.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ let translate_ffi (ffi : Ast_external_attributes.ffi ) prim_name
251251

252252
let translate cxt
253253
({prim_name ; prim_native_name}
254-
: Ast_external_attributes.prim) args =
254+
: Primitive.description) args =
255255
if Ast_external_attributes.is_bs_external_prefix prim_native_name then
256256
begin
257257
match Ast_external_attributes.unsafe_from_string prim_native_name with

jscomp/syntax/ast_external_attributes.ml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type ffi =
7070
| Js_get_index
7171
| Js_set_index
7272

73-
type prim = Primitive.description
73+
7474

7575
let valid_js_char =
7676
let a = Array.init 256 (fun i ->
@@ -89,7 +89,7 @@ let valid_first_js_char =
8989
(** Approximation could be improved *)
9090
let valid_ident (s : string) =
9191
let len = String.length s in
92-
valid_js_char s.[0] && valid_first_js_char s.[0] &&
92+
len > 0 && valid_js_char s.[0] && valid_first_js_char s.[0] &&
9393
(let module E = struct exception E end in
9494
try
9595
for i = 1 to len - 1 do
@@ -100,21 +100,18 @@ let valid_ident (s : string) =
100100
with E.E -> false )
101101

102102
let valid_global_name ?loc txt =
103-
let error () =
104-
Location.raise_errorf ?loc "Not a valid name %s" txt in
105-
if txt = "" then
106-
error ()
107-
else
103+
if not (valid_ident txt) then
108104
let v = Ext_string.split_by ~keep_empty:true (fun x -> x = '.') txt in
109105
List.iter
110106
(fun s ->
111-
if not (valid_ident s) then error ()
107+
if not (valid_ident s) then
108+
Location.raise_errorf ?loc "Not a valid name %s" txt
112109
) v
113110

114111
let valid_method_name ?loc txt =
115-
let error () =
116-
Location.raise_errorf ?loc "Not a valid name %s" txt in
117-
if not (valid_ident txt) then error ()
112+
if not (valid_ident txt) then
113+
Location.raise_errorf ?loc "Not a valid name %s" txt
114+
118115

119116

120117
let check_external_module_name ?loc x =

jscomp/syntax/ast_external_attributes.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type t =
7474
| Bs of arg_kind list * arg_type * ffi
7575
| Normal
7676

77-
type prim = Primitive.description
77+
7878

7979

8080

0 commit comments

Comments
 (0)