Skip to content

Commit

Permalink
Replace the deprecated produceCachedData option used in vm module…
Browse files Browse the repository at this point in the history
… with `script.createCachedData()` (#13741)

* Replace the deprecated vm produceCachedData option with createCachedData

* Use BABEL_8_BREAKING flag
  • Loading branch information
TagawaHirotaka committed Sep 11, 2021
1 parent 0ca601a commit 9780c56
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions packages/babel-helper-transform-fixture-test-runner/src/index.ts
Expand Up @@ -95,16 +95,26 @@ function runCacheableScriptInTestContext(
cachedScripts.set(filename, cached);
}

const script = new vm.Script(cached.code, {
filename,
displayErrors: true,
lineOffset: -1,
cachedData: cached.cachedData,
produceCachedData: true,
});

if (script.cachedDataProduced) {
cached.cachedData = script.cachedData;
let script: vm.Script;
if (process.env.BABEL_8_BREAKING) {
script = new vm.Script(cached.code, {
filename,
displayErrors: true,
lineOffset: -1,
cachedData: cached.cachedData,
});
cached.cachedData = script.createCachedData();
} else {
script = new vm.Script(cached.code, {
filename,
displayErrors: true,
lineOffset: -1,
cachedData: cached.cachedData,
produceCachedData: true,
});
if (script.cachedDataProduced) {
cached.cachedData = script.cachedData;
}
}

const module = {
Expand Down

0 comments on commit 9780c56

Please sign in to comment.