| | |
| | | Object.defineProperty(exports, '__esModule', { |
| | | value: true |
| | | }); |
| | | exports.createTranspilingRequire = createTranspilingRequire; |
| | | exports.createScriptTransformer = createScriptTransformer; |
| | | exports.createTranspilingRequire = createTranspilingRequire; |
| | | |
| | | function _crypto() { |
| | | const data = require('crypto'); |
| | |
| | | require('./enhanceUnexpectedTokenMessage') |
| | | ); |
| | | |
| | | var _runtimeErrorsAndWarnings = require('./runtimeErrorsAndWarnings'); |
| | | |
| | | var _shouldInstrument = _interopRequireDefault(require('./shouldInstrument')); |
| | | |
| | | function _interopRequireDefault(obj) { |
| | |
| | | |
| | | class ScriptTransformer { |
| | | constructor(_config, _cacheFS) { |
| | | this._config = _config; |
| | | this._cacheFS = _cacheFS; |
| | | |
| | | _defineProperty(this, '_cache', void 0); |
| | | |
| | | _defineProperty(this, '_transformCache', new Map()); |
| | | |
| | | _defineProperty(this, '_transformsAreLoaded', false); |
| | | |
| | | this._config = _config; |
| | | this._cacheFS = _cacheFS; |
| | | const configString = (0, _fastJsonStableStringify().default)(this._config); |
| | | let projectCache = projectCaches.get(configString); |
| | | |
| | |
| | | ); |
| | | |
| | | if (!transformer) { |
| | | throw new TypeError('Jest: a transform must export something.'); |
| | | throw new Error( |
| | | (0, _runtimeErrorsAndWarnings.makeInvalidTransformerError)( |
| | | transformPath |
| | | ) |
| | | ); |
| | | } |
| | | |
| | | if (typeof transformer.createTransformer === 'function') { |
| | |
| | | typeof transformer.process !== 'function' && |
| | | typeof transformer.processAsync !== 'function' |
| | | ) { |
| | | throw new TypeError( |
| | | 'Jest: a transform must export a `process` or `processAsync` function.' |
| | | throw new Error( |
| | | (0, _runtimeErrorsAndWarnings.makeInvalidTransformerError)( |
| | | transformPath |
| | | ) |
| | | ); |
| | | } |
| | | |
| | |
| | | } else if (processed != null && typeof processed.code === 'string') { |
| | | transformed = processed; |
| | | } else { |
| | | throw new TypeError( |
| | | "Jest: a transform's `process` function must return a string, " + |
| | | 'or an object with `code` key containing this string. ' + |
| | | "It's `processAsync` function must return a Promise resolving to it." |
| | | throw new Error( |
| | | (0, _runtimeErrorsAndWarnings.makeInvalidReturnValueError)() |
| | | ); |
| | | } |
| | | } |
| | |
| | | } catch { |
| | | const transformPath = this._getTransformPath(filename); |
| | | |
| | | invariant(transformPath); |
| | | console.warn( |
| | | `jest-transform: The source map produced for the file ${filename} ` + |
| | | `by ${transformPath} was invalid. Proceeding without source ` + |
| | | 'mapping for that file.' |
| | | (0, _runtimeErrorsAndWarnings.makeInvalidSourceMapWarning)( |
| | | filename, |
| | | transformPath |
| | | ) |
| | | ); |
| | | } |
| | | } // That means that the transform has a custom instrumentation |
| | |
| | | return null; |
| | | } |
| | | |
| | | const code = content.substr(33); |
| | | const code = content.substring(33); |
| | | const checksum = (0, _crypto().createHash)('md5').update(code).digest('hex'); |
| | | |
| | | if (checksum === content.substr(0, 32)) { |
| | | if (checksum === content.substring(0, 32)) { |
| | | return code; |
| | | } |
| | | |
| | |
| | | invariant(name); |
| | | invariant( |
| | | typeof transformer.process === 'function', |
| | | `Jest: synchronous transformer ${name} must export a "process" function.` |
| | | (0, _runtimeErrorsAndWarnings.makeInvalidSyncTransformerError)(name) |
| | | ); |
| | | } |
| | | |