Skip to content

Commit 67c3fd4

Browse files
committed
Allow to override strict mode setting for modules
1 parent 6fcb707 commit 67c3fd4

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/resolver-compat.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function makeExternalMatcher(obj) {
4646

4747
class LegacyResolver extends DefaultResolver {
4848

49-
constructor(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler, externals, allowTransitive) {
50-
super(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler);
49+
constructor(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler, strict, externals, allowTransitive) {
50+
super(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler, strict);
5151
this.externals = externals;
5252
this.currMod = undefined;
5353
this.trustedMods = new WeakMap();
@@ -282,7 +282,8 @@ function resolverFromOptions(vm, options, override, compiler) {
282282
root: rootPaths,
283283
resolve: customResolver,
284284
customRequire: hostRequire = defaultRequire,
285-
context = 'host'
285+
context = 'host',
286+
strict = true,
286287
} = options;
287288

288289
const builtins = genBuiltinsFromOptions(vm, builtinOpt, mockOpt, override);
@@ -325,7 +326,7 @@ function resolverFromOptions(vm, options, override, compiler) {
325326
}
326327

327328
if (typeof externalOpt !== 'object') {
328-
return new DefaultResolver(builtins, checkPath, [], () => context, newCustomResolver, hostRequire, compiler);
329+
return new DefaultResolver(builtins, checkPath, [], () => context, newCustomResolver, hostRequire, compiler, strict);
329330
}
330331

331332
let transitive = false;
@@ -336,7 +337,7 @@ function resolverFromOptions(vm, options, override, compiler) {
336337
transitive = context === 'sandbox' && externalOpt.transitive;
337338
}
338339
externals = external.map(makeExternalMatcher);
339-
return new LegacyResolver(builtins, checkPath, [], () => context, newCustomResolver, hostRequire, compiler, externals, transitive);
340+
return new LegacyResolver(builtins, checkPath, [], () => context, newCustomResolver, hostRequire, compiler, strict, externals, transitive);
340341
}
341342

342343
exports.resolverFromOptions = resolverFromOptions;

lib/resolver.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ class Resolver {
140140

141141
class DefaultResolver extends Resolver {
142142

143-
constructor(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler) {
143+
constructor(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler, strict) {
144144
super(builtinModules, globalPaths, hostRequire);
145145
this.checkPath = checkPath;
146146
this.pathContext = pathContext;
147147
this.customResolver = customResolver;
148148
this.compiler = compiler;
149+
this.strict = strict;
149150
this.packageCache = {__proto__: null};
150151
this.scriptCache = {__proto__: null};
151152
}
@@ -200,7 +201,7 @@ class DefaultResolver extends Resolver {
200201
this.checkAccess(mod, filename);
201202
if (this.pathContext(filename, 'js') === 'sandbox') {
202203
const script = this.readScript(filename);
203-
vm.run(script, {filename, strict: true, module: mod, wrapper: 'none', dirname: mod.path});
204+
vm.run(script, {filename, strict: this.strict, module: mod, wrapper: 'none', dirname: mod.path});
204205
} else {
205206
const m = this.hostRequire(filename);
206207
mod.exports = vm.readonly(m);

0 commit comments

Comments
 (0)