Unverified Commit 75203eb8 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix missing injectCaller (#7223)

parent 13c55a19
...@@ -4,6 +4,7 @@ import { loader } from 'webpack' ...@@ -4,6 +4,7 @@ import { loader } from 'webpack'
import { join, basename } from 'path' import { join, basename } from 'path'
import loaderUtils from 'loader-utils' import loaderUtils from 'loader-utils'
import cache from './next-babel-loader/cache' import cache from './next-babel-loader/cache'
import injectCaller from './next-babel-loader/injectCaller'
import transform, { version as transformVersion } from './next-babel-loader/transform' import transform, { version as transformVersion } from './next-babel-loader/transform'
// increment 'a' to invalidate cache // increment 'a' to invalidate cache
...@@ -57,7 +58,7 @@ const nextBabelLoader: loader.Loader = function (source, inputSourceMap) { ...@@ -57,7 +58,7 @@ const nextBabelLoader: loader.Loader = function (source, inputSourceMap) {
delete programmaticOptions.asyncToPromises delete programmaticOptions.asyncToPromises
delete programmaticOptions.distDir delete programmaticOptions.distDir
const config: any = babel.loadPartialConfig(programmaticOptions); const config: any = babel.loadPartialConfig(injectCaller(programmaticOptions));
if (config) { if (config) {
let options = config.options; let options = config.options;
......
import * as babel from "@babel/core"
export default function injectCaller (opts: any) {
if (!supportsCallerOption()) return opts;
return Object.assign({}, opts, {
caller: Object.assign(
{
name: "babel-loader",
// Webpack >= 2 supports ESM and dynamic import.
supportsStaticESM: true,
supportsDynamicImport: true,
},
opts.caller,
),
});
};
// TODO: We can remove this eventually, I'm just adding it so that people have
// a little time to migrate to the newer RCs of @babel/core without getting
// hard-to-diagnose errors about unknown 'caller' options.
let supportsCallerOptionFlag: any = undefined;
function supportsCallerOption() {
if (supportsCallerOptionFlag === undefined) {
try {
// Rather than try to match the Babel version, we just see if it throws
// when passed a 'caller' flag, and use that to decide if it is supported.
babel.loadPartialConfig({
// @ts-ignore
caller: undefined,
babelrc: false,
configFile: false,
});
supportsCallerOptionFlag = true;
} catch (err) {
supportsCallerOptionFlag = false;
}
}
return supportsCallerOptionFlag;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment