Add warnings to places where we might allow promises to be returned in later minors.

This commit is contained in:
Logan Smyth
2017-11-13 11:32:23 -08:00
parent 394ad93d22
commit 0e88156d0c
6 changed files with 76 additions and 2 deletions

View File

@@ -153,6 +153,16 @@ const readConfigJS = makeStrongCache((filepath, cache) => {
);
}
if (typeof options.then === "function") {
throw new Error(
`You appear to be using an async configuration, ` +
`which your current version of Babel does not support. ` +
`We may add support for this in the future, ` +
`but if you're on the most recent version of @babel/core and still ` +
`seeing this error, then you'll need to synchronously return your config.`,
);
}
return {
filepath,
dirname: path.dirname(filepath),

View File

@@ -205,6 +205,15 @@ const loadDescriptor = makeWeakCache(
throw new Error("Plugin/Preset did not return an object.");
}
if (typeof item.then === "function") {
throw new Error(
`You appear to be using an async plugin, ` +
`which your current version of Babel does not support.` +
`If you're using a published plugin, ` +
`you may need to upgrade your @babel/core version.`,
);
}
return { value: item, options, dirname, alias };
},
);

View File

@@ -38,6 +38,15 @@ export default function generateCode(
result = generate(ast, opts.generatorOpts, code);
} else if (results.length === 1) {
result = results[0];
if (typeof result.then === "function") {
throw new Error(
`You appear to be using an async parser plugin, ` +
`which your current version of Babel does not support. ` +
`If you're using a published plugin, ` +
`you may need to upgrade your @babel/core version.`,
);
}
} else {
throw new Error("More than one plugin attempted to override codegen.");
}

View File

@@ -86,7 +86,18 @@ function transformFile(file: File, pluginPasses: PluginPasses): void {
for (const [plugin, pass] of passPairs) {
const fn = plugin.pre;
if (fn) fn.call(pass, file);
if (fn) {
const result = fn.call(pass, file);
if (isThenable(result)) {
throw new Error(
`You appear to be using an plugin with an async .pre, ` +
`which your current version of Babel does not support.` +
`If you're using a published plugin, you may need to upgrade ` +
`your @babel/core version.`,
);
}
}
}
// merge all plugin visitors into a single visitor
@@ -99,7 +110,26 @@ function transformFile(file: File, pluginPasses: PluginPasses): void {
for (const [plugin, pass] of passPairs) {
const fn = plugin.post;
if (fn) fn.call(pass, file);
if (fn) {
const result = fn.call(pass, file);
if (isThenable(result)) {
throw new Error(
`You appear to be using an plugin with an async .post, ` +
`which your current version of Babel does not support.` +
`If you're using a published plugin, you may need to upgrade ` +
`your @babel/core version.`,
);
}
}
}
}
}
function isThenable(val: mixed): boolean {
return (
!!val &&
(typeof val === "object" || typeof val === "function") &&
typeof val.then === "function"
);
}

View File

@@ -76,6 +76,14 @@ function parser(pluginPasses, options, code) {
if (results.length === 0) {
return parse(code, options.parserOpts);
} else if (results.length === 1) {
if (typeof results[0].then === "function") {
throw new Error(
`You appear to be using an async codegen plugin, ` +
`which your current version of Babel does not support. ` +
`If you're using a published plugin, you may need to upgrade ` +
`your @babel/core version.`,
);
}
return results[0];
}
throw new Error("More than one plugin attempted to override parsing.");

View File

@@ -28,6 +28,14 @@ export function _call(fns?: Array<Function>): boolean {
if (!node) return true;
const ret = fn.call(this.state, this, this.state);
if (ret && typeof ret === "object" && typeof ret.then === "function") {
throw new Error(
`You appear to be using an plugin with an async traversay visitors, ` +
`which your current version of Babel does not support.` +
`If you're using a published plugin, you may need to upgrade ` +
`your @babel/core version.`,
);
}
if (ret) {
throw new Error(`Unexpected return value from visitor method ${fn}`);
}