ts-jest 29.3.2 → 29.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,155 +1,150 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
- if (ar || !(i in from)) {
32
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
- ar[i] = from[i];
34
- }
35
- }
36
- return to.concat(ar || Array.prototype.slice.call(from));
37
- };
38
- var __values = (this && this.__values) || function(o) {
39
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
- if (m) return m.call(o);
41
- if (o && typeof o.length === "number") return {
42
- next: function () {
43
- if (o && i >= o.length) o = void 0;
44
- return { value: o && o[i++], done: !o };
45
- }
46
- };
47
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
- };
49
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
4
  };
52
5
  Object.defineProperty(exports, "__esModule", { value: true });
53
6
  exports.TsCompiler = void 0;
54
- var path_1 = require("path");
55
- var bs_logger_1 = require("bs-logger");
56
- var lodash_memoize_1 = __importDefault(require("lodash.memoize"));
57
- var typescript_1 = __importDefault(require("typescript"));
58
- var constants_1 = require("../../constants");
59
- var transpile_module_1 = require("../../transpilers/typescript/transpile-module");
60
- var utils_1 = require("../../utils");
61
- var messages_1 = require("../../utils/messages");
62
- var compiler_utils_1 = require("./compiler-utils");
63
- var assertCompilerOptionsWithJestTransformMode = function (compilerOptions, isEsmMode, logger) {
7
+ const path_1 = require("path");
8
+ const bs_logger_1 = require("bs-logger");
9
+ const lodash_memoize_1 = __importDefault(require("lodash.memoize"));
10
+ const typescript_1 = __importDefault(require("typescript"));
11
+ const constants_1 = require("../../constants");
12
+ const transpile_module_1 = require("../../transpilers/typescript/transpile-module");
13
+ const utils_1 = require("../../utils");
14
+ const messages_1 = require("../../utils/messages");
15
+ const compiler_utils_1 = require("./compiler-utils");
16
+ const assertCompilerOptionsWithJestTransformMode = (compilerOptions, isEsmMode, logger) => {
64
17
  if (isEsmMode && compilerOptions.module === typescript_1.default.ModuleKind.CommonJS) {
65
18
  logger.error("The current compiler option \"module\" value is not suitable for Jest ESM mode. Please either use ES module kinds or Node16/NodeNext module kinds with \"type: module\" in package.json" /* Errors.InvalidModuleKindForEsm */);
66
19
  }
67
20
  };
68
- var TsCompiler = /** @class */ (function () {
69
- function TsCompiler(configSet, runtimeCacheFS) {
70
- var _a;
71
- var _this = this;
21
+ class TsCompiler {
22
+ configSet;
23
+ runtimeCacheFS;
24
+ _logger;
25
+ _ts;
26
+ _initialCompilerOptions;
27
+ _compilerOptions;
28
+ /**
29
+ * @private
30
+ */
31
+ _runtimeCacheFS;
32
+ /**
33
+ * @private
34
+ */
35
+ _fileContentCache;
36
+ /**
37
+ * @internal
38
+ */
39
+ _parsedTsConfig;
40
+ /**
41
+ * @internal
42
+ */
43
+ _fileVersionCache;
44
+ /**
45
+ * @internal
46
+ */
47
+ _cachedReadFile;
48
+ /**
49
+ * @internal
50
+ */
51
+ _projectVersion = 1;
52
+ /**
53
+ * @internal
54
+ */
55
+ _languageService;
56
+ /**
57
+ * @internal
58
+ */
59
+ _moduleResolutionHost;
60
+ /**
61
+ * @internal
62
+ */
63
+ _moduleResolutionCache;
64
+ program;
65
+ constructor(configSet, runtimeCacheFS) {
72
66
  this.configSet = configSet;
73
67
  this.runtimeCacheFS = runtimeCacheFS;
74
- /**
75
- * @internal
76
- */
77
- this._projectVersion = 1;
78
68
  this._ts = configSet.compilerModule;
79
69
  this._logger = utils_1.rootLogger.child({ namespace: 'ts-compiler' });
80
70
  this._parsedTsConfig = this.configSet.parsedTsConfig;
81
- this._initialCompilerOptions = __assign({}, this._parsedTsConfig.options);
82
- this._compilerOptions = __assign({}, this._initialCompilerOptions);
71
+ this._initialCompilerOptions = { ...this._parsedTsConfig.options };
72
+ this._compilerOptions = { ...this._initialCompilerOptions };
83
73
  this._runtimeCacheFS = runtimeCacheFS;
84
74
  if (!this.configSet.isolatedModules) {
85
75
  this._fileContentCache = new Map();
86
76
  this._fileVersionCache = new Map();
87
- this._cachedReadFile = this._logger.wrap((_a = {
88
- namespace: 'ts:serviceHost',
89
- call: null
90
- },
91
- _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace,
92
- _a), 'readFile', (0, lodash_memoize_1.default)(this._ts.sys.readFile));
77
+ this._cachedReadFile = this._logger.wrap({
78
+ namespace: 'ts:serviceHost',
79
+ call: null,
80
+ [bs_logger_1.LogContexts.logLevel]: bs_logger_1.LogLevels.trace,
81
+ }, 'readFile', (0, lodash_memoize_1.default)(this._ts.sys.readFile));
93
82
  /* istanbul ignore next */
94
83
  this._moduleResolutionHost = {
95
84
  fileExists: (0, lodash_memoize_1.default)(this._ts.sys.fileExists),
96
85
  readFile: this._cachedReadFile,
97
86
  directoryExists: (0, lodash_memoize_1.default)(this._ts.sys.directoryExists),
98
- getCurrentDirectory: function () { return _this.configSet.cwd; },
87
+ getCurrentDirectory: () => this.configSet.cwd,
99
88
  realpath: this._ts.sys.realpath && (0, lodash_memoize_1.default)(this._ts.sys.realpath),
100
89
  getDirectories: (0, lodash_memoize_1.default)(this._ts.sys.getDirectories),
101
- useCaseSensitiveFileNames: function () { return _this._ts.sys.useCaseSensitiveFileNames; },
90
+ useCaseSensitiveFileNames: () => this._ts.sys.useCaseSensitiveFileNames,
102
91
  };
103
- this._moduleResolutionCache = this._ts.createModuleResolutionCache(this.configSet.cwd, this._ts.sys.useCaseSensitiveFileNames ? function (x) { return x; } : function (x) { return x.toLowerCase(); }, this._compilerOptions);
92
+ this._moduleResolutionCache = this._ts.createModuleResolutionCache(this.configSet.cwd, this._ts.sys.useCaseSensitiveFileNames ? (x) => x : (x) => x.toLowerCase(), this._compilerOptions);
104
93
  this._createLanguageService();
105
94
  }
106
95
  }
107
- TsCompiler.prototype.getResolvedModules = function (fileContent, fileName, runtimeCacheFS) {
108
- var _this = this;
96
+ getResolvedModules(fileContent, fileName, runtimeCacheFS) {
109
97
  // In watch mode, it is possible that the initial cacheFS becomes empty
110
98
  if (!this.runtimeCacheFS.size) {
111
99
  this._runtimeCacheFS = runtimeCacheFS;
112
100
  }
113
- this._logger.debug({ fileName: fileName }, 'getResolvedModules(): resolve direct imported module paths');
114
- var importedModulePaths = Array.from(new Set(this._getImportedModulePaths(fileContent, fileName)));
115
- this._logger.debug({ fileName: fileName }, 'getResolvedModules(): resolve nested imported module paths from directed imported module paths');
116
- importedModulePaths.forEach(function (importedModulePath) {
117
- var resolvedFileContent = _this._getFileContentFromCache(importedModulePath);
118
- importedModulePaths.push.apply(importedModulePaths, __spreadArray([], __read(_this._getImportedModulePaths(resolvedFileContent, importedModulePath).filter(function (modulePath) { return !importedModulePaths.includes(modulePath); })), false));
101
+ this._logger.debug({ fileName }, 'getResolvedModules(): resolve direct imported module paths');
102
+ const importedModulePaths = Array.from(new Set(this._getImportedModulePaths(fileContent, fileName)));
103
+ this._logger.debug({ fileName }, 'getResolvedModules(): resolve nested imported module paths from directed imported module paths');
104
+ importedModulePaths.forEach((importedModulePath) => {
105
+ const resolvedFileContent = this._getFileContentFromCache(importedModulePath);
106
+ importedModulePaths.push(...this._getImportedModulePaths(resolvedFileContent, importedModulePath).filter((modulePath) => !importedModulePaths.includes(modulePath)));
119
107
  });
120
108
  return importedModulePaths;
121
- };
122
- TsCompiler.prototype.fixupCompilerOptionsForModuleKind = function (compilerOptions, isEsm) {
123
- var _a, _b;
124
- var moduleResolution = (_a = this._ts.ModuleResolutionKind.Node10) !== null && _a !== void 0 ? _a : this._ts.ModuleResolutionKind.NodeJs;
109
+ }
110
+ fixupCompilerOptionsForModuleKind(compilerOptions, isEsm) {
111
+ const moduleResolution = this._ts.ModuleResolutionKind.Node10 ?? this._ts.ModuleResolutionKind.NodeJs;
125
112
  if (!isEsm) {
126
- return __assign(__assign({}, compilerOptions), { module: this._ts.ModuleKind.CommonJS, moduleResolution: moduleResolution,
113
+ return {
114
+ ...compilerOptions,
115
+ module: this._ts.ModuleKind.CommonJS,
116
+ moduleResolution,
127
117
  /**
128
118
  * This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
129
119
  */
130
- customConditions: undefined });
120
+ customConditions: undefined,
121
+ };
131
122
  }
132
- var moduleKind = (_b = compilerOptions.module) !== null && _b !== void 0 ? _b : this._ts.ModuleKind.ESNext;
133
- var esModuleInterop = compilerOptions.esModuleInterop;
123
+ let moduleKind = compilerOptions.module ?? this._ts.ModuleKind.ESNext;
124
+ let esModuleInterop = compilerOptions.esModuleInterop;
134
125
  if ((0, transpile_module_1.isModernNodeModuleKind)(moduleKind)) {
135
126
  esModuleInterop = true;
136
127
  moduleKind = this._ts.ModuleKind.ESNext;
137
128
  }
138
- return __assign(__assign({}, compilerOptions), { module: moduleKind, esModuleInterop: esModuleInterop, moduleResolution: moduleResolution,
129
+ return {
130
+ ...compilerOptions,
131
+ module: moduleKind,
132
+ esModuleInterop,
133
+ moduleResolution,
139
134
  /**
140
135
  * This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
141
136
  */
142
- customConditions: undefined });
143
- };
144
- TsCompiler.prototype.getCompiledOutput = function (fileContent, fileName, options) {
145
- var e_1, _a;
146
- var isEsmMode = this.configSet.useESM && options.supportsStaticESM;
137
+ customConditions: undefined,
138
+ };
139
+ }
140
+ getCompiledOutput(fileContent, fileName, options) {
141
+ const isEsmMode = this.configSet.useESM && options.supportsStaticESM;
147
142
  this._compilerOptions = this.fixupCompilerOptionsForModuleKind(this._initialCompilerOptions, isEsmMode);
148
143
  if (!this._initialCompilerOptions.isolatedModules && (0, transpile_module_1.isModernNodeModuleKind)(this._initialCompilerOptions.module)) {
149
144
  this._logger.warn("Using hybrid module kind (Node16/18/Next) is only supported in \"isolatedModules: true\". Please set \"isolatedModules: true\" in your tsconfig.json." /* Helps.UsingModernNodeResolution */);
150
145
  }
151
- var moduleKind = this._initialCompilerOptions.module;
152
- var currentModuleKind = this._compilerOptions.module;
146
+ const moduleKind = this._initialCompilerOptions.module;
147
+ const currentModuleKind = this._compilerOptions.module;
153
148
  if (this._languageService) {
154
149
  if (constants_1.JS_JSX_REGEX.test(fileName) && !this._compilerOptions.allowJs) {
155
150
  this._logger.warn({ fileName: fileName }, (0, messages_1.interpolate)("Got a `.js` file to compile while `allowJs` option is not set to `true` (file: {{path}}). To fix this:\n - if you want TypeScript to process JS files, set `allowJs` to `true` in your TypeScript config (usually tsconfig.json)\n - if you do not want TypeScript to process your `.js` files, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match `.js` files anymore" /* Errors.GotJsFileButAllowJsFalse */, { path: fileName }));
@@ -157,36 +152,31 @@ var TsCompiler = /** @class */ (function () {
157
152
  code: fileContent,
158
153
  };
159
154
  }
160
- this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling using language service');
155
+ this._logger.debug({ fileName }, 'getCompiledOutput(): compiling using language service');
161
156
  // Must set memory cache before attempting to compile
162
157
  this._updateMemoryCache(fileContent, fileName, currentModuleKind === moduleKind);
163
- var output = this._languageService.getEmitOutput(fileName);
164
- var diagnostics = this.getDiagnostics(fileName);
158
+ const output = this._languageService.getEmitOutput(fileName);
159
+ const diagnostics = this.getDiagnostics(fileName);
165
160
  if (!isEsmMode && diagnostics.length) {
166
161
  this.configSet.raiseDiagnostics(diagnostics, fileName, this._logger);
167
162
  if (options.watchMode) {
168
- this._logger.debug({ fileName: fileName }, '_doTypeChecking(): starting watch mode computing diagnostics');
169
- try {
170
- for (var _b = __values(options.depGraphs.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
171
- var entry = _c.value;
172
- var normalizedModuleNames = entry[1].resolvedModuleNames.map(function (moduleName) { return (0, path_1.normalize)(moduleName); });
173
- var fileToReTypeCheck = entry[0];
174
- if (normalizedModuleNames.includes(fileName) && this.configSet.shouldReportDiagnostics(fileToReTypeCheck)) {
175
- this._logger.debug({ fileToReTypeCheck: fileToReTypeCheck }, '_doTypeChecking(): computing diagnostics using language service');
176
- this._updateMemoryCache(this._getFileContentFromCache(fileToReTypeCheck), fileToReTypeCheck);
177
- var importedModulesDiagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileToReTypeCheck)), false), __read(this._languageService.getSyntacticDiagnostics(fileToReTypeCheck)), false);
178
- // will raise or just warn diagnostics depending on config
179
- this.configSet.raiseDiagnostics(importedModulesDiagnostics, fileName, this._logger);
180
- }
163
+ this._logger.debug({ fileName }, '_doTypeChecking(): starting watch mode computing diagnostics');
164
+ for (const entry of options.depGraphs.entries()) {
165
+ const normalizedModuleNames = entry[1].resolvedModuleNames.map((moduleName) => (0, path_1.normalize)(moduleName));
166
+ const fileToReTypeCheck = entry[0];
167
+ if (normalizedModuleNames.includes(fileName) && this.configSet.shouldReportDiagnostics(fileToReTypeCheck)) {
168
+ this._logger.debug({ fileToReTypeCheck }, '_doTypeChecking(): computing diagnostics using language service');
169
+ this._updateMemoryCache(this._getFileContentFromCache(fileToReTypeCheck), fileToReTypeCheck);
170
+ const importedModulesDiagnostics = [
171
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
172
+ ...this._languageService.getSemanticDiagnostics(fileToReTypeCheck),
173
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
174
+ ...this._languageService.getSyntacticDiagnostics(fileToReTypeCheck),
175
+ ];
176
+ // will raise or just warn diagnostics depending on config
177
+ this.configSet.raiseDiagnostics(importedModulesDiagnostics, fileName, this._logger);
181
178
  }
182
179
  }
183
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
184
- finally {
185
- try {
186
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
187
- }
188
- finally { if (e_1) throw e_1.error; }
189
- }
190
180
  }
191
181
  }
192
182
  if (output.emitSkipped) {
@@ -206,21 +196,21 @@ var TsCompiler = /** @class */ (function () {
206
196
  file: (0, path_1.basename)(fileName),
207
197
  }));
208
198
  }
209
- var outputFiles = output.outputFiles;
199
+ const { outputFiles } = output;
210
200
  return this._compilerOptions.sourceMap
211
201
  ? {
212
202
  code: (0, compiler_utils_1.updateOutput)(outputFiles[1].text, fileName, outputFiles[0].text),
213
- diagnostics: diagnostics,
203
+ diagnostics,
214
204
  }
215
205
  : {
216
206
  code: (0, compiler_utils_1.updateOutput)(outputFiles[0].text, fileName),
217
- diagnostics: diagnostics,
207
+ diagnostics,
218
208
  };
219
209
  }
220
210
  else {
221
- this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling as isolated module');
211
+ this._logger.debug({ fileName }, 'getCompiledOutput(): compiling as isolated module');
222
212
  assertCompilerOptionsWithJestTransformMode(this._initialCompilerOptions, isEsmMode, this._logger);
223
- var result = this._transpileOutput(fileContent, fileName);
213
+ const result = this._transpileOutput(fileContent, fileName);
224
214
  if (result.diagnostics && this.configSet.shouldReportDiagnostics(fileName)) {
225
215
  this.configSet.raiseDiagnostics(result.diagnostics, fileName, this._logger);
226
216
  }
@@ -228,9 +218,8 @@ var TsCompiler = /** @class */ (function () {
228
218
  code: (0, compiler_utils_1.updateOutput)(result.outputText, fileName, result.sourceMapText),
229
219
  };
230
220
  }
231
- };
232
- TsCompiler.prototype._transpileOutput = function (fileContent, fileName) {
233
- var _this = this;
221
+ }
222
+ _transpileOutput(fileContent, fileName) {
234
223
  /**
235
224
  * @deprecated
236
225
  *
@@ -238,57 +227,48 @@ var TsCompiler = /** @class */ (function () {
238
227
  */
239
228
  if (!(0, transpile_module_1.isModernNodeModuleKind)(this._initialCompilerOptions.module)) {
240
229
  return this._ts.transpileModule(fileContent, {
241
- fileName: fileName,
230
+ fileName,
242
231
  transformers: this._makeTransformers(this.configSet.resolvedTransformers),
243
232
  compilerOptions: this._compilerOptions,
244
233
  reportDiagnostics: this.configSet.shouldReportDiagnostics(fileName),
245
234
  });
246
235
  }
247
236
  return (0, transpile_module_1.tsTranspileModule)(fileContent, {
248
- fileName: fileName,
249
- transformers: function (program) {
250
- _this.program = program;
251
- return _this._makeTransformers(_this.configSet.resolvedTransformers);
237
+ fileName,
238
+ transformers: (program) => {
239
+ this.program = program;
240
+ return this._makeTransformers(this.configSet.resolvedTransformers);
252
241
  },
253
242
  compilerOptions: this._initialCompilerOptions,
254
243
  reportDiagnostics: fileName ? this.configSet.shouldReportDiagnostics(fileName) : false,
255
244
  });
256
- };
257
- TsCompiler.prototype._makeTransformers = function (customTransformers) {
258
- var _this = this;
245
+ }
246
+ _makeTransformers(customTransformers) {
259
247
  return {
260
- before: customTransformers.before.map(function (beforeTransformer) {
261
- return beforeTransformer.factory(_this, beforeTransformer.options);
262
- }),
263
- after: customTransformers.after.map(function (afterTransformer) {
264
- return afterTransformer.factory(_this, afterTransformer.options);
265
- }),
266
- afterDeclarations: customTransformers.afterDeclarations.map(function (afterDeclarations) {
267
- return afterDeclarations.factory(_this, afterDeclarations.options);
268
- }),
248
+ before: customTransformers.before.map((beforeTransformer) => beforeTransformer.factory(this, beforeTransformer.options)),
249
+ after: customTransformers.after.map((afterTransformer) => afterTransformer.factory(this, afterTransformer.options)),
250
+ afterDeclarations: customTransformers.afterDeclarations.map((afterDeclarations) => afterDeclarations.factory(this, afterDeclarations.options)),
269
251
  };
270
- };
252
+ }
271
253
  /**
272
254
  * @internal
273
255
  */
274
- TsCompiler.prototype._createLanguageService = function () {
275
- var _this = this;
276
- var _a;
256
+ _createLanguageService() {
277
257
  // Initialize memory cache for typescript compiler
278
258
  this._parsedTsConfig.fileNames
279
- .filter(function (fileName) { return constants_1.TS_TSX_REGEX.test(fileName) && !_this.configSet.isTestFile(fileName); })
259
+ .filter((fileName) => constants_1.TS_TSX_REGEX.test(fileName) && !this.configSet.isTestFile(fileName))
280
260
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
281
- .forEach(function (fileName) { return _this._fileVersionCache.set(fileName, 0); });
261
+ .forEach((fileName) => this._fileVersionCache.set(fileName, 0));
282
262
  /* istanbul ignore next */
283
- var serviceHost = {
284
- useCaseSensitiveFileNames: function () { return _this._ts.sys.useCaseSensitiveFileNames; },
285
- getProjectVersion: function () { return String(_this._projectVersion); },
263
+ const serviceHost = {
264
+ useCaseSensitiveFileNames: () => this._ts.sys.useCaseSensitiveFileNames,
265
+ getProjectVersion: () => String(this._projectVersion),
286
266
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
287
- getScriptFileNames: function () { return __spreadArray([], __read(_this._fileVersionCache.keys()), false); },
288
- getScriptVersion: function (fileName) {
289
- var normalizedFileName = (0, path_1.normalize)(fileName);
267
+ getScriptFileNames: () => [...this._fileVersionCache.keys()],
268
+ getScriptVersion: (fileName) => {
269
+ const normalizedFileName = (0, path_1.normalize)(fileName);
290
270
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
291
- var version = _this._fileVersionCache.get(normalizedFileName);
271
+ const version = this._fileVersionCache.get(normalizedFileName);
292
272
  // We need to return `undefined` and not a string here because TypeScript will use
293
273
  // `getScriptVersion` and compare against their own version - which can be `undefined`.
294
274
  // If we don't return `undefined` it results in `undefined === "undefined"` and run
@@ -297,91 +277,90 @@ var TsCompiler = /** @class */ (function () {
297
277
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
298
278
  return version === undefined ? undefined : String(version);
299
279
  },
300
- getScriptSnapshot: function (fileName) {
301
- var _a, _b, _c, _d;
302
- var normalizedFileName = (0, path_1.normalize)(fileName);
303
- var hit = _this._isFileInCache(normalizedFileName);
304
- _this._logger.trace({ normalizedFileName: normalizedFileName, cacheHit: hit }, 'getScriptSnapshot():', 'cache', hit ? 'hit' : 'miss');
280
+ getScriptSnapshot: (fileName) => {
281
+ const normalizedFileName = (0, path_1.normalize)(fileName);
282
+ const hit = this._isFileInCache(normalizedFileName);
283
+ this._logger.trace({ normalizedFileName, cacheHit: hit }, 'getScriptSnapshot():', 'cache', hit ? 'hit' : 'miss');
305
284
  // Read file content from either memory cache or Jest runtime cache or fallback to file system read
306
285
  if (!hit) {
307
- var fileContent =
286
+ const fileContent =
308
287
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
309
- (_d = (_b = (_a = _this._fileContentCache.get(normalizedFileName)) !== null && _a !== void 0 ? _a : _this._runtimeCacheFS.get(normalizedFileName)) !== null && _b !== void 0 ? _b : (_c = _this._cachedReadFile) === null || _c === void 0 ? void 0 : _c.call(_this, normalizedFileName)) !== null && _d !== void 0 ? _d : undefined;
288
+ this._fileContentCache.get(normalizedFileName) ??
289
+ this._runtimeCacheFS.get(normalizedFileName) ??
290
+ this._cachedReadFile?.(normalizedFileName) ??
291
+ undefined;
310
292
  if (fileContent !== undefined) {
311
293
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
312
- _this._fileContentCache.set(normalizedFileName, fileContent);
294
+ this._fileContentCache.set(normalizedFileName, fileContent);
313
295
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
314
- _this._fileVersionCache.set(normalizedFileName, 1);
296
+ this._fileVersionCache.set(normalizedFileName, 1);
315
297
  }
316
298
  }
317
299
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
318
- var contents = _this._fileContentCache.get(normalizedFileName);
300
+ const contents = this._fileContentCache.get(normalizedFileName);
319
301
  if (contents === undefined)
320
302
  return;
321
- return _this._ts.ScriptSnapshot.fromString(contents);
303
+ return this._ts.ScriptSnapshot.fromString(contents);
322
304
  },
323
305
  fileExists: (0, lodash_memoize_1.default)(this._ts.sys.fileExists),
324
- readFile: (_a = this._cachedReadFile) !== null && _a !== void 0 ? _a : this._ts.sys.readFile,
306
+ readFile: this._cachedReadFile ?? this._ts.sys.readFile,
325
307
  readDirectory: (0, lodash_memoize_1.default)(this._ts.sys.readDirectory),
326
308
  getDirectories: (0, lodash_memoize_1.default)(this._ts.sys.getDirectories),
327
309
  directoryExists: (0, lodash_memoize_1.default)(this._ts.sys.directoryExists),
328
310
  realpath: this._ts.sys.realpath && (0, lodash_memoize_1.default)(this._ts.sys.realpath),
329
- getNewLine: function () { return constants_1.LINE_FEED; },
330
- getCurrentDirectory: function () { return _this.configSet.cwd; },
331
- getCompilationSettings: function () { return _this._compilerOptions; },
332
- getDefaultLibFileName: function () { return _this._ts.getDefaultLibFilePath(_this._compilerOptions); },
333
- getCustomTransformers: function () { return _this._makeTransformers(_this.configSet.resolvedTransformers); },
334
- resolveModuleNames: function (moduleNames, containingFile) {
335
- return moduleNames.map(function (moduleName) { return _this._resolveModuleName(moduleName, containingFile).resolvedModule; });
336
- },
311
+ getNewLine: () => constants_1.LINE_FEED,
312
+ getCurrentDirectory: () => this.configSet.cwd,
313
+ getCompilationSettings: () => this._compilerOptions,
314
+ getDefaultLibFileName: () => this._ts.getDefaultLibFilePath(this._compilerOptions),
315
+ getCustomTransformers: () => this._makeTransformers(this.configSet.resolvedTransformers),
316
+ resolveModuleNames: (moduleNames, containingFile) => moduleNames.map((moduleName) => this._resolveModuleName(moduleName, containingFile).resolvedModule),
337
317
  };
338
318
  this._logger.debug('created language service');
339
319
  this._languageService = this._ts.createLanguageService(serviceHost, this._ts.createDocumentRegistry(this._ts.sys.useCaseSensitiveFileNames, this.configSet.cwd));
340
320
  this.program = this._languageService.getProgram();
341
- };
321
+ }
342
322
  /**
343
323
  * @internal
344
324
  */
345
- TsCompiler.prototype._getFileContentFromCache = function (filePath) {
346
- var normalizedFilePath = (0, path_1.normalize)(filePath);
347
- var resolvedFileContent = this._runtimeCacheFS.get(normalizedFilePath);
325
+ _getFileContentFromCache(filePath) {
326
+ const normalizedFilePath = (0, path_1.normalize)(filePath);
327
+ let resolvedFileContent = this._runtimeCacheFS.get(normalizedFilePath);
348
328
  if (!resolvedFileContent) {
349
329
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
350
330
  resolvedFileContent = this._moduleResolutionHost.readFile(normalizedFilePath);
351
331
  this._runtimeCacheFS.set(normalizedFilePath, resolvedFileContent);
352
332
  }
353
333
  return resolvedFileContent;
354
- };
334
+ }
355
335
  /**
356
336
  * @internal
357
337
  */
358
- TsCompiler.prototype._getImportedModulePaths = function (resolvedFileContent, containingFile) {
359
- var _this = this;
338
+ _getImportedModulePaths(resolvedFileContent, containingFile) {
360
339
  return this._ts
361
340
  .preProcessFile(resolvedFileContent, true, true)
362
- .importedFiles.map(function (importedFile) {
363
- var resolvedModule = _this._resolveModuleName(importedFile.fileName, containingFile).resolvedModule;
341
+ .importedFiles.map((importedFile) => {
342
+ const { resolvedModule } = this._resolveModuleName(importedFile.fileName, containingFile);
364
343
  /* istanbul ignore next already covered */
365
- var resolvedFileName = resolvedModule === null || resolvedModule === void 0 ? void 0 : resolvedModule.resolvedFileName;
344
+ const resolvedFileName = resolvedModule?.resolvedFileName;
366
345
  /* istanbul ignore next already covered */
367
- return resolvedFileName && !(resolvedModule === null || resolvedModule === void 0 ? void 0 : resolvedModule.isExternalLibraryImport) ? resolvedFileName : '';
346
+ return resolvedFileName && !resolvedModule?.isExternalLibraryImport ? resolvedFileName : '';
368
347
  })
369
- .filter(function (resolveFileName) { return !!resolveFileName; });
370
- };
348
+ .filter((resolveFileName) => !!resolveFileName);
349
+ }
371
350
  /**
372
351
  * @internal
373
352
  */
374
- TsCompiler.prototype._resolveModuleName = function (moduleNameToResolve, containingFile) {
353
+ _resolveModuleName(moduleNameToResolve, containingFile) {
375
354
  return this._ts.resolveModuleName(moduleNameToResolve, containingFile, this._compilerOptions,
376
355
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
377
356
  this._moduleResolutionHost,
378
357
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
379
358
  this._moduleResolutionCache);
380
- };
359
+ }
381
360
  /**
382
361
  * @internal
383
362
  */
384
- TsCompiler.prototype._isFileInCache = function (fileName) {
363
+ _isFileInCache(fileName) {
385
364
  return (
386
365
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
387
366
  this._fileContentCache.has(fileName) &&
@@ -389,15 +368,14 @@ var TsCompiler = /** @class */ (function () {
389
368
  this._fileVersionCache.has(fileName) &&
390
369
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
391
370
  this._fileVersionCache.get(fileName) !== 0);
392
- };
371
+ }
393
372
  /**
394
373
  * @internal
395
374
  */
396
- TsCompiler.prototype._updateMemoryCache = function (contents, fileName, isModuleKindTheSame) {
397
- if (isModuleKindTheSame === void 0) { isModuleKindTheSame = true; }
398
- this._logger.debug({ fileName: fileName }, 'updateMemoryCache: update memory cache for language service');
399
- var shouldIncrementProjectVersion = false;
400
- var hit = this._isFileInCache(fileName);
375
+ _updateMemoryCache(contents, fileName, isModuleKindTheSame = true) {
376
+ this._logger.debug({ fileName }, 'updateMemoryCache: update memory cache for language service');
377
+ let shouldIncrementProjectVersion = false;
378
+ const hit = this._isFileInCache(fileName);
401
379
  if (!hit) {
402
380
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
403
381
  this._fileVersionCache.set(fileName, 1);
@@ -405,9 +383,9 @@ var TsCompiler = /** @class */ (function () {
405
383
  }
406
384
  else {
407
385
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
408
- var prevVersion = this._fileVersionCache.get(fileName);
386
+ const prevVersion = this._fileVersionCache.get(fileName);
409
387
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
410
- var previousContents = this._fileContentCache.get(fileName);
388
+ const previousContents = this._fileContentCache.get(fileName);
411
389
  // Avoid incrementing cache when nothing has changed.
412
390
  if (previousContents !== contents) {
413
391
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -426,19 +404,22 @@ var TsCompiler = /** @class */ (function () {
426
404
  }
427
405
  if (shouldIncrementProjectVersion)
428
406
  this._projectVersion++;
429
- };
407
+ }
430
408
  /**
431
409
  * @internal
432
410
  */
433
- TsCompiler.prototype.getDiagnostics = function (fileName) {
434
- var diagnostics = [];
411
+ getDiagnostics(fileName) {
412
+ const diagnostics = [];
435
413
  if (this.configSet.shouldReportDiagnostics(fileName)) {
436
- this._logger.debug({ fileName: fileName }, '_doTypeChecking(): computing diagnostics using language service');
414
+ this._logger.debug({ fileName }, '_doTypeChecking(): computing diagnostics using language service');
437
415
  // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
438
- diagnostics.push.apply(diagnostics, __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileName)), false), __read(this._languageService.getSyntacticDiagnostics(fileName)), false));
416
+ diagnostics.push(
417
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
418
+ ...this._languageService.getSemanticDiagnostics(fileName),
419
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
420
+ ...this._languageService.getSyntacticDiagnostics(fileName));
439
421
  }
440
422
  return diagnostics;
441
- };
442
- return TsCompiler;
443
- }());
423
+ }
424
+ }
444
425
  exports.TsCompiler = TsCompiler;