diff --git a/jscomp/frontend/ast_payload.ml b/jscomp/frontend/ast_payload.ml index 79a30bedd9..65459ffa6c 100644 --- a/jscomp/frontend/ast_payload.ml +++ b/jscomp/frontend/ast_payload.ml @@ -85,7 +85,7 @@ let raw_as_string_exp_exn Bs_flow_ast_utils.check_flow_errors ~loc ~offset:(Bs_flow_ast_utils.flow_deli_offset deli) (match kind with | Raw_re | Raw_exp -> - let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in + let (_loc,e),errors = Parser_flow.parse_expression (Parser_env.init_env None str) false in if kind = Raw_re then (match e with | Literal {value = RegExp _} -> () diff --git a/jscomp/frontend/bs_flow_ast_utils.ml b/jscomp/frontend/bs_flow_ast_utils.ml index 17831f140a..227c7e735d 100644 --- a/jscomp/frontend/bs_flow_ast_utils.ml +++ b/jscomp/frontend/bs_flow_ast_utils.ml @@ -49,16 +49,16 @@ let flow_deli_offset deli = (* Here the loc is the payload loc *) let check_flow_errors ~(loc : Location.t) ~offset - (errors : (Loc.t * Parse_error.t) list) = + (errors : (Loc.t * Parse_error.t) list) : unit = match errors with | [] -> () | ({start ; _end },first_error) :: _ -> let loc_start = loc.loc_start in - Location.raise_errorf - ~loc:{loc with + Location.prerr_warning + {loc with loc_start = offset_pos loc_start start offset ; loc_end = offset_pos loc_start _end - offset } "%s" - (Parse_error.PP.error first_error) \ No newline at end of file + offset } + (Bs_ffi_warning (Parse_error.PP.error first_error)) \ No newline at end of file diff --git a/jscomp/frontend/classify_function.ml b/jscomp/frontend/classify_function.ml index 93c1e549d3..e5cddf0ba7 100644 --- a/jscomp/frontend/classify_function.ml +++ b/jscomp/frontend/classify_function.ml @@ -83,16 +83,20 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp = - in parsing - in code generation *) -let classify ?check (prog : string) : Js_raw_info.exp = +let classify ?(check : (Location.t*int) option) (prog : string) : Js_raw_info.exp = let prog, errors = Parser_flow.parse_expression (Parser_env.init_env None prog) false in - (match check with - | Some (loc,offset) -> + match check, errors with + | Some (loc,offset), _ :: _ -> Bs_flow_ast_utils.check_flow_errors - ~loc ~offset errors - | None -> ()); - classify_exp prog + ~loc ~offset errors; + Js_exp_unknown + | Some _, [] + | None , [] -> + classify_exp prog + | None , _ :: _ -> Js_exp_unknown + let classify_stmt (prog : string) : Js_raw_info.stmt = diff --git a/jscomp/test/build.ninja b/jscomp/test/build.ninja index ac55adeab5..e1c7892bf5 100644 --- a/jscomp/test/build.ninja +++ b/jscomp/test/build.ninja @@ -334,6 +334,7 @@ o test/gpr_4519_test.cmi test/gpr_4519_test.cmj : cc test/gpr_4519_test.ml | tes o test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib o test/gpr_4639_test.cmi test/gpr_4639_test.cmj : cc test/gpr_4639_test.ml | $stdlib o test/gpr_4924_test.cmi test/gpr_4924_test.cmj : cc test/gpr_4924_test.ml | $stdlib +o test/gpr_4931.cmi test/gpr_4931.cmj : cc test/gpr_4931.ml | $stdlib o test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib o test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib o test/gpr_858_test.cmi test/gpr_858_test.cmj : cc test/gpr_858_test.ml | $stdlib diff --git a/jscomp/test/gpr_4931.js b/jscomp/test/gpr_4931.js new file mode 100644 index 0000000000..d15fbf5180 --- /dev/null +++ b/jscomp/test/gpr_4931.js @@ -0,0 +1,9 @@ +'use strict'; + + +if (import.meta.hot){ + console.log('es6') +} +; + +/* Not a pure module */ diff --git a/jscomp/test/gpr_4931.ml b/jscomp/test/gpr_4931.ml new file mode 100644 index 0000000000..653cb40a97 --- /dev/null +++ b/jscomp/test/gpr_4931.ml @@ -0,0 +1,11 @@ + +[@@@config { + flags = [|"-w";"-103"|] +}] + + +[%%raw{| +if (import.meta.hot){ + console.log('es6') +} +|}] \ No newline at end of file diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index af519408f0..545089701f 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -115329,19 +115329,19 @@ let flow_deli_offset deli = (* Here the loc is the payload loc *) let check_flow_errors ~(loc : Location.t) ~offset - (errors : (Loc.t * Parse_error.t) list) = + (errors : (Loc.t * Parse_error.t) list) : unit = match errors with | [] -> () | ({start ; _end },first_error) :: _ -> let loc_start = loc.loc_start in - Location.raise_errorf - ~loc:{loc with + Location.prerr_warning + {loc with loc_start = offset_pos loc_start start offset ; loc_end = offset_pos loc_start _end - offset } "%s" - (Parse_error.PP.error first_error) + offset } + (Bs_ffi_warning (Parse_error.PP.error first_error)) end module Flow_ast = struct @@ -393849,16 +393849,20 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp = - in parsing - in code generation *) -let classify ?check (prog : string) : Js_raw_info.exp = +let classify ?(check : (Location.t*int) option) (prog : string) : Js_raw_info.exp = let prog, errors = Parser_flow.parse_expression (Parser_env.init_env None prog) false in - (match check with - | Some (loc,offset) -> + match check, errors with + | Some (loc,offset), _ :: _ -> Bs_flow_ast_utils.check_flow_errors - ~loc ~offset errors - | None -> ()); - classify_exp prog + ~loc ~offset errors; + Js_exp_unknown + | Some _, [] + | None , [] -> + classify_exp prog + | None , _ :: _ -> Js_exp_unknown + let classify_stmt (prog : string) : Js_raw_info.stmt = @@ -398775,7 +398779,7 @@ let raw_as_string_exp_exn Bs_flow_ast_utils.check_flow_errors ~loc ~offset:(Bs_flow_ast_utils.flow_deli_offset deli) (match kind with | Raw_re | Raw_exp -> - let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in + let (_loc,e),errors = Parser_flow.parse_expression (Parser_env.init_env None str) false in if kind = Raw_re then (match e with | Literal {value = RegExp _} -> () diff --git a/lib/4.06.1/unstable/js_refmt_compiler.ml b/lib/4.06.1/unstable/js_refmt_compiler.ml index 66bd49d8cc..0286aea4ff 100644 --- a/lib/4.06.1/unstable/js_refmt_compiler.ml +++ b/lib/4.06.1/unstable/js_refmt_compiler.ml @@ -115329,19 +115329,19 @@ let flow_deli_offset deli = (* Here the loc is the payload loc *) let check_flow_errors ~(loc : Location.t) ~offset - (errors : (Loc.t * Parse_error.t) list) = + (errors : (Loc.t * Parse_error.t) list) : unit = match errors with | [] -> () | ({start ; _end },first_error) :: _ -> let loc_start = loc.loc_start in - Location.raise_errorf - ~loc:{loc with + Location.prerr_warning + {loc with loc_start = offset_pos loc_start start offset ; loc_end = offset_pos loc_start _end - offset } "%s" - (Parse_error.PP.error first_error) + offset } + (Bs_ffi_warning (Parse_error.PP.error first_error)) end module Flow_ast = struct @@ -393849,16 +393849,20 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp = - in parsing - in code generation *) -let classify ?check (prog : string) : Js_raw_info.exp = +let classify ?(check : (Location.t*int) option) (prog : string) : Js_raw_info.exp = let prog, errors = Parser_flow.parse_expression (Parser_env.init_env None prog) false in - (match check with - | Some (loc,offset) -> + match check, errors with + | Some (loc,offset), _ :: _ -> Bs_flow_ast_utils.check_flow_errors - ~loc ~offset errors - | None -> ()); - classify_exp prog + ~loc ~offset errors; + Js_exp_unknown + | Some _, [] + | None , [] -> + classify_exp prog + | None , _ :: _ -> Js_exp_unknown + let classify_stmt (prog : string) : Js_raw_info.stmt = @@ -398775,7 +398779,7 @@ let raw_as_string_exp_exn Bs_flow_ast_utils.check_flow_errors ~loc ~offset:(Bs_flow_ast_utils.flow_deli_offset deli) (match kind with | Raw_re | Raw_exp -> - let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in + let (_loc,e),errors = Parser_flow.parse_expression (Parser_env.init_env None str) false in if kind = Raw_re then (match e with | Literal {value = RegExp _} -> () diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index d329a78a80..1dfca7321f 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -5457,19 +5457,19 @@ let flow_deli_offset deli = (* Here the loc is the payload loc *) let check_flow_errors ~(loc : Location.t) ~offset - (errors : (Loc.t * Parse_error.t) list) = + (errors : (Loc.t * Parse_error.t) list) : unit = match errors with | [] -> () | ({start ; _end },first_error) :: _ -> let loc_start = loc.loc_start in - Location.raise_errorf - ~loc:{loc with + Location.prerr_warning + {loc with loc_start = offset_pos loc_start start offset ; loc_end = offset_pos loc_start _end - offset } "%s" - (Parse_error.PP.error first_error) + offset } + (Bs_ffi_warning (Parse_error.PP.error first_error)) end module Ext_array : sig #1 "ext_array.mli" @@ -288242,7 +288242,7 @@ let raw_as_string_exp_exn Bs_flow_ast_utils.check_flow_errors ~loc ~offset:(Bs_flow_ast_utils.flow_deli_offset deli) (match kind with | Raw_re | Raw_exp -> - let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in + let (_loc,e),errors = Parser_flow.parse_expression (Parser_env.init_env None str) false in if kind = Raw_re then (match e with | Literal {value = RegExp _} -> () @@ -397047,16 +397047,20 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp = - in parsing - in code generation *) -let classify ?check (prog : string) : Js_raw_info.exp = +let classify ?(check : (Location.t*int) option) (prog : string) : Js_raw_info.exp = let prog, errors = Parser_flow.parse_expression (Parser_env.init_env None prog) false in - (match check with - | Some (loc,offset) -> + match check, errors with + | Some (loc,offset), _ :: _ -> Bs_flow_ast_utils.check_flow_errors - ~loc ~offset errors - | None -> ()); - classify_exp prog + ~loc ~offset errors; + Js_exp_unknown + | Some _, [] + | None , [] -> + classify_exp prog + | None , _ :: _ -> Js_exp_unknown + let classify_stmt (prog : string) : Js_raw_info.stmt =