@@ -225,27 +225,33 @@ let parser ~debug ~emitter ~path =
225
225
Component names:
226
226
- handled like other Longitent.t, except lowercase id is marked Token.JsxLowercase
227
227
*)
228
- let rec isSelfClosing args =
229
- match args with
230
- | [] -> false
231
- | [
232
- ( Asttypes. Labelled " children" ,
233
- {
234
- Parsetree. pexp_desc =
235
- Pexp_construct ({txt = Longident. Lident " []" }, None );
236
- } );
237
- _;
238
- ] ->
239
- true
240
- | _ :: rest -> isSelfClosing rest
241
- in
242
- emitter (* --> <div.. *)
228
+ emitter (* --> <div... *)
243
229
|> emitJsxTag ~debug ~name: " <"
244
230
~pos:
245
231
(let pos = Utils. tupleOfLexing e.pexp_loc.loc_start in
246
232
(fst pos, snd pos - 1 (* the AST skips the loc of < somehow *) ));
247
233
emitter |> emitJsxOpen ~lid: lident.txt ~debug ~loc: pexp_loc;
248
- (if not (isSelfClosing args) then
234
+
235
+ let posOfGreatherthanAfterProps =
236
+ let rec loop = function
237
+ | (Asttypes. Labelled " children" , {Parsetree. pexp_loc = {loc_start}})
238
+ :: _ ->
239
+ Utils. tupleOfLexing loc_start
240
+ | _ :: args -> loop args
241
+ | [] -> (- 1 , - 1 )
242
+ (* should not happen *)
243
+ in
244
+ loop args
245
+ in
246
+ let posOfFinalGreatherthan =
247
+ let pos = Utils. tupleOfLexing e.pexp_loc.loc_end in
248
+ (fst pos, snd pos - 1 )
249
+ in
250
+ let selfClosing =
251
+ fst posOfGreatherthanAfterProps == fst posOfFinalGreatherthan
252
+ && snd posOfGreatherthanAfterProps + 1 == snd posOfFinalGreatherthan
253
+ in
254
+ (if not selfClosing then
249
255
let lineStart, colStart = Utils. tupleOfLexing pexp_loc.loc_start in
250
256
let lineEnd, colEnd = Utils. tupleOfLexing pexp_loc.loc_end in
251
257
let length = if lineStart = lineEnd then colEnd - colStart else 0 in
@@ -254,22 +260,10 @@ let parser ~debug ~emitter ~path =
254
260
emitter
255
261
|> emitJsxClose ~debug ~lid: lident.txt
256
262
~pos: (lineEndWhole, colEndWhole - 1 );
257
-
258
- let rec emitGreatherthanAfterProps args =
259
- match args with
260
- | (Asttypes. Labelled " children" , {Parsetree. pexp_loc = {loc_start}})
261
- :: _ ->
262
- emitter
263
- |> emitJsxTag ~debug ~name: " >" ~pos: (Utils. tupleOfLexing loc_start)
264
- | _ :: args -> emitGreatherthanAfterProps args
265
- | [] -> ()
266
- in
267
- emitGreatherthanAfterProps args (* <foo ...props > <-- *) ;
263
+ emitter (* <foo ...props > <-- *)
264
+ |> emitJsxTag ~debug ~name: " >" ~pos: posOfGreatherthanAfterProps;
268
265
emitter (* <foo> ... </foo> <-- *)
269
- |> emitJsxTag ~debug ~name: " >"
270
- ~pos:
271
- (let pos = Utils. tupleOfLexing e.pexp_loc.loc_end in
272
- (fst pos, snd pos - 1 ))));
266
+ |> emitJsxTag ~debug ~name: " >" ~pos: posOfFinalGreatherthan));
273
267
274
268
let _ = args |> List. map (fun (_lbl , arg ) -> mapper.expr mapper arg) in
275
269
e
0 commit comments