Skip to content

Commit

Permalink
Fix Babel 8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jul 20, 2023
1 parent 70f74d8 commit ca5c009
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/index.js
Expand Up @@ -12,7 +12,14 @@ try {

// Since we've got the reverse bridge package at @babel/core@6.x, give
// people useful feedback if they try to use it alongside babel-loader.
if (/^6\./.test(babel.version)) {
let babelVersion;
try {
babelVersion = babel.version;
} catch (e) {
// In Babel 8, .version cannot be synchronously accesssed.
// It's ok, it's not Babel 7.
}

Check warning on line 21 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L19-L21

Added lines #L19 - L21 were not covered by tests
if (babelVersion && /^6\./.test(babelVersion)) {
throw new Error(
"\n babel-loader@9 will not work with the '@babel/core@6' bridge package. " +
"If you want to use Babel 6.x, install 'babel-loader@7'.",
Expand Down Expand Up @@ -176,7 +183,7 @@ async function loader(source, inputSourceMap, overrides) {
cacheDirectory = null,
cacheIdentifier = JSON.stringify({
options,
"@babel/core": transform.version,
"@babel/core": babel.version,
"@babel/loader": version,
}),
cacheCompression = true,
Expand Down
4 changes: 3 additions & 1 deletion src/transform.js
Expand Up @@ -36,4 +36,6 @@ module.exports = async function (source, options) {
};
};

module.exports.version = babel.version;
Object.defineProperty(module.exports, "version", {
get: () => babel.version,
});

0 comments on commit ca5c009

Please sign in to comment.