Skip to content

Commit bed7bb2

Browse files
authored
Merge pull request #2726 from BuckleScript/relax_bs_raw
generalize bs.raw
2 parents 05d6517 + d5c941d commit bed7bb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+38140
-37682
lines changed

jscomp/all.depend

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,10 @@ syntax/ast_exp_apply.cmx : ext/literals.cmx ext/ext_list.cmx \
254254
syntax/ast_tuple_pattern_flatten.cmx syntax/ast_literal.cmx \
255255
syntax/ast_attributes.cmx syntax/ast_exp_apply.cmi
256256
syntax/ast_exp_extension.cmx : ext/literals.cmx ext/ext_string.cmx \
257-
ext/ext_ref.cmx syntax/bs_ast_mapper.cmx syntax/ast_util.cmx \
258-
syntax/ast_payload.cmx syntax/ast_literal.cmx syntax/ast_derive.cmx \
259-
syntax/ast_core_type.cmx syntax/ast_comb.cmx syntax/ast_exp_extension.cmi
257+
ext/ext_ref.cmx ext/ext_pervasives.cmx common/bs_version.cmx \
258+
syntax/bs_ast_mapper.cmx syntax/ast_util.cmx syntax/ast_payload.cmx \
259+
syntax/ast_literal.cmx syntax/ast_derive.cmx syntax/ast_core_type.cmx \
260+
syntax/ast_comb.cmx syntax/ast_exp_extension.cmi
260261
syntax/ast_core_type_class_type.cmx : ext/literals.cmx ext/ext_ref.cmx \
261262
ext/ext_list.cmx syntax/bs_ast_mapper.cmx syntax/ast_util.cmx \
262263
syntax/ast_literal.cmx syntax/ast_comb.cmx syntax/ast_attributes.cmx \
@@ -455,7 +456,7 @@ core/lam.cmx : ext/ordered_hash_map_local_ident.cmx ext/literals.cmx \
455456
ext/ident_hashtbl.cmx ext/ident_hash_set.cmx ext/hash_set_ident_mask.cmx \
456457
syntax/external_ffi_types.cmx syntax/external_arg_spec.cmx \
457458
ext/ext_string.cmx ext/ext_scc.cmx common/ext_log.cmx ext/ext_list.cmx \
458-
core/lam.cmi
459+
syntax/ast_exp_extension.cmx core/lam.cmi
459460
core/lam_print.cmx : core/lam.cmx ext/ext_list.cmx core/lam_print.cmi
460461
core/lam_beta_reduce_util.cmx : core/lam.cmx ext/ident_hashtbl.cmx \
461462
core/lam_beta_reduce_util.cmi

jscomp/bin/all_ounit_tests.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,6 +3556,7 @@ val setter_suffix_len : int
35563556
val debugger : string
35573557
val raw_expr : string
35583558
val raw_stmt : string
3559+
val raw_function : string
35593560
val unsafe_downgrade : string
35603561
val fn_run : string
35613562
val method_run : string
@@ -3690,6 +3691,7 @@ let setter_suffix_len = String.length setter_suffix
36903691
let debugger = "debugger"
36913692
let raw_expr = "raw_expr"
36923693
let raw_stmt = "raw_stmt"
3694+
let raw_function = "raw_function"
36933695
let unsafe_downgrade = "unsafe_downgrade"
36943696
let fn_run = "fn_run"
36953697
let method_run = "method_run"

jscomp/core/bs_conditional_initial.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
let setup_env () =
2727
#if BS_DEBUG then
28-
Js_config.set_debug_file "gpr_2700_test.ml";
28+
Js_config.set_debug_file "gpr_2682_test.ml";
2929
#end
3030
Lexer.replace_directive_bool "BS" true;
3131
Lexer.replace_directive_string "BS_VERSION" Bs_version.version

jscomp/core/j.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ and tag_info = Js_op.tag_info
6161
and required_modules = Js_op.required_modules
6262

6363
and code_info = Js_op.code_info
64+
65+
6466
(** object literal, if key is ident, in this case, it might be renamed by
6567
Google Closure optimizer,
6668
currently we always use quote
@@ -166,6 +168,7 @@ and expression_desc =
166168
| Unicode of string
167169
(* It is escaped string, print delimited by '"'*)
168170
| Raw_js_code of string * code_info
171+
| Raw_js_function of string * string list
169172
(* literally raw JS code
170173
*)
171174
| Array of expression list * mutable_flag

jscomp/core/js_analyzer.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ let free_variables_of_expression used_idents defined_idents st =
8383

8484
let rec no_side_effect_expression_desc (x : J.expression_desc) =
8585
match x with
86+
| Raw_js_function _
8687
| Undefined
8788
| Null
8889
| Bool _
@@ -264,6 +265,7 @@ let rec eq_expression
264265
| Fun _
265266
| Unicode _
266267
| Raw_js_code _
268+
| Raw_js_function _
267269
| Array _
268270
| Caml_block _
269271
(* | Caml_uninitialized_obj _ *)

jscomp/core/js_dump.ml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ let op_prec, op_str =
6565
Js_op_util.(op_prec, op_str)
6666

6767

68+
let rec comma_strings f (ls : string list) =
69+
match ls with
70+
| [] -> ()
71+
| [x] -> P.string f x
72+
| y :: ys ->
73+
P.string f y;
74+
P.string f L.comma;
75+
comma_strings f ys
76+
6877
let rec comma_idents cxt f (ls : Ident.t list) =
6978
match ls with
7079
| [] -> cxt
@@ -539,7 +548,15 @@ and
539548
*)
540549
Js_dump_string.pp_string f s;
541550
cxt
542-
551+
| Raw_js_function (s,params) ->
552+
P.string f L.function_;
553+
P.space f ;
554+
P.paren_group f 1 (fun _ ->
555+
comma_strings f params
556+
);
557+
P.brace f (fun _ ->
558+
P.string f s);
559+
cxt
543560
| Raw_js_code (s,info) ->
544561
begin match info with
545562
| Exp ->
@@ -1025,7 +1042,9 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
10251042
| Call ({expression_desc = Fun _; },_,_) -> true
10261043
(* | Caml_uninitialized_obj _ *)
10271044
| Raw_js_code (_, Exp)
1028-
| Fun _ | Object _ -> true
1045+
| Fun _
1046+
| Raw_js_function _
1047+
| Object _ -> true
10291048
| Raw_js_code (_,Stmt)
10301049
| Caml_block_set_tag _
10311050
| Length _

jscomp/core/js_exp_make.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ let unicode ?comment s : t =
141141
let raw_js_code ?comment info s : t =
142142
{expression_desc = Raw_js_code (s,info) ; comment }
143143

144+
let raw_js_function ?comment arg block : t =
145+
{expression_desc = Raw_js_function(arg,block); comment}
146+
144147
let array ?comment mt es : t =
145148
{expression_desc = Array (es,mt) ; comment}
146149

jscomp/core/js_exp_make.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ val dummy_obj : ?comment:string -> unit -> t
317317
val of_block : ?comment:string -> ?e:J.expression -> J.statement list -> t
318318

319319
val raw_js_code : ?comment:string -> J.code_info -> string -> t
320-
320+
val raw_js_function : ?comment:string -> string -> string list -> t
321321
val nil : t
322322
val is_null : unary_op
323323

jscomp/core/js_fold.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ class virtual fold =
358358
| Unicode _x -> let o = o#string _x in o
359359
| Raw_js_code (_x, _x_i1) ->
360360
let o = o#string _x in let o = o#code_info _x_i1 in o
361+
| Raw_js_function (_x, _x_i1) ->
362+
let o = o#string _x in
363+
let o = o#list (fun o -> o#string) _x_i1 in o
361364
| Array (_x, _x_i1) ->
362365
let o = o#list (fun o -> o#expression) _x in
363366
let o = o#mutable_flag _x_i1 in o

jscomp/core/js_map.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ class virtual map =
396396
| Raw_js_code (_x, _x_i1) ->
397397
let _x = o#string _x in
398398
let _x_i1 = o#code_info _x_i1 in Raw_js_code (_x, _x_i1)
399+
| Raw_js_function (_x, _x_i1) ->
400+
let _x = o#string _x in
401+
let _x_i1 = o#list (fun o -> o#string) _x_i1
402+
in Raw_js_function (_x, _x_i1)
399403
| Array (_x, _x_i1) ->
400404
let _x = o#list (fun o -> o#expression) _x in
401405
let _x_i1 = o#mutable_flag _x_i1 in Array (_x, _x_i1)

0 commit comments

Comments
 (0)