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

source-academy / js-slang / 24868044425

24 Apr 2026 01:47AM UTC coverage: 78.522% (+0.1%) from 78.391%
24868044425

push

github

web-flow
Error Handling and Stringify Changes (#1893)

* Modify stringify to prioritize toReplString

* Make the extract declarations helper actually work

* Add ability to change loader for source modules

* Add a new option for controlling how Source modules are loaded

* Improve typing for CSE machine

* Add ability to check if modules are loaded with the wrong Source chapter

* Refactor errors to extend from Error class

* Refactor modules errors

* Refactor parser errors

* Refactor cse machine errors

* Mostly fix error handling in the tracer

* Tidy up generator and explainer implementations for tracer

* Remove unnecessary imports and type guards

* Adjust rttc checks to be type guards instead of returning errors

* Adjust miscellanous error changes

* Add eslint rule for useless constructor

* Fix incorrect ordering for checking exceptionerrors

* Minor changes

* Run format

* Run linting

* Override the message property, but also enable noImplicitOverride to prevent accidental overriding

* Add some documentation to some errors

* Add errors to possible imports for modules

* Update getIds helper

* Minor fix to test case

* Run format

* Allow modules to try and load the context of other modules without crashing

* Fix incorrect stdlib name

* Add some more functions to the stdlib list library

* Change to use GeneralRuntimeError for list

* Revert "Change to use GeneralRuntimeError for list"

This reverts commit 642bd99e6.

* Update src/errors/errors.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Add ability to change manifest and docs importers

* Change how external builtins are defined

* Fix typings and list lib overloads

* Miscellanous changes

* Add the Source equality function to stdlib/misc

* Merge from main branch for tracer

* Add handling for the new importers

* Change errors and made redex a local variable

* Improve tracer typing

* Relocate... (continued)

3125 of 4193 branches covered (74.53%)

Branch coverage included in aggregate %.

899 of 1089 new or added lines in 96 files covered. (82.55%)

21 existing lines in 12 files now uncovered.

7031 of 8741 relevant lines covered (80.44%)

185057.72 hits per line

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

41.03
/src/stepper/nodes/Expression/ArrayExpression.ts
1
import type { ArrayExpression, Comment, Expression, SourceLocation } from 'estree';
2
import type { StepperExpression, StepperPattern } from '..';
3
import { convert } from '../../generator';
4
import { StepperBaseNode } from '../../interface';
5
import type { RedexInfo } from '../..';
6
import { InternalRuntimeError } from '../../../errors/base';
7

8
export class StepperArrayExpression
9
  extends StepperBaseNode<ArrayExpression>
10
  implements ArrayExpression
11
{
12
  constructor(
13
    public readonly elements: (StepperExpression | null)[],
1,282✔
14
    leadingComments?: Comment[],
15
    trailingComments?: Comment[],
16
    loc?: SourceLocation | null,
17
    range?: [number, number],
18
  ) {
19
    super('ArrayExpression', leadingComments, trailingComments, loc, range);
1,282✔
20
  }
21

22
  static create(node: ArrayExpression) {
23
    return new StepperArrayExpression(
1✔
NEW
24
      node.elements.map(element => (element ? convert(element as Expression) : null)),
×
25
      node.leadingComments,
26
      node.trailingComments,
27
      node.loc,
28
      node.range,
29
    );
30
  }
31

32
  public override isContractible(): boolean {
33
    return false;
1✔
34
  }
35

36
  public override isOneStepPossible(redex: RedexInfo): boolean {
37
    return this.elements.some(element => element?.isOneStepPossible(redex));
37,216✔
38
  }
39

40
  public override contract(redex: RedexInfo): StepperExpression {
41
    redex.preRedex = [this];
×
NEW
42
    throw new InternalRuntimeError('Array expressions cannot be contracted', this);
×
43
  }
44

45
  public override oneStep(redex: RedexInfo): StepperExpression {
46
    if (this.isContractible()) {
×
NEW
47
      return this.contract(redex);
×
48
    }
49

50
    for (let i = 0; i < this.elements.length; i++) {
×
51
      const element = this.elements[i];
×
NEW
52
      if (element?.isOneStepPossible(redex)) {
×
53
        const newElements = [...this.elements];
×
NEW
54
        newElements[i] = element.oneStep(redex);
×
55
        return new StepperArrayExpression(
×
56
          newElements,
57
          this.leadingComments,
58
          this.trailingComments,
59
          this.loc,
60
          this.range,
61
        );
62
      }
63
    }
64

NEW
65
    throw new InternalRuntimeError('No one step possible for ArrayExpression', this);
×
66
  }
67

68
  public override substitute(
69
    id: StepperPattern,
70
    value: StepperExpression,
71
    redex: RedexInfo,
72
  ): StepperExpression {
73
    return new StepperArrayExpression(
1,210✔
74
      this.elements.map(element => (element ? element.substitute(id, value, redex) : null)),
2,420!
75
      this.leadingComments,
76
      this.trailingComments,
77
      this.loc,
78
      this.range,
79
    );
80
  }
81

82
  public override freeNames(): string[] {
83
    const names = this.elements
403✔
84
      .filter(element => element !== null)
806✔
85
      .flatMap(element => element.freeNames());
806✔
86
    return Array.from(new Set(names));
403✔
87
  }
88

89
  public override allNames(): string[] {
90
    const names = this.elements
104✔
91
      .filter(element => element !== null)
208✔
92
      .flatMap(element => element.allNames());
208✔
93
    return Array.from(new Set(names));
104✔
94
  }
95

96
  public override rename(before: string, after: string): StepperExpression {
97
    return new StepperArrayExpression(
×
98
      this.elements.map(element => (element ? element.rename(before, after) : null)),
×
99
      this.leadingComments,
100
      this.trailingComments,
101
      this.loc,
102
      this.range,
103
    );
104
  }
105
}
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