hinmil 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +166 -2
- package/dist/commentParser.d.ts +9 -0
- package/dist/commentParser.d.ts.map +1 -1
- package/dist/commentParser.js +21 -1
- package/dist/commentParser.js.map +1 -1
- package/dist/infer/annotations.d.ts +7 -0
- package/dist/infer/annotations.d.ts.map +1 -1
- package/dist/infer/annotations.js +26 -16
- package/dist/infer/annotations.js.map +1 -1
- package/dist/infer/calls.d.ts.map +1 -1
- package/dist/infer/calls.js +24 -9
- package/dist/infer/calls.js.map +1 -1
- package/dist/infer/expr-functions.d.ts +0 -6
- package/dist/infer/expr-functions.d.ts.map +1 -1
- package/dist/infer/expr-functions.js +32 -0
- package/dist/infer/expr-functions.js.map +1 -1
- package/dist/infer/expr-member.d.ts.map +1 -1
- package/dist/infer/expr-member.js +21 -0
- package/dist/infer/expr-member.js.map +1 -1
- package/dist/infer/functionPatterns.d.ts.map +1 -1
- package/dist/infer/functionPatterns.js +29 -6
- package/dist/infer/functionPatterns.js.map +1 -1
- package/dist/infer/helpers.d.ts +4 -1
- package/dist/infer/helpers.d.ts.map +1 -1
- package/dist/infer/helpers.js +9 -2
- package/dist/infer/helpers.js.map +1 -1
- package/dist/infer/index.d.ts +5 -0
- package/dist/infer/index.d.ts.map +1 -1
- package/dist/infer/index.js +6 -0
- package/dist/infer/index.js.map +1 -1
- package/dist/infer/setupPass.d.ts.map +1 -1
- package/dist/infer/setupPass.js +7 -0
- package/dist/infer/setupPass.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/services/diagnosticCodes.d.ts.map +1 -1
- package/dist/services/diagnosticCodes.js +2 -0
- package/dist/services/diagnosticCodes.js.map +1 -1
- package/dist/services/diagnostics.d.ts.map +1 -1
- package/dist/services/diagnostics.js +17 -0
- package/dist/services/diagnostics.js.map +1 -1
- package/dist/services/files.d.ts +14 -0
- package/dist/services/files.d.ts.map +1 -1
- package/dist/services/files.js +49 -2
- package/dist/services/files.js.map +1 -1
- package/dist/services/hmFileServices.d.ts.map +1 -1
- package/dist/services/hmFileServices.js +15 -0
- package/dist/services/hmFileServices.js.map +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# HinMil — Hindley-Milner for JavaScript
|
|
2
2
|
|
|
3
|
+
[](https://marketplace.visualstudio.com/items?itemName=hinmil.hinmil)
|
|
4
|
+
[](https://www.npmjs.com/package/hinmil)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://github.com/tureluren/hinmil/actions/workflows/ci.yml)
|
|
7
|
+
|
|
3
8
|
HinMil is a VS Code extension that type-checks plain JavaScript. You write type
|
|
4
9
|
signatures in ordinary comments, and a Hindley-Milner inference engine checks
|
|
5
10
|
your code against them while you type. There is no build step and no
|
|
@@ -10,6 +15,8 @@ transpilation — the files stay plain `.js`.
|
|
|
10
15
|
const lineTotal = (quantity, unitPrice) => quantity * unitPrice;
|
|
11
16
|
```
|
|
12
17
|
|
|
18
|
+

|
|
19
|
+
|
|
13
20
|
On top of the checker sit the editor features you would expect: hover types,
|
|
14
21
|
diagnostics, completion, signature help, quick fixes, rename, and an outline
|
|
15
22
|
view. The type system itself goes further than you might assume for a
|
|
@@ -19,8 +26,63 @@ narrowing. The sections below cover all of it.
|
|
|
19
26
|
|
|
20
27
|
---
|
|
21
28
|
|
|
29
|
+
## Why HinMil?
|
|
30
|
+
|
|
31
|
+
If you already write Hindley-Milner signatures in your comments, as the
|
|
32
|
+
documentation of Ramda, Sanctuary, Fluture and fantasy-land does, HinMil
|
|
33
|
+
turns them into checked types. Your code stays plain JavaScript that runs as
|
|
34
|
+
it is.
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
// ::constraint Functor f { f :: { map :: f a ~> (a -> b) -> f b } }
|
|
38
|
+
|
|
39
|
+
// map :: Functor f => (a -> b) -> f a -> f b
|
|
40
|
+
const map = fn => functor => functor.map (fn);
|
|
41
|
+
|
|
42
|
+
const lengths = map (s => s.length) (["Ada", "Alan"]); // [Number]
|
|
43
|
+
const wrong = map (s => s.length) (42);
|
|
44
|
+
// ✗ Type mismatch: Cannot unify 'Number' with 'f a'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
How it compares to the other ways of getting types into JavaScript:
|
|
48
|
+
|
|
49
|
+
| | HinMil | TypeScript | JSDoc + `checkJs` | Flow |
|
|
50
|
+
|---|---|---|---|---|
|
|
51
|
+
| Files stay plain `.js`, no build step | yes | no: `.ts` is compiled or stripped | yes | only with its `/*: T */` comment syntax |
|
|
52
|
+
| How you write a type | one HM line above the declaration | inline annotations | `@param`, `@returns`, `@template` tags | inline annotations |
|
|
53
|
+
| Inference without annotations | Hindley-Milner: `compose = (f, g) => x => f (g (x))` gets `(a -> b, c -> a) -> c -> b` | local; an unannotated parameter is `any` | as TypeScript | local; exports need annotations |
|
|
54
|
+
| Curried functions (`a -> b -> c`) | the natural form | possible, verbose with generics | verbose | possible, verbose |
|
|
55
|
+
| Higher-kinded types and type classes (`Functor f =>`) | yes | no, only through encodings | no | no |
|
|
56
|
+
| Sum types | `Maybe :: Just a \| Nothing`, with constructors and narrowing | discriminated unions | as TypeScript | disjoint unions |
|
|
57
|
+
| Types for npm packages | React, Node built-ins, and packages that ship HM annotations; everything else is `Any` | nearly every package (DefinitelyTyped) | as TypeScript | flow-typed, fewer |
|
|
58
|
+
| Editors | VS Code, plus a CLI for CI | every major editor | every major editor | most editors |
|
|
59
|
+
| Maturity | new (0.x) | very mature | very mature | mature, mostly used at Meta |
|
|
60
|
+
|
|
61
|
+
**When to choose what:**
|
|
62
|
+
|
|
63
|
+
- **TypeScript** when you need the ecosystem: types for every dependency,
|
|
64
|
+
editor support everywhere, refactorings, and a team that already knows it.
|
|
65
|
+
- **JSDoc + `checkJs`** when you want TypeScript's checker without a build
|
|
66
|
+
step and do not mind the verbose tag syntax.
|
|
67
|
+
- **HinMil** when you write JavaScript in a functional style (currying,
|
|
68
|
+
composition, algebraic data types, fantasy-land type classes) and want the
|
|
69
|
+
signatures you already write to be checked, without leaving plain `.js`.
|
|
70
|
+
|
|
71
|
+
**Honest limitations:**
|
|
72
|
+
|
|
73
|
+
- A package without HM annotations is `Any`, and `Any` fits everywhere. A
|
|
74
|
+
check is only as strict as the types it can see.
|
|
75
|
+
- Inference is strongest on functions and records. A method call on an
|
|
76
|
+
unannotated parameter (`items => items.reduce (…)`) stays open, so annotate
|
|
77
|
+
the functions you export.
|
|
78
|
+
- HinMil checks; it never changes or emits code. It is young, has one
|
|
79
|
+
maintainer, and the editor integration is VS Code only.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
22
83
|
## Table of Contents
|
|
23
84
|
|
|
85
|
+
- [Why HinMil?](#why-hinmil)
|
|
24
86
|
- [Getting Started](#getting-started)
|
|
25
87
|
- [Type Annotations](#type-annotations)
|
|
26
88
|
- [Method Annotations](#method-annotations)
|
|
@@ -51,6 +113,7 @@ narrowing. The sections below cover all of it.
|
|
|
51
113
|
- [::prefer — Disambiguate Overlapping Imports](#prefer--disambiguate-overlapping-imports)
|
|
52
114
|
- [::extend — Extend a Type Alias](#extend--extend-a-type-alias)
|
|
53
115
|
- [::rep — Constraint Representatives](#rep--constraint-representatives)
|
|
116
|
+
- [::curried — Curried Library Functions](#curried--curried-library-functions)
|
|
54
117
|
- [::hidden / ::private — Completion Visibility](#hidden--private--completion-visibility)
|
|
55
118
|
- [::ignore / ::ignore-file / ::ignore-function](#ignore--ignore-file--ignore-function)
|
|
56
119
|
- [Type System](#type-system)
|
|
@@ -78,6 +141,7 @@ narrowing. The sections below cover all of it.
|
|
|
78
141
|
- [Cross-package chaining](#cross-package-chaining)
|
|
79
142
|
- [Using a typed npm package (consumer side)](#using-a-typed-npm-package-consumer-side)
|
|
80
143
|
- [When signatures don't show up](#when-signatures-dont-show-up)
|
|
144
|
+
- [Ramda](#ramda)
|
|
81
145
|
- [Built-in Method Types](#built-in-method-types)
|
|
82
146
|
- [Array Methods](#array-methods)
|
|
83
147
|
- [String Methods](#string-methods)
|
|
@@ -110,6 +174,10 @@ const lineTotal = (quantity, unitPrice) => quantity * unitPrice;
|
|
|
110
174
|
That is the whole setup. The language server activates on the first JS file
|
|
111
175
|
you open and checks as you type.
|
|
112
176
|
|
|
177
|
+
To see it working first, clone
|
|
178
|
+
[hinmil-example](https://github.com/tureluren/hinmil-example): a few small
|
|
179
|
+
files, each with one deliberate type error, ready to open in VS Code.
|
|
180
|
+
|
|
113
181
|
Next steps, all optional:
|
|
114
182
|
|
|
115
183
|
- **A project configuration** (`hinmil.config.json`, or `"hinmil"` in
|
|
@@ -350,6 +418,8 @@ HM type annotations inside JS comments are syntax-highlighted automatically:
|
|
|
350
418
|
|
|
351
419
|
Can be toggled on/off via `hinmil.syntaxHighlighting.enabled`.
|
|
352
420
|
|
|
421
|
+

|
|
422
|
+
|
|
353
423
|
---
|
|
354
424
|
|
|
355
425
|
## Sum Types
|
|
@@ -890,6 +960,54 @@ const r = orEmpty([1, 2]); // fine — without the ::rep this reports:
|
|
|
890
960
|
// Type 'Array' does not satisfy constraint 'Monoid': missing method 'empty'
|
|
891
961
|
```
|
|
892
962
|
|
|
963
|
+
### `::curried` — Curried Library Functions
|
|
964
|
+
|
|
965
|
+
Only in `.hm` files. `::curried` directly above a declaration lets that
|
|
966
|
+
function take its arguments in any grouping, the way the functions of Ramda
|
|
967
|
+
and similar libraries do. One `::curried` covers the overload lines of the
|
|
968
|
+
name below it:
|
|
969
|
+
|
|
970
|
+
```
|
|
971
|
+
// fnkit.hm
|
|
972
|
+
::curried
|
|
973
|
+
map :: (a -> b) -> [a] -> [b]
|
|
974
|
+
map :: (a -> b) -> Object String a -> Object String b
|
|
975
|
+
::curried
|
|
976
|
+
subtract :: Number -> Number -> Number
|
|
977
|
+
negate :: Number -> Number
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
```javascript
|
|
981
|
+
map (f, xs); // all at once
|
|
982
|
+
map (f) (xs); // one at a time
|
|
983
|
+
F.map (f, xs); // through `import * as F from "fnkit"`
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
Without the directive, a curried signature `a -> b -> c` takes one
|
|
987
|
+
argument per call, as a plain `a => b => c` does. A `::curried` that is
|
|
988
|
+
not directly above a function of at least two arguments is reported as a
|
|
989
|
+
warning in the `.hm` file.
|
|
990
|
+
|
|
991
|
+
In a JavaScript file `::curried` is reported (HM5002): there the code
|
|
992
|
+
shows whether a function is curried. A function built with a curry helper
|
|
993
|
+
accepts any grouping as soon as the helper has a curry signature, also
|
|
994
|
+
when the helper comes from a `.hm` file or a namespace import
|
|
995
|
+
(`R.curry (…)`), and also when the function carries its own annotation:
|
|
996
|
+
|
|
997
|
+
```javascript
|
|
998
|
+
// discounted :: Number -> Number -> Number
|
|
999
|
+
const discounted = curry ((pct, price) => price * (1 - pct / 100));
|
|
1000
|
+
discounted (10, 250); // fine
|
|
1001
|
+
discounted (10) (250); // fine
|
|
1002
|
+
```
|
|
1003
|
+
|
|
1004
|
+
A hand-written `pct => price => …` really needs one argument per call,
|
|
1005
|
+
and HinMil keeps checking it that way.
|
|
1006
|
+
|
|
1007
|
+
An argument whose type is `Placeholder` (declare `Placeholder ::
|
|
1008
|
+
Placeholder` and `__ :: Placeholder`) leaves its parameter open:
|
|
1009
|
+
`subtract (__, 10)` is `Number -> Number`.
|
|
1010
|
+
|
|
893
1011
|
### `::hidden` / `::private` — Completion Visibility
|
|
894
1012
|
|
|
895
1013
|
Keep a method or property out of completion lists. Place the directive on the
|
|
@@ -1093,6 +1211,19 @@ Open vs. open records unify their tails through a shared row variable;
|
|
|
1093
1211
|
closed-vs-closed unification silently accepts extra caller fields for
|
|
1094
1212
|
JS compatibility.
|
|
1095
1213
|
|
|
1214
|
+
Reading a field that an open record does not list adds it to the row, as
|
|
1215
|
+
long as that row is still free. A callback typed from a library signature
|
|
1216
|
+
(`prop :: k -> { [k] :: a, ...r } -> a`) can read other fields this way:
|
|
1217
|
+
|
|
1218
|
+
```javascript
|
|
1219
|
+
// isBigUnpaid :: { total :: Number, paid :: t, ...r } -> Boolean (inferred)
|
|
1220
|
+
const isBigUnpaid = both (complement (prop ("paid")), (order) => order.total > 50);
|
|
1221
|
+
```
|
|
1222
|
+
|
|
1223
|
+
A function checked against its own annotation keeps its row fixed: with
|
|
1224
|
+
`pickName :: { name :: String, ...rest } -> String`, reading `o.title` is
|
|
1225
|
+
an error.
|
|
1226
|
+
|
|
1096
1227
|
One exception catches typos: an **object literal** passed where a
|
|
1097
1228
|
**named** closed record (an alias) is expected may not have fields the
|
|
1098
1229
|
alias does not declare. That is reported as HM1010, with a "did you
|
|
@@ -1358,6 +1489,10 @@ curriedTotal(2)(50, 10) // apply + partial
|
|
|
1358
1489
|
|
|
1359
1490
|
> **Note:** Without wrapping in `curry()`, a function with signature `(a, b, c) -> d` simply expects all arguments at once. The LSP only generates curried overloads when it detects the `curry()` call.
|
|
1360
1491
|
|
|
1492
|
+
A library whose functions are already curried (Ramda and its relatives) is
|
|
1493
|
+
described in a `.hm` file with [`::curried`](#curried--curried-library-functions);
|
|
1494
|
+
see [Ramda](#ramda) for a complete example.
|
|
1495
|
+
|
|
1361
1496
|
### Pipe & Compose
|
|
1362
1497
|
|
|
1363
1498
|
The LSP supports variadic `pipe` and `compose` functions using **spread tuple syntax** in annotations. It validates that chained functions connect properly — the output of one must match the input of the next.
|
|
@@ -1724,6 +1859,35 @@ A few common gotchas:
|
|
|
1724
1859
|
- **Re-export chain >256 files** — scan cap is hit; declare a sidecar
|
|
1725
1860
|
for the affected names.
|
|
1726
1861
|
|
|
1862
|
+
### Ramda
|
|
1863
|
+
|
|
1864
|
+
Ramda does not ship HM types itself. The example project
|
|
1865
|
+
[hinmil-example](https://github.com/tureluren/hinmil-example) has a
|
|
1866
|
+
[`hm-types/ramda.hm`](https://github.com/tureluren/hinmil-example/blob/main/hm-types/ramda.hm)
|
|
1867
|
+
for 84 of its most used functions (Ramda 0.29 and later), written with
|
|
1868
|
+
[`::curried`](#curried--curried-library-functions). Copy it to
|
|
1869
|
+
`hm-types/ramda.hm` in your project, and named and namespace imports are
|
|
1870
|
+
typed, in Ramda's curried style, with the `__` placeholder:
|
|
1871
|
+
|
|
1872
|
+
```javascript
|
|
1873
|
+
import * as R from "ramda";
|
|
1874
|
+
|
|
1875
|
+
const orders = [
|
|
1876
|
+
{ id: "o1", customer: "Ada", total: 120, paid: true },
|
|
1877
|
+
{ id: "o2", customer: "Alan", total: 35, paid: false },
|
|
1878
|
+
];
|
|
1879
|
+
|
|
1880
|
+
const unpaid = R.filter (R.propEq (false, "paid"), orders); // the full order type
|
|
1881
|
+
const byCustomer = R.groupBy (R.prop ("customer")) (orders); // orders per customer: { [String] :: [{ id, customer, … }] }
|
|
1882
|
+
const outstanding = R.pipe (R.map (R.prop ("total")), R.sum); // [{ total :: Number, ...r }] -> Number
|
|
1883
|
+
const withoutFee = R.subtract (R.__, 2.5); // Number -> Number
|
|
1884
|
+
|
|
1885
|
+
const broken = R.pipe (R.map (R.prop ("total")), R.sum, R.toUpper);
|
|
1886
|
+
// ✗ Type mismatch: Cannot unify 'String' with 'Number'
|
|
1887
|
+
```
|
|
1888
|
+
|
|
1889
|
+
A function that is not in the file is `Any` once Ramda is installed.
|
|
1890
|
+
|
|
1727
1891
|
---
|
|
1728
1892
|
|
|
1729
1893
|
## Built-in Method Types
|
|
@@ -2081,10 +2245,10 @@ npm run typecheck:hm
|
|
|
2081
2245
|
| **4003** | Constraint | Invalid constraint definition |
|
|
2082
2246
|
| **4004** | Constraint | Constraint kind mismatch (e.g. concrete type where a container is required) |
|
|
2083
2247
|
| **5001** | Curry | Curry arity mismatch |
|
|
2084
|
-
| **5002** | Curry | Curry type error |
|
|
2248
|
+
| **5002** | Curry | Curry type error, or `::curried` in a JavaScript file (only `.hm` files) |
|
|
2085
2249
|
| **5003** | Curry | Over-application of curried function |
|
|
2086
2250
|
| **5004** | Curry | Fan-out arity mismatch |
|
|
2087
|
-
| **6001** | Info | Missing annotation (informational) |
|
|
2251
|
+
| **6001** | Info | Missing annotation (informational). Not reported for a point-free binding (`const total = pipe (map (prop ("total")), sum)`); a call that wraps one function literal (`curry ((a, b) => …)`) is still asked |
|
|
2088
2252
|
| **6002** | Info | Sum type variant missing an annotated method implementation |
|
|
2089
2253
|
| **7001** | Relation | Invalid table relation / picked projection |
|
|
2090
2254
|
| **9001** | Parse | Source code parse error |
|
package/dist/commentParser.d.ts
CHANGED
|
@@ -268,6 +268,15 @@ export interface RepDirective {
|
|
|
268
268
|
* (see Fase 5). Returns one entry per well-formed directive; malformed
|
|
269
269
|
* directives are silently skipped (the caller emits no parser error).
|
|
270
270
|
*/
|
|
271
|
+
/**
|
|
272
|
+
* Every `::curried` directive in the comments of a JavaScript source. The
|
|
273
|
+
* directive belongs in `.hm` files only; in JavaScript the curried behaviour
|
|
274
|
+
* of a function follows from its code (see `setupPass`).
|
|
275
|
+
*/
|
|
276
|
+
export declare function extractCurriedDirectiveLocations(source: string): {
|
|
277
|
+
start: number;
|
|
278
|
+
end: number;
|
|
279
|
+
}[];
|
|
271
280
|
export declare function extractRepDirectives(source: string): RepDirective[];
|
|
272
281
|
/**
|
|
273
282
|
* Extract all `// ::global ...` directive comment bodies from source.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commentParser.d.ts","sourceRoot":"","sources":["../src/commentParser.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,KAAK,MAAM,MAAM,UAAU,CAAC;AAGxC,OAAO,EAAE,IAAI,EAAE,MAAM,EAA2E,MAAM,YAAY,CAAC;AAGnH;;;;;;iBAMiB;AACjB,eAAO,MAAM,4BAA4B,qCAAqC,CAAC;AAM/E;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,CAAC,gBAAgB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAU3H;AAMD;;;;;;;;;;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,MAAM,GAAG,YAAY,EAAE,CA4BpE;AAYD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAe9D;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CA2BvE;AAKD;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAgD3E;AAsZD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAoB7D;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAUtE"}
|
package/dist/commentParser.js
CHANGED
|
@@ -67,6 +67,7 @@ exports.extractTypeDirectivesWithLocations = extractTypeDirectivesWithLocations;
|
|
|
67
67
|
exports.extractPreferDirectives = extractPreferDirectives;
|
|
68
68
|
exports.extractAliasExtensions = extractAliasExtensions;
|
|
69
69
|
exports.extractConstraintDirectives = extractConstraintDirectives;
|
|
70
|
+
exports.extractCurriedDirectiveLocations = extractCurriedDirectiveLocations;
|
|
70
71
|
exports.extractRepDirectives = extractRepDirectives;
|
|
71
72
|
exports.extractGlobalDirectives = extractGlobalDirectives;
|
|
72
73
|
exports.fieldTypeVars = fieldTypeVars;
|
|
@@ -548,7 +549,7 @@ function extractAnnotationsImpl(source) {
|
|
|
548
549
|
// Skip ::directive keywords — these are handled by their own extractors.
|
|
549
550
|
// Directives use `::keyword` (no space before keyword after `::` in the
|
|
550
551
|
// comment body), while type annotations always have a space after `::`.
|
|
551
|
-
if (!annotationName && /^(?:types|constraint|global|narrow|hidden|private|extend|rep|prefer|builtin|ignore(?:-file|-function)?)\b/.test(raw))
|
|
552
|
+
if (!annotationName && /^(?:types|constraint|global|narrow|hidden|private|extend|rep|prefer|builtin|curried|ignore(?:-file|-function)?)\b/.test(raw))
|
|
552
553
|
continue;
|
|
553
554
|
// Skip shorthand data type declarations (e.g. `// Either2 :: Left e | Right a`).
|
|
554
555
|
// These are handled by extractDataDirectives instead. Also covers the
|
|
@@ -1351,6 +1352,25 @@ const REP_DIRECTIVE_PATTERN = /^[\s*]*::rep\s+([A-Z][\w$]*)\s+([A-Z][\w$]*)(#|\.
|
|
|
1351
1352
|
* (see Fase 5). Returns one entry per well-formed directive; malformed
|
|
1352
1353
|
* directives are silently skipped (the caller emits no parser error).
|
|
1353
1354
|
*/
|
|
1355
|
+
/**
|
|
1356
|
+
* Every `::curried` directive in the comments of a JavaScript source. The
|
|
1357
|
+
* directive belongs in `.hm` files only; in JavaScript the curried behaviour
|
|
1358
|
+
* of a function follows from its code (see `setupPass`).
|
|
1359
|
+
*/
|
|
1360
|
+
function extractCurriedDirectiveLocations(source) {
|
|
1361
|
+
if (!source.includes('::curried'))
|
|
1362
|
+
return [];
|
|
1363
|
+
const parsed = parseWithComments(source);
|
|
1364
|
+
if (!parsed)
|
|
1365
|
+
return [];
|
|
1366
|
+
const out = [];
|
|
1367
|
+
for (const comment of parsed.comments) {
|
|
1368
|
+
const lines = comment.type === 'Block' ? comment.value.split(/\r?\n/) : [comment.value];
|
|
1369
|
+
if (lines.some(l => /^[\s*]*::curried\b/.test(l)))
|
|
1370
|
+
out.push({ start: comment.start, end: comment.end });
|
|
1371
|
+
}
|
|
1372
|
+
return out;
|
|
1373
|
+
}
|
|
1354
1374
|
function extractRepDirectives(source) {
|
|
1355
1375
|
const parsed = parseWithComments(source);
|
|
1356
1376
|
const results = [];
|