Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Allow vm script options in compile()
Browse files Browse the repository at this point in the history
i.e. `filename`, etc.
  • Loading branch information
TooTallNate committed Oct 18, 2019
1 parent 006fb0d commit 3211594
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { wrap } from 'co';
import { isRegExp } from 'util';
import { generate } from 'escodegen';
import { parseScript } from 'esprima';
import { Context, runInNewContext } from 'vm';
import { Context, RunningScriptOptions, runInNewContext } from 'vm';
import { visit, namedTypes as n, builders as b } from 'ast-types';
import supportsAsync from './supports-async';

Expand Down Expand Up @@ -145,7 +145,7 @@ namespace degenerator {
export interface DegeneratorOptions {
output?: string;
}
export interface CompileOptions extends DegeneratorOptions {
export type CompileOptions = DegeneratorOptions & RunningScriptOptions & {
sandbox?: Context;
}
export function compile<T>(
Expand All @@ -158,7 +158,8 @@ namespace degenerator {
const compiled = degenerator(code, names, { ...options, output });
const fn = runInNewContext(
`${compiled};${returnName}`,
options.sandbox
options.sandbox,
options
);
if (supportsAsync) {
return fn as T;
Expand Down

0 comments on commit 3211594

Please sign in to comment.