diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fe1734c0ba..e9fa571287a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Fix unpacking first-class module in default argument of react component. https://github.com/rescript-lang/rescript/pull/8296 - Fix exception record field regression. https://github.com/rescript-lang/rescript/pull/8319 - Rewatch: ignore stale lock for unrelated process name. https://github.com/rescript-lang/rescript/pull/8316 +- Fix handling of exotic identifiers for let bindings in GenType. https://github.com/rescript-lang/rescript/pull/8315 #### :memo: Documentation diff --git a/compiler/gentype/TranslateSignature.ml b/compiler/gentype/TranslateSignature.ml index 0033ab1edb0..9271f41a90d 100644 --- a/compiler/gentype/TranslateSignature.ml +++ b/compiler/gentype/TranslateSignature.ml @@ -13,7 +13,7 @@ let translate_signature_value ~config ~output_file_relative ~resolver ~type_env (val_id, val_attributes |> Annotation.from_attributes ~config ~loc:val_loc) with | id, GenType -> - id |> Ident.name + id |> Ident.name |> Ext_ident.unwrap_uppercase_exotic |> Translation.translate_value ~attributes:val_attributes ~config ~doc_string:(Annotation.doc_string_from_attrs val_attributes) ~output_file_relative ~resolver ~type_env ~type_expr diff --git a/compiler/gentype/TranslateSignatureFromTypes.ml b/compiler/gentype/TranslateSignatureFromTypes.ml index 2a12d6e3505..8672a95c39a 100644 --- a/compiler/gentype/TranslateSignatureFromTypes.ml +++ b/compiler/gentype/TranslateSignatureFromTypes.ml @@ -72,7 +72,7 @@ and translate_signature_item_from_types ~config ~output_file_relative ~resolver |> translate_module_declaration_from_types ~config ~output_file_relative ~resolver ~type_env ~id | Types.Sig_value (id, {val_attributes; val_loc; val_type}) -> - let name = id |> Ident.name in + let name = id |> Ident.name |> Ext_ident.unwrap_uppercase_exotic in if !Debug.translation then Log_.item "Translate Sig Value %s\n" name; let module_item = Runtime.new_module_item ~name in type_env |> TypeEnv.update_module_item ~module_item; diff --git a/compiler/gentype/TranslateStructure.ml b/compiler/gentype/TranslateStructure.ml index 8e60259d681..f0f89f943a3 100644 --- a/compiler/gentype/TranslateStructure.ml +++ b/compiler/gentype/TranslateStructure.ml @@ -104,7 +104,7 @@ let translate_value_binding ~config ~output_file_relative ~resolver ~type_env {Typedtree.vb_attributes; vb_expr; vb_pat} : Translation.t = match vb_pat.pat_desc with | Tpat_var (id, _) | Tpat_alias ({pat_desc = Tpat_any}, id, _) -> - let name = id |> Ident.name in + let name = id |> Ident.name |> Ext_ident.unwrap_uppercase_exotic in if !Debug.translation then Log_.item "Translate Value Binding %s\n" name; let module_item = Runtime.new_module_item ~name in type_env |> TypeEnv.update_module_item ~module_item; @@ -113,7 +113,7 @@ let translate_value_binding ~config ~output_file_relative ~resolver ~type_env |> Annotation.from_attributes ~config ~loc:vb_pat.pat_loc = GenType then - id |> Ident.name + name |> Translation.translate_value ~attributes:vb_attributes ~config ~doc_string:(Annotation.doc_string_from_attrs vb_attributes) ~output_file_relative ~resolver ~type_env ~type_expr:vb_pat.pat_type diff --git a/tests/gentype_tests/typescript-react-example/src/EscapedNames.gen.tsx b/tests/gentype_tests/typescript-react-example/src/EscapedNames.gen.tsx index e4ade9ad948..64081ba15ef 100644 --- a/tests/gentype_tests/typescript-react-example/src/EscapedNames.gen.tsx +++ b/tests/gentype_tests/typescript-react-example/src/EscapedNames.gen.tsx @@ -20,4 +20,10 @@ export type record = { readonly UPPERCASE: number }; +export type props = {}; + export const myRecord: record = EscapedNamesJS.myRecord as any; + +export const Icon_Add: React.ComponentType<{}> = EscapedNamesJS.Icon_Add as any; + +export const SomeValue: string = EscapedNamesJS.SomeValue as any; diff --git a/tests/gentype_tests/typescript-react-example/src/EscapedNames.res b/tests/gentype_tests/typescript-react-example/src/EscapedNames.res index 9093f9ef49e..2f6d2416644 100644 --- a/tests/gentype_tests/typescript-react-example/src/EscapedNames.res +++ b/tests/gentype_tests/typescript-react-example/src/EscapedNames.res @@ -24,3 +24,12 @@ let myRecord = { \"Illegal-field name": 7, \"UPPERCASE": 100, } + +/* https://github.com/rescript-lang/rescript/issues/8312 */ +type props = {} +let make = (_: props) => React.null +@genType +let \"Icon_Add": props => React.element = make + +@genType +let \"SomeValue" = "hello" diff --git a/tests/gentype_tests/typescript-react-example/src/EscapedNames.res.js b/tests/gentype_tests/typescript-react-example/src/EscapedNames.res.js index 791308c9bda..a80ce5ec43b 100644 --- a/tests/gentype_tests/typescript-react-example/src/EscapedNames.res.js +++ b/tests/gentype_tests/typescript-react-example/src/EscapedNames.res.js @@ -1,6 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +function make(param) { + return null; +} + let myRecord = { normalField: "Illegal\"Name", "Renamed'Field": 42, @@ -8,7 +12,14 @@ let myRecord = { UPPERCASE: 100 }; +let Icon_Add = make; + +let SomeValue = "hello"; + export { myRecord, + make, + Icon_Add, + SomeValue, } /* No side effect */