Skip to content

Commit 1f43149

Browse files
committed
fix: drop labels from single-source constructors
Update DOMMatrix, DOMMatrixReadOnly, Path2D, and ReadableStream single-source constructor overloads to take direct unlabeled arguments. Refresh compile-coverage tests and contributor documentation to match the constructor naming convention.
1 parent 07aaf50 commit 1f43149

10 files changed

Lines changed: 42 additions & 41 deletions

File tree

docs/content/docs/contributing/api-modelling.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ And if a constructor really does have a default form, split it instead of hiding
8888
external make: unit => domMatrix = "DOMMatrix"
8989
9090
@new
91-
external fromString: (~init: string) => domMatrix = "DOMMatrix"
91+
external fromString: string => domMatrix = "DOMMatrix"
9292
9393
@new
94-
external fromArray: (~init: array<float>) => domMatrix = "DOMMatrix"
94+
external fromArray: array<float> => domMatrix = "DOMMatrix"
9595
```
9696

97+
Single-source constructor variants should take the source value directly without a label.
98+
9799
Keep `makeWith*` names for non-default convenience constructors that are not part of a source-type overload family.
98100

99101
Constructor naming is currently verified with compile-coverage tests. Runtime verification for these constructor families will be added later when the Vitest and happy-dom harness lands.

docs/content/docs/contributing/documentation.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,25 @@ external fetch: (window, string, ~init: requestInit=?)
4848

4949
Constructor overloads should use the same structure, but make the differentiating input shape explicit.
5050
Link ReScript stdlib types such as `string`, `array<'a>`, `ArrayBuffer.t`, and `DataView.t`, and link project-local records or aliases when the constructor takes one of those shapes.
51+
If a constructor variant has a single source input, show it as a direct unlabeled argument in both the signature and example.
5152

5253
````ReScript
5354
/*
54-
`fromArray(~init: array<float>)`
55+
`fromArray(array<float>)`
5556
5657
The DOMMatrix() constructor creates a new DOMMatrix from an array of matrix component values.
5758
5859
Source shape:
59-
- `init`: ReScript [array](https://rescript-lang.org/docs/manual/api/stdlib/array) of numeric values accepted by MDN [DOMMatrix()](https://developer.mozilla.org/docs/Web/API/DOMMatrix/DOMMatrix).
60+
- ReScript [array](https://rescript-lang.org/docs/manual/api/stdlib/array) of numeric values accepted by MDN [DOMMatrix()](https://developer.mozilla.org/docs/Web/API/DOMMatrix/DOMMatrix).
6061
6162
```res
62-
let matrix = DOMMatrix.fromArray(~init=[1., 0., 0., 1., 0., 0.])
63+
let matrix = DOMMatrix.fromArray([1., 0., 0., 1., 0., 0.])
6364
```
6465
6566
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DOMMatrix)
6667
*/
6768
@new
68-
external fromArray: (~init: array<float>) => domMatrix = "DOMMatrix"
69+
external fromArray: array<float> => domMatrix = "DOMMatrix"
6970
````
7071

7172
For now, these examples stay compile-coverage oriented. Runtime verification of constructor behavior will be handled later via Vitest and happy-dom.

packages/Canvas/src/Path2D.res

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,38 @@ let path = Path2D.make()
1818
external make: unit => Types.path2D = "Path2D"
1919

2020
/**
21-
`fromPath2D(~path: Path2D.t)`
21+
`fromPath2D(path2D)`
2222
2323
The Path2D() constructor creates a new Path2D object by copying another Path2D source.
2424
2525
Source shape:
2626
- local [`Path2D.t`](#t) mapped to MDN [Path2D](https://developer.mozilla.org/docs/Web/API/Path2D).
2727
2828
```res
29-
let copiedPath = Path2D.fromPath2D(~path=existingPath)
29+
let copiedPath = Path2D.fromPath2D(existingPath)
3030
```
3131
3232
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Path2D)
3333
*/
3434
@new
35-
external fromPath2D: (~path: Types.path2D) => Types.path2D = "Path2D"
35+
external fromPath2D: Types.path2D => Types.path2D = "Path2D"
3636

3737
/**
38-
`fromString(~path: string)`
38+
`fromString(string)`
3939
4040
The Path2D() constructor creates a new Path2D object from SVG path data text.
4141
4242
Source shape:
43-
- `path`: ReScript [string](https://rescript-lang.org/docs/manual/primitive-types/#string) containing SVG path data accepted by MDN [Path2D()](https://developer.mozilla.org/docs/Web/API/Path2D/Path2D).
43+
- ReScript [string](https://rescript-lang.org/docs/manual/primitive-types/#string) containing SVG path data accepted by MDN [Path2D()](https://developer.mozilla.org/docs/Web/API/Path2D/Path2D).
4444
4545
```res
46-
let path = Path2D.fromString(~path="M0 0 L10 10")
46+
let path = Path2D.fromString("M0 0 L10 10")
4747
```
4848
4949
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Path2D)
5050
*/
5151
@new
52-
external fromString: (~path: string) => Types.path2D = "Path2D"
52+
external fromString: string => Types.path2D = "Path2D"
5353

