Skip to content

Proof of concept: support directives. #5999

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 1 commit into from
Feb 10, 2023
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# 10.1.3

#### :nail_care: Polish

- Add the gap property to jsxDOMStyle https://github.com/rescript-lang/rescript-compiler/pull/5956

#### :bug: Bug Fix

- Fix issue where error messages related to non-existent props were displayed without location information https://github.com/rescript-lang/syntax/pull/730
- Fix issue where uncurried functions were incorrectly converting the type of a prop given as a default value to curried https://github.com/rescript-lang/syntax/pull/731
- Fix issue with nested async functions, where the inner function would be emitted without `async` https://github.com/rescript-lang/rescript-compiler/pull/5984
Expand All @@ -28,6 +28,10 @@
- Fix issue with using alias and default value together https://github.com/rescript-lang/syntax/pull/734
- Fix issue in `Js.Promise2` where `then` and `catch` were returning `undefined` https://github.com/rescript-lang/rescript-compiler/pull/5996

#### :rocket: New Feature

- Add experimental suppport for directives. An annotation such as `@@directive("use client;")` emits `use client;` verbatim before imports https://github.com/rescript-lang/rescript-compiler/pull/5999

# 10.1.2

#### :bug: Bug Fix
Expand Down
5 changes: 3 additions & 2 deletions jscomp/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ type jsx_module = React
type jsx_mode = Classic | Automatic

let no_version_header = ref false
let directives = ref []
let cross_module_inline = ref false
let diagnose = ref false

let get_diagnose () =
!diagnose

# 38 "common/js_config.pp.ml"
# 39 "common/js_config.pp.ml"
|| Sys.getenv_opt "RES_DEBUG_FILE" <> None

# 41 "common/js_config.pp.ml"
# 42 "common/js_config.pp.ml"
(* let (//) = Filename.concat *)

(* let get_packages_info () = !packages_info *)
Expand Down
3 changes: 3 additions & 0 deletions jscomp/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type jsx_mode = Classic | Automatic
val no_version_header : bool ref
(** set/get header *)

val directives : string list ref
(** directives printed verbatims just after the version header *)

(** return [package_name] and [path]
when in script mode:
*)
Expand Down
1 change: 1 addition & 0 deletions jscomp/common/js_config.pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type jsx_module = React
type jsx_mode = Classic | Automatic

let no_version_header = ref false
let directives = ref []
let cross_module_inline = ref false
let diagnose = ref false

Expand Down
4 changes: 4 additions & 0 deletions jscomp/core/js_dump_program.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ let pp_deps_program ~(output_prefix : string)
if not !Js_config.no_version_header then (
P.string f Bs_version.header;
P.newline f);
!Js_config.directives |> List.iter (fun prim ->
P.string f prim;
P.newline f);

if deps_program_is_empty program then P.string f empty_explanation
(* This is empty module, it won't be referred anywhere *)
else
Expand Down
4 changes: 4 additions & 0 deletions jscomp/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
})
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
| Pstr_attribute ({ txt = "directive" },
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
Js_config.directives := d :: !Js_config.directives;
str
| _ -> default_mapper.structure_item self str

let local_module_name =
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/build.ninja

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions jscomp/test/directives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
first directive;
second directive;
'use strict';

var Belt_Array = require("../../lib/js/belt_Array.js");

var a = Belt_Array.forEach;

exports.a = a;
/* No side effect */
5 changes: 5 additions & 0 deletions jscomp/test/directives.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@@directive("first directive;")
@@directive("second directive;")

let a = Belt.Array.forEach

12 changes: 12 additions & 0 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17380,6 +17380,9 @@ type jsx_mode = Classic | Automatic
val no_version_header : bool ref
(** set/get header *)

val directives : string list ref
(** directives printed verbatims just after the version header *)

(** return [package_name] and [path]
when in script mode:
*)
Expand Down Expand Up @@ -17494,6 +17497,7 @@ type jsx_module = React
type jsx_mode = Classic | Automatic

let no_version_header = ref false
let directives = ref []
let cross_module_inline = ref false
let diagnose = ref false

Expand Down Expand Up @@ -89287,6 +89291,10 @@ let pp_deps_program ~(output_prefix : string)
if not !Js_config.no_version_header then (
P.string f Bs_version.header;
P.newline f);
!Js_config.directives |> List.iter (fun prim ->
P.string f prim;
P.newline f);

if deps_program_is_empty program then P.string f empty_explanation
(* This is empty module, it won't be referred anywhere *)
else
Expand Down Expand Up @@ -273344,6 +273352,10 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
})
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
| Pstr_attribute ({ txt = "directive" },
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
Js_config.directives := d :: !Js_config.directives;
str
| _ -> default_mapper.structure_item self str

let local_module_name =
Expand Down
12 changes: 12 additions & 0 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17380,6 +17380,9 @@ type jsx_mode = Classic | Automatic
val no_version_header : bool ref
(** set/get header *)

val directives : string list ref
(** directives printed verbatims just after the version header *)

(** return [package_name] and [path]
when in script mode:
*)
Expand Down Expand Up @@ -17494,6 +17497,7 @@ type jsx_module = React
type jsx_mode = Classic | Automatic

let no_version_header = ref false
let directives = ref []
let cross_module_inline = ref false
let diagnose = ref false

Expand Down Expand Up @@ -89287,6 +89291,10 @@ let pp_deps_program ~(output_prefix : string)
if not !Js_config.no_version_header then (
P.string f Bs_version.header;
P.newline f);
!Js_config.directives |> List.iter (fun prim ->
P.string f prim;
P.newline f);

if deps_program_is_empty program then P.string f empty_explanation
(* This is empty module, it won't be referred anywhere *)
else
Expand Down Expand Up @@ -273344,6 +273352,10 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
})
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
| Pstr_attribute ({ txt = "directive" },
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
Js_config.directives := d :: !Js_config.directives;
str
| _ -> default_mapper.structure_item self str

let local_module_name =
Expand Down
12 changes: 12 additions & 0 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -180346,6 +180346,9 @@ type jsx_mode = Classic | Automatic
val no_version_header : bool ref
(** set/get header *)

val directives : string list ref
(** directives printed verbatims just after the version header *)

(** return [package_name] and [path]
when in script mode:
*)
Expand Down Expand Up @@ -180460,6 +180463,7 @@ type jsx_module = React
type jsx_mode = Classic | Automatic

let no_version_header = ref false
let directives = ref []
let cross_module_inline = ref false
let diagnose = ref false

Expand Down Expand Up @@ -258786,6 +258790,10 @@ let pp_deps_program ~(output_prefix : string)
if not !Js_config.no_version_header then (
P.string f Bs_version.header;
P.newline f);
!Js_config.directives |> List.iter (fun prim ->
P.string f prim;
P.newline f);

if deps_program_is_empty program then P.string f empty_explanation
(* This is empty module, it won't be referred anywhere *)
else
Expand Down Expand Up @@ -283731,6 +283739,10 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
})
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
| Pstr_attribute ({ txt = "directive" },
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
Js_config.directives := d :: !Js_config.directives;
str
| _ -> default_mapper.structure_item self str

let local_module_name =
Expand Down