Browse Source

Replace underscores to prevent collisions in flat paths.

Bruno Garcia 12 years ago
parent
commit
59784999d2
1 changed files with 9 additions and 1 deletions
  1. 9 1
      genjs.ml

+ 9 - 1
genjs.ml

@@ -60,7 +60,15 @@ type ctx = {
 }
 
 let dot_path = Ast.s_type_path
-let flat_path (p,s) = match p with [] -> s | _ -> String.concat "_" p ^ "_" ^ s
+
+let flat_path (p,s) =
+	(* Replace _ with _$ in paths to prevent name collisions. *)
+	let escape str = String.concat "_$" (ExtString.String.nsplit str "_") in
+
+	match p with
+	| [] -> escape s
+	| _ -> String.concat "_" (List.map escape p) ^ "_" ^ (escape s)
+
 let s_path ctx = if ctx.js_flatten then flat_path else dot_path
 
 let kwds =