Skip to content
Merged
Prev Previous commit
Next Next commit
Cleanup
  • Loading branch information
cknitt committed Feb 20, 2024
commit f02409a2cc08b865e0b919056491279625773778
3 changes: 1 addition & 2 deletions jscomp/frontend/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ let rs_externals (attrs : t) pval_prim =
prims_to_be_encoded pval_prim
| _, _ ->
Ext_list.exists_fst attrs (fun ({txt} : string Asttypes.loc) ->
Ext_string.starts_with txt "bs."
|| Ext_array.exists external_attrs (fun (x : string) -> txt = x))
Ext_array.exists external_attrs (fun (x : string) -> txt = x))
|| prims_to_be_encoded pval_prim

let is_inline : attr -> bool = fun ({txt}, _) -> txt = "inline"
Expand Down
13 changes: 4 additions & 9 deletions jscomp/frontend/bs_ast_invariant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@
*)
let is_bs_attribute txt =
Copy link
Member Author

@cknitt cknitt Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not invoked for the non-bs attributes and therefore the unused attribute check was not working for those, see #6636.

Some more investigation needed though as adding "as" causes tests to fail. This should be done in a separate PR.

match txt with
(* TODO: Issue 6636 *)
| "string" | "uncurry" -> true
| _ ->
let len = String.length txt in
len >= 2
(*TODO: check the stringing padding rule, this preciate may not be needed *)
&& String.unsafe_get txt 0 = 'b'
&& String.unsafe_get txt 1 = 's'
&& (len = 2 || String.unsafe_get txt 2 = '.')
| "bs" | "config" | "ignore" | "int" | "optional" | "string" | "uncurry"
| "unwrap" ->
true
| _ -> false

let used_attributes : string Asttypes.loc Hash_set_poly.t =
Hash_set_poly.create 16
Expand Down
12 changes: 0 additions & 12 deletions jscomp/syntax/src/res_ast_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,6 @@ let normalize =
let open Ast_mapper in
{
default_mapper with
extension =
(fun mapper ext ->
match ext with
| id, payload ->
( {id with txt = Res_printer.convertBsExtension id.txt},
default_mapper.payload mapper payload ));
attribute =
(fun mapper attr ->
match attr with
| id, payload ->
( {id with txt = Res_printer.convertBsExternalAttribute id.txt},
default_mapper.payload mapper payload ));
attributes =
(fun mapper attrs ->
attrs
Expand Down
47 changes: 2 additions & 45 deletions jscomp/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,6 @@ type callbackStyle =
*)
| ArgumentsFitOnOneLine

(* Since compiler version 8.3, the bs. prefix is no longer needed *)
(* Synced from
https://github.com/rescript-lang/rescript-compiler/blob/29174de1a5fde3b16cf05d10f5ac109cfac5c4ca/jscomp/frontend/ast_external_process.ml#L291-L367 *)
let convertBsExternalAttribute = function
| "bs.as" -> "as"
| "bs.deriving" -> "deriving"
| "bs.get" -> "get"
| "bs.get_index" -> "get_index"
| "bs.ignore" -> "ignore"
| "bs.inline" -> "inline"
| "bs.int" -> "int"
| "bs.meth" -> "meth"
| "bs.module" -> "module"
| "bs.new" -> "new"
| "bs.obj" -> "obj"
| "bs.optional" -> "optional"
| "bs.return" -> "return"
| "bs.send" -> "send"
| "bs.scope" -> "scope"
| "bs.set" -> "set"
| "bs.set_index" -> "set_index"
| "bs.splice" | "bs.variadic" -> "variadic"
| "bs.string" -> "string"
| "bs.this" -> "this"
| "bs.uncurry" -> "uncurry"
| "bs.unwrap" -> "unwrap"
| "bs.val" -> "val"
(* bs.send.pipe shouldn't be transformed *)
| txt -> txt

(* These haven't been needed for a long time now *)
(* Synced from
https://github.com/rescript-lang/rescript-compiler/blob/29174de1a5fde3b16cf05d10f5ac109cfac5c4ca/jscomp/frontend/ast_exp_extension.ml *)
let convertBsExtension = function
| "bs.debugger" -> "debugger"
| "bs.external" -> "raw"
(* We should never see this one since we use the sugared object form, but still *)
| "bs.obj" -> "obj"
| "bs.raw" -> "raw"
| "bs.re" -> "re"
(* TODO: what about bs.time and bs.node? *)
| txt -> txt

let addParens doc =
Doc.group
(Doc.concat
Expand Down Expand Up @@ -2154,7 +2111,7 @@ and printPackageConstraint ~state i cmtTbl (longidentLoc, typ) =
]

and printExtension ~state ~atModuleLvl (stringLoc, payload) cmtTbl =
let txt = convertBsExtension stringLoc.Location.txt in
let txt = stringLoc.Location.txt in
let extName =
let doc =
Doc.concat
Expand Down Expand Up @@ -5466,7 +5423,7 @@ and printAttribute ?(standalone = false) ~state
(Doc.concat
[
Doc.text (if standalone then "@@" else "@");
Doc.text (convertBsExternalAttribute id.txt);
Doc.text id.txt;
printPayload ~state payload cmtTbl;
]),
Doc.line )
Expand Down
3 changes: 0 additions & 3 deletions jscomp/syntax/src/res_printer.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
val convertBsExternalAttribute : string -> string
val convertBsExtension : string -> string

val printTypeParams :
(Parsetree.core_type * Asttypes.variance) list ->
Res_comments_table.t ->
Expand Down