MCPcopy
hub / github.com/bytenode/bytenode / compileCode

Function compileCode

lib/index.js:134–150  ·  view source on GitHub ↗
(javascriptCode, compress)

Source from the content-addressed store, hash-verified

132 * @returns {Buffer} The generated bytecode.
133 */
134const compileCode = function (javascriptCode, compress) {
135 if (typeof javascriptCode !== 'string') {
136 throw new Error(`javascriptCode must be string. ${typeof javascriptCode} was given.`);
137 }
138
139 const script = new vm.Script(javascriptCode, {
140 produceCachedData: true
141 });
142
143 let bytecodeBuffer = (script.createCachedData && script.createCachedData.call)
144 ? script.createCachedData()
145 : script.cachedData;
146
147 if (compress) bytecodeBuffer = brotliCompressSync(bytecodeBuffer);
148
149 return bytecodeBuffer;
150};
151
152/**
153 * This function runs the compileCode() function (above)

Callers 3

generateScriptFunction · 0.85
fixBytecodeFunction · 0.85
compileFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…