Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit e9105a4

Browse files
author
Iwan
committed
Print attributes without the @bs prefix where possible.
1 parent 28441d8 commit e9105a4

File tree

19 files changed

+139
-86
lines changed

19 files changed

+139
-86
lines changed

src/res_ast_conversion.ml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,36 @@ let stringLiteralMapper stringData =
321321
let normalize =
322322
let open Ast_mapper in
323323
{ default_mapper with
324+
attribute = (fun mapper attr ->
325+
match attr with
326+
| (id, payload) ->
327+
(* Reminder, keep this in sync with src/res_printer.ml *)
328+
let contents = match id.txt with
329+
| "bs.val" -> "val"
330+
| "bs.module" -> "module"
331+
| "bs.scope" -> "scope"
332+
| "bs.splice" | "bs.variadic" -> "variadic"
333+
| "bs.set" -> "set"
334+
| "bs.set_index" -> "set_index"
335+
| "bs.get" -> "get"
336+
| "bs.get_index" -> "get_index"
337+
| "bs.new" -> "new"
338+
| "bs.obj" -> "obj"
339+
| "bs.return" -> "return"
340+
| "bs.uncurry" -> "uncurry"
341+
| "bs.this" -> "this"
342+
| "bs.meth" -> "meth"
343+
| "bs.deriving" -> "deriving"
344+
| "bs.string" -> "string"
345+
| "bs.int" -> "int"
346+
| "bs.ignore" -> "ignore"
347+
| "bs.unwrap" -> "unwrap"
348+
| "bs.as" -> "as"
349+
| "bs.optional" -> "optional"
350+
| txt -> txt
351+
in
352+
({id with txt = contents}, default_mapper.payload mapper payload)
353+
);
324354
attributes = (fun mapper attrs ->
325355
attrs
326356
|> List.filter (fun attr ->

src/res_printer.ml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4824,10 +4824,34 @@ and printPayload (payload : Parsetree.payload) cmtTbl =
48244824
]
48254825

48264826
and printAttribute ((id, payload) : Parsetree.attribute) cmtTbl =
4827+
let contents = match id.txt with
4828+
| "bs.val" -> "val"
4829+
| "bs.module" -> "module"
4830+
| "bs.scope" -> "scope"
4831+
| "bs.splice" | "bs.variadic" -> "variadic"
4832+
| "bs.set" -> "set"
4833+
| "bs.set_index" -> "set_index"
4834+
| "bs.get" -> "get"
4835+
| "bs.get_index" -> "get_index"
4836+
| "bs.new" -> "new"
4837+
| "bs.obj" -> "obj"
4838+
| "bs.return" -> "return"
4839+
| "bs.uncurry" -> "uncurry"
4840+
| "bs.this" -> "this"
4841+
| "bs.meth" -> "meth"
4842+
| "bs.deriving" -> "deriving"
4843+
| "bs.string" -> "string"
4844+
| "bs.int" -> "int"
4845+
| "bs.ignore" -> "ignore"
4846+
| "bs.unwrap" -> "unwrap"
4847+
| "bs.as" -> "as"
4848+
| "bs.optional" -> "optional"
4849+
| txt -> txt
4850+
in
48274851
Doc.group (
48284852
Doc.concat [
48294853
Doc.text "@";
4830-
Doc.text id.txt;
4854+
Doc.text contents;
48314855
printPayload payload cmtTbl
48324856
]
48334857
)

tests/conversion/reason/__snapshots__/render.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ module Form = %form(
12451245
name: string,
12461246
email: string,
12471247
message: string,
1248-
@bs.as(\\"form-name\\")
1248+
@as(\\"form-name\\")
12491249
formName: string,
12501250
}
12511251
type output = input

tests/ppx/react/__snapshots__/render.spec.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`commentAtTop.res 1`] = `
4-
"@bs.obj
4+
"@obj
55
external makeProps: (~msg: 'msg, ~key: string=?, unit) => {\\"msg\\": 'msg} = \\"\\" // test React JSX file
66
77
let make =
@@ -17,14 +17,14 @@ let make = {
1717
1818
exports[`externalWithCustomName.res 1`] = `
1919
"module Foo = {
20-
@bs.obj
20+
@obj
2121
external componentProps: (
2222
~a: int,
2323
~b: string,
2424
~key: string=?,
2525
unit,
2626
) => {\\"a\\": int, \\"b\\": string} = \\"\\"
27-
@bs.module(\\"Foo\\")
27+
@module(\\"Foo\\")
2828
external component: React.componentLike<
2929
{\\"a\\": int, \\"b\\": string},
3030
React.element,
@@ -40,7 +40,7 @@ let t = React.createElement(
4040
4141
exports[`innerModule.res 1`] = `
4242
"module Bar = {
43-
@bs.obj
43+
@obj
4444
external makeProps: (
4545
~a: 'a,
4646
~b: 'b,
@@ -57,7 +57,7 @@ exports[`innerModule.res 1`] = `
5757
make(~b=\\\\\\"Props\\"[\\"b\\"], ~a=\\\\\\"Props\\"[\\"a\\"], ())
5858
\\\\\\"InnerModule$Bar\\"
5959
}
60-
@bs.obj
60+
@obj
6161
external componentProps: (
6262
~a: 'a,
6363
~b: 'b,
@@ -80,7 +80,7 @@ exports[`innerModule.res 1`] = `
8080
`;
8181
8282
exports[`topLevel.res 1`] = `
83-
"@bs.obj
83+
"@obj
8484
external makeProps: (
8585
~a: 'a,
8686
~b: 'b,

tests/ppx/react/externalWithCustomName.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Foo = {
2-
@react.component @bs.module("Foo")
2+
@react.component @module("Foo")
33
external component: (~a: int, ~b: string, _) => React.element = "component"
44
}
55

tests/printer/comments/__snapshots__/render.spec.js.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,32 +1732,32 @@ type /* c0 */ color /* c1 */ = /* before manifest */ Colour.t /* after manifest
17321732
}
17331733
17341734
type domProps = {
1735-
@bs.optional
1735+
@optional
17361736
viewTarget: string,
1737-
@bs.optional
1737+
@optional
17381738
visibility: string,
17391739
/* width::string? => */
1740-
@bs.optional
1740+
@optional
17411741
widths: string,
1742-
@bs.optional
1742+
@optional
17431743
wordSpacing: string,
1744-
@bs.optional
1744+
@optional
17451745
writingMode: string,
1746-
@bs.optional
1746+
@optional
17471747
x: string,
1748-
@bs.optional
1748+
@optional
17491749
x1: string,
17501750
}
17511751
1752-
@bs.deriving(abstract)
1752+
@deriving(abstract)
17531753
type t = {
17541754
/* MDX shortnames for more advanced components */
1755-
@bs.as(\\"Cite\\")
1755+
@as(\\"Cite\\")
17561756
cite: React.component<{
17571757
\\"author\\": option<string>,
17581758
\\"children\\": React.element,
17591759
}>,
1760-
@bs.as(\\"Info\\") @bs.optional
1760+
@as(\\"Info\\") @optional
17611761
info: React.component<props>,
17621762
}
17631763

tests/printer/comments/typeDefinition.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,32 @@ type /* c0 */ color /* c1 */ = /* before manifest */ Colour.t /* after manifest
5858
}
5959

6060
type domProps = {
61-
@bs.optional
61+
@optional
6262
viewTarget: string,
63-
@bs.optional
63+
@optional
6464
visibility: string,
6565
/*width::string? =>*/
66-
@bs.optional
66+
@optional
6767
widths: string,
68-
@bs.optional
68+
@optional
6969
wordSpacing: string,
70-
@bs.optional
70+
@optional
7171
writingMode: string,
72-
@bs.optional
72+
@optional
7373
x: string,
74-
@bs.optional
74+
@optional
7575
x1: string,
7676
}
7777

78-
@bs.deriving(abstract)
78+
@deriving(abstract)
7979
type t = {
8080
/* MDX shortnames for more advanced components */
81-
@bs.as("Cite")
81+
@as("Cite")
8282
cite: React.component<{
8383
"author": option<string>,
8484
"children": React.element,
8585
}>,
86-
@bs.as("Info") @bs.optional
86+
@as("Info") @optional
8787
info: React.component<props>,
8888
}
8989

tests/printer/expr/__snapshots__/render.spec.js.snap

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,8 @@ let () = {
791791
let reifyStyle = (type a, x: 'a): (style<a>, a) => {
792792
module Internal = {
793793
type rec constructor
794-
@bs.val
795-
external canvasGradient: constructor = \\"CanvasGradient\\" /* internal */
796-
@bs.val external canvasPattern: constructor = \\"CanvasPattern\\" /* internal */
794+
@val external canvasGradient: constructor = \\"CanvasGradient\\" /* internal */
795+
@val external canvasPattern: constructor = \\"CanvasPattern\\" /* internal */
797796
let instanceOf = (
798797
%bs.raw(\`function(x,y) {return +(x instanceof y)}\`): (
799798
'a,
@@ -3255,19 +3254,19 @@ let d = #abcd
32553254
32563255
external openSync: (
32573256
path,
3258-
@bs.string
3257+
@string
32593258
[
3260-
| @bs.as(\\"r\\") #Read
3261-
| @bs.as(\\"r+\\") #Read_write
3262-
| @bs.as(\\"rs+\\") #Read_write_sync
3263-
| @bs.as(\\"w\\") #Write
3264-
| @bs.as(\\"wx\\") #Write_fail_if_exists
3265-
| @bs.as(\\"w+\\") #Write_read
3266-
| @bs.as(\\"wx+\\") #Write_read_fail_if_exists
3267-
| @bs.as(\\"a\\") #Append
3268-
| @bs.as(\\"ax\\") #Append_fail_if_exists
3269-
| @bs.as(\\"a+\\") #Append_read
3270-
| @bs.as(\\"ax+\\") #Append_read_fail_if_exists
3259+
| @as(\\"r\\") #Read
3260+
| @as(\\"r+\\") #Read_write
3261+
| @as(\\"rs+\\") #Read_write_sync
3262+
| @as(\\"w\\") #Write
3263+
| @as(\\"wx\\") #Write_fail_if_exists
3264+
| @as(\\"w+\\") #Write_read
3265+
| @as(\\"wx+\\") #Write_read_fail_if_exists
3266+
| @as(\\"a\\") #Append
3267+
| @as(\\"ax\\") #Append_fail_if_exists
3268+
| @as(\\"a+\\") #Append_read
3269+
| @as(\\"ax+\\") #Append_read_fail_if_exists
32713270
],
32723271
) => unit = \\"openSync\\"
32733272
"

tests/printer/expr/block.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ let () = {
1616
let reifyStyle = (type a, x: 'a): (style<a>, a) => {
1717
module Internal = {
1818
type rec constructor
19-
@bs.val external canvasGradient: constructor = "CanvasGradient" /* internal */
20-
@bs.val external canvasPattern: constructor = "CanvasPattern" /* internal */
19+
@val external canvasGradient: constructor = "CanvasGradient" /* internal */
20+
@val external canvasPattern: constructor = "CanvasPattern" /* internal */
2121
let instanceOf = (
2222
%bs.raw(`function(x,y) {return +(x instanceof y)}`): ('a, constructor) => bool
2323
) /* internal */

tests/printer/expr/polyvariant.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ let d = #abcd
118118

119119
external openSync: (
120120
path,
121-
@bs.string [
122-
| @bs.as("r") #Read
123-
| @bs.as("r+") #Read_write
124-
| @bs.as("rs+") #Read_write_sync
125-
| @bs.as("w") #Write
126-
| @bs.as("wx") #Write_fail_if_exists
127-
| @bs.as("w+") #Write_read
128-
| @bs.as("wx+") #Write_read_fail_if_exists
129-
| @bs.as("a") #Append
130-
| @bs.as("ax") #Append_fail_if_exists
131-
| @bs.as("a+") #Append_read
132-
| @bs.as("ax+") #Append_read_fail_if_exists
121+
@string [
122+
| @as("r") #Read
123+
| @as("r+") #Read_write
124+
| @as("rs+") #Read_write_sync
125+
| @as("w") #Write
126+
| @as("wx") #Write_fail_if_exists
127+
| @as("w+") #Write_read
128+
| @as("wx+") #Write_read_fail_if_exists
129+
| @as("a") #Append
130+
| @as("ax") #Append_fail_if_exists
131+
| @as("a+") #Append_read
132+
| @as("ax+") #Append_read_fail_if_exists
133133
],
134134
) => unit = "openSync"

tests/printer/other/__snapshots__/render.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ module Range = {
300300
children: React.element,
301301
}
302302
303-
@bs.module(\\"react-range\\") @react.component
303+
@module(\\"react-range\\") @react.component
304304
external make: (
305305
~min: int,
306306
~max: int,

tests/printer/other/fatSlider.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Range = {
1111
children: React.element,
1212
}
1313

14-
@bs.module("react-range") @react.component
14+
@module("react-range") @react.component
1515
external make: (
1616
~min: int,
1717
~max: int,

tests/printer/structure/__snapshots__/render.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ exports[`extension.js 1`] = `
9494
`;
9595
9696
exports[`external.js 1`] = `
97-
"@bs.val external null: reactElement = \\"null\\"
97+
"@val external null: reactElement = \\"null\\"
9898
9999
external string: string => reactElement = \\"%identity\\"
100100
@@ -115,7 +115,7 @@ include WebGl
115115
include (
116116
/* Use varargs to avoid the ReactJS warning for duplicate keys in children */
117117
{
118-
@bs.val @bs.module(\\"react\\")
118+
@val @module(\\"react\\")
119119
external createElementInternalHack: 'a = \\"createElement\\"
120120
@bs.send
121121
external apply: (

tests/printer/structure/external.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@bs.val external null: reactElement = "null";
1+
@val external null: reactElement = "null";
22

33
external string: string => reactElement = "%identity";
44

tests/printer/structure/include.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include WebGl
66
include (
77
/* Use varargs to avoid the ReactJS warning for duplicate keys in children */
88
{
9-
@bs.val @bs.module("react")
9+
@val @module("react")
1010
external createElementInternalHack: 'a = "createElement"
1111
@bs.send
1212
external apply: (

0 commit comments

Comments
 (0)