• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / js-slang / 6107141959

07 Sep 2023 08:11AM UTC coverage: 82.853% (+0.2%) from 82.683%
6107141959

push

github

web-flow
Use Asynchronous Code for Loading Modules (#1471)

* Add async loading code

* Made infinite loop checking async

* Update stepper to be async

* Add assert and misc utils

* Update transpiler to be async

* Update runners

* Add new import options

* Ignore tests during typechecking

* Relocate typeguards

* Update with assertions and typeguards

* Update repl transpiler to be async

* Abstract out module context initialization and tab loading

* Renamed promise timeout error and added tests

* Remove old code

* Update options

* Add files to avoid line ending issues

* Use POSIX paths on Windows systems

* Ran format

* Update eslint rules to follow exclusion of tests

* Incorporate changes for posix path handling

* Minor change to resolve certain webpack issues with the frontend

* Use a different posix path import

* Allow loading of export default tabs

* Refactor collation of import declarations

---------

Co-authored-by: Ian Yong <ianyongyc@gmail.com>

3629 of 4814 branches covered (0.0%)

Branch coverage included in aggregate %.

266 of 266 new or added lines in 25 files covered. (100.0%)

10886 of 12705 relevant lines covered (85.68%)

96881.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/src/utils/arrayMap.ts
1
/**
2
 * Convenience class for maps that store an array of values
3
 */
4
export default class ArrayMap<K, V> {
1✔
5
  constructor(private readonly map: Map<K, V[]> = new Map()) {}
3✔
6

7
  public get(key: K) {
8
    return this.map.get(key)
4✔
9
  }
10

11
  public add(key: K, item: V) {
12
    if (!this.map.has(key)) {
12✔
13
      this.map.set(key, [])
4✔
14
    }
15
    this.map.get(key)!.push(item)
12✔
16
  }
17

18
  public entries() {
19
    return Array.from(this.map.entries())
1✔
20
  }
21

22
  public keys() {
23
    return new Set(this.map.keys())
×
24
  }
25

26
  /**
27
   * Similar to `mapAsync`, but for an async mapping function that does not return any value
28
   */
29
  public async forEachAsync<F extends (k: K, v: V[]) => Promise<void>>(forEach: F): Promise<void> {
30
    await Promise.all(this.entries().map(([key, value]) => forEach(key, value)))
×
31
  }
32

33
  /**
34
   * Using a mapping function that returns a promise, transform an array map
35
   * to another array map with different keys and values. All calls to the mapping function
36
   * execute asynchronously
37
   */
38
  public async mapAsync<F extends (k: K, v: V[]) => Promise<[any, any[]]>>(mapper: F) {
39
    const pairs = await Promise.all(this.entries().map(([key, value]) => mapper(key, value)))
2✔
40

41
    type U = Awaited<ReturnType<F>>
42
    const tempMap = new Map<U[0], U[1]>(pairs)
1✔
43
    return new ArrayMap<U[0], U[1][number]>(tempMap)
1✔
44
  }
45

46
  public [Symbol.toStringTag]() {
47
    return this.entries().map(([key, value]) => `${key}: ${value}`)
×
48
  }
49
}
50

51
/**
52
 * Create an ArrayMap from an iterable of key value pairs
53
 */
54
export function arrayMapFrom<K, V extends Array<any>>(
55
  pairs: Iterable<[K, V]>
56
): ArrayMap<K, V[number]>
57
export function arrayMapFrom<K, V>(pairs: Iterable<[K, V]>): ArrayMap<K, V>
58
export function arrayMapFrom<K, V>(pairs: Iterable<[K, V | V[]]>) {
1✔
59
  const res = new ArrayMap<K, V>()
2✔
60
  for (const [k, v] of pairs) {
2✔
61
    if (Array.isArray(v)) {
4!
62
      for (const each of v) {
4✔
63
        res.add(k, each)
12✔
64
      }
65
    } else {
66
      res.add(k, v)
×
67
    }
68
  }
69

70
  return res
2✔
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc