Skip to content

fix #4931, turn flow parse error into a warning instead #4932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jscomp/frontend/ast_payload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 _} -> ()
Expand Down
10 changes: 5 additions & 5 deletions jscomp/frontend/bs_flow_ast_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
offset }
(Bs_ffi_warning (Parse_error.PP.error first_error))
16 changes: 10 additions & 6 deletions jscomp/frontend/classify_function.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions jscomp/test/build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions jscomp/test/gpr_4931.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';


if (import.meta.hot){
console.log('es6')
}
;

/* Not a pure module */
11 changes: 11 additions & 0 deletions jscomp/test/gpr_4931.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

[@@@config {
flags = [|"-w";"-103"|]
}]


[%%raw{|
if (import.meta.hot){
console.log('es6')
}
|}]
28 changes: 16 additions & 12 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 _} -> ()
Expand Down
28 changes: 16 additions & 12 deletions lib/4.06.1/unstable/js_refmt_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 _} -> ()
Expand Down
28 changes: 16 additions & 12 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 _} -> ()
Expand Down Expand Up @@ -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 =
Expand Down