@@ -6906,7 +6906,7 @@ val equal : Ident.t -> Ident.t -> bool
69066906end = struct
69076907#1 "ext_ident.ml"
69086908(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
6909- *
6909+ *
69106910 * This program is free software: you can redistribute it and/or modify
69116911 * it under the terms of the GNU Lesser General Public License as published by
69126912 * the Free Software Foundation, either version 3 of the License, or
@@ -6924,7 +6924,7 @@ end = struct
69246924 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69256925 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69266926 * GNU Lesser General Public License for more details.
6927- *
6927+ *
69286928 * You should have received a copy of the GNU Lesser General Public License
69296929 * along with this program; if not, write to the Free Software
69306930 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
@@ -6948,32 +6948,32 @@ let js_flag = 0b1_000 (* check with ocaml compiler *)
69486948*)
69496949let js_object_flag = 0b100_000 (* javascript object flags *)
69506950
6951- let is_js (i : Ident.t) =
6952- i.flags land js_flag <> 0
6951+ let is_js (i : Ident.t) =
6952+ i.flags land js_flag <> 0
69536953
6954- let is_js_or_global (i : Ident.t) =
6955- i.flags land (8 lor 1) <> 0
6954+ let is_js_or_global (i : Ident.t) =
6955+ i.flags land (8 lor 1) <> 0
69566956
69576957
6958- let is_js_object (i : Ident.t) =
6959- i.flags land js_object_flag <> 0
6958+ let is_js_object (i : Ident.t) =
6959+ i.flags land js_object_flag <> 0
69606960
6961- let make_js_object (i : Ident.t) =
6962- i.flags <- i.flags lor js_object_flag
6961+ let make_js_object (i : Ident.t) =
6962+ i.flags <- i.flags lor js_object_flag
69636963
69646964(* It's a js function hard coded by js api, so when printing,
6965- it should preserve the name
6965+ it should preserve the name
69666966*)
6967- let create_js (name : string) : Ident.t =
6967+ let create_js (name : string) : Ident.t =
69686968 { name = name; flags = js_flag ; stamp = 0}
69696969
69706970let create = Ident.create
69716971
69726972(* FIXME: no need for `$' operator *)
6973- let create_tmp ?(name=Literals.tmp) () = create name
6973+ let create_tmp ?(name=Literals.tmp) () = create name
69746974
69756975
6976- let js_module_table : Ident.t String_hashtbl.t = String_hashtbl.create 31
6976+ let js_module_table : Ident.t String_hashtbl.t = String_hashtbl.create 31
69776977
69786978(* This is for a js exeternal module, we can change it when printing
69796979 for example
@@ -6984,25 +6984,25 @@ let js_module_table : Ident.t String_hashtbl.t = String_hashtbl.create 31
69846984
69856985 Given a name, if duplicated, they should have the same id
69866986*)
6987- let create_js_module (name : string) : Ident.t =
6988- let name =
6989- String.concat "" @@ Ext_list.map (Ext_string.capitalize_ascii ) @@
6987+ let create_js_module (name : string) : Ident.t =
6988+ let name =
6989+ String.concat "" @@ Ext_list.map (Ext_string.capitalize_ascii ) @@
69906990 Ext_string.split name '-' in
69916991 (* TODO: if we do such transformation, we should avoid collision for example:
6992- react-dom
6992+ react-dom
69936993 react--dom
69946994 check collision later
69956995 *)
6996- match String_hashtbl.find_exn js_module_table name with
6997- | exception Not_found ->
6996+ match String_hashtbl.find_exn js_module_table name with
6997+ | exception Not_found ->
69986998 let ans = Ident.create name in
69996999 (* let ans = { v with flags = js_module_flag} in *)
70007000 String_hashtbl.add js_module_table name ans;
70017001 ans
7002- | v -> (* v *) Ident.rename v
7002+ | v -> (* v *) Ident.rename v
70037003
70047004
7005- let reserved_words =
7005+ let reserved_words =
70067006 [|
70077007 (* keywork *)
70087008 "break";
@@ -7039,7 +7039,7 @@ let reserved_words =
70397039 (* also reserved in ECMAScript 3 *)
70407040 "abstract"; "boolean"; "byte"; "char"; "const"; "double";
70417041 "final"; "float"; "goto"; "int"; "long"; "native"; "short";
7042- "synchronized";
7042+ "synchronized";
70437043 (* "throws"; *)
70447044 (* seems to be fine, like nodejs [assert.throws] *)
70457045 "transient"; "volatile";
@@ -7064,7 +7064,7 @@ let reserved_words =
70647064 "String";
70657065 "Boolean";
70667066 "Number";
7067-
7067+ "Buffer"; (* Node *)
70687068 "Map"; (* es6*)
70697069 "Set";
70707070
@@ -7091,7 +7091,7 @@ let reserved_words =
70917091 "parseFloat";
70927092 "parseInt";
70937093
7094- (** reserved for commonjs and NodeJS globals*)
7094+ (** reserved for commonjs and NodeJS globals*)
70957095 "require";
70967096 "exports";
70977097 "module";
@@ -7110,36 +7110,36 @@ let reserved_words =
71107110 "__esModule"
71117111 |]
71127112
7113- let reserved_map =
7114- let len = Array.length reserved_words in
7113+ let reserved_map =
7114+ let len = Array.length reserved_words in
71157115 let set = String_hash_set.create 1024 in (* large hash set for perfect hashing *)
7116- for i = 0 to len - 1 do
7116+ for i = 0 to len - 1 do
71177117 String_hash_set.add set reserved_words.(i);
71187118 done ;
7119- set
7119+ set
71207120
71217121
71227122
7123- exception Not_normal_letter of int
7124- let name_mangle name =
7123+ exception Not_normal_letter of int
7124+ let name_mangle name =
71257125
71267126 let len = String.length name in
71277127 try
7128- for i = 0 to len - 1 do
7129- match String.unsafe_get name i with
7128+ for i = 0 to len - 1 do
7129+ match String.unsafe_get name i with
71307130 | 'a' .. 'z' | 'A' .. 'Z'
71317131 | '0' .. '9' | '_' | '$'
71327132 -> ()
71337133 | _ -> raise (Not_normal_letter i)
71347134 done;
71357135 name (* Normal letter *)
7136- with
7136+ with
71377137 | Not_normal_letter 0 ->
71387138
7139- let buffer = Buffer.create len in
7140- for j = 0 to len - 1 do
7139+ let buffer = Buffer.create len in
7140+ for j = 0 to len - 1 do
71417141 let c = String.unsafe_get name j in
7142- match c with
7142+ match c with
71437143 | '*' -> Buffer.add_string buffer "$star"
71447144 | '\'' -> Buffer.add_string buffer "$prime"
71457145 | '!' -> Buffer.add_string buffer "$bang"
@@ -7157,25 +7157,25 @@ let name_mangle name =
71577157 | '~' -> Buffer.add_string buffer "$tilde"
71587158 | '#' -> Buffer.add_string buffer "$hash"
71597159 | ':' -> Buffer.add_string buffer "$colon"
7160- | 'a'..'z' | 'A'..'Z'| '_'
7160+ | 'a'..'z' | 'A'..'Z'| '_'
71617161 | '$'
71627162 | '0'..'9'-> Buffer.add_char buffer c
71637163 | _ -> Buffer.add_string buffer "$unknown"
71647164 done; Buffer.contents buffer
7165- | Not_normal_letter i ->
7165+ | Not_normal_letter i ->
71667166 String.sub name 0 i ^
7167- (let buffer = Buffer.create len in
7168- for j = i to len - 1 do
7167+ (let buffer = Buffer.create len in
7168+ for j = i to len - 1 do
71697169 let c = String.unsafe_get name j in
7170- match c with
7170+ match c with
71717171 | '*' -> Buffer.add_string buffer "$star"
71727172 | '\'' -> Buffer.add_string buffer "$prime"
71737173 | '!' -> Buffer.add_string buffer "$bang"
71747174 | '>' -> Buffer.add_string buffer "$great"
71757175 | '<' -> Buffer.add_string buffer "$less"
71767176 | '=' -> Buffer.add_string buffer "$eq"
71777177 | '+' -> Buffer.add_string buffer "$plus"
7178- | '-' -> Buffer.add_string buffer "$"
7178+ | '-' -> Buffer.add_string buffer "$"
71797179 (* Note ocaml compiler also has [self-] *)
71807180 | '@' -> Buffer.add_string buffer "$at"
71817181 | '^' -> Buffer.add_string buffer "$caret"
@@ -7187,7 +7187,7 @@ let name_mangle name =
71877187 | '#' -> Buffer.add_string buffer "$hash"
71887188 | ':' -> Buffer.add_string buffer "$colon"
71897189 | '$' -> Buffer.add_string buffer "$dollar"
7190- | 'a'..'z' | 'A'..'Z'| '_'
7190+ | 'a'..'z' | 'A'..'Z'| '_'
71917191 | '0'..'9'-> Buffer.add_char buffer c
71927192 | _ -> Buffer.add_string buffer "$unknown"
71937193 done; Buffer.contents buffer)
@@ -7198,41 +7198,41 @@ let name_mangle name =
71987198 - : string = "$caret"
71997199 ]}
72007200 [convert name] if [name] is a js keyword,add "$$"
7201- otherwise do the name mangling to make sure ocaml identifier it is
7201+ otherwise do the name mangling to make sure ocaml identifier it is
72027202 a valid js identifier
72037203*)
7204- let convert (name : string) =
7205- if String_hash_set.mem reserved_map name then "$$" ^ name
7206- else name_mangle name
7204+ let convert (name : string) =
7205+ if String_hash_set.mem reserved_map name then "$$" ^ name
7206+ else name_mangle name
72077207
72087208(** keyword could be used in property *)
72097209
7210- (* It is currently made a persistent ident to avoid fresh ids
7210+ (* It is currently made a persistent ident to avoid fresh ids
72117211 which would result in different signature files
72127212 - other solution: use lazy values
72137213*)
72147214let make_unused () = create "_"
72157215
72167216
72177217
7218- let reset () =
7218+ let reset () =
72197219 String_hashtbl.clear js_module_table
72207220
72217221
72227222let undefined = create_js "undefined"
72237223let nil = create_js "null"
72247224
7225- (* Has to be total order, [x < y]
7225+ (* Has to be total order, [x < y]
72267226 and [x > y] should be consistent
7227- flags are not relevant here
7227+ flags are not relevant here
72287228*)
7229- let compare (x : Ident.t ) ( y : Ident.t) =
7229+ let compare (x : Ident.t ) ( y : Ident.t) =
72307230 let u = x.stamp - y.stamp in
7231- if u = 0 then
7232- Ext_string.compare x.name y.name
7233- else u
7231+ if u = 0 then
7232+ Ext_string.compare x.name y.name
7233+ else u
72347234
7235- let equal ( x : Ident.t) ( y : Ident.t) =
7235+ let equal ( x : Ident.t) ( y : Ident.t) =
72367236 if x.stamp <> 0 then x.stamp = y.stamp
72377237 else y.stamp = 0 && x.name = y.name
72387238
0 commit comments