Skip to content

Commit b288c74

Browse files
authored
Merge pull request #4932 from rescript-lang/gpr_4931
fix #4931, turn flow parse error into a warning instead
2 parents 8545c9e + 27ef969 commit b288c74

File tree

9 files changed

+85
-48
lines changed

9 files changed

+85
-48
lines changed

jscomp/frontend/ast_payload.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ let raw_as_string_exp_exn
8585
Bs_flow_ast_utils.check_flow_errors ~loc ~offset:(Bs_flow_ast_utils.flow_deli_offset deli) (match kind with
8686
| Raw_re
8787
| Raw_exp ->
88-
let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in
88+
let (_loc,e),errors = Parser_flow.parse_expression (Parser_env.init_env None str) false in
8989
if kind = Raw_re then
9090
(match e with
9191
| Literal {value = RegExp _} -> ()

jscomp/frontend/bs_flow_ast_utils.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ let flow_deli_offset deli =
4949
(* Here the loc is the payload loc *)
5050
let check_flow_errors ~(loc : Location.t)
5151
~offset
52-
(errors : (Loc.t * Parse_error.t) list) =
52+
(errors : (Loc.t * Parse_error.t) list) : unit =
5353
match errors with
5454
| [] -> ()
5555
| ({start ;
5656
_end },first_error) :: _ ->
5757
let loc_start = loc.loc_start in
58-
Location.raise_errorf
59-
~loc:{loc with
58+
Location.prerr_warning
59+
{loc with
6060
loc_start = offset_pos loc_start start
6161
offset ;
6262
loc_end = offset_pos loc_start _end
63-
offset } "%s"
64-
(Parse_error.PP.error first_error)
63+
offset }
64+
(Bs_ffi_warning (Parse_error.PP.error first_error))

jscomp/frontend/classify_function.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,20 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp =
8383
- in parsing
8484
- in code generation
8585
*)
86-
let classify ?check (prog : string) : Js_raw_info.exp =
86+
let classify ?(check : (Location.t*int) option) (prog : string) : Js_raw_info.exp =
8787
let prog, errors =
8888
Parser_flow.parse_expression
8989
(Parser_env.init_env None prog) false in
90-
(match check with
91-
| Some (loc,offset) ->
90+
match check, errors with
91+
| Some (loc,offset), _ :: _ ->
9292
Bs_flow_ast_utils.check_flow_errors
93-
~loc ~offset errors
94-
| None -> ());
95-
classify_exp prog
93+
~loc ~offset errors;
94+
Js_exp_unknown
95+
| Some _, []
96+
| None , [] ->
97+
classify_exp prog
98+
| None , _ :: _ -> Js_exp_unknown
99+
96100

97101

98102
let classify_stmt (prog : string) : Js_raw_info.stmt =

jscomp/test/build.ninja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ o test/gpr_4519_test.cmi test/gpr_4519_test.cmj : cc test/gpr_4519_test.ml | tes
334334
o test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib
335335
o test/gpr_4639_test.cmi test/gpr_4639_test.cmj : cc test/gpr_4639_test.ml | $stdlib
336336
o test/gpr_4924_test.cmi test/gpr_4924_test.cmj : cc test/gpr_4924_test.ml | $stdlib
337+
o test/gpr_4931.cmi test/gpr_4931.cmj : cc test/gpr_4931.ml | $stdlib
337338
o test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib
338339
o test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib
339340
o test/gpr_858_test.cmi test/gpr_858_test.cmj : cc test/gpr_858_test.ml | $stdlib

jscomp/test/gpr_4931.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
4+
if (import.meta.hot){
5+
console.log('es6')
6+
}
7+
;
8+
9+
/* Not a pure module */

jscomp/test/gpr_4931.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
[@@@config {
3+
flags = [|"-w";"-103"|]
4+
}]
5+
6+
7+
[%%raw{|
8+
if (import.meta.hot){
9+
console.log('es6')
10+
}
11+
|}]

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115329,19 +115329,19 @@ let flow_deli_offset deli =
115329115329
(* Here the loc is the payload loc *)
115330115330
let check_flow_errors ~(loc : Location.t)
115331115331
~offset
115332-
(errors : (Loc.t * Parse_error.t) list) =
115332+
(errors : (Loc.t * Parse_error.t) list) : unit =
115333115333
match errors with
115334115334
| [] -> ()
115335115335
| ({start ;
115336115336
_end },first_error) :: _ ->
115337115337
let loc_start = loc.loc_start in
115338-
Location.raise_errorf
115339-
~loc:{loc with
115338+
Location.prerr_warning
115339+
{loc with
115340115340
loc_start = offset_pos loc_start start
115341115341
offset ;
115342115342
loc_end = offset_pos loc_start _end
115343-
offset } "%s"
115344-
(Parse_error.PP.error first_error)
115343+
offset }
115344+
(Bs_ffi_warning (Parse_error.PP.error first_error))
115345115345
end
115346115346
module Flow_ast
115347115347
= struct
@@ -393849,16 +393849,20 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp =
393849393849
- in parsing
393850393850
- in code generation
393851393851
*)
393852-
let classify ?check (prog : string) : Js_raw_info.exp =
393852+
let classify ?(check : (Location.t*int) option) (prog : string) : Js_raw_info.exp =
393853393853
let prog, errors =
393854393854
Parser_flow.parse_expression
393855393855
(Parser_env.init_env None prog) false in
393856-
(match check with
393857-
| Some (loc,offset) ->
393856+
match check, errors with
393857+
| Some (loc,offset), _ :: _ ->
393858393858
Bs_flow_ast_utils.check_flow_errors
393859-
~loc ~offset errors
393860-
| None -> ());
393861-
classify_exp prog
393859+
~loc ~offset errors;
393860+
Js_exp_unknown
393861+
| Some _, []
393862+
| None , [] ->
393863+
classify_exp prog
393864+
| None , _ :: _ -> Js_exp_unknown
393865+
393862393866

393863393867

393864393868
let classify_stmt (prog : string) : Js_raw_info.stmt =
@@ -398775,7 +398779,7 @@ let raw_as_string_exp_exn
398775398779
Bs_flow_ast_utils.check_flow_errors ~loc ~offset:(Bs_flow_ast_utils.flow_deli_offset deli) (match kind with
398776398780
| Raw_re
398777398781
| Raw_exp ->
398778-
let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in
398782+
let (_loc,e),errors = Parser_flow.parse_expression (Parser_env.init_env None str) false in
398779398783
if kind = Raw_re then
398780398784
(match e with
398781398785
| Literal {value = RegExp _} -> ()

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115329,19 +115329,19 @@ let flow_deli_offset deli =
115329115329
(* Here the loc is the payload loc *)
115330115330
let check_flow_errors ~(loc : Location.t)
115331115331
~offset
115332-
(errors : (Loc.t * Parse_error.t) list) =
115332+
(errors : (Loc.t * Parse_error.t) list) : unit =
115333115333
match errors with
115334115334
| [] -> ()
115335115335
| ({start ;
115336115336
_end },first_error) :: _ ->
115337115337
let loc_start = loc.loc_start in
115338-
Location.raise_errorf
115339-
~loc:{loc with
115338+
Location.prerr_warning
115339+
{loc with
115340115340
loc_start = offset_pos loc_start start
115341115341
offset ;
115342115342
loc_end = offset_pos loc_start _end
115343-
offset } "%s"
115344-
(Parse_error.PP.error first_error)
115343+
offset }
115344+
(Bs_ffi_warning (Parse_error.PP.error first_error))
115345115345
end
115346115346
module Flow_ast
115347115347
= struct
@@ -393849,16 +393849,20 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp =
393849393849
- in parsing
393850393850
- in code generation
393851393851
*)
393852-
let classify ?check (prog : string) : Js_raw_info.exp =
393852+
let classify ?(check : (Location.t*int) option) (prog : string) : Js_raw_info.exp =
393853393853
let prog, errors =
393854393854
Parser_flow.parse_expression
393855393855
(Parser_env.init_env None prog) false in
393856-
(match check with
393857-
| Some (loc,offset) ->
393856+
match check, errors with
393857+
| Some (loc,offset), _ :: _ ->
393858393858
Bs_flow_ast_utils.check_flow_errors
393859-
~loc ~offset errors
393860-
| None -> ());
393861-
classify_exp prog
393859+
~loc ~offset errors;
393860+
Js_exp_unknown
393861+
| Some _, []
393862+
| None , [] ->
393863+
classify_exp prog
393864+
| None , _ :: _ -> Js_exp_unknown
393865+
393862393866

393863393867

393864393868
let classify_stmt (prog : string) : Js_raw_info.stmt =
@@ -398775,7 +398779,7 @@ let raw_as_string_exp_exn
398775398779
Bs_flow_ast_utils.check_flow_errors ~loc ~offset:(Bs_flow_ast_utils.flow_deli_offset deli) (match kind with
398776398780
| Raw_re
398777398781
| Raw_exp ->
398778-
let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in
398782+
let (_loc,e),errors = Parser_flow.parse_expression (Parser_env.init_env None str) false in
398779398783
if kind = Raw_re then
398780398784
(match e with
398781398785
| Literal {value = RegExp _} -> ()

lib/4.06.1/whole_compiler.ml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5457,19 +5457,19 @@ let flow_deli_offset deli =
54575457
(* Here the loc is the payload loc *)
54585458
let check_flow_errors ~(loc : Location.t)
54595459
~offset
5460-
(errors : (Loc.t * Parse_error.t) list) =
5460+
(errors : (Loc.t * Parse_error.t) list) : unit =
54615461
match errors with
54625462
| [] -> ()
54635463
| ({start ;
54645464
_end },first_error) :: _ ->
54655465
let loc_start = loc.loc_start in
5466-
Location.raise_errorf
5467-
~loc:{loc with
5466+
Location.prerr_warning
5467+
{loc with
54685468
loc_start = offset_pos loc_start start
54695469
offset ;
54705470
loc_end = offset_pos loc_start _end
5471-
offset } "%s"
5472-
(Parse_error.PP.error first_error)
5471+
offset }
5472+
(Bs_ffi_warning (Parse_error.PP.error first_error))
54735473
end
54745474
module Ext_array : sig
54755475
#1 "ext_array.mli"
@@ -288242,7 +288242,7 @@ let raw_as_string_exp_exn
288242288242
Bs_flow_ast_utils.check_flow_errors ~loc ~offset:(Bs_flow_ast_utils.flow_deli_offset deli) (match kind with
288243288243
| Raw_re
288244288244
| Raw_exp ->
288245-
let (_loc,e),errors = (Parser_flow.parse_expression (Parser_env.init_env None str) false) in
288245+
let (_loc,e),errors = Parser_flow.parse_expression (Parser_env.init_env None str) false in
288246288246
if kind = Raw_re then
288247288247
(match e with
288248288248
| Literal {value = RegExp _} -> ()
@@ -397047,16 +397047,20 @@ let classify_exp (prog : _ Flow_ast.Expression.t ) : Js_raw_info.exp =
397047397047
- in parsing
397048397048
- in code generation
397049397049
*)
397050-
let classify ?check (prog : string) : Js_raw_info.exp =
397050+
let classify ?(check : (Location.t*int) option) (prog : string) : Js_raw_info.exp =
397051397051
let prog, errors =
397052397052
Parser_flow.parse_expression
397053397053
(Parser_env.init_env None prog) false in
397054-
(match check with
397055-
| Some (loc,offset) ->
397054+
match check, errors with
397055+
| Some (loc,offset), _ :: _ ->
397056397056
Bs_flow_ast_utils.check_flow_errors
397057-
~loc ~offset errors
397058-
| None -> ());
397059-
classify_exp prog
397057+
~loc ~offset errors;
397058+
Js_exp_unknown
397059+
| Some _, []
397060+
| None , [] ->
397061+
classify_exp prog
397062+
| None , _ :: _ -> Js_exp_unknown
397063+
397060397064

397061397065

397062397066
let classify_stmt (prog : string) : Js_raw_info.stmt =

0 commit comments

Comments
 (0)