Skip to content

Commit c8d51cf

Browse files
committed
fix(babel): fixes the babel 6 hack
1 parent a68c216 commit c8d51cf

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/util/hacks.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { File } from 'babel-core/lib/transformation/file'
2-
31
import * as hacks from './hacks'
42

53
jest.mock(
@@ -20,10 +18,15 @@ jest.mock(
2018
{ virtual: true },
2119
)
2220

21+
beforeEach(() => {
22+
jest.resetModules()
23+
})
24+
2325
describe('patchBabelCore_githubIssue6577', () => {
2426
const INPUT = 'foo:bar'
2527
const initOptions = ({ version = '6.0.0', sourceMaps }: { version?: any; sourceMaps?: any } = {}) => {
2628
hacks.patchBabelCore_githubIssue6577({ version } as any)
29+
const { File } = require('babel-core/lib/transformation/file')
2730
return new File().initOptions({ sourceMaps, inputSourceMap: true })
2831
}
2932

src/util/hacks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export const patchBabelCore_githubIssue6577: ModulePatcher<TBabelCore> = babel =
1212
// This is a hack to bypass it and fix our issue #627
1313
// The bug disallow debugging when using Babel Jest with babel-core@6.x because of
1414
// source-maps not being inlined
15-
if (typeof babel.version === 'string' && semver.satisfies(babel.version, '>=6 <7')) {
15+
if (typeof babel.version !== 'string') return babel
16+
const version = semver.coerce(babel.version)
17+
if (version && version.major === 6) {
1618
try {
1719
const File = require('babel-core/lib/transformation/file').File
1820
File.prototype.initOptions = (original => {

0 commit comments

Comments
 (0)