@@ -124,8 +124,8 @@ let emitFromLoc ~loc ~type_ emitter =
124
124
125
125
let emitLongident ?(backwards = false ) ?(jsx = false )
126
126
?(lowerCaseToken = if jsx then Token. JsxLowercase else Token. Variable )
127
- ?(upperCaseToken = Token. Namespace ) ?(lastToken = None ) ~ pos ~ lid ~ debug
128
- emitter =
127
+ ?(upperCaseToken = Token. Namespace ) ?(lastToken = None ) ?( posEnd = None )
128
+ ~ pos ~ lid ~ debug emitter =
129
129
let rec flatten acc lid =
130
130
match lid with
131
131
| Longident. Lident txt -> txt :: acc
@@ -142,10 +142,19 @@ let emitLongident ?(backwards = false) ?(jsx = false)
142
142
| Some type_ -> type_
143
143
| None -> if isUppercaseId id then upperCaseToken else lowerCaseToken
144
144
in
145
+ let posAfter = (fst pos, snd pos + String. length id) in
146
+ let posEnd, lenMismatch =
147
+ (* There could be a length mismatch when ids are quoted
148
+ e.g. variable /"true" or object field {"x":...} *)
149
+ match posEnd with
150
+ | Some posEnd -> (posEnd, posEnd <> posAfter)
151
+ | None -> (posAfter, false )
152
+ in
145
153
if debug then
146
- Printf. printf " Lident: %s %s %s\n " id (posToString pos)
154
+ Printf. printf " Lident: %s %s%s %s\n " id (posToString pos)
155
+ (if lenMismatch then " ->" ^ posToString posEnd else " " )
147
156
(Token. tokenTypeDebug type_);
148
- emitter |> emitFromPos pos (fst pos, snd pos + String. length id) ~type_
157
+ emitter |> emitFromPos pos posEnd ~type_
149
158
| id :: segments when isUppercaseId id || isLowercaseId id ->
150
159
let type_ = if isUppercaseId id then upperCaseToken else lowerCaseToken in
151
160
if debug then
@@ -190,6 +199,7 @@ let emitRecordLabel ~(label : Longident.t Location.loc) ~debug emitter =
190
199
emitter
191
200
|> emitLongident ~lower CaseToken:Token. Property
192
201
~pos: (Utils. tupleOfLexing label.loc.loc_start)
202
+ ~pos End:(Some (Utils. tupleOfLexing label.loc.loc_end))
193
203
~lid: label.txt ~debug
194
204
195
205
let emitVariant ~(name : Longident.t Location.loc ) ~debug emitter =
@@ -240,23 +250,13 @@ let parser ~debug ~emitter ~path =
240
250
in
241
251
let expr (mapper : Ast_mapper.mapper ) (e : Parsetree.expression ) =
242
252
match e.pexp_desc with
243
- | Pexp_ident {txt = Lident id}
244
- when id <> " =" && id <> " =="
245
- && snd (Utils. tupleOfLexing e.pexp_loc.loc_end)
246
- - snd (Utils. tupleOfLexing e.pexp_loc.loc_start)
247
- > String. length id
248
- (* /"stuff" *) ->
249
- let type_ = Token. Variable in
250
- if debug then
251
- Printf. printf " QuotedIdent: %s %s %s\n " id
252
- (posToString (Utils. tupleOfLexing e.pexp_loc.loc_start))
253
- (Token. tokenTypeDebug type_);
254
- emitter |> emitFromLoc ~loc: e.pexp_loc ~type_ ;
255
- Ast_mapper. default_mapper.expr mapper e
256
253
| Pexp_ident {txt = lid ; loc} ->
257
254
if lid <> Lident " not" then
258
255
emitter
259
- |> emitLongident ~pos: (Utils. tupleOfLexing loc.loc_start) ~lid ~debug ;
256
+ |> emitLongident
257
+ ~pos: (Utils. tupleOfLexing loc.loc_start)
258
+ ~pos End:(Some (Utils. tupleOfLexing loc.loc_end))
259
+ ~lid ~debug ;
260
260
Ast_mapper. default_mapper.expr mapper e
261
261
| Pexp_apply ({pexp_desc = Pexp_ident lident; pexp_loc}, args)
262
262
when Res_parsetree_viewer. isJsxExpression e ->
0 commit comments