mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Docs: Update benchmark for test 4
This commit is contained in:
60
tests/4_transpiler/outputs/google_gemini-2.5-pro.js
Normal file
60
tests/4_transpiler/outputs/google_gemini-2.5-pro.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const bundleApp = async (entryFile, files) => {
|
||||
const Babel = (await import('https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js')).default;
|
||||
|
||||
const resolvePath = (base, relative) => {
|
||||
if (!/^\./.test(relative)) return relative;
|
||||
const stack = base.split('/').slice(0, -1);
|
||||
relative.split('/').forEach(part => {
|
||||
if (part === '..') stack.pop();
|
||||
else if (part !== '.') stack.push(part);
|
||||
});
|
||||
return stack.join('/');
|
||||
};
|
||||
|
||||
const modules = [];
|
||||
const moduleMap = new Map();
|
||||
|
||||
const createModule = async (filename) => {
|
||||
if (moduleMap.has(filename)) return moduleMap.get(filename);
|
||||
|
||||
const code = files[filename];
|
||||
if (code === undefined) throw new Error(`File not found: ${filename}`);
|
||||
|
||||
const id = modules.length;
|
||||
moduleMap.set(filename, id);
|
||||
modules.push(null);
|
||||
|
||||
const { code: transformedCode } = Babel.transform(code, { presets: ['env'] });
|
||||
const depRegex = /(?<![.\w$])require\s*\(['"]([^'"]+)['"]\)/g;
|
||||
const dependencies = [...transformedCode.matchAll(depRegex)].map(m => m[1]);
|
||||
|
||||
const mapping = {};
|
||||
await Promise.all(dependencies.map(async depPath => {
|
||||
const absPath = resolvePath(filename, depPath);
|
||||
mapping[depPath] = await createModule(absPath);
|
||||
}));
|
||||
|
||||
modules[id] = { code: transformedCode, mapping };
|
||||
return id;
|
||||
};
|
||||
|
||||
const entryId = await createModule(entryFile);
|
||||
|
||||
const moduleDefs = modules.map(
|
||||
({ code, mapping }) => `[function(require,module,exports){${code}},${JSON.stringify(mapping)}]`
|
||||
).join(',');
|
||||
|
||||
return `(function() {
|
||||
const modules = [${moduleDefs}];
|
||||
const cache = {};
|
||||
const require = id => {
|
||||
if (cache[id]) return cache[id].exports;
|
||||
const [fn, mapping] = modules[id];
|
||||
const module = cache[id] = { exports: {} };
|
||||
fn(path => require(mapping[path]), module, module.exports);
|
||||
return module.exports;
|
||||
};
|
||||
return require(${entryId});
|
||||
})()`;
|
||||
};
|
||||
export default bundleApp;
|
||||
Reference in New Issue
Block a user