Skip to content

Commit

Permalink
always use getVmContext if available
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 19, 2020
1 parent fe59f22 commit 383610c
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,24 +785,39 @@ class Runtime {

let compiledFunction: ModuleWrapper | null = null;

if (
typeof compileFunction === 'function' &&
typeof this._environment.getVmContext === 'function'
) {
// Use this if available instead of deprecated `JestEnvironment.runScript`
if (typeof this._environment.getVmContext === 'function') {
const vmContext = this._environment.getVmContext();

if (vmContext) {
try {
compiledFunction = compileFunction(
if (typeof compileFunction === 'function') {
try {
compiledFunction = compileFunction(
transformedFile.code,
this.constructInjectedModuleParameters(),
{
filename,
parsingContext: vmContext,
},
) as ModuleWrapper;
} catch (e) {
throw handlePotentialSyntaxError(e);
}
} else {
const script = this.createScriptFromCode(
transformedFile.code,
this.constructInjectedModuleParameters(),
{
filename,
parsingContext: vmContext,
},
) as ModuleWrapper;
} catch (e) {
throw handlePotentialSyntaxError(e);
filename,
);

const runScript = script.runInContext(
vmContext,
) as RunScriptEvalResult;

if (runScript === null) {
compiledFunction = null;
} else {
compiledFunction = runScript[EVAL_RESULT_VARIABLE];
}
}
}
} else {
Expand Down

0 comments on commit 383610c

Please sign in to comment.