Skip to content
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
11 changes: 9 additions & 2 deletions jscomp/core/classify_function.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ let classify (prog : string) : Js_raw_info.exp =
}) , [] ->
Js_function
{arity = List.length params; arrow = true}
|(_, Literal _), [] ->
Js_literal
|(_, Literal {comments}), [] ->
let comment =
match comments with
| None -> None
| Some {leading = [_, Block comment]} -> Some ("/*" ^ comment ^ "*/")
| Some {leading = [_, Line comment]} -> Some ("//" ^ comment)
| Some _ -> None
in
Js_literal {comment}
| _ ->
Js_exp_unknown
| exception _ ->
Expand Down
9 changes: 8 additions & 1 deletion jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
(match info with
| Exp exp_info ->
let raw_paren =
not (exp_info = Js_literal || raw_snippet_exp_simple_enough s) in
not (match exp_info with Js_literal _ -> true | _ -> false || raw_snippet_exp_simple_enough s) in
if raw_paren then P.string f L.lparen;
P.string f s ;
if raw_paren then P.string f L.rparen;
Expand Down Expand Up @@ -1059,6 +1059,13 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
| Raw_js_code {code = s; code_info = Stmt (Js_stmt_comment)} ->
P.string f s;
cxt
| Raw_js_code {code = s; code_info = Exp (Js_literal {comment})} ->
(match comment with
| Some s ->
P.string f s;
| None -> ());
cxt

| _ ->
let cxt =
(
Expand Down
5 changes: 4 additions & 1 deletion jscomp/core/js_raw_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

type exp =
| Js_function of {arity : int ; arrow : bool}
| Js_literal
| Js_literal of {comment : string option}
(* A special handling of
[%raw "/*lint*/ 0"]
*)
(* Flow ast module
{[
and value =
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
(* | Pjs_is_instance_array *)
| Pwrap_exn
| Praw_js_function _
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal) | Stmt Js_stmt_comment}
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal _) | Stmt Js_stmt_comment}
-> true
| Pjs_apply
| Pjs_runtime_apply
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/raw_pure_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var x3 = /ghoghos/;
*/

function f(x) {
((/*hgosgh */ undefined));
//eslint-disable
/*hgosgh */
return x;
}

Expand Down
4 changes: 3 additions & 1 deletion jscomp/test/raw_pure_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ let x3 = [%raw{|/ghoghos/|}]
let f = [%raw"/*hello*/ 0 "]
let hh = List.length
let f x =
ignore [%raw "/*hgosgh */ undefined"];
ignore [%raw "//eslint-disable
0"];
ignore [%raw {|/*hgosgh */0 |}];
x
(* let s = [%raw {hgosgho| (a,x) => {

Expand Down
5 changes: 4 additions & 1 deletion lib/4.06.1/bsdep.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34160,7 +34160,10 @@ module Js_raw_info

type exp =
| Js_function of {arity : int ; arrow : bool}
| Js_literal
| Js_literal of {comment : string option}
(* A special handling of
[%raw "/*lint*/ 0"]
*)
(* Flow ast module
{[
and value =
Expand Down
5 changes: 4 additions & 1 deletion lib/4.06.1/bsppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280236,7 +280236,10 @@ module Js_raw_info

type exp =
| Js_function of {arity : int ; arrow : bool}
| Js_literal
| Js_literal of {comment : string option}
(* A special handling of
[%raw "/*lint*/ 0"]
*)
(* Flow ast module
{[
and value =
Expand Down
27 changes: 22 additions & 5 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279891,7 +279891,10 @@ module Js_raw_info

type exp =
| Js_function of {arity : int ; arrow : bool}
| Js_literal
| Js_literal of {comment : string option}
(* A special handling of
[%raw "/*lint*/ 0"]
*)
(* Flow ast module
{[
and value =
Expand Down Expand Up @@ -378280,7 +378283,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
(match info with
| Exp exp_info ->
let raw_paren =
not (exp_info = Js_literal || raw_snippet_exp_simple_enough s) in
not (match exp_info with Js_literal _ -> true | _ -> false || raw_snippet_exp_simple_enough s) in
if raw_paren then P.string f L.lparen;
P.string f s ;
if raw_paren then P.string f L.rparen;
Expand Down Expand Up @@ -378689,6 +378692,13 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
| Raw_js_code {code = s; code_info = Stmt (Js_stmt_comment)} ->
P.string f s;
cxt
| Raw_js_code {code = s; code_info = Exp (Js_literal {comment})} ->
(match comment with
| Some s ->
P.string f s;
| None -> ());
cxt

| _ ->
let cxt =
(
Expand Down Expand Up @@ -393442,7 +393452,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
(* | Pjs_is_instance_array *)
| Pwrap_exn
| Praw_js_function _
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal) | Stmt Js_stmt_comment}
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal _) | Stmt Js_stmt_comment}
-> true
| Pjs_apply
| Pjs_runtime_apply
Expand Down Expand Up @@ -405065,8 +405075,15 @@ let classify (prog : string) : Js_raw_info.exp =
}) , [] ->
Js_function
{arity = List.length params; arrow = true}
|(_, Literal _), [] ->
Js_literal
|(_, Literal {comments}), [] ->
let comment =
match comments with
| None -> None
| Some {leading = [_, Block comment]} -> Some ("/*" ^ comment ^ "*/")
| Some {leading = [_, Line comment]} -> Some ("//" ^ comment)
| Some _ -> None
in
Js_literal {comment}
| _ ->
Js_exp_unknown
| exception _ ->
Expand Down
27 changes: 22 additions & 5 deletions lib/4.06.1/unstable/js_refmt_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279891,7 +279891,10 @@ module Js_raw_info

type exp =
| Js_function of {arity : int ; arrow : bool}
| Js_literal
| Js_literal of {comment : string option}
(* A special handling of
[%raw "/*lint*/ 0"]
*)
(* Flow ast module
{[
and value =
Expand Down Expand Up @@ -378280,7 +378283,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
(match info with
| Exp exp_info ->
let raw_paren =
not (exp_info = Js_literal || raw_snippet_exp_simple_enough s) in
not (match exp_info with Js_literal _ -> true | _ -> false || raw_snippet_exp_simple_enough s) in
if raw_paren then P.string f L.lparen;
P.string f s ;
if raw_paren then P.string f L.rparen;
Expand Down Expand Up @@ -378689,6 +378692,13 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
| Raw_js_code {code = s; code_info = Stmt (Js_stmt_comment)} ->
P.string f s;
cxt
| Raw_js_code {code = s; code_info = Exp (Js_literal {comment})} ->
(match comment with
| Some s ->
P.string f s;
| None -> ());
cxt

| _ ->
let cxt =
(
Expand Down Expand Up @@ -393442,7 +393452,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
(* | Pjs_is_instance_array *)
| Pwrap_exn
| Praw_js_function _
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal) | Stmt Js_stmt_comment}
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal _) | Stmt Js_stmt_comment}
-> true
| Pjs_apply
| Pjs_runtime_apply
Expand Down Expand Up @@ -405065,8 +405075,15 @@ let classify (prog : string) : Js_raw_info.exp =
}) , [] ->
Js_function
{arity = List.length params; arrow = true}
|(_, Literal _), [] ->
Js_literal
|(_, Literal {comments}), [] ->
let comment =
match comments with
| None -> None
| Some {leading = [_, Block comment]} -> Some ("/*" ^ comment ^ "*/")
| Some {leading = [_, Line comment]} -> Some ("//" ^ comment)
| Some _ -> None
in
Js_literal {comment}
| _ ->
Js_exp_unknown
| exception _ ->
Expand Down
5 changes: 4 additions & 1 deletion lib/4.06.1/unstable/native_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9301,7 +9301,10 @@ module Js_raw_info

type exp =
| Js_function of {arity : int ; arrow : bool}
| Js_literal
| Js_literal of {comment : string option}
(* A special handling of
[%raw "/*lint*/ 0"]
*)
(* Flow ast module
{[
and value =
Expand Down
27 changes: 22 additions & 5 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68577,7 +68577,10 @@ module Js_raw_info

type exp =
| Js_function of {arity : int ; arrow : bool}
| Js_literal
| Js_literal of {comment : string option}
(* A special handling of
[%raw "/*lint*/ 0"]
*)
(* Flow ast module
{[
and value =
Expand Down Expand Up @@ -100797,7 +100800,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
(match info with
| Exp exp_info ->
let raw_paren =
not (exp_info = Js_literal || raw_snippet_exp_simple_enough s) in
not (match exp_info with Js_literal _ -> true | _ -> false || raw_snippet_exp_simple_enough s) in
if raw_paren then P.string f L.lparen;
P.string f s ;
if raw_paren then P.string f L.rparen;
Expand Down Expand Up @@ -101206,6 +101209,13 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
| Raw_js_code {code = s; code_info = Stmt (Js_stmt_comment)} ->
P.string f s;
cxt
| Raw_js_code {code = s; code_info = Exp (Js_literal {comment})} ->
(match comment with
| Some s ->
P.string f s;
| None -> ());
cxt

| _ ->
let cxt =
(
Expand Down Expand Up @@ -106618,7 +106628,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
(* | Pjs_is_instance_array *)
| Pwrap_exn
| Praw_js_function _
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal) | Stmt Js_stmt_comment}
| Praw_js_code {code_info = Exp (Js_function _ | Js_literal _) | Stmt Js_stmt_comment}
-> true
| Pjs_apply
| Pjs_runtime_apply
Expand Down Expand Up @@ -400643,8 +400653,15 @@ let classify (prog : string) : Js_raw_info.exp =
}) , [] ->
Js_function
{arity = List.length params; arrow = true}
|(_, Literal _), [] ->
Js_literal
|(_, Literal {comments}), [] ->
let comment =
match comments with
| None -> None
| Some {leading = [_, Block comment]} -> Some ("/*" ^ comment ^ "*/")
| Some {leading = [_, Line comment]} -> Some ("//" ^ comment)
| Some _ -> None
in
Js_literal {comment}
| _ ->
Js_exp_unknown
| exception _ ->
Expand Down