Skip to content

Commit

Permalink
fix(babel): fixes the babel 6 hack
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 15, 2018
1 parent a68c216 commit c8d51cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/util/hacks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { File } from 'babel-core/lib/transformation/file'

import * as hacks from './hacks'

jest.mock(
Expand All @@ -20,10 +18,15 @@ jest.mock(
{ virtual: true },
)

beforeEach(() => {
jest.resetModules()
})

describe('patchBabelCore_githubIssue6577', () => {
const INPUT = 'foo:bar'
const initOptions = ({ version = '6.0.0', sourceMaps }: { version?: any; sourceMaps?: any } = {}) => {
hacks.patchBabelCore_githubIssue6577({ version } as any)
const { File } = require('babel-core/lib/transformation/file')
return new File().initOptions({ sourceMaps, inputSourceMap: true })
}

Expand Down
4 changes: 3 additions & 1 deletion src/util/hacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const patchBabelCore_githubIssue6577: ModulePatcher<TBabelCore> = babel =
// This is a hack to bypass it and fix our issue #627
// The bug disallow debugging when using Babel Jest with [email protected] because of
// source-maps not being inlined
if (typeof babel.version === 'string' && semver.satisfies(babel.version, '>=6 <7')) {
if (typeof babel.version !== 'string') return babel
const version = semver.coerce(babel.version)
if (version && version.major === 6) {
try {
const File = require('babel-core/lib/transformation/file').File
File.prototype.initOptions = (original => {
Expand Down

0 comments on commit c8d51cf

Please sign in to comment.