diff --git a/jscomp/gentype/Runtime.ml b/jscomp/gentype/Runtime.ml
index 102ef3538e..f3085508c7 100644
--- a/jscomp/gentype/Runtime.ml
+++ b/jscomp/gentype/Runtime.ml
@@ -46,94 +46,3 @@ let isMutableObjectField name =
let checkMutableObjectField ~previousName ~name = previousName = name ^ "#="
let default = "$$default"
-
-module Mangle = struct
- let keywords =
- [|
- "and";
- "as";
- "assert";
- "begin";
- "class";
- "constraint";
- "do";
- "done";
- "downto";
- "else";
- "end";
- "exception";
- "external";
- "false";
- "for";
- "fun";
- "function";
- "functor";
- "if";
- "in";
- "include";
- "inherit";
- "initializer";
- "lazy";
- "let";
- "match";
- "method";
- "module";
- "mutable";
- "new";
- "nonrec";
- "object";
- "of";
- "open";
- "or";
- "private";
- "rec";
- "sig";
- "struct";
- "then";
- "to";
- "true";
- "try";
- "type";
- "val";
- "virtual";
- "when";
- "while";
- "with";
- "mod";
- "land";
- "lor";
- "lxor";
- "lsl";
- "lsr";
- "asr";
- |]
-
- let table = Hashtbl.create (keywords |> Array.length);;
-
- keywords |> Array.iter (fun x -> Hashtbl.add table ("_" ^ x) x)
-
- (**
- Apply ReScript's mangling rules for object field names:
- Remove trailing "__" if present.
- Otherwise remove leading "_" when followed by an uppercase letter, or keyword.
- *)
- let translate x =
- let len = x |> String.length in
- if
- len > 2
- && (x.[len - 1] [@doesNotRaise]) = '_'
- && (x.[len - 2] [@doesNotRaise]) = '_'
- then (* "foo__" -> "foo" *) String.sub x 0 (len - 2) [@doesNotRaise]
- else if len > 1 && (x.[0] [@doesNotRaise]) = '_' then
- if (x.[1] [@doesNotRaise]) >= 'A' && (x.[1] [@doesNotRaise]) <= 'Z' then
- (* "_Uppercase" => "Uppercase"s *)
- String.sub x 1 (len - 1) [@doesNotRaise]
- else
- (* "_rec" -> "rec" *)
- match Hashtbl.find table x with
- | y -> y
- | exception Not_found -> x
- else x
-end
-
-let mangleObjectField = Mangle.translate
diff --git a/jscomp/gentype/Runtime.mli b/jscomp/gentype/Runtime.mli
index 43867f5e35..f0fdf3e90b 100644
--- a/jscomp/gentype/Runtime.mli
+++ b/jscomp/gentype/Runtime.mli
@@ -10,7 +10,6 @@ val default : string
val emitModuleAccessPath : config:Config.t -> moduleAccessPath -> string
val isMutableObjectField : string -> bool
-val mangleObjectField : string -> string
val newModuleItem : name:string -> moduleItem
val newRecordValue : unboxed:bool -> recordGen -> recordValue
val recordGen : unit -> recordGen
diff --git a/jscomp/gentype/TranslateCoreType.ml b/jscomp/gentype/TranslateCoreType.ml
index f467167c9c..be34ad0392 100644
--- a/jscomp/gentype/TranslateCoreType.ml
+++ b/jscomp/gentype/TranslateCoreType.ml
@@ -80,7 +80,7 @@ let rec translateArrowType ~config ~typeVarsGen ~noFunctionReturnDependencies
~revArgs:
(( Label
(match asLabel = "" with
- | true -> lbl |> Runtime.mangleObjectField
+ | true -> lbl
| false -> asLabel),
type1 )
:: revArgs)
@@ -92,8 +92,7 @@ let rec translateArrowType ~config ~typeVarsGen ~noFunctionReturnDependencies
coreType2
|> translateArrowType ~config ~typeVarsGen ~noFunctionReturnDependencies
~typeEnv ~revArgDeps:nextRevDeps
- ~revArgs:
- ((OptLabel (lbl |> Runtime.mangleObjectField), type1) :: revArgs))
+ ~revArgs:((OptLabel lbl, type1) :: revArgs))
| _ ->
let {dependencies; type_ = retType} =
coreType |> translateCoreType_ ~config ~typeVarsGen ~typeEnv
diff --git a/jscomp/gentype/TranslateTypeExprFromTypes.ml b/jscomp/gentype/TranslateTypeExprFromTypes.ml
index a0c563e409..486dda1ea7 100644
--- a/jscomp/gentype/TranslateTypeExprFromTypes.ml
+++ b/jscomp/gentype/TranslateTypeExprFromTypes.ml
@@ -44,7 +44,6 @@ let translateObjType closedFlag fieldsTranslations =
| Option t -> (Optional, t)
| _ -> (Mandatory, t)
in
- let name = name |> Runtime.mangleObjectField in
{
mutable_;
nameJS = name;
@@ -298,8 +297,7 @@ let rec translateArrowType ~config ~typeVarsGen ~typeEnv ~revArgDeps ~revArgs
typeExpr2
|> translateArrowType ~config ~typeVarsGen ~typeEnv
~revArgDeps:nextRevDeps
- ~revArgs:
- ((Label (lbl |> Runtime.mangleObjectField), type1) :: revArgs)
+ ~revArgs:((Label lbl, type1) :: revArgs)
| Some (lbl, t1) ->
let {dependencies; type_ = type1} =
t1 |> translateTypeExprFromTypes_ ~config ~typeVarsGen ~typeEnv
@@ -308,8 +306,7 @@ let rec translateArrowType ~config ~typeVarsGen ~typeEnv ~revArgDeps ~revArgs
typeExpr2
|> translateArrowType ~config ~typeVarsGen ~typeEnv
~revArgDeps:nextRevDeps
- ~revArgs:
- ((OptLabel (lbl |> Runtime.mangleObjectField), type1) :: revArgs))
+ ~revArgs:((OptLabel lbl, type1) :: revArgs))
| _ ->
let {dependencies; type_ = retType} =
typeExpr |> translateTypeExprFromTypes_ ~config ~typeVarsGen ~typeEnv
diff --git a/jscomp/gentype_tests/typescript-react-example/Makefile b/jscomp/gentype_tests/typescript-react-example/Makefile
index 2bb4e9b8a2..ebd7a84182 100644
--- a/jscomp/gentype_tests/typescript-react-example/Makefile
+++ b/jscomp/gentype_tests/typescript-react-example/Makefile
@@ -1,10 +1,9 @@
SHELL = /bin/bash
-node_modules/.bin/tsc:
+test:
npm install
-
-test: node_modules/.bin/tsc
npm run build
+ npm run tsc
clean:
rm -rf node_modules lib src/*.bs.js src/*.gen.tsx
diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json
index 5c0087119d..757e369ddd 100644
--- a/jscomp/gentype_tests/typescript-react-example/package-lock.json
+++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json
@@ -21,7 +21,7 @@
},
"../../..": {
"name": "rescript",
- "version": "11.0.0-beta.5",
+ "version": "11.0.0-rc.2",
"dev": true,
"hasInstallScript": true,
"license": "SEE LICENSE IN LICENSE",
diff --git a/jscomp/gentype_tests/typescript-react-example/src/Hooks.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Hooks.bs.js
index 75166fdf1f..7749eea179 100644
--- a/jscomp/gentype_tests/typescript-react-example/src/Hooks.bs.js
+++ b/jscomp/gentype_tests/typescript-react-example/src/Hooks.bs.js
@@ -103,8 +103,8 @@ function functionWithRenamedArgs(_to, _Type, cb) {
}
function Hooks$WithRename$componentWithRenamedArgs(Props) {
- var _to = Props.to;
- var _Type = Props.Type;
+ var _to = Props._to;
+ var _Type = Props._Type;
var cb = Props.cb;
Curry._1(cb, _to);
return _to.name + _Type.name;
diff --git a/jscomp/gentype_tests/typescript-react-example/src/Hooks.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Hooks.gen.tsx
index f4c0651a29..5fa19cd4c6 100644
--- a/jscomp/gentype_tests/typescript-react-example/src/Hooks.gen.tsx
+++ b/jscomp/gentype_tests/typescript-react-example/src/Hooks.gen.tsx
@@ -14,7 +14,7 @@ import type {TypedArray2_Uint8Array_t as Js_TypedArray2_Uint8Array_t} from '../s
export type vehicle = { readonly name: string };
// tslint:disable-next-line:interface-over-type-literal
-export type cb = (_1:{ readonly to: vehicle }) => void;
+export type cb = (_1:{ readonly _to: vehicle }) => void;
// tslint:disable-next-line:interface-over-type-literal
export type r = { readonly x: string };
@@ -72,21 +72,21 @@ export type NoProps_make_Props = {};
export const NoProps_make: React.ComponentType<{}> = HooksBS.NoProps.make;
export const functionWithRenamedArgs: (_1:{
- readonly to: vehicle;
- readonly Type: vehicle;
+ readonly _to: vehicle;
+ readonly _Type: vehicle;
readonly cb: cb
}) => string = HooksBS.functionWithRenamedArgs;
// tslint:disable-next-line:interface-over-type-literal
export type WithRename_componentWithRenamedArgs_Props = {
- readonly Type: vehicle;
- readonly to: vehicle;
+ readonly _Type: vehicle;
+ readonly _to: vehicle;
readonly cb: cb
};
export const WithRename_componentWithRenamedArgs: React.ComponentType<{
- readonly Type: vehicle;
- readonly to: vehicle;
+ readonly _Type: vehicle;
+ readonly _to: vehicle;
readonly cb: cb
}> = HooksBS.WithRename.componentWithRenamedArgs;
@@ -153,8 +153,8 @@ export const Inner: {
export const RenderPropRequiresConversion: { make: React.ComponentType<{ readonly renderVehicle: React.ComponentType<{ readonly number: number; readonly vehicle: vehicle }> }> } = HooksBS.RenderPropRequiresConversion
export const WithRename: { componentWithRenamedArgs: React.ComponentType<{
- readonly Type: vehicle;
- readonly to: vehicle;
+ readonly _Type: vehicle;
+ readonly _to: vehicle;
readonly cb: cb
}> } = HooksBS.WithRename
diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.bs.js b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.bs.js
index f37611892f..ef7c09ca98 100644
--- a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.bs.js
+++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.bs.js
@@ -37,19 +37,19 @@ function testConvertLocation(x) {
}
var testMarshalFields = {
- rec: "rec",
+ _rec: "rec",
_switch: "_switch",
switch: "switch",
__: "__",
- _: "_",
- foo: "foo",
- _foo: "_foo",
- Uppercase: "Uppercase",
- _Uppercase: "_Uppercase"
+ ___: "_",
+ foo__: "foo",
+ _foo__: "_foo",
+ _Uppercase: "Uppercase",
+ _Uppercase__: "_Uppercase"
};
function setMatch(x) {
- x.match = 34;
+ x._match = 34;
}
function testInstantiateTypeParameter(x) {
diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx
index 3d4974ee56..7f7da2be5a 100644
--- a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx
+++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx
@@ -67,19 +67,19 @@ export type decorator = (_1:a) => b;
// tslint:disable-next-line:interface-over-type-literal
export type marshalFields = {
- readonly rec: string;
+ readonly _rec: string;
readonly _switch: string;
readonly switch: string;
readonly __: string;
- readonly _: string;
- readonly foo: string;
- readonly _foo: string;
- readonly Uppercase: string;
- readonly _Uppercase: string
+ readonly ___: string;
+ readonly foo__: string;
+ readonly _foo__: string;
+ readonly _Uppercase: string;
+ readonly _Uppercase__: string
};
// tslint:disable-next-line:interface-over-type-literal
-export type marshalMutableField = { match: number };
+export type marshalMutableField = { _match: number };
// tslint:disable-next-line:interface-over-type-literal
export type ocaml_array = a[];