Skip to content

Commit

Permalink
relax name conversion rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed Jun 21, 2016
1 parent db73a51 commit 0459c2b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
11 changes: 6 additions & 5 deletions jscomp/ext/ext_ident.ml
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,10 @@ let convert keyword (name : string) =
let len = String.length name in
try
for i = 0 to len - 1 do
let c = String.unsafe_get name i in
if
not ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c = '_' || c = '$' )
then
raise (E.Not_normal_letter i)
match String.unsafe_get name i with
| 'a' .. 'z' | 'A' .. 'Z'
| '0' .. '9' | '_' | '$' -> ()
| _ -> raise (E.Not_normal_letter i)
done;
name
with E.Not_normal_letter i ->
Expand Down Expand Up @@ -244,6 +243,8 @@ let convert keyword (name : string) =
| _ -> Buffer.add_string buffer "$unknown"
done; Buffer.contents buffer)

let property_no_need_convert s =
s == convert false s

(* It is currently made a persistent ident to avoid fresh ids
which would result in different signature files
Expand Down
2 changes: 2 additions & 0 deletions jscomp/ext/ext_ident.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ val is_unused_ident : Ident.t -> bool
if name is not converted, the reference should be equal
*)
val convert : bool -> string -> string
val property_no_need_convert : string -> bool

val undefined : Ident.t
val is_js_or_global : Ident.t -> bool
val nil : Ident.t
42 changes: 18 additions & 24 deletions jscomp/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ let pp_string f ?(quote='"') ?(utf=false) s =
;;

let property_string f s =
let s' = Ext_ident.convert false s in
if s == s' then
if Ext_ident.property_no_need_convert s then
P.string f s
else
pp_string f ~utf:true ~quote:(best_string_quote s) s
Expand Down Expand Up @@ -930,29 +929,24 @@ and
if l > 15 then P.paren_group f 1 action else action ()

| Dot (e, s,normal) ->
if normal then
begin
let action () =
let cxt = expression 15 cxt f e in
let action () =
let cxt = expression 15 cxt f e in
if Ext_ident.property_no_need_convert s then
begin
P.string f L.dot;
P.string f (Ext_ident.convert true s);
(* See [Js_program_loader.obj_of_exports]
maybe in the ast level we should have
refer and export
*)
cxt in
if l > 15 then P.paren_group f 1 action else action ()
end
else begin
let action () =
P.group f 1 @@ fun _ ->
let cxt = expression 15 cxt f e in
(P.bracket_group f 1 @@ fun _ ->
pp_string f (* ~utf:(kind = `Utf8) *) ~quote:( best_string_quote s) s);
cxt
in
if l > 15 then P.paren_group f 1 action else action ()
end
P.string f s;
end
else
begin
P.bracket_group f 1 @@ fun _ ->
pp_string f (* ~utf:(kind = `Utf8) *) ~quote:( best_string_quote s) s
end;
(* See [Js_program_loader.obj_of_exports]
maybe in the ast level we should have
refer and export
*)
cxt in
if l > 15 then P.paren_group f 1 action else action ()

| New (e, el) ->
let action () =
Expand Down

0 comments on commit 0459c2b

Please sign in to comment.