gcanti / monocle-ts

Functional optics: a (partial) porting of Scala monocle
https://gcanti.github.io/monocle-ts/
MIT License
1.05k stars 52 forks source link

Add missing pure annotations #175

Closed OliverJAsh closed 2 years ago

OliverJAsh commented 2 years ago

We also need to add pure annotations to the classes defined in index.js, however we can't add the pure annotation in the correct position because these are transpiled to IIFEs.

For example: https://github.com/gcanti/monocle-ts/blob/9bd7fa62e97f96c92c7ac7f4be9de3752842e5ee/src/index.ts#L1465

This will become:

var Setter = /** @class */ (function () {
    function Setter() {
    }
    return Setter;
}());
export { Setter };

The pure annotation needs to be added like so:

-var Setter = /** @class */ (function () {
+var Setter = /** @class */ /*#__PURE__*/ (function () {

I believe this can be solved by using a Babel plugin that adds the pure annotation to output of TypeScript. Alternatively, we can disable class transpilation.


Pure annotations are very easy to miss and hard to get right, so perhaps we should automate this across the fp-ts ecosystem, using something like one of these tools. WDYT @gcanti?

OliverJAsh commented 2 years ago

I believe this can be solved by using a Babel plugin that adds the pure annotation to output of TypeScript.

Pure annotations are very easy to miss and hard to get right, so perhaps we should automate this across the fp-ts ecosystem, using something like one of these tools. WDYT @gcanti?

@gcanti Have you tried to do anything like this before? If not then I can take a look.

gcanti commented 2 years ago

@OliverJAsh No I haven't, I was afraid to mess up the tsc output