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

source-academy / js-slang / 15237418122

25 May 2025 11:31AM UTC coverage: 77.048% (-3.5%) from 80.538%
15237418122

push

github

web-flow
Rewrite: Stepper (#1742)

3433 of 4826 branches covered (71.14%)

Branch coverage included in aggregate %.

1032 of 1260 new or added lines in 27 files covered. (81.9%)

440 existing lines in 29 files now uncovered.

10099 of 12737 relevant lines covered (79.29%)

142411.96 hits per line

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

89.58
/src/runner/fullJSRunner.ts
1
/* eslint-disable @typescript-eslint/no-unused-vars */
2
import { generate } from 'astring'
59✔
3
import type es from 'estree'
4
import { RawSourceMap } from 'source-map'
5

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

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

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

41
  return program.body as es.Statement[]
16✔
42
}
43

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

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

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

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

90
export default fullJSRunner
59✔
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