Skip to content

Commit f407f88

Browse files
committed
fix(jest-27): replace export const with export default
This issue was caused by jestjs/jest#11193
1 parent f2896e4 commit f407f88

1 file changed

Lines changed: 43 additions & 41 deletions

File tree

src/index.ts

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,49 @@ export interface Options {
1010
target?: string
1111
}
1212

13-
export const createTransformer = (options: Options | null) => {
14-
if (!options) options = {}
15-
const { loaders = {} } = options
16-
delete options.loaders
17-
return {
18-
process(content: string, filename: string) {
19-
const ext = getExt(filename)
20-
const strict = /^(im|ex)port /m.test(content)
21-
const result = transformSync(content, {
22-
loader: loaders[ext] || (extname(filename).slice(1) as Loader),
23-
format: 'cjs',
24-
target: 'es2018',
25-
sourcemap: 'external',
26-
sourcefile: filename,
27-
...options,
28-
// Esbuild does not enable strict mode when compiling ES modules to
29-
// CommonJS format: https://github.com/evanw/esbuild/issues/422#issuecomment-739740602
30-
banner: strict ? '"use strict";' : undefined,
31-
})
32-
if (/\bjest\.mock\b/.test(result.code)) {
33-
const { nebu } = require('nebu') as typeof import('nebu')
34-
result.code = nebu.process(result.code, {
35-
plugins: [hoistJestMock],
36-
state: { strict },
37-
}).js
38-
}
39-
const map = {
40-
...JSON.parse(result.map),
41-
sourcesContent: null,
42-
}
43-
// Append the inline sourcemap manually to ensure the "sourcesContent"
44-
// is null. Otherwise, breakpoints won't pause within the actual source.
45-
return {
46-
code:
47-
result.code +
48-
'\n//# sourceMappingURL=data:application/json;base64,' +
49-
Buffer.from(JSON.stringify(map)).toString('base64'),
50-
map,
51-
}
52-
},
53-
}
13+
export default {
14+
createTransformer(options: Options | null) {
15+
if (!options) options = {}
16+
const { loaders = {} } = options
17+
delete options.loaders
18+
return {
19+
process(content: string, filename: string) {
20+
const ext = getExt(filename)
21+
const strict = /^(im|ex)port /m.test(content)
22+
const result = transformSync(content, {
23+
loader: loaders[ext] || (extname(filename).slice(1) as Loader),
24+
format: 'cjs',
25+
target: 'es2018',
26+
sourcemap: 'external',
27+
sourcefile: filename,
28+
...options,
29+
// Esbuild does not enable strict mode when compiling ES modules to
30+
// CommonJS format: https://github.com/evanw/esbuild/issues/422#issuecomment-739740602
31+
banner: strict ? '"use strict";' : undefined,
32+
})
33+
if (/\bjest\.mock\b/.test(result.code)) {
34+
const { nebu } = require('nebu') as typeof import('nebu')
35+
result.code = nebu.process(result.code, {
36+
plugins: [hoistJestMock],
37+
state: { strict },
38+
}).js
39+
}
40+
const map = {
41+
...JSON.parse(result.map),
42+
sourcesContent: null,
43+
}
44+
// Append the inline sourcemap manually to ensure the "sourcesContent"
45+
// is null. Otherwise, breakpoints won't pause within the actual source.
46+
return {
47+
code:
48+
result.code +
49+
'\n//# sourceMappingURL=data:application/json;base64,' +
50+
Buffer.from(JSON.stringify(map)).toString('base64'),
51+
map,
52+
}
53+
},
54+
}
55+
},
5456
}
5557

5658
function getExt(str: string) {

0 commit comments

Comments
 (0)