Do not mutate ast (#8342)

This clones the given ast prior to working on it to avoid mutating the AST given to `transformFromAST`.
This commit is contained in:
Thiago Arrais
2018-07-23 23:20:55 -03:00
committed by Henry Zhu
parent d781e207c8
commit 6f3a800677
2 changed files with 40 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
import path from "path";
import buildDebug from "debug";
import cloneDeep from "lodash/cloneDeep";
import * as t from "@babel/types";
import type { PluginPasses } from "../config";
import convertSourceMap, { typeof Converter } from "convert-source-map";
@@ -75,6 +76,7 @@ export default function normalizeFile(
} else if (ast.type !== "File") {
throw new Error("AST root must be a Program or File node");
}
ast = cloneDeep(ast);
} else {
// The parser's AST types aren't fully compatible with the types generated
// by the logic in babel-types.