Reuse VM context across webpack magic comments

This commit is contained in:
David Michon 2024-01-31 18:27:28 -08:00
parent b9fb99c63c
commit fbf92fe522
1 changed files with 8 additions and 1 deletions

View File

@ -435,6 +435,10 @@ class JavascriptParser extends Parser {
/** @type {WeakMap<Expression, Set<string>> | undefined} */
this.destructuringAssignmentProperties = undefined;
this.currentTagData = undefined;
this.magicCommentContext = vm.createContext(undefined, {
name: "Webpack Magic Comment Parser",
codeGeneration: { strings: false, wasm: false }
});
this._initializeEvaluating();
}
@ -4465,7 +4469,10 @@ class JavascriptParser extends Parser {
// try compile only if webpack options comment is present
try {
for (let [key, val] of Object.entries(
vm.runInNewContext(`(function(){return {${value}};})()`)
vm.runInContext(
`(function(){return {${value}};})()`,
this.magicCommentContext
)
)) {
if (typeof val === "object" && val !== null) {
if (val.constructor.name === "RegExp") val = new RegExp(val);