diff --git a/packages/babel-core/src/helpers/normalize-ast.js b/packages/babel-core/src/helpers/normalize-ast.js deleted file mode 100644 index d2c91cef91..0000000000 --- a/packages/babel-core/src/helpers/normalize-ast.js +++ /dev/null @@ -1,23 +0,0 @@ -import * as t from "babel-types"; - -/** - * Normalize an AST. - * - * - Wrap `Program` node with a `File` node. - */ - -export default function ( - ast: Object, - comments?: Array, - tokens?: Array, -) { - if (ast) { - if (ast.type === "Program") { - return t.file(ast, comments || [], tokens || []); - } else if (ast.type === "File") { - return ast; - } - } - - throw new Error("Not a valid ast?"); -} diff --git a/packages/babel-core/src/transformation/pipeline.js b/packages/babel-core/src/transformation/pipeline.js index 8f0815e6f8..7c2db49cc9 100644 --- a/packages/babel-core/src/transformation/pipeline.js +++ b/packages/babel-core/src/transformation/pipeline.js @@ -1,7 +1,7 @@ /* global BabelFileResult, BabelFileMetadata */ import fs from "fs"; -import normalizeAst from "../helpers/normalize-ast"; +import * as t from "babel-types"; import File from "./file"; import OptionManager from "../config/option-manager"; @@ -30,7 +30,11 @@ export function transformFromAst(ast: Object, code: string, opts: Object): Babel opts = new OptionManager().init(opts); if (opts === null) return null; - ast = normalizeAst(ast); + if (ast && ast.type === "Program") { + return t.file(ast, [], []); + } else if (!ast || ast.type !== "File") { + throw new Error("Not a valid ast?"); + } const file = new File(opts); return file.wrap(code, function () {