From a35c863341da20e95073b3e5e8fad7d23fbe8c1b Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 25 Jun 2015 03:50:10 +0100 Subject: [PATCH] deprecate returning source strings from visitor methods --- src/babel/traversal/path/replacement.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/babel/traversal/path/replacement.js b/src/babel/traversal/path/replacement.js index e86a117392..a28ac00a23 100644 --- a/src/babel/traversal/path/replacement.js +++ b/src/babel/traversal/path/replacement.js @@ -112,6 +112,13 @@ export function replaceWith(replacement, whateverAllowed) { if (typeof replacement === "string") { if (whateverAllowed) { + this.hub.file.log.deprecate("Returning a string from a visitor method will be removed in the future. String " + + "building is NOT a substitute for AST generation. String building leads to " + + "terrible performance due to the additional parsing overhead and will lead to " + + "extremely brittle transformers. For those extreme cases where you're dealing " + + "with strings from a foreign source you may continue to use " + + "`path.replaceWithSourceString(code)`. Just please don't abuse this. Bad plugins " + + "hurt the ecosystem."); return this.replaceWithSourceString(replacement); } else { throw new Error("Don't use `path.replaceWith()` with a string, use `path.replaceWithSourceString()`");