Skip to content

Commit 4877a70

Browse files
committed
Use custom tags.
1 parent fc813fd commit 4877a70

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

jscomp/test/variantsMatching.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,12 @@ var MyNullableExtended = {
347347

348348
function area(shape) {
349349
switch (shape.TAG) {
350-
case "Circle" :
351-
return Math.PI * Math.pow(shape._0.radius, 2);
352-
case "Square" :
353-
return Math.pow(shape._0.sideLength, 2);
354-
case "Rectangle" :
355-
var match = shape._0;
356-
return match.width * match.height;
350+
case 1 :
351+
return Math.PI * Math.pow(shape.radius, 2);
352+
case "square" :
353+
return Math.pow(shape.sideLength, 2);
354+
case "rectangle" :
355+
return shape.width * shape.height;
357356

358357
}
359358
}

jscomp/test/variantsMatching.res

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,26 +237,10 @@ module TaggedUnions = {
237237
}
238238
}
239239
*/
240-
type circle = {
241-
kind: string,
242-
radius: float,
243-
}
244-
245-
type square = {
246-
kind: string,
247-
sideLength: float,
248-
}
249-
250-
type rectangle = {
251-
kind: string,
252-
width: float,
253-
height: float,
254-
}
255-
256240
type shape =
257-
| Circle(circle)
258-
| Square(square)
259-
| Rectangle(rectangle)
241+
| @as(1) Circle({kind: string, radius: float})
242+
| @as("square") Square({kind: string, sideLength: float})
243+
| @as("rectangle") Rectangle({kind: string, width: float, height: float})
260244

261245
let area = (shape: shape): float => {
262246
switch shape {

0 commit comments

Comments
 (0)