Skip to content

Commit 900daf6

Browse files
committed
Compiler: improve implem of J.is_ident
1 parent 8398222 commit 900daf6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler/javascript.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ let string_of_number v =
205205
then s2
206206
else Printf.sprintf "%.18g" v
207207

208+
exception Not_an_ident
208209
let is_ident =
209210
let l = Array.init 256 (fun i ->
210211
let c = Char.chr i in
@@ -218,10 +219,12 @@ let is_ident =
218219
try
219220
for i = 0 to String.length s - 1 do
220221
let code = l.(Char.code(s.[i])) in
221-
if i = 0 then assert (code = 1) else assert (code >= 1)
222+
if i = 0
223+
then (if code <> 1 then raise Not_an_ident)
224+
else (if code < 1 then raise Not_an_ident)
222225
done;
223226
true
224-
with _ -> false
227+
with Not_an_ident -> false
225228

226229
module IdentSet = Set.Make(struct type t = ident let compare = compare_ident end)
227230
module IdentMap = Map.Make(struct type t = ident let compare = compare_ident end)

0 commit comments

Comments
 (0)