Skip to content

Commit fac1aa7

Browse files
authored
🤖 Merge PR DefinitelyTyped#72615 fix(node/vm): fix CompileFunctionOptions.cachedData type & add jsdoc by @hkleungai
1 parent 141c7f7 commit fac1aa7

File tree

6 files changed

+111
-15
lines changed

6 files changed

+111
-15
lines changed

‎types/node/test/vm.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,37 @@ import {
5252
}
5353

5454
{
55-
const fn: Function = compileFunction("console.log(\"test\")", [] as readonly string[], {
55+
const code = "console.log(\"test\")";
56+
const params = [] as const;
57+
58+
let fn = compileFunction(code);
59+
fn = compileFunction(code, params);
60+
fn = compileFunction(code, params, {});
61+
fn = compileFunction(code, params, {
62+
filename: "",
63+
lineOffset: 0,
64+
columnOffset: 0,
5665
parsingContext: createContext(),
5766
contextExtensions: [{
5867
a: 1,
5968
}],
6069
produceCachedData: false,
6170
cachedData: Buffer.from("nope"),
6271
});
72+
fn = compileFunction(code, params, {
73+
cachedData: new Uint8Array(),
74+
});
75+
fn = compileFunction(code, params, {
76+
cachedData: new DataView(new ArrayBuffer(10)),
77+
});
78+
79+
fn satisfies Function;
80+
// $ExpectType Buffer<ArrayBufferLike> | undefined
81+
fn.cachedData;
82+
// $ExpectType boolean | undefined
83+
fn.cachedDataProduced;
84+
// $ExpectType boolean | undefined
85+
fn.cachedDataRejected;
6386
}
6487

6588
{

‎types/node/v18/test/vm.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,37 @@ import {
6262
}
6363

6464
{
65-
const fn: Function = compileFunction("console.log(\"test\")", [] as readonly string[], {
65+
const code = "console.log(\"test\")";
66+
const params = [] as const;
67+
68+
let fn = compileFunction(code);
69+
fn = compileFunction(code, params);
70+
fn = compileFunction(code, params, {});
71+
fn = compileFunction(code, params, {
72+
filename: "",
73+
lineOffset: 0,
74+
columnOffset: 0,
6675
parsingContext: createContext(),
6776
contextExtensions: [{
6877
a: 1,
6978
}],
7079
produceCachedData: false,
7180
cachedData: Buffer.from("nope"),
7281
});
82+
fn = compileFunction(code, params, {
83+
cachedData: new Uint8Array(),
84+
});
85+
fn = compileFunction(code, params, {
86+
cachedData: new DataView(new ArrayBuffer(10)),
87+
});
88+
89+
fn satisfies Function;
90+
// $ExpectType Buffer<ArrayBufferLike> | undefined
91+
fn.cachedData;
92+
// $ExpectType boolean | undefined
93+
fn.cachedDataProduced;
94+
// $ExpectType boolean | undefined
95+
fn.cachedDataRejected;
7396
}
7497

7598
{

‎types/node/v18/vm.d.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ declare module "vm" {
5858
}
5959
interface ScriptOptions extends BaseOptions {
6060
/**
61-
* V8's code cache data for the supplied source.
61+
* Provides an optional data with V8's code cache data for the supplied source.
6262
*/
6363
cachedData?: Buffer | NodeJS.ArrayBufferView | undefined;
6464
/** @deprecated in favor of `script.createCachedData()` */
@@ -108,18 +108,24 @@ declare module "vm" {
108108
microtaskMode?: CreateContextOptions["microtaskMode"];
109109
}
110110
interface RunningCodeOptions extends RunningScriptOptions {
111-
cachedData?: ScriptOptions["cachedData"];
111+
/**
112+
* Provides an optional data with V8's code cache data for the supplied source.
113+
*/
114+
cachedData?: ScriptOptions["cachedData"] | undefined;
112115
importModuleDynamically?: ScriptOptions["importModuleDynamically"];
113116
}
114117
interface RunningCodeInNewContextOptions extends RunningScriptInNewContextOptions {
115-
cachedData?: ScriptOptions["cachedData"];
118+
/**
119+
* Provides an optional data with V8's code cache data for the supplied source.
120+
*/
121+
cachedData?: ScriptOptions["cachedData"] | undefined;
116122
importModuleDynamically?: ScriptOptions["importModuleDynamically"];
117123
}
118124
interface CompileFunctionOptions extends BaseOptions {
119125
/**
120126
* Provides an optional data with V8's code cache data for the supplied source.
121127
*/
122-
cachedData?: Buffer | undefined;
128+
cachedData?: ScriptOptions["cachedData"] | undefined;
123129
/**
124130
* Specifies whether to produce new cache data.
125131
* Default: `false`,
@@ -612,6 +618,9 @@ declare module "vm" {
612618
* @default 'vm:module(i)' where i is a context-specific ascending index.
613619
*/
614620
identifier?: string | undefined;
621+
/**
622+
* Provides an optional data with V8's code cache data for the supplied source.
623+
*/
615624
cachedData?: ScriptOptions["cachedData"] | undefined;
616625
context?: Context | undefined;
617626
lineOffset?: BaseOptions["lineOffset"] | undefined;

‎types/node/v20/test/vm.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,37 @@ import {
6262
}
6363

6464
{
65-
const fn: Function = compileFunction("console.log(\"test\")", [] as readonly string[], {
65+
const code = "console.log(\"test\")";
66+
const params = [] as const;
67+
68+
let fn = compileFunction(code);
69+
fn = compileFunction(code, params);
70+
fn = compileFunction(code, params, {});
71+
fn = compileFunction(code, params, {
72+
filename: "",
73+
lineOffset: 0,
74+
columnOffset: 0,
6675
parsingContext: createContext(),
6776
contextExtensions: [{
6877
a: 1,
6978
}],
7079
produceCachedData: false,
7180
cachedData: Buffer.from("nope"),
7281
});
82+
fn = compileFunction(code, params, {
83+
cachedData: new Uint8Array(),
84+
});
85+
fn = compileFunction(code, params, {
86+
cachedData: new DataView(new ArrayBuffer(10)),
87+
});
88+
89+
fn satisfies Function;
90+
// $ExpectType Buffer<ArrayBufferLike> | undefined
91+
fn.cachedData;
92+
// $ExpectType boolean | undefined
93+
fn.cachedDataProduced;
94+
// $ExpectType boolean | undefined
95+
fn.cachedDataRejected;
7396
}
7497

7598
{

‎types/node/v20/vm.d.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ declare module "vm" {
5858
}
5959
interface ScriptOptions extends BaseOptions {
6060
/**
61-
* V8's code cache data for the supplied source.
61+
* Provides an optional data with V8's code cache data for the supplied source.
6262
*/
6363
cachedData?: Buffer | NodeJS.ArrayBufferView | undefined;
6464
/** @deprecated in favor of `script.createCachedData()` */
@@ -110,18 +110,24 @@ declare module "vm" {
110110
microtaskMode?: CreateContextOptions["microtaskMode"];
111111
}
112112
interface RunningCodeOptions extends RunningScriptOptions {
113-
cachedData?: ScriptOptions["cachedData"];
113+
/**
114+
* Provides an optional data with V8's code cache data for the supplied source.
115+
*/
116+
cachedData?: ScriptOptions["cachedData"] | undefined;
114117
importModuleDynamically?: ScriptOptions["importModuleDynamically"];
115118
}
116119
interface RunningCodeInNewContextOptions extends RunningScriptInNewContextOptions {
117-
cachedData?: ScriptOptions["cachedData"];
120+
/**
121+
* Provides an optional data with V8's code cache data for the supplied source.
122+
*/
123+
cachedData?: ScriptOptions["cachedData"] | undefined;
118124
importModuleDynamically?: ScriptOptions["importModuleDynamically"];
119125
}
120126
interface CompileFunctionOptions extends BaseOptions {
121127
/**
122128
* Provides an optional data with V8's code cache data for the supplied source.
123129
*/
124-
cachedData?: Buffer | undefined;
130+
cachedData?: ScriptOptions["cachedData"] | undefined;
125131
/**
126132
* Specifies whether to produce new cache data.
127133
* @default false
@@ -807,6 +813,9 @@ declare module "vm" {
807813
* @default 'vm:module(i)' where i is a context-specific ascending index.
808814
*/
809815
identifier?: string | undefined;
816+
/**
817+
* Provides an optional data with V8's code cache data for the supplied source.
818+
*/
810819
cachedData?: ScriptOptions["cachedData"] | undefined;
811820
context?: Context | undefined;
812821
lineOffset?: BaseOptions["lineOffset"] | undefined;

‎types/node/vm.d.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ declare module "vm" {
5858
}
5959
interface ScriptOptions extends BaseOptions {
6060
/**
61-
* V8's code cache data for the supplied source.
61+
* Provides an optional data with V8's code cache data for the supplied source.
6262
*/
6363
cachedData?: Buffer | NodeJS.ArrayBufferView | undefined;
6464
/** @deprecated in favor of `script.createCachedData()` */
@@ -110,18 +110,24 @@ declare module "vm" {
110110
microtaskMode?: CreateContextOptions["microtaskMode"];
111111
}
112112
interface RunningCodeOptions extends RunningScriptOptions {
113-
cachedData?: ScriptOptions["cachedData"];
113+
/**
114+
* Provides an optional data with V8's code cache data for the supplied source.
115+
*/
116+
cachedData?: ScriptOptions["cachedData"] | undefined;
114117
importModuleDynamically?: ScriptOptions["importModuleDynamically"];
115118
}
116119
interface RunningCodeInNewContextOptions extends RunningScriptInNewContextOptions {
117-
cachedData?: ScriptOptions["cachedData"];
120+
/**
121+
* Provides an optional data with V8's code cache data for the supplied source.
122+
*/
123+
cachedData?: ScriptOptions["cachedData"] | undefined;
118124
importModuleDynamically?: ScriptOptions["importModuleDynamically"];
119125
}
120126
interface CompileFunctionOptions extends BaseOptions {
121127
/**
122128
* Provides an optional data with V8's code cache data for the supplied source.
123129
*/
124-
cachedData?: Buffer | undefined;
130+
cachedData?: ScriptOptions["cachedData"] | undefined;
125131
/**
126132
* Specifies whether to produce new cache data.
127133
* @default false
@@ -848,6 +854,9 @@ declare module "vm" {
848854
* @default 'vm:module(i)' where i is a context-specific ascending index.
849855
*/
850856
identifier?: string | undefined;
857+
/**
858+
* Provides an optional data with V8's code cache data for the supplied source.
859+
*/
851860
cachedData?: ScriptOptions["cachedData"] | undefined;
852861
context?: Context | undefined;
853862
lineOffset?: BaseOptions["lineOffset"] | undefined;

0 commit comments

Comments
 (0)