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 89ca9f4 commit 4e099d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions packages/gatsby/src/bootstrap/resolve-module-exports.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @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`)

const testRequireError = require(`../utils/test-require-error`).default
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"

const staticallyAnalyzeExports = (modulePath, resolver = require.resolve) => {
let absPath
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 4e099d4

Please sign in to comment.