5454
/**
5555
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/closePath)

packages/DOM/src/DOMMatrix.res

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,38 @@ let matrix = DOMMatrix.make()
1616
external make: unit => Types.domMatrix = "DOMMatrix"
1717

1818
/**
19-
`fromString(~init: string)`
19+
`fromString(string)`
2020
2121
The DOMMatrix() constructor creates a new DOMMatrix from a transform string.
2222
2323
Source shape:
24-
- `init`: ReScript [string](https://rescript-lang.org/docs/manual/primitive-types/#string) accepted by MDN [DOMMatrix()](https://developer.mozilla.org/docs/Web/API/DOMMatrix/DOMMatrix).
24+
- ReScript [string](https://rescript-lang.org/docs/manual/primitive-types/#string) accepted by MDN [DOMMatrix()](https://developer.mozilla.org/docs/Web/API/DOMMatrix/DOMMatrix).
2525
2626
```res
27-
let matrix = DOMMatrix.fromString(~init="matrix(1, 0, 0, 1, 0, 0)")
27+
let matrix = DOMMatrix.fromString("matrix(1, 0, 0, 1, 0, 0)")
2828
```
2929
3030
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DOMMatrix)
3131
*/
3232
@new
33-
external fromString: (~init: string) => Types.domMatrix = "DOMMatrix"
33+
external fromString: string => Types.domMatrix = "DOMMatrix"
3434

3535
/**
36-
`fromArray(~init: array<float>)`
36+
`fromArray(array<float>)`
3737
3838
The DOMMatrix() constructor creates a new DOMMatrix from an array of matrix component values.
3939
4040
Source shape:
41-
- `init`: ReScript [array](https://rescript-lang.org/docs/manual/api/stdlib/array) of numeric values accepted by MDN [DOMMatrix()](https://developer.mozilla.org/docs/Web/API/DOMMatrix/DOMMatrix).
41+
- ReScript [array](https://rescript-lang.org/docs/manual/api/stdlib/array) of numeric values accepted by MDN [DOMMatrix()](https://developer.mozilla.org/docs/Web/API/DOMMatrix/DOMMatrix).
4242
4343
```res
44-
let matrix = DOMMatrix.fromArray(~init=[1., 0., 0., 1., 0., 0.])
44+
let matrix = DOMMatrix.fromArray([1., 0., 0., 1., 0., 0.])
4545
```
4646
4747
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DOMMatrix)
4848
*/
4949
@new
50-
external fromArray: (~init: array<float>) => Types.domMatrix = "DOMMatrix"
50+
external fromArray: array<float> => Types.domMatrix = "DOMMatrix"
5151

5252
external asDOMMatrixReadOnly: Types.domMatrix => Types.domMatrixReadOnly = "%identity"
5353
@scope("DOMMatrix")

packages/DOM/src/DOMMatrixReadOnly.res

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,38 @@ let matrix = DOMMatrixReadOnly.make()
1616
external make: unit => Types.domMatrixReadOnly = "DOMMatrixReadOnly"
1717

1818
/**
19-
`fromString(~init: string)`
19+
`fromString(string)`
2020
2121
The DOMMatrixReadOnly() constructor creates a new DOMMatrixReadOnly value from a transform string.
2222
2323
Source shape:
24-
- `init`: ReScript [string](https://rescript-lang.org/docs/manual/primitive-types/#string) accepted by MDN [DOMMatrixReadOnly()](https://developer.mozilla.org/docs/Web/API/DOMMatrixReadOnly/DOMMatrixReadOnly).
24+
- ReScript [string](https://rescript-lang.org/docs/manual/primitive-types/#string) accepted by MDN [DOMMatrixReadOnly()](https://developer.mozilla.org/docs/Web/API/DOMMatrixReadOnly/DOMMatrixReadOnly).
2525
2626
```res
27-
let matrix = DOMMatrixReadOnly.fromString(~init="matrix(1, 0, 0, 1, 0, 0)")
27+
let matrix = DOMMatrixReadOnly.fromString("matrix(1, 0, 0, 1, 0, 0)")
2828
```
2929
3030
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DOMMatrixReadOnly)
3131
*/
3232
@new
33-
external fromString: (~init: string) => Types.domMatrixReadOnly = "DOMMatrixReadOnly"
33+
external fromString: string => Types.domMatrixReadOnly = "DOMMatrixReadOnly"
3434

