Skip to content

Commit

Permalink
Remove handling of babelrc (jestjs#3344)
Browse files Browse the repository at this point in the history
babelrc is the config file of babel and not babylon
  • Loading branch information
danez authored and skovhus committed Apr 29, 2017
1 parent 56e5c48 commit 4db7bd4
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions packages/jest-editor-support/src/parsers/BabylonParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,13 @@ const {readFileSync} = require('fs');
const babylon = require('babylon');
const {Expect, ItBlock} = require('./ParserNodes');

const path = require('path');
const fs = require('fs');

const BABELRC_FILENAME = '.babelrc';
const cache = Object.create(null);

// This is a copy of babel-jest's parser, but it takes create-react-app
// into account, and will return an empty JSON object instead of "".
const getBabelRC = (filename, {useCache}) => {
// Special case for create-react-app, which hides the .babelrc
const paths: string[] = ['node_modules/react-scripts/'];
let directory = filename;
while (directory !== (directory = path.dirname(directory))) {
if (useCache && cache[directory]) {
break;
}

paths.push(directory);
const configFilePath = path.join(directory, BABELRC_FILENAME);
if (fs.existsSync(configFilePath)) {
cache[directory] = fs.readFileSync(configFilePath, 'utf8');
break;
}
}
paths.forEach(directoryPath => {
cache[directoryPath] = cache[directory];
});

// return an empy JSON parse compatible string
return cache[directory] || '{}';
};

const parse = (file: string) => {
const itBlocks: ItBlock[] = [];
const expects: Expect[] = [];

const data = readFileSync(file).toString();
const babelRC = getBabelRC(file, {useCache: true});
const babel = JSON.parse(babelRC);

const plugins = Array.isArray(babel.plugins)
? babel.plugins.concat(['*'])
: ['*'];

const config = {plugins, sourceType: 'module'};
const config = {plugins: ['*'], sourceType: 'module'};
const ast = babylon.parse(data, config);

// An `it`/`test` was found in the AST
Expand Down

0 comments on commit 4db7bd4

Please sign in to comment.