Skip to content

Commit

Permalink
Add TS argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored and SimenB committed Sep 21, 2018
1 parent 8d6248e commit e47e545
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/jest-editor-support/src/parsers/babylon_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export type BabylonParserResult = {
itBlocks: Array<ItBlock>,
};

export const getASTfor = (file: string): ?BabylonFile => {
export const getASTfor = (
file: string,
enableTypeScript: boolean = false,
): ?BabylonFile => {
const data = fs.readFileSync(file).toString();
const config = {
// Enable all (most of) the things
Expand Down Expand Up @@ -50,7 +53,7 @@ export const getASTfor = (file: string): ?BabylonFile => {
sourceType: 'module',
};

if (process.env.JEST_BABEL_TYPESCRIPT) {
if (enableTypeScript) {
config.plugins.push('typescript');
} else {
config.plugins.push('flow', 'flowComments');
Expand All @@ -59,10 +62,13 @@ export const getASTfor = (file: string): ?BabylonFile => {
return babelParse(data, config);
};

export const parse = (file: string): BabylonParserResult => {
export const parse = (
file: string,
enableTypeScript: boolean = false,
): BabylonParserResult => {
const itBlocks: ItBlock[] = [];
const expects: Expect[] = [];
const ast = getASTfor(file);
const ast = getASTfor(file, enableTypeScript);

// An `it`/`test` was found in the AST
// So take the AST node and create an object for us
Expand Down

0 comments on commit e47e545

Please sign in to comment.