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

source-academy / js-slang / 23995741899

05 Apr 2026 06:14AM UTC coverage: 77.093% (+0.002%) from 77.091%
23995741899

push

github

web-flow
Upgrade to TypeScript 6 and Prettier improvements (#1936)

* Upgrade TypeScript to v6

* Fix import source

* Fix tsconfig

* Fix preexisting type errors

* Remove scm-slang

* Bump node types

* Fix tsconfig

* Fix node types specifier

* Enable trailing commas

* Enable semicolons

* Check and commit files with changed line numbers

* Update Yarn to 4.13.0

* Remove unneeded sicp package deps

3112 of 4282 branches covered (72.68%)

Branch coverage included in aggregate %.

3761 of 5218 new or added lines in 152 files covered. (72.08%)

26 existing lines in 9 files now uncovered.

7136 of 9011 relevant lines covered (79.19%)

175254.05 hits per line

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

87.8
/src/runner/fullJSRunner.ts
1
import { generate } from 'astring';
2
import type es from 'estree';
3
import { RawSourceMap } from 'source-map';
4

5
import { NATIVE_STORAGE_ID } from '../constants';
6
import { RuntimeSourceError } from '../errors/runtimeSourceError';
7
import { parse } from '../parser/parser';
8
import {
9
  evallerReplacer,
10
  getBuiltins,
11
  getGloballyDeclaredIdentifiers,
12
  transpile,
13
} from '../transpiler/transpiler';
14
import type { Context, NativeStorage } from '../types';
15
import * as create from '../utils/ast/astCreator';
16
import { getFunctionDeclarationNamesInProgram } from '../utils/uniqueIds';
17
import { toSourceError } from './errors';
18
import type { Runner } from './types';
19

20
function fullJSEval(code: string, nativeStorage: NativeStorage): any {
21
  if (nativeStorage.evaller) {
94✔
22
    return nativeStorage.evaller(code);
50✔
23
  } else {
24
    return eval(code);
44✔
25
  }
26
}
27

28
function preparePrelude(context: Context): es.Statement[] | undefined {
29
  if (context.prelude === null) {
47✔
30
    return [];
31✔
31
  }
32
  const prelude = context.prelude;
16✔
33
  context.prelude = null;
16✔
34
  const program = parse(prelude, context);
16✔
35
  if (program === null) {
16!
NEW
36
    return undefined;
×
37
  }
38

39
  return program.body as es.Statement[];
16✔
40
}
41

42
function containsPrevEval(context: Context): boolean {
43
  return context.nativeStorage.evaller != null;
47✔
44
}
45

46
const fullJSRunner: Runner = async (program, context) => {
53✔
47
  // prelude & builtins
48
  // only process builtins and preludes if it is a fresh eval context
49
  const prelude = preparePrelude(context);
47✔
50
  if (prelude === undefined) {
47!
NEW
51
    return { status: 'error', context };
×
52
  }
53
  const preludeAndBuiltins: es.Statement[] = containsPrevEval(context)
47✔
54
    ? []
55
    : [...getBuiltins(context.nativeStorage), ...prelude];
56

57
  // evaluate and create a separate block for preludes and builtins
58
  const preEvalProgram: es.Program = create.program([
47✔
59
    ...preludeAndBuiltins,
60
    evallerReplacer(create.identifier(NATIVE_STORAGE_ID), new Set()),
61
  ]);
62
  getFunctionDeclarationNamesInProgram(preEvalProgram).forEach(id =>
47✔
63
    context.nativeStorage.previousProgramsIdentifiers.add(id),
763✔
64
  );
65
  getGloballyDeclaredIdentifiers(preEvalProgram).forEach(id =>
47✔
66
    context.nativeStorage.previousProgramsIdentifiers.add(id),
3,023✔
67
  );
68
  const preEvalCode: string = generate(preEvalProgram);
47✔
69
  fullJSEval(preEvalCode, context.nativeStorage);
47✔
70

71
  let transpiled;
72
  let sourceMapJson: RawSourceMap | undefined;
73
  try {
47✔
74
    ({ transpiled, sourceMapJson } = transpile(program, context));
47✔
75
    return {
47✔
76
      status: 'finished',
77
      context,
78
      value: fullJSEval(transpiled, context.nativeStorage),
79
    };
80
  } catch (error) {
81
    context.errors.push(
7✔
82
      error instanceof RuntimeSourceError ? error : await toSourceError(error, sourceMapJson),
7!
83
    );
84
    return { status: 'error', context };
7✔
85
  }
86
};
87

88
export default fullJSRunner;
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