3535
/**
36-
`fromArray(~init: array<float>)`
36+
`fromArray(array<float>)`
3737
3838
The DOMMatrixReadOnly() constructor creates a new DOMMatrixReadOnly value from an array of matrix component values.
3939
4040
Source shape:
41-
- `init`: ReScript [array](https://rescript-lang.org/docs/manual/api/stdlib/array) of numeric values accepted by MDN [DOMMatrixReadOnly()](https://developer.mozilla.org/docs/Web/API/DOMMatrixReadOnly/DOMMatrixReadOnly).
41+
- ReScript [array](https://rescript-lang.org/docs/manual/api/stdlib/array) of numeric values accepted by MDN [DOMMatrixReadOnly()](https://developer.mozilla.org/docs/Web/API/DOMMatrixReadOnly/DOMMatrixReadOnly).
4242
4343
```res
44-
let matrix = DOMMatrixReadOnly.fromArray(~init=[1., 0., 0., 1., 0., 0.])
44+
let matrix = DOMMatrixReadOnly.fromArray([1., 0., 0., 1., 0., 0.])
4545
```
4646
4747
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DOMMatrixReadOnly)
4848
*/
4949
@new
50-
external fromArray: (~init: array<float>) => Types.domMatrixReadOnly = "DOMMatrixReadOnly"
50+
external fromArray: array<float> => Types.domMatrixReadOnly = "DOMMatrixReadOnly"
5151

5252
@scope("DOMMatrixReadOnly")
5353
external fromMatrix: (~other: Types.domMatrixInit=?) => Types.domMatrixReadOnly = "fromMatrix"

packages/File/src/ReadableStream.res

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,21 @@ let stream: ReadableStream.t<string> = ReadableStream.make()
2121
external make: unit => t<'t> = "ReadableStream"
2222

2323
/**
24-
`fromUnderlyingSource(~underlyingSource: underlyingSource<'t>)`
24+
`fromUnderlyingSource(underlyingSource<'t>)`
2525
2626
The ReadableStream() constructor creates a new ReadableStream from an underlying source definition.
2727
2828
Source shape:
2929
- local [`underlyingSource<'t>`](../#underlyingSource) values accepted by MDN [ReadableStream()](https://developer.mozilla.org/docs/Web/API/ReadableStream/ReadableStream).
3030
3131
```res
32-
let stream =
33-
ReadableStream.fromUnderlyingSource(~underlyingSource=myUnderlyingSource)
32+
let stream = ReadableStream.fromUnderlyingSource(myUnderlyingSource)
3433
```
3534
3635
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ReadableStream)
3736
*/
3837
@new
39-
external fromUnderlyingSource: (~underlyingSource: Types.underlyingSource<'t>) => t<'t> =
40-
"ReadableStream"
38+
external fromUnderlyingSource: Types.underlyingSource<'t> => t<'t> = "ReadableStream"
4139

4240
/**
4341
`fromUnderlyingSourceWithStrategy(~underlyingSource: underlyingSource<'t>, ~strategy: queuingStrategy<'t>)`

tests/CanvasAPI/Path2D__test.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let path2D: WebApiCanvas.Types.path2D = Obj.magic()
22

33
let _make = WebApiCanvas.Path2D.make()
4-
let _fromPath2D = WebApiCanvas.Path2D.fromPath2D(~path=path2D)
5-
let _fromString = WebApiCanvas.Path2D.fromString(~path="M0 0 L10 10")
4+
let _fromPath2D = WebApiCanvas.Path2D.fromPath2D(path2D)
5+
let _fromString = WebApiCanvas.Path2D.fromString("M0 0 L10 10")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let _make = WebApiDOM.DOMMatrixReadOnly.make()
22

3-
let _fromString = WebApiDOM.DOMMatrixReadOnly.fromString(~init="matrix(1, 0, 0, 1, 0, 0)")
3+
let _fromString = WebApiDOM.DOMMatrixReadOnly.fromString("matrix(1, 0, 0, 1, 0, 0)")
44

5-
let _fromArray = WebApiDOM.DOMMatrixReadOnly.fromArray(~init=[1., 0., 0., 1., 0., 0.])
5+
let _fromArray = WebApiDOM.DOMMatrixReadOnly.fromArray([1., 0., 0., 1., 0., 0.])

tests/DOMAPI/DOMMatrix__test.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
let _make = WebApiDOM.DOMMatrix.make()
2-
let _fromString = WebApiDOM.DOMMatrix.fromString(~init="matrix(1, 0, 0, 1, 0, 0)")
3-
let _fromArray = WebApiDOM.DOMMatrix.fromArray(~init=[1., 0., 0., 1., 0., 0.])
2+
let _fromString = WebApiDOM.DOMMatrix.fromString("matrix(1, 0, 0, 1, 0, 0)")
3+
let _fromArray = WebApiDOM.DOMMatrix.fromArray([1., 0., 0., 1., 0., 0.])

tests/FileAPI/ReadableStream__test.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let strategy: WebApiFile.Types.queuingStrategy<string> = Obj.magic()
33

44
let _make: WebApiFile.ReadableStream.t<string> = WebApiFile.ReadableStream.make()
55

6-
let _fromUnderlyingSource = WebApiFile.ReadableStream.fromUnderlyingSource(~underlyingSource)
6+
let _fromUnderlyingSource = WebApiFile.ReadableStream.fromUnderlyingSource(underlyingSource)
77

88
let _fromUnderlyingSourceWithStrategy = WebApiFile.ReadableStream.fromUnderlyingSourceWithStrategy(
99
~underlyingSource,

0 commit comments

Comments
 (0)