From 58a59cfa4e47df9f708f74e424aa840cd3fc6984 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 22 Jul 2021 18:07:54 -0400 Subject: [PATCH] Don't let Babel incorrectly clone the input AST. Fixes test failures in #478. --- lib/visit.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/visit.js b/lib/visit.js index 41b0b175f..d95d75304 100644 --- a/lib/visit.js +++ b/lib/visit.js @@ -18,7 +18,14 @@ exports.transform = function transform(node, options) { var result = require("@babel/core").transformFromAstSync(node, null, { presets: [require("regenerator-preset")], code: false, - ast: true + ast: true, + // The deep-clone utility that Babel uses (based on V8's Serialization API + // https://nodejs.org/api/v8.html#v8_serialization_api in Node.js) removes + // the prototypes from the cloned node.loc.lines objects that Recast uses + // internally, leading to _blockHoist test failures in tests.transform.js. + // Also, unless cloning is somehow truly necessary, it should be faster to + // skip this step. + cloneInputAst: false }); node = result.ast;