• 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

88.57
/src/parser/source/typed/utils.ts
1
import * as es from 'estree';
2

3
/**
4
 * Transforms an AST generated by the Babel parser into one
5
 * that is compliant with the ESTree types. While the Babel
6
 * parser-generated AST is mostly compliant with the ESTree
7
 * specifications due to the use of the 'estree' plugin, not
8
 * everything is compliant with the ESTree types.
9
 *
10
 * @param program The AST to be transformed.
11
 */
12
export const transformBabelASTToESTreeCompliantAST = (program: es.Program): void => {
65✔
13
  renameFilenameAttributeToSource(program);
159✔
14
};
15

16
/**
17
 * Renames the 'filename' attribute on AST nodes to 'source'.
18
 * This is because the Babel parser tags AST nodes with the
19
 * 'filename' attribute when the name of the file in which
20
 * the AST was generated from is given. However, by the ESTree
21
 * types that js-slang uses, this attribute should be named
22
 * 'source' instead of 'filename'. As a workaround, we
23
 * recursively walk the AST generated by the Babel parser and
24
 * replace all instances of the 'filename' attribute with
25
 * 'source'.
26
 *
27
 * Note that we do not use acorn-walk here as a precondition
28
 * of acorn-walk is that the AST is compliant with the ESTree
29
 * specifications. Since the reason why we are transforming
30
 * the AST generated by the Babel parser is because it is not
31
 * entirely compliant with the ESTree specifications in the
32
 * first place, we avoid the use of acorn-walk.
33
 *
34
 * @param node The node to be transformed.
35
 */
36
const renameFilenameAttributeToSource = (node: Record<string, any>): void => {
65✔
37
  // Rename all 'filename' attributes to 'source'.
38
  if (node.hasOwnProperty('filename')) {
162,672✔
39
    node.source = node.filename;
6,840✔
40
    delete node.filename;
6,840✔
41
  }
42
  // Iterate over all property values of the AST node.
43
  Object.values(node).forEach(value => {
162,672✔
44
    // If the value is null or undefined, do nothing.
45
    if (value === null || value === undefined) {
539,493✔
46
      return;
71,109✔
47
    }
48
    // If the value is an array, check if any of its elements
49
    // are objects (i.e., AST nodes) which we should recurse on.
50
    if (Array.isArray(value)) {
468,384✔
51
      value.forEach(element => {
19,077✔
52
        if (element === null || element === undefined) {
9,064!
NEW
53
          return;
×
54
        }
55
        if (typeof element !== 'object') {
9,064!
NEW
56
          return;
×
57
        }
58
        renameFilenameAttributeToSource(element);
9,064✔
59
      });
60
    }
61
    // If the value is a primitive type, do nothing.
62
    if (typeof value !== 'object') {
468,384✔
63
      return;
314,935✔
64
    }
65
    // Otherwise, the value is an object (i.e., AST node) which
66
    // we recurse on.
67
    renameFilenameAttributeToSource(value);
153,449✔
68
  });
69
};
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