blob: 9d3e288c9c09910dfedc37b526610ee9c493ac04 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2const lazy = (mod, fn, id) => mod === undefined ? fn(id) : mod;
3
4module.exports = fn => {
5 return id => {
6 let mod;
7
8 const handler = {
9 get: (target, property) => {
10 mod = lazy(mod, fn, id);
11 return Reflect.get(mod, property);
12 },
13 apply: (target, thisArg, argumentsList) => {
14 mod = lazy(mod, fn, id);
15 return Reflect.apply(mod, thisArg, argumentsList);
16 },
17 construct: (target, argumentsList) => {
18 mod = lazy(mod, fn, id);
19 return Reflect.construct(mod, argumentsList);
20 }
21 };
22
23 // eslint-disable-next-line prefer-arrow-callback
24 return new Proxy(function () {}, handler);
25 };
26};