• 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

96.55
/src/modules/preprocessor/filePaths.ts
1
import {
2
  ConsecutiveSlashesInFilePathError,
3
  IllegalCharInFilePathError,
4
  InvalidFilePathError,
5
} from '../errors';
6

7
/**
8
 * Maps non-alphanumeric characters that are legal in file paths
9
 * to strings which are legal in function names.
10
 */
11
export const nonAlphanumericCharEncoding: Record<string, string> = {
58✔
12
  // While the underscore character is legal in both file paths
13
  // and function names, it is the only character to be legal
14
  // in both that is not an alphanumeric character. For simplicity,
15
  // we handle it the same way as the other non-alphanumeric
16
  // characters.
17
  _: '_',
18
  '/': '$',
19
  // The following encodings work because we disallow file paths
20
  // with consecutive slash characters (//). Note that when using
21
  // the 'replace' or 'replaceAll' functions, the dollar sign ($)
22
  // takes on a special meaning. As such, to insert a dollar sign,
23
  // we need to write '$$'. See
24
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement
25
  // for more information.
26
  '.': '$$$$dot$$$$', // '$$dot$$'
27
  '-': '$$$$dash$$$$', // '$$dash$$'
28
};
29

30
/**
31
 * Transforms the given file path to a valid function name. The
32
 * characters in a valid function name must be either an
33
 * alphanumeric character, the underscore (_), or the dollar ($).
34
 *
35
 * In addition, the returned function name has underscores appended
36
 * on both ends to make it even less likely that the function name
37
 * will collide with a user-inputted name.
38
 *
39
 * @param filePath The file path to transform.
40
 */
41
export const transformFilePathToValidFunctionName = (filePath: string): string => {
58✔
42
  const encodeChars = Object.entries(nonAlphanumericCharEncoding).reduce(
65✔
43
    (
44
      accumulatedFunction: (filePath: string) => string,
45
      [charToReplace, replacementString]: [string, string],
46
    ) => {
47
      return (filePath: string): string =>
260✔
48
        accumulatedFunction(filePath).replaceAll(charToReplace, replacementString);
260✔
49
    },
50
    (filePath: string): string => filePath,
65✔
51
  );
52
  return `__${encodeChars(filePath)}__`;
65✔
53
};
54

55
/**
56
 * Transforms the given function name to the expected name that
57
 * the variable holding the result of invoking the function should
58
 * have. The main consideration of this transformation is that
59
 * the resulting name should not conflict with any of the names
60
 * that can be generated by `transformFilePathToValidFunctionName`.
61
 *
62
 * @param functionName The function name to transform.
63
 */
64
export const transformFunctionNameToInvokedFunctionResultVariableName = (
58✔
65
  functionName: string,
66
): string => {
67
  return `_${functionName}_`;
33✔
68
};
69

70
const isAlphanumeric = (char: string): boolean => {
58✔
71
  return /[a-zA-Z0-9]/i.exec(char) !== null;
8,276✔
72
};
73

74
/**
75
 * Validates the given file path, returning an `InvalidFilePathError`
76
 * if the file path is invalid & `null` otherwise. A file path is
77
 * valid if it only contains alphanumeric characters and the characters
78
 * defined in `charEncoding`, and does not contain consecutive slash
79
 * characters (//).
80
 *
81
 * @param filePath The file path to check.
82
 */
83
export const validateFilePath = (filePath: string): InvalidFilePathError | null => {
58✔
84
  if (filePath.includes('//')) {
764✔
85
    return new ConsecutiveSlashesInFilePathError(filePath);
4✔
86
  }
87
  for (const char of filePath) {
760✔
88
    if (isAlphanumeric(char)) {
8,276✔
89
      continue;
6,756✔
90
    }
91
    if (char in nonAlphanumericCharEncoding) {
1,520✔
92
      continue;
1,516✔
93
    }
94
    return new IllegalCharInFilePathError(filePath);
4✔
95
  }
96
  return null;
756✔
97
};
98

99
/**
100
 * Returns whether a string is a file path. We define a file
101
 * path to be any string containing the '/' character.
102
 *
103
 * @param value The value of the string.
104
 */
105
export const isFilePath = (value: string): boolean => {
58✔
NEW
106
  return value.includes('/');
×
107
};
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