Skip to content

Commit 5b7e606

Browse files
authored
Merge pull request #4169 from BuckleScript/try_no_post_install
An escape hatch for eslint style switches
2 parents 2b09b55 + cdc7e50 commit 5b7e606

File tree

12 files changed

+105
-25
lines changed

12 files changed

+105
-25
lines changed

jscomp/core/classify_function.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ let classify (prog : string) : Js_raw_info.exp =
4242
}) , [] ->
4343
Js_function
4444
{arity = List.length params; arrow = true}
45-
|(_, Literal _), [] ->
46-
Js_literal
45+
|(_, Literal {comments}), [] ->
46+
let comment =
47+
match comments with
48+
| None -> None
49+
| Some {leading = [_, Block comment]} -> Some ("/*" ^ comment ^ "*/")
50+
| Some {leading = [_, Line comment]} -> Some ("//" ^ comment)
51+
| Some _ -> None
52+
in
53+
Js_literal {comment}
4754
| _ ->
4855
Js_exp_unknown
4956
| exception _ ->

jscomp/core/js_dump.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
650650
(match info with
651651
| Exp exp_info ->
652652
let raw_paren =
653-
not (exp_info = Js_literal || raw_snippet_exp_simple_enough s) in
653+
not (match exp_info with Js_literal _ -> true | _ -> false || raw_snippet_exp_simple_enough s) in
654654
if raw_paren then P.string f L.lparen;
655655
P.string f s ;
656656
if raw_paren then P.string f L.rparen;
@@ -1059,6 +1059,13 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
10591059
| Raw_js_code {code = s; code_info = Stmt (Js_stmt_comment)} ->
10601060
P.string f s;
10611061
cxt
1062+
| Raw_js_code {code = s; code_info = Exp (Js_literal {comment})} ->
1063+
(match comment with
1064+
| Some s ->
1065+
P.string f s;
1066+
| None -> ());
1067+
cxt
1068+
10621069
| _ ->
10631070
let cxt =
10641071
(

jscomp/core/js_raw_info.ml

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

2626
type exp =
2727
| Js_function of {arity : int ; arrow : bool}
28-
| Js_literal
28+
| Js_literal of {comment : string option}
29+
(* A special handling of
30+
[%raw "/*lint*/ 0"]
31+
*)
2932
(* Flow ast module
3033
{[
3134
and value =

jscomp/core/lam_analysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
166166
(* | Pjs_is_instance_array *)
167167
| Pwrap_exn
168168
| Praw_js_function _
169-
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal) | Stmt Js_stmt_comment}
169+
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal _) | Stmt Js_stmt_comment}
170170
-> true
171171
| Pjs_apply
172172
| Pjs_runtime_apply

jscomp/test/raw_pure_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ var x3 = /ghoghos/;
1717
*/
1818

1919
function f(x) {
20-
((/*hgosgh */ undefined));
20+
//eslint-disable
21+
/*hgosgh */
2122
return x;
2223
}
2324

jscomp/test/raw_pure_test.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ let x3 = [%raw{|/ghoghos/|}]
2929
let f = [%raw"/*hello*/ 0 "]
3030
let hh = List.length
3131
let f x =
32-
ignore [%raw "/*hgosgh */ undefined"];
32+
ignore [%raw "//eslint-disable
33+
0"];
34+
ignore [%raw {|/*hgosgh */0 |}];
3335
x
3436
(* let s = [%raw {hgosgho| (a,x) => {
3537

lib/4.06.1/bsdep.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34160,7 +34160,10 @@ module Js_raw_info
3416034160

3416134161
type exp =
3416234162
| Js_function of {arity : int ; arrow : bool}
34163-
| Js_literal
34163+
| Js_literal of {comment : string option}
34164+
(* A special handling of
34165+
[%raw "/*lint*/ 0"]
34166+
*)
3416434167
(* Flow ast module
3416534168
{[
3416634169
and value =

lib/4.06.1/bsppx.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280236,7 +280236,10 @@ module Js_raw_info
280236280236

280237280237
type exp =
280238280238
| Js_function of {arity : int ; arrow : bool}
280239-
| Js_literal
280239+
| Js_literal of {comment : string option}
280240+
(* A special handling of
280241+
[%raw "/*lint*/ 0"]
280242+
*)
280240280243
(* Flow ast module
280241280244
{[
280242280245
and value =

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279891,7 +279891,10 @@ module Js_raw_info
279891279891

279892279892
type exp =
279893279893
| Js_function of {arity : int ; arrow : bool}
279894-
| Js_literal
279894+
| Js_literal of {comment : string option}
279895+
(* A special handling of
279896+
[%raw "/*lint*/ 0"]
279897+
*)
279895279898
(* Flow ast module
279896279899
{[
279897279900
and value =
@@ -378280,7 +378283,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
378280378283
(match info with
378281378284
| Exp exp_info ->
378282378285
let raw_paren =
378283-
not (exp_info = Js_literal || raw_snippet_exp_simple_enough s) in
378286+
not (match exp_info with Js_literal _ -> true | _ -> false || raw_snippet_exp_simple_enough s) in
378284378287
if raw_paren then P.string f L.lparen;
378285378288
P.string f s ;
378286378289
if raw_paren then P.string f L.rparen;
@@ -378689,6 +378692,13 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
378689378692
| Raw_js_code {code = s; code_info = Stmt (Js_stmt_comment)} ->
378690378693
P.string f s;
378691378694
cxt
378695+
| Raw_js_code {code = s; code_info = Exp (Js_literal {comment})} ->
378696+
(match comment with
378697+
| Some s ->
378698+
P.string f s;
378699+
| None -> ());
378700+
cxt
378701+
378692378702
| _ ->
378693378703
let cxt =
378694378704
(
@@ -393442,7 +393452,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
393442393452
(* | Pjs_is_instance_array *)
393443393453
| Pwrap_exn
393444393454
| Praw_js_function _
393445-
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal) | Stmt Js_stmt_comment}
393455+
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal _) | Stmt Js_stmt_comment}
393446393456
-> true
393447393457
| Pjs_apply
393448393458
| Pjs_runtime_apply
@@ -405065,8 +405075,15 @@ let classify (prog : string) : Js_raw_info.exp =
405065405075
}) , [] ->
405066405076
Js_function
405067405077
{arity = List.length params; arrow = true}
405068-
|(_, Literal _), [] ->
405069-
Js_literal
405078+
|(_, Literal {comments}), [] ->
405079+
let comment =
405080+
match comments with
405081+
| None -> None
405082+
| Some {leading = [_, Block comment]} -> Some ("/*" ^ comment ^ "*/")
405083+
| Some {leading = [_, Line comment]} -> Some ("//" ^ comment)
405084+
| Some _ -> None
405085+
in
405086+
Js_literal {comment}
405070405087
| _ ->
405071405088
Js_exp_unknown
405072405089
| exception _ ->

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279891,7 +279891,10 @@ module Js_raw_info
279891279891

279892279892
type exp =
279893279893
| Js_function of {arity : int ; arrow : bool}
279894-
| Js_literal
279894+
| Js_literal of {comment : string option}
279895+
(* A special handling of
279896+
[%raw "/*lint*/ 0"]
279897+
*)
279895279898
(* Flow ast module
279896279899
{[
279897279900
and value =
@@ -378280,7 +378283,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
378280378283
(match info with
378281378284
| Exp exp_info ->
378282378285
let raw_paren =
378283-
not (exp_info = Js_literal || raw_snippet_exp_simple_enough s) in
378286+
not (match exp_info with Js_literal _ -> true | _ -> false || raw_snippet_exp_simple_enough s) in
378284378287
if raw_paren then P.string f L.lparen;
378285378288
P.string f s ;
378286378289
if raw_paren then P.string f L.rparen;
@@ -378689,6 +378692,13 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
378689378692
| Raw_js_code {code = s; code_info = Stmt (Js_stmt_comment)} ->
378690378693
P.string f s;
378691378694
cxt
378695+
| Raw_js_code {code = s; code_info = Exp (Js_literal {comment})} ->
378696+
(match comment with
378697+
| Some s ->
378698+
P.string f s;
378699+
| None -> ());
378700+
cxt
378701+
378692378702
| _ ->
378693378703
let cxt =
378694378704
(
@@ -393442,7 +393452,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
393442393452
(* | Pjs_is_instance_array *)
393443393453
| Pwrap_exn
393444393454
| Praw_js_function _
393445-
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal) | Stmt Js_stmt_comment}
393455+
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal _) | Stmt Js_stmt_comment}
393446393456
-> true
393447393457
| Pjs_apply
393448393458
| Pjs_runtime_apply
@@ -405065,8 +405075,15 @@ let classify (prog : string) : Js_raw_info.exp =
405065405075
}) , [] ->
405066405076
Js_function
405067405077
{arity = List.length params; arrow = true}
405068-
|(_, Literal _), [] ->
405069-
Js_literal
405078+
|(_, Literal {comments}), [] ->
405079+
let comment =
405080+
match comments with
405081+
| None -> None
405082+
| Some {leading = [_, Block comment]} -> Some ("/*" ^ comment ^ "*/")
405083+
| Some {leading = [_, Line comment]} -> Some ("//" ^ comment)
405084+
| Some _ -> None
405085+
in
405086+
Js_literal {comment}
405070405087
| _ ->
405071405088
Js_exp_unknown
405072405089
| exception _ ->

0 commit comments

Comments
 (0)