MCPcopy Create free account
hub / github.com/braziljs/eloquente-javascript / evalModule

Method evalModule

src/client/sandbox.mjs:95–107  ·  view source on GitHub ↗
(name, code)

Source from the content-addressed store, hash-verified

93 }
94
95 evalModule(name, code) {
96 if (/\.json$/.test(name))
97 return this.loaded.store(name, {exports: JSON.parse(code)})
98
99 let work = findDeps(code).map(dep => this.loaded.compute(resolveRelative(name, dep)))
100 return Promise.all(work).then(() => {
101 let f = new this.win.Function("require, exports, module, __dirname, __filename",
102 code + "\n//# sourceURL=code" + randomID())
103 let module = this.loaded.store(name, {exports: {}})
104 f(dep => this.require(resolveRelative(name, dep)), module.exports, module, name, name)
105 return module
106 })
107 }
108
109 require(name) {
110 let found = resolved.get(name)

Callers 1

constructorMethod · 0.95

Calls 9

requireMethod · 0.95
findDepsFunction · 0.85
resolveRelativeFunction · 0.85
randomIDFunction · 0.85
fFunction · 0.85
storeMethod · 0.45
parseMethod · 0.45
mapMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected