Skip to content

Commit

Permalink
chore(gatsby): Convert babel-parse-to-ast to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
john015 committed Mar 22, 2020
1 parent 70596d5 commit 08ac352
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/gatsby/src/bootstrap/resolve-module-exports.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @flow
const fs = require(`fs`)
const traverse = require(`@babel/traverse`).default
const get = require(`lodash/get`)
const { codeFrameColumns } = require(`@babel/code-frame`)
const { babelParseToAst } = require(`../utils/babel-parse-to-ast`)
const report = require(`gatsby-cli/lib/reporter`)
import fs from "fs"
import traverse from "@babel/traverse"
import get from "lodash/get"
import { codeFrameColumns } from "@babel/code-frame"
import { babelParseToAst } from "../utils/babel-parse-to-ast"
import report from "gatsby-cli/lib/reporter"

import { testRequireError } from "../utils/test-require-error"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @flow */
const parser = require(`@babel/parser`)
import * as parser from "@babel/parser"
import { File } from "@babel/types"

const PARSER_OPTIONS = {
allowImportExportEverywhere: true,
Expand Down Expand Up @@ -43,7 +43,7 @@ const PARSER_OPTIONS = {
],
}

export function getBabelParserOptions(filePath: string) {
export function getBabelParserOptions(filePath: string): object {
// Flow and TypeScript plugins can't be enabled simultaneously
if (/\.tsx?/.test(filePath)) {
const { plugins } = PARSER_OPTIONS
Expand All @@ -57,6 +57,6 @@ export function getBabelParserOptions(filePath: string) {
return PARSER_OPTIONS
}

export function babelParseToAst(contents: string, filePath: string) {
export function babelParseToAst(contents: string, filePath: string): File {
return parser.parse(contents, getBabelParserOptions(filePath))
}

0 comments on commit 08ac352

Please sign in to comment.