Skip to content

Commit

Permalink
Reuse VM context across webpack magic comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichon-msft committed Feb 1, 2024
1 parent b9fb99c commit fbf92fe
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/javascript/JavascriptParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fbf92fe

Please sign in to comment.