Skip to content

Commit fbf92fe

Browse files
committed
Reuse VM context across webpack magic comments
1 parent b9fb99c commit fbf92fe

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/javascript/JavascriptParser.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ class JavascriptParser extends Parser {
435435
/** @type {WeakMap<Expression, Set<string>> | undefined} */
436436
this.destructuringAssignmentProperties = undefined;
437437
this.currentTagData = undefined;
438+
this.magicCommentContext = vm.createContext(undefined, {
439+
name: "Webpack Magic Comment Parser",
440+
codeGeneration: { strings: false, wasm: false }
441+
});
438442
this._initializeEvaluating();
439443
}
440444

@@ -4465,7 +4469,10 @@ class JavascriptParser extends Parser {
44654469
// try compile only if webpack options comment is present
44664470
try {
44674471
for (let [key, val] of Object.entries(
4468-
vm.runInNewContext(`(function(){return {${value}};})()`)
4472+
vm.runInContext(
4473+
`(function(){return {${value}};})()`,
4474+
this.magicCommentContext
4475+
)
44694476
)) {
44704477
if (typeof val === "object" && val !== null) {
44714478
if (val.constructor.name === "RegExp") val = new RegExp(val);

0 commit comments

Comments
 (0)