Skip to content

Commit b8f1156

Browse files
committed
tweak
1 parent a49c911 commit b8f1156

File tree

9 files changed

+18
-17
lines changed

9 files changed

+18
-17
lines changed

jscomp/core/classify_function.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp =
7979
| exception _ ->
8080
Js_exp_unknown
8181

82+
(** It seems we do the parse twice
83+
- in parsing
84+
- in code generation
85+
*)
8286
let classify (prog : string) : Js_raw_info.exp =
8387
let prog, errors =
8488
Parser_flow.parse_expression

jscomp/core/js_dump.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
650650
| Exp exp_info ->
651651
let raw_paren =
652652
not (match exp_info with
653-
| Js_literal _ | Js_raw_json -> true
653+
| Js_literal _ -> true
654654
| Js_function _ | Js_exp_unknown -> false || raw_snippet_exp_simple_enough s) in
655655
if raw_paren then P.string f L.lparen;
656656
P.string f s ;

jscomp/core/js_raw_info.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type exp =
4040
| RegExp of RegExp.t
4141
]}
4242
*)
43-
| Js_raw_json
4443
| Js_exp_unknown
4544

4645

jscomp/core/lam_compile_const.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ let translate_arg_cst (cst : External_arg_spec.cst) =
131131
| Arg_string_lit i ->
132132
E.str i
133133
| Arg_js_null -> E.nil
134-
| Arg_js_json s
135-
-> E.raw_js_code (Exp Js_raw_json) s
134+
| Arg_js_literal s
135+
-> E.raw_js_code (Exp (Js_literal {comment = None})) s
136136

137137
| Arg_js_true -> E.bool true
138138
| Arg_js_false -> E.bool false

jscomp/syntax/ast_attributes.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ let iter_process_bs_int_as (attrs : t) =
265265
type as_const_payload =
266266
| Int of int
267267
| Str of string
268-
| Json_str of string
269-
268+
| Js_literal_str of string
270269
let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
271270
let st = ref None in
272271
Ext_list.iter attrs
@@ -283,10 +282,9 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
283282
| Some (s,None) ->
284283
st := Some (Str (s))
285284
| Some (s, Some "json") ->
286-
st := Some (Json_str s )
285+
st := Some (Js_literal_str s )
287286
| None | Some (_, Some _) ->
288287
Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
289-
290288
end
291289
| Some v->
292290
st := (Some (Int v))

jscomp/syntax/ast_attributes.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ val iter_process_bs_int_as :
8282
type as_const_payload =
8383
| Int of int
8484
| Str of string
85-
| Json_str of string
86-
85+
| Js_literal_str of string
8786

8887
val iter_process_bs_string_or_int_as :
8988
t ->

jscomp/syntax/ast_external_process.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
112112
(* This type is used in bs.obj only to construct obj type*)
113113
Arg_cst(External_arg_spec.cst_int i)
114114
| Some (Str i)->
115-
Arg_cst (External_arg_spec.cst_string i)
116-
| Some (Json_str s) ->
115+
Arg_cst (External_arg_spec.cst_string i)
116+
| Some (Js_literal_str s) ->
117117
(* FIXME: This seems to be wrong in bs.obj, we should disable such payload in bs.obj *)
118118
Arg_cst (External_arg_spec.cst_json ptyp.ptyp_loc s)
119119
else (* ([`a|`b] [@bs.string]) *)
@@ -138,7 +138,7 @@ let refine_obj_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
138138
Ast_literal.type_int ~loc:ptyp.ptyp_loc (), Arg_cst(External_arg_spec.cst_int i)
139139
| Some (Str i)->
140140
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_string i)
141-
| Some (Json_str _) ->
141+
| Some (Js_literal_str _ ) ->
142142
Location.raise_errorf ~loc:ptyp.ptyp_loc "json payload is not supported in bs.obj since its type can not be inferred"
143143
else (* ([`a|`b] [@bs.string]) *)
144144
ptyp, spec_of_ptyp nolabel ptyp

jscomp/syntax/external_arg_spec.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type cst =
3131
| Arg_js_null
3232
| Arg_js_true
3333
| Arg_js_false
34-
| Arg_js_json of string
34+
| Arg_js_literal of string
3535

3636
type label_noname =
3737
| Arg_label
@@ -106,7 +106,7 @@ let cst_json (loc : Location.t) s : cst =
106106
| True _ -> Arg_js_true
107107
| False _ -> Arg_js_false
108108
| Null _ -> Arg_js_null
109-
| _ -> Arg_js_json s
109+
| _ -> Arg_js_literal s
110110
| exception Ext_json_parse.Error (start,finish,error_info)
111111
->
112112
let loc1 = {
@@ -117,7 +117,7 @@ let cst_json (loc : Location.t) s : cst =
117117
Ext_position.offset loc.loc_start finish;
118118
} in
119119
raise (Error (loc1 , error_info))
120-
120+
let cst_obj_literal s = Arg_js_literal s
121121
let cst_int i = Arg_int_lit i
122122
let cst_string s = Arg_string_lit s
123123
let empty_label = Obj_empty

jscomp/syntax/external_arg_spec.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type cst = private
2828
| Arg_js_null
2929
| Arg_js_true
3030
| Arg_js_false
31-
| Arg_js_json of string
31+
| Arg_js_literal of string
3232

3333

3434
type label = private
@@ -78,6 +78,7 @@ type param = {
7878
type obj_params = obj_param list
7979
type params = param list
8080

81+
val cst_obj_literal : string -> cst
8182
val cst_json : Location.t -> string -> cst
8283
val cst_int : int -> cst
8384
val cst_string : string -> cst

0 commit comments

Comments
 (0)