File tree Expand file tree Collapse file tree 13 files changed +62
-15
lines changed
gentype_tests/typescript-react-example Expand file tree Collapse file tree 13 files changed +62
-15
lines changed Original file line number Diff line number Diff line change 1515#### :bug : Bug Fix
1616
1717- Fix issue with Dynamic import of module in nested expressions https://github.com/rescript-lang/rescript-compiler/pull/6431
18+ - Fix issue where GenType was not supporting ` @tag ` on ordinary variatns https://github.com/rescript-lang/rescript-compiler/pull/6437
1819
1920# 11.0.0-rc.4
2021
Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ let tagIsGenTypeAs s = s = "genType.as" || s = "gentype.as"
2222let tagIsAs s = s = " bs.as" || s = " as"
2323let tagIsInt s = s = " bs.int" || s = " int"
2424let tagIsString s = s = " bs.string" || s = " string"
25+
26+ let tagIsTag s = s = " tag"
27+
2528let tagIsUnboxed s = s = " unboxed" || s = " ocaml.unboxed"
2629let tagIsGenTypeImport s = s = " genType.import" || s = " gentype.import"
2730let tagIsGenTypeOpaque s = s = " genType.opaque" || s = " gentype.opaque"
@@ -146,6 +149,11 @@ let getAttributeImportRenaming attributes =
146149 (Some importString, Some renameString)
147150 | _ -> (None , genTypeAsRenaming)
148151
152+ let getTag attributes =
153+ match attributes |> getAttributePayload tagIsTag with
154+ | Some (_ , StringPayload s ) -> Some s
155+ | _ -> None
156+
149157let getDocPayload attributes =
150158 let docPayload = attributes |> getAttributePayload tagIsDoc in
151159 match docPayload with
Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
156156 |> String. concat " , " )
157157 ^ " ]"
158158 | TypeVar s -> s
159- | Variant {inherits; noPayloads; payloads; polymorphic; unboxed} ->
159+ | Variant {inherits; noPayloads; payloads; polymorphic; tag; unboxed} ->
160160 let inheritsRendered =
161161 inherits
162162 |> List. map (fun type_ ->
@@ -183,7 +183,8 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
183183 in
184184 let tagField =
185185 case |> labelJSToString
186- |> field ~name: (Runtime. jsVariantTag ~polymorphic: false )
186+ |> field
187+ ~name: (Runtime. jsVariantTag ~polymorphic: false ~tag )
187188 in
188189 match (unboxed, type_) with
189190 | true , type_ ->
@@ -198,7 +199,7 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
198199 (* poly variant *)
199200 [
200201 case |> labelJSToString
201- |> field ~name: (Runtime. jsVariantTag ~polymorphic );
202+ |> field ~name: (Runtime. jsVariantTag ~polymorphic ~tag );
202203 type_ |> render
203204 |> field ~name: (Runtime. jsVariantValue ~polymorphic );
204205 ]
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ and variant = {
9999 noPayloads : case list ;
100100 payloads : payload list ;
101101 polymorphic : bool ; (* If true, this is a polymorphic variant *)
102+ tag : string option ; (* The name of the tag field at runtime *)
102103 unboxed : bool ;
103104}
104105
@@ -168,8 +169,8 @@ let rec depToResolvedName (dep : dep) =
168169 | Internal resolvedName -> resolvedName
169170 | Dot (p , s ) -> ResolvedName. dot s (p |> depToResolvedName)
170171
171- let createVariant ~inherits ~noPayloads ~payloads ~polymorphic ~unboxed =
172- Variant {inherits; noPayloads; payloads; polymorphic; unboxed}
172+ let createVariant ~inherits ~noPayloads ~payloads ~polymorphic ~tag ~ unboxed =
173+ Variant {inherits; noPayloads; payloads; polymorphic; tag; unboxed}
173174
174175let ident ?(builtin = true ) ?(typeArgs = [] ) name =
175176 Ident {builtin; name; typeArgs}
Original file line number Diff line number Diff line change @@ -24,10 +24,13 @@ let rec emitModuleAccessPath ~config moduleAccessPath =
2424 | Dot (p , moduleItem ) ->
2525 p |> emitModuleAccessPath ~config |> EmitText. fieldAccess ~label: moduleItem
2626
27- let jsVariantTag ~polymorphic =
27+ let jsVariantTag ~polymorphic ~ tag =
2828 match polymorphic with
2929 | true -> " NAME"
30- | false -> " TAG"
30+ | false -> (
31+ match tag with
32+ | Some tag -> tag
33+ | None -> " TAG" )
3134
3235let jsVariantPayloadTag ~n = " _" ^ string_of_int n
3336
Original file line number Diff line number Diff line change @@ -14,6 +14,6 @@ val newModuleItem : name:string -> moduleItem
1414val newRecordValue : unboxed :bool -> recordGen -> recordValue
1515val recordGen : unit -> recordGen
1616val recordValueToString : recordValue -> string
17- val jsVariantTag : polymorphic :bool -> string
17+ val jsVariantTag : polymorphic :bool -> tag : string option -> string
1818val jsVariantPayloadTag : n :int -> string
1919val jsVariantValue : polymorphic :bool -> string
Original file line number Diff line number Diff line change @@ -212,7 +212,7 @@ and translateCoreType_ ~config ~typeVarsGen
212212 let inherits = inheritsTranslations |> List. map (fun {type_} -> type_) in
213213 let type_ =
214214 createVariant ~no Payloads ~payloads ~inherits ~polymorphic: true
215- ~unboxed: false
215+ ~tag: None ~ unboxed:false
216216 in
217217 let dependencies =
218218 (inheritsTranslations
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
6666 let unboxedAnnotation =
6767 typeAttributes |> Annotation. hasAttribute Annotation. tagIsUnboxed
6868 in
69+ let tagAnnotation = typeAttributes |> Annotation. getTag in
6970 let returnTypeDeclaration (typeDeclaration : CodeItem.typeDeclaration ) =
7071 match opaque = Some true with
7172 | true -> [{typeDeclaration with importTypes = [] }]
@@ -203,7 +204,7 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
203204 else variant.payloads
204205 in
205206 createVariant ~inherits: variant.inherits ~no Payloads ~payloads
206- ~polymorphic: true ~unboxed: false
207+ ~polymorphic: true ~tag: None ~ unboxed:false
207208 | _ -> translation.type_
208209 in
209210 {translation with type_} |> handleGeneralDeclaration
@@ -295,7 +296,7 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
295296 in
296297 let variantTyp =
297298 createVariant ~inherits: [] ~no Payloads ~payloads ~polymorphic: false
298- ~unboxed: unboxedAnnotation
299+ ~tag: tagAnnotation ~ unboxed: unboxedAnnotation
299300 in
300301 let resolvedTypeName = typeName |> TypeEnv. addModulePath ~type Env in
301302 let exportFromTypeDeclaration =
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
147147 case 0 " Ok" paramTranslation1.type_;
148148 case 1 " Error" paramTranslation2.type_;
149149 ]
150- ~polymorphic: false ~unboxed: false
150+ ~polymorphic: false ~tag: None ~ unboxed:false
151151 in
152152 {
153153 dependencies =
@@ -386,7 +386,7 @@ and translateTypeExprFromTypes_ ~config ~typeVarsGen ~typeEnv
386386 in
387387 let type_ =
388388 createVariant ~inherits: [] ~no Payloads ~payloads: [] ~polymorphic: true
389- ~unboxed: false
389+ ~tag: None ~ unboxed:false
390390 in
391391 {dependencies = [] ; type_}
392392 | {noPayloads = [] ; payloads = [(_label, t)]; unknowns = [] } ->
@@ -415,7 +415,7 @@ and translateTypeExprFromTypes_ ~config ~typeVarsGen ~typeEnv
415415 in
416416 let type_ =
417417 createVariant ~inherits: [] ~no Payloads ~payloads ~polymorphic: true
418- ~unboxed: false
418+ ~tag: None ~ unboxed:false
419419 in
420420 let dependencies =
421421 payloadTranslations
You can’t perform that action at this time.
0 commit comments