Skip to content

Commit e2e1e3c

Browse files
authored
Allow oneliner when including module with single type alias (#7502)
* Allow oneliner when including module with single type alias * Add changelog * Not sure why this changed * Ah, needed a make lib
1 parent 7b4bc42 commit e2e1e3c

File tree

8 files changed

+178
-134
lines changed

8 files changed

+178
-134
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
- Suggest awaiting promise before using it when types mismatch. https://github.com/rescript-lang/rescript/pull/7498
2626
- Complete from `RegExp` stdlib module for regexes. https://github.com/rescript-lang/rescript/pull/7425
27+
- Allow oneliner formatting when including module with single type alias. https://github.com/rescript-lang/rescript/pull/7502
2728

2829
# 12.0.0-alpha.13
2930

compiler/syntax/src/res_printer.ml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,50 @@ and print_include_declaration ~state
10811081
print_attributes ~state include_declaration.pincl_attributes cmt_tbl;
10821082
Doc.text "include ";
10831083
(let include_doc =
1084-
print_mod_expr ~state include_declaration.pincl_mod cmt_tbl
1084+
match include_declaration.pincl_mod.pmod_desc with
1085+
(*
1086+
include Module.Name({ type t = t })
1087+
try as oneliner if there is a single type alias declaration
1088+
*)
1089+
| Pmod_apply
1090+
( {pmod_desc = Pmod_ident longident_loc},
1091+
{
1092+
pmod_desc =
1093+
Pmod_structure
1094+
[
1095+
({
1096+
pstr_desc =
1097+
Pstr_type
1098+
( _,
1099+
[
1100+
{
1101+
ptype_kind = Ptype_abstract;
1102+
ptype_manifest = Some _;
1103+
};
1104+
] );
1105+
} as structure_item);
1106+
];
1107+
} ) ->
1108+
Doc.concat
1109+
[
1110+
print_longident_location longident_loc cmt_tbl;
1111+
Doc.lparen;
1112+
Doc.breakable_group ~force_break:false
1113+
(Doc.concat
1114+
[
1115+
Doc.lbrace;
1116+
Doc.indent
1117+
(Doc.concat
1118+
[
1119+
Doc.soft_line;
1120+
print_structure_item ~state structure_item cmt_tbl;
1121+
]);
1122+
Doc.soft_line;
1123+
Doc.rbrace;
1124+
]);
1125+
Doc.rparen;
1126+
]
1127+
| _ -> print_mod_expr ~state include_declaration.pincl_mod cmt_tbl
10851128
in
10861129
if Parens.include_mod_expr include_declaration.pincl_mod then
10871130
add_parens include_doc

runtime/JsxEvent.res

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ module Clipboard = {
9595
type tag
9696
type t = synthetic<tag>
9797

98-
include MakeEventWithType({
99-
type t = t
100-
})
98+
include MakeEventWithType({type t = t})
10199

102100
@get external clipboardData: t => {..} = "clipboardData"
103101
/* Should return Dom.dataTransfer */
@@ -107,9 +105,7 @@ module Composition = {
107105
type tag
108106
type t = synthetic<tag>
109107

110-
include MakeEventWithType({
111-
type t = t
112-
})
108+
include MakeEventWithType({type t = t})
113109

114110
@get external data: t => string = "data"
115111
}
@@ -118,9 +114,7 @@ module Keyboard = {
118114
type tag
119115
type t = synthetic<tag>
120116

121-
include MakeEventWithType({
122-
type t = t
123-
})
117+
include MakeEventWithType({type t = t})
124118

125119
@get external altKey: t => bool = "altKey"
126120
@get external charCode: t => int = "charCode"
@@ -142,9 +136,7 @@ module Focus = {
142136
type tag
143137
type t = synthetic<tag>
144138

145-
include MakeEventWithType({
146-
type t = t
147-
})
139+
include MakeEventWithType({type t = t})
148140

149141
@get @return(nullable) external relatedTarget: t => option<{..}> = "relatedTarget"
150142
/* Should return Dom.eventTarget */
@@ -154,18 +146,14 @@ module Form = {
154146
type tag
155147
type t = synthetic<tag>
156148

157-
include MakeEventWithType({
158-
type t = t
159-
})
149+
include MakeEventWithType({type t = t})
160150
}
161151

162152
module Mouse = {
163153
type tag
164154
type t = synthetic<tag>
165155

166-
include MakeEventWithType({
167-
type t = t
168-
})
156+
include MakeEventWithType({type t = t})
169157

170158
@get external altKey: t => bool = "altKey"
171159
@get external button: t => int = "button"
@@ -194,9 +182,7 @@ module Pointer = {
194182
type tag
195183
type t = synthetic<tag>
196184

197-
include MakeEventWithType({
198-
type t = t
199-
})
185+
include MakeEventWithType({type t = t})
200186

201187
/* UIEvent */
202188
@get @get
@@ -244,18 +230,14 @@ module Selection = {
244230
type tag
245231
type t = synthetic<tag>
246232

247-
include MakeEventWithType({
248-
type t = t
249-
})
233+
include MakeEventWithType({type t = t})
250234
}
251235

252236
module Touch = {
253237
type tag
254238
type t = synthetic<tag>
255239

256-
include MakeEventWithType({
257-
type t = t
258-
})
240+
include MakeEventWithType({type t = t})
259241

260242
@get external altKey: t => bool = "altKey"
261243
@get external changedTouches: t => {..} = "changedTouches"
@@ -278,9 +260,7 @@ module UI = {
278260
type tag
279261
type t = synthetic<tag>
280262

281-
include MakeEventWithType({
282-
type t = t
283-
})
263+
include MakeEventWithType({type t = t})
284264

285265
@get external detail: t => int = "detail"
286266
/* external view : t -> Dom.window = "view" [@@get] */
@@ -291,9 +271,7 @@ module Wheel = {
291271
type tag
292272
type t = synthetic<tag>
293273

294-
include MakeEventWithType({
295-
type t = t
296-
})
274+
include MakeEventWithType({type t = t})
297275

298276
@get external deltaMode: t => int = "deltaMode"
299277
@get external deltaX: t => float = "deltaX"
@@ -305,27 +283,21 @@ module Media = {
305283
type tag
306284
type t = synthetic<tag>
307285

308-
include MakeEventWithType({
309-
type t = t
310-
})
286+
include MakeEventWithType({type t = t})
311287
}
312288

313289
module Image = {
314290
type tag
315291
type t = synthetic<tag>
316292

317-
include MakeEventWithType({
318-
type t = t
319-
})
293+
include MakeEventWithType({type t = t})
320294
}
321295

322296
module Animation = {
323297
type tag
324298
type t = synthetic<tag>
325299

326-
include MakeEventWithType({
327-
type t = t
328-
})
300+
include MakeEventWithType({type t = t})
329301

330302
@get external animationName: t => string = "animationName"
331303
@get external pseudoElement: t => string = "pseudoElement"
@@ -336,9 +308,7 @@ module Transition = {
336308
type tag
337309
type t = synthetic<tag>
338310

339-
include MakeEventWithType({
340-
type t = t
341-
})
311+
include MakeEventWithType({type t = t})
342312

343313
@get external propertyName: t => string = "propertyName"
344314
@get external pseudoElement: t => string = "pseudoElement"

tests/analysis_tests/tests/src/expected/Completion.res.txt

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/dependencies/rescript-react/src/ReactEvent.res

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,21 @@ external toSyntheticEvent: synthetic<'a> => Synthetic.t = "%identity"
5959
module Clipboard = {
6060
type tag = JsxEvent.Clipboard.tag
6161
type t = synthetic<tag>
62-
include MakeEventWithType({
63-
type t = t
64-
})
62+
include MakeEventWithType({type t = t})
6563
@get external clipboardData: t => {..} = "clipboardData" /* Should return Dom.dataTransfer */
6664
}
6765

6866
module Composition = {
6967
type tag = JsxEvent.Composition.tag
7068
type t = synthetic<tag>
71-
include MakeEventWithType({
72-
type t = t
73-
})
69+
include MakeEventWithType({type t = t})
7470
@get external data: t => string = "data"
7571
}
7672

7773
module Keyboard = {
7874
type tag = JsxEvent.Keyboard.tag
7975
type t = synthetic<tag>
80-
include MakeEventWithType({
81-
type t = t
82-
})
76+
include MakeEventWithType({type t = t})
8377
@get external altKey: t => bool = "altKey"
8478
@get external charCode: t => int = "charCode"
8579
@get external code: t => string = "code"
@@ -99,27 +93,21 @@ module Keyboard = {
9993
module Focus = {
10094
type tag = JsxEvent.Focus.tag
10195
type t = synthetic<tag>
102-
include MakeEventWithType({
103-
type t = t
104-
})
96+
include MakeEventWithType({type t = t})
10597
@get @return(nullable)
10698
external relatedTarget: t => option<{..}> = "relatedTarget" /* Should return Dom.eventTarget */
10799
}
108100

109101
module Form = {
110102
type tag = JsxEvent.Form.tag
111103
type t = synthetic<tag>
112-
include MakeEventWithType({
113-
type t = t
114-
})
104+
include MakeEventWithType({type t = t})
115105
}
116106

117107
module Mouse = {
118108
type tag = JsxEvent.Mouse.tag
119109
type t = synthetic<tag>
120-
include MakeEventWithType({
121-
type t = t
122-
})
110+
include MakeEventWithType({type t = t})
123111
@get external altKey: t => bool = "altKey"
124112
@get external button: t => int = "button"
125113
@get external buttons: t => int = "buttons"
@@ -143,9 +131,7 @@ module Mouse = {
143131
module Pointer = {
144132
type tag = JsxEvent.Pointer.tag
145133
type t = synthetic<tag>
146-
include MakeEventWithType({
147-
type t = t
148-
})
134+
include MakeEventWithType({type t = t})
149135

150136
// UIEvent
151137
@get external detail: t => int = "detail"
@@ -190,17 +176,13 @@ module Pointer = {
190176
module Selection = {
191177
type tag = JsxEvent.Selection.tag
192178
type t = synthetic<tag>
193-
include MakeEventWithType({
194-
type t = t
195-
})
179+
include MakeEventWithType({type t = t})
196180
}
197181

198182
module Touch = {
199183
type tag = JsxEvent.Touch.tag
200184
type t = synthetic<tag>
201-
include MakeEventWithType({
202-
type t = t
203-
})
185+
include MakeEventWithType({type t = t})
204186
@get external altKey: t => bool = "altKey"
205187
@get external changedTouches: t => {..} = "changedTouches" /* Should return Dom.touchList */
206188
@get external ctrlKey: t => bool = "ctrlKey"
@@ -215,19 +197,15 @@ module Touch = {
215197
module UI = {
216198
type tag = JsxEvent.UI.tag
217199
type t = synthetic<tag>
218-
include MakeEventWithType({
219-
type t = t
220-
})
200+
include MakeEventWithType({type t = t})
221201
@get external detail: t => int = "detail"
222202
@get external view: t => Dom.window = "view" /* Should return DOMAbstractView/WindowProxy */
223203
}
224204

225205
module Wheel = {
226206
type tag = JsxEvent.Wheel.tag
227207
type t = synthetic<tag>
228-
include MakeEventWithType({
229-
type t = t
230-
})
208+
include MakeEventWithType({type t = t})
231209
@get external deltaMode: t => int = "deltaMode"
232210
@get external deltaX: t => float = "deltaX"
233211
@get external deltaY: t => float = "deltaY"
@@ -237,25 +215,19 @@ module Wheel = {
237215
module Media = {
238216
type tag = JsxEvent.Media.tag
239217
type t = synthetic<tag>
240-
include MakeEventWithType({
241-
type t = t
242-
})
218+
include MakeEventWithType({type t = t})
243219
}
244220

245221
module Image = {
246222
type tag = JsxEvent.Image.tag
247223
type t = synthetic<tag>
248-
include MakeEventWithType({
249-
type t = t
250-
})
224+
include MakeEventWithType({type t = t})
251225
}
252226

253227
module Animation = {
254228
type tag = JsxEvent.Animation.tag
255229
type t = synthetic<tag>
256-
include MakeEventWithType({
257-
type t = t
258-
})
230+
include MakeEventWithType({type t = t})
259231
@get external animationName: t => string = "animationName"
260232
@get external pseudoElement: t => string = "pseudoElement"
261233
@get external elapsedTime: t => float = "elapsedTime"
@@ -264,9 +236,7 @@ module Animation = {
264236
module Transition = {
265237
type tag = JsxEvent.Transition.tag
266238
type t = synthetic<tag>
267-
include MakeEventWithType({
268-
type t = t
269-
})
239+
include MakeEventWithType({type t = t})
270240
@get external propertyName: t => string = "propertyName"
271241
@get external pseudoElement: t => string = "pseudoElement"
272242
@get external elapsedTime: t => float = "elapsedTime"

0 commit comments

Comments
 (0)