mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 00:27:55 +00:00
Docs: Update benchmark for test 4
This commit is contained in:
24
results.json
24
results.json
@@ -23,7 +23,8 @@
|
|||||||
"6_csv_processor": 4.774563675000041,
|
"6_csv_processor": 4.774563675000041,
|
||||||
"7_scheduler": 10.645383548000012,
|
"7_scheduler": 10.645383548000012,
|
||||||
"8_json_validator": 3.43886771999998,
|
"8_json_validator": 3.43886771999998,
|
||||||
"9_stream_visualizer": 4.354729013999982
|
"9_stream_visualizer": 4.354729013999982,
|
||||||
|
"4_transpiler": 8.389267120000005
|
||||||
},
|
},
|
||||||
"openai/gpt-5.1-codex": {
|
"openai/gpt-5.1-codex": {
|
||||||
"10_scrypt_hash": 7.498817803999991,
|
"10_scrypt_hash": 7.498817803999991,
|
||||||
@@ -36,7 +37,8 @@
|
|||||||
"6_csv_processor": 37.769467569000085,
|
"6_csv_processor": 37.769467569000085,
|
||||||
"7_scheduler": 79.01968128499995,
|
"7_scheduler": 79.01968128499995,
|
||||||
"8_json_validator": 8.087602373000001,
|
"8_json_validator": 8.087602373000001,
|
||||||
"9_stream_visualizer": 12.885421481000026
|
"9_stream_visualizer": 12.885421481000026,
|
||||||
|
"4_transpiler": 51.812796853999984
|
||||||
},
|
},
|
||||||
"moonshotai/kimi-k2-thinking": {
|
"moonshotai/kimi-k2-thinking": {
|
||||||
"10_scrypt_hash": 53.01161044100009,
|
"10_scrypt_hash": 53.01161044100009,
|
||||||
@@ -49,7 +51,8 @@
|
|||||||
"6_csv_processor": 100.07209453999997,
|
"6_csv_processor": 100.07209453999997,
|
||||||
"7_scheduler": 204.68869797400012,
|
"7_scheduler": 204.68869797400012,
|
||||||
"8_json_validator": 282.8534934129999,
|
"8_json_validator": 282.8534934129999,
|
||||||
"9_stream_visualizer": 445.8482685430001
|
"9_stream_visualizer": 445.8482685430001,
|
||||||
|
"4_transpiler": 25.871377203000012
|
||||||
},
|
},
|
||||||
"google/gemini-2.5-pro": {
|
"google/gemini-2.5-pro": {
|
||||||
"10_scrypt_hash": 33.595784767000005,
|
"10_scrypt_hash": 33.595784767000005,
|
||||||
@@ -62,7 +65,8 @@
|
|||||||
"6_csv_processor": 28.51295679199975,
|
"6_csv_processor": 28.51295679199975,
|
||||||
"7_scheduler": 98.78428086399985,
|
"7_scheduler": 98.78428086399985,
|
||||||
"8_json_validator": 17.644947614999953,
|
"8_json_validator": 17.644947614999953,
|
||||||
"9_stream_visualizer": 42.817067843999716
|
"9_stream_visualizer": 42.817067843999716,
|
||||||
|
"4_transpiler": 79.54909138500004
|
||||||
},
|
},
|
||||||
"openrouter/sherlock-think-alpha": {
|
"openrouter/sherlock-think-alpha": {
|
||||||
"10_scrypt_hash": 14.262482631000225,
|
"10_scrypt_hash": 14.262482631000225,
|
||||||
@@ -361,7 +365,8 @@
|
|||||||
"6_csv_processor": 74.62322437199997,
|
"6_csv_processor": 74.62322437199997,
|
||||||
"7_scheduler": 79.87219575399999,
|
"7_scheduler": 79.87219575399999,
|
||||||
"8_json_validator": 28.535885181999998,
|
"8_json_validator": 28.535885181999998,
|
||||||
"9_stream_visualizer": 21.60573508199997
|
"9_stream_visualizer": 21.60573508199997,
|
||||||
|
"4_transpiler": 51.93870672
|
||||||
},
|
},
|
||||||
"x-ai/grok-4.1-fast": {
|
"x-ai/grok-4.1-fast": {
|
||||||
"10_scrypt_hash": 7.757944809,
|
"10_scrypt_hash": 7.757944809,
|
||||||
@@ -374,7 +379,8 @@
|
|||||||
"6_csv_processor": 56.944877974,
|
"6_csv_processor": 56.944877974,
|
||||||
"7_scheduler": 48.61515529499997,
|
"7_scheduler": 48.61515529499997,
|
||||||
"8_json_validator": 36.715725561,
|
"8_json_validator": 36.715725561,
|
||||||
"9_stream_visualizer": 20.464613763000003
|
"9_stream_visualizer": 20.464613763000003,
|
||||||
|
"4_transpiler": 90.58870585400001
|
||||||
},
|
},
|
||||||
"anthropic/claude-opus-4.5 TEMP:0.7": {
|
"anthropic/claude-opus-4.5 TEMP:0.7": {
|
||||||
"10_scrypt_hash": 3.390702887,
|
"10_scrypt_hash": 3.390702887,
|
||||||
@@ -387,7 +393,8 @@
|
|||||||
"6_csv_processor": 5.3806070250000015,
|
"6_csv_processor": 5.3806070250000015,
|
||||||
"7_scheduler": 13.963300305999997,
|
"7_scheduler": 13.963300305999997,
|
||||||
"8_json_validator": 3.6207129579999964,
|
"8_json_validator": 3.6207129579999964,
|
||||||
"9_stream_visualizer": 4.672214089000001
|
"9_stream_visualizer": 4.672214089000001,
|
||||||
|
"4_transpiler": 12.686495516999999
|
||||||
},
|
},
|
||||||
"openrouter/bert-nebulon-alpha": {
|
"openrouter/bert-nebulon-alpha": {
|
||||||
"10_scrypt_hash": 8.55691055,
|
"10_scrypt_hash": 8.55691055,
|
||||||
@@ -400,6 +407,7 @@
|
|||||||
"6_csv_processor": 21.607565694999998,
|
"6_csv_processor": 21.607565694999998,
|
||||||
"7_scheduler": 22.426437961999998,
|
"7_scheduler": 22.426437961999998,
|
||||||
"8_json_validator": 12.943359998,
|
"8_json_validator": 12.943359998,
|
||||||
"9_stream_visualizer": 12.601481400000004
|
"9_stream_visualizer": 12.601481400000004,
|
||||||
|
"4_transpiler": 18.506576999999997
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
async function bundleApp(entryFile, files) {
|
||||||
|
const Babel = await import('https://esm.sh/@babel/standalone');
|
||||||
|
const modules = {};
|
||||||
|
const visited = new Set();
|
||||||
|
|
||||||
|
const resolve = (from, to) => {
|
||||||
|
if (!to.startsWith('./') && !to.startsWith('../')) return to;
|
||||||
|
const fromParts = from.split('/').slice(0, -1);
|
||||||
|
const toParts = to.split('/');
|
||||||
|
for (const p of toParts) {
|
||||||
|
if (p === '..') fromParts.pop();
|
||||||
|
else if (p !== '.') fromParts.push(p);
|
||||||
|
}
|
||||||
|
return fromParts.join('/') || toParts[toParts.length - 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
const extractDeps = code => {
|
||||||
|
const deps = [];
|
||||||
|
const re = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
||||||
|
let m;
|
||||||
|
while ((m = re.exec(code))) deps.push(m[1]);
|
||||||
|
return deps;
|
||||||
|
};
|
||||||
|
|
||||||
|
const process = file => {
|
||||||
|
if (visited.has(file)) return;
|
||||||
|
visited.add(file);
|
||||||
|
if (!(file in files)) throw new Error(`Missing file: ${file}`);
|
||||||
|
const transformed = Babel.transform(files[file], {
|
||||||
|
presets: ['env'],
|
||||||
|
filename: file
|
||||||
|
}).code;
|
||||||
|
const deps = extractDeps(transformed);
|
||||||
|
const resolved = {};
|
||||||
|
for (const d of deps) {
|
||||||
|
const r = resolve(file, d);
|
||||||
|
resolved[d] = r;
|
||||||
|
process(r);
|
||||||
|
}
|
||||||
|
modules[file] = { code: transformed, deps: resolved };
|
||||||
|
};
|
||||||
|
|
||||||
|
process(entryFile);
|
||||||
|
|
||||||
|
const modulesObj = JSON.stringify(
|
||||||
|
Object.fromEntries(
|
||||||
|
Object.entries(modules).map(([k, v]) => [
|
||||||
|
k,
|
||||||
|
{ code: v.code, deps: v.deps }
|
||||||
|
])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return `(function(){
|
||||||
|
var __modules__=${modulesObj};
|
||||||
|
var __cache__={};
|
||||||
|
var __resolve__=function(f,t){
|
||||||
|
var d=__modules__[f].deps;
|
||||||
|
return d[t]||t;
|
||||||
|
};
|
||||||
|
var __require__=function(from,id){
|
||||||
|
var resolved=__resolve__(from,id);
|
||||||
|
if(__cache__[resolved])return __cache__[resolved].exports;
|
||||||
|
var mod=__modules__[resolved];
|
||||||
|
if(!mod)throw new Error("Cannot find module: "+resolved);
|
||||||
|
var module={exports:{}};
|
||||||
|
__cache__[resolved]=module;
|
||||||
|
var fn=new Function("require","module","exports",mod.code);
|
||||||
|
fn(function(id){return __require__(resolved,id);},module,module.exports);
|
||||||
|
return module.exports;
|
||||||
|
};
|
||||||
|
return __require__("","${entryFile}");
|
||||||
|
})()`;
|
||||||
|
}
|
||||||
|
export default bundleApp;
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
async function bundleApp(entryFile, files) {
|
||||||
|
const { transform } = await import('https://unpkg.com/@babel/standalone/babel.min.js');
|
||||||
|
|
||||||
|
const modules = {};
|
||||||
|
const visited = new Set();
|
||||||
|
|
||||||
|
const normalizePath = (path) => {
|
||||||
|
return path.replace(/^\.\//, '').replace(/\.js$/, '') + '.js';
|
||||||
|
};
|
||||||
|
|
||||||
|
const extractRequires = (code) => {
|
||||||
|
const requires = [];
|
||||||
|
const regex = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
||||||
|
let match;
|
||||||
|
while ((match = regex.exec(code)) !== null) {
|
||||||
|
requires.push(match[1]);
|
||||||
|
}
|
||||||
|
return requires;
|
||||||
|
};
|
||||||
|
|
||||||
|
const traverse = (fileName) => {
|
||||||
|
const normalizedName = normalizePath(fileName);
|
||||||
|
|
||||||
|
if (visited.has(normalizedName)) return;
|
||||||
|
if (!files[normalizedName]) {
|
||||||
|
throw new Error(`Missing file: ${normalizedName}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
visited.add(normalizedName);
|
||||||
|
|
||||||
|
const transformed = transform(files[normalizedName], {
|
||||||
|
presets: ['env']
|
||||||
|
}).code;
|
||||||
|
|
||||||
|
modules[normalizedName] = transformed;
|
||||||
|
|
||||||
|
const deps = extractRequires(transformed);
|
||||||
|
deps.forEach(dep => traverse(dep));
|
||||||
|
};
|
||||||
|
|
||||||
|
traverse(entryFile);
|
||||||
|
|
||||||
|
const moduleEntries = Object.entries(modules).map(([name, code]) =>
|
||||||
|
`${JSON.stringify(name)}: function(require, module, exports) {\n${code}\n}`
|
||||||
|
).join(',\n');
|
||||||
|
|
||||||
|
return `(function() {
|
||||||
|
const modules = {
|
||||||
|
${moduleEntries}
|
||||||
|
};
|
||||||
|
|
||||||
|
const cache = {};
|
||||||
|
|
||||||
|
function require(name) {
|
||||||
|
const normalized = name.replace(/^\.\//, '').replace(/\.js$/, '') + '.js';
|
||||||
|
|
||||||
|
if (cache[normalized]) {
|
||||||
|
return cache[normalized].exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!modules[normalized]) {
|
||||||
|
throw new Error('Module not found: ' + normalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
const module = { exports: {} };
|
||||||
|
cache[normalized] = module;
|
||||||
|
|
||||||
|
modules[normalized](require, module, module.exports);
|
||||||
|
|
||||||
|
return module.exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
return require(${JSON.stringify(normalizePath(entryFile))});
|
||||||
|
})();`;
|
||||||
|
}
|
||||||
|
export default bundleApp;
|
||||||
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;
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
const bundleApp = async (entry, files) => {
|
||||||
|
const { transform } = await import('https://esm.sh/@babel/standalone');
|
||||||
|
let id = 0, queue = [{ name: entry, id: id++ }], modules = [];
|
||||||
|
|
||||||
|
for (const asset of queue) {
|
||||||
|
if (files[asset.name] == null) throw new Error(`Missing file: ${asset.name}`);
|
||||||
|
|
||||||
|
const { code } = transform(files[asset.name], { presets: ['env'] });
|
||||||
|
const map = {};
|
||||||
|
|
||||||
|
code.replace(/require\s*\(\s*['"](.+?)['"]\s*\)/g, (_, path) => {
|
||||||
|
const base = asset.name.split('/'), rel = path.split('/');
|
||||||
|
base.pop();
|
||||||
|
rel.forEach(p => p === '..' ? base.pop() : p !== '.' && base.push(p));
|
||||||
|
const abs = base.join('/');
|
||||||
|
|
||||||
|
let child = queue.find(x => x.name === abs);
|
||||||
|
if (!child) queue.push(child = { name: abs, id: id++ });
|
||||||
|
map[path] = child.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
modules.push(`${asset.id}:[function(require,module,exports){${code}},${JSON.stringify(map)}]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return `;(function(m){
|
||||||
|
var c={};
|
||||||
|
function r(i){
|
||||||
|
if(c[i])return c[i].exports;
|
||||||
|
var mod=c[i]={exports:{}}, fn=m[i][0], map=m[i][1];
|
||||||
|
fn(p=>r(map[p]||p), mod, mod.exports);
|
||||||
|
return mod.exports;
|
||||||
|
}
|
||||||
|
return r(0);
|
||||||
|
})({${modules.join(',')}})`;
|
||||||
|
};
|
||||||
|
export default bundleApp;
|
||||||
41
tests/4_transpiler/outputs/moonshotai_kimi-k2-thinking.js
Normal file
41
tests/4_transpiler/outputs/moonshotai_kimi-k2-thinking.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
async function bundleApp(entryFile, files) {
|
||||||
|
const Babel = (await import("https://unpkg.com/@babel/standalone/babel.min.js")).default;
|
||||||
|
|
||||||
|
const graph = new Map;
|
||||||
|
const processing = new Set;
|
||||||
|
|
||||||
|
function resolve(from, to) {
|
||||||
|
if (!to.startsWith(".")) return to;
|
||||||
|
const parts = from.split("/");
|
||||||
|
parts.pop();
|
||||||
|
for (const p of to.split("/")) p === ".." ? parts.pop() : p && p !== "." && parts.push(p);
|
||||||
|
return parts.join("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
function extract(code) {
|
||||||
|
const deps = [];
|
||||||
|
code.replace(/require\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g, (_, d) => deps.push(d));
|
||||||
|
return deps;
|
||||||
|
}
|
||||||
|
|
||||||
|
function walk(file) {
|
||||||
|
if (graph.has(file)) return;
|
||||||
|
if (processing.has(file)) throw new Error(`Circular: ${file}`);
|
||||||
|
if (!(file in files)) throw new Error(`Missing: ${file}`);
|
||||||
|
processing.add(file);
|
||||||
|
const code = Babel.transform(files[file], { presets: [["env", { modules: "cjs" }]] }).code;
|
||||||
|
const deps = extract(code).map(d => resolve(file, d));
|
||||||
|
graph.set(file, { code, deps });
|
||||||
|
deps.forEach(walk);
|
||||||
|
processing.delete(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
walk(entryFile);
|
||||||
|
|
||||||
|
return `(function(){const modules={},cache={};function require(path){if(cache[path])return cache[path].exports;const module={exports:{}};cache[path]=module;const fn=modules[path];if(!fn) {
|
||||||
|
throw new Error('Missing: ' + path);
|
||||||
|
}fn(require,module,module.exports);return module.exports;}
|
||||||
|
${Array.from(graph, ([p, {code}]) => `modules['${p}']=(function(require,module,exports){\n${code}\n});`).join("\n")}
|
||||||
|
return require('${entryFile}');})()`;
|
||||||
|
}
|
||||||
|
export default bundleApp;
|
||||||
32
tests/4_transpiler/outputs/openai_gpt-5.1-codex.js
Normal file
32
tests/4_transpiler/outputs/openai_gpt-5.1-codex.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
const bundleApp=async(entry,files)=>{
|
||||||
|
const {transform}=(await import('https://esm.sh/@babel/standalone@7.23.9')).default
|
||||||
|
const mods=new Map
|
||||||
|
const norm=(from,to)=>{
|
||||||
|
if(!to.startsWith('.'))return to
|
||||||
|
const parts=from.split('/')
|
||||||
|
parts.pop()
|
||||||
|
to.split('/').forEach(part=>{
|
||||||
|
if(!part||part=='.')return
|
||||||
|
part=='..'?parts.pop():parts.push(part)
|
||||||
|
})
|
||||||
|
return parts.join('/')
|
||||||
|
}
|
||||||
|
const walk=file=>{
|
||||||
|
if(mods.has(file))return
|
||||||
|
const src=files[file]
|
||||||
|
if(src==null)throw new Error(`Missing file: ${file}`)
|
||||||
|
const {code}=transform(src,{presets:[['env',{modules:'commonjs'}]],sourceType:'module'})
|
||||||
|
const deps={}
|
||||||
|
for(const m of code.matchAll(/require\((['"])(.+?)\1\)/g)){
|
||||||
|
const spec=m[2]
|
||||||
|
deps[spec]=norm(file,spec)
|
||||||
|
}
|
||||||
|
mods.set(file,{code,deps})
|
||||||
|
Object.values(deps).forEach(walk)
|
||||||
|
}
|
||||||
|
walk(entry)
|
||||||
|
const esc=s=>s.replace(/\\/g,'\\\\').replace(/`/g,'\\`').replace(/\$\{/g,'\\${')
|
||||||
|
const body=[...mods].map(([id,{code,deps}])=>`"${id}":[function(require,module,exports){${esc(code)}},${JSON.stringify(deps)}]`).join(',')
|
||||||
|
return `(()=>{var m={${body}},c={},p=(f,s)=>{if(!s.startsWith('.'))return s;var a=f.split('/');a.pop();s.split('/').forEach(b=>{if(!b||b=='.')return;b=='..'?a.pop():a.push(b)});return a.join('/')},r=f=>{if(!m[f])throw new Error("Missing module "+f);if(c[f])return c[f].exports;var d=m[f],mod={exports:{}};c[f]=mod;d[0](g=>{var t=d[1][g];return r(t?t:p(f,g))},mod,mod.exports);return mod.exports};return r("${entry}")})()`
|
||||||
|
}
|
||||||
|
export default bundleApp;
|
||||||
62
tests/4_transpiler/outputs/openrouter_bert-nebulon-alpha.js
Normal file
62
tests/4_transpiler/outputs/openrouter_bert-nebulon-alpha.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
const bundleApp = async (entryFile, files) => {
|
||||||
|
const babel = await import('https://unpkg.com/@babel/standalone/babel.min.js');
|
||||||
|
const graph = {};
|
||||||
|
const visited = new Set();
|
||||||
|
|
||||||
|
const traverse = async (filename) => {
|
||||||
|
if (visited.has(filename)) return;
|
||||||
|
visited.add(filename);
|
||||||
|
|
||||||
|
if (!files[filename]) throw new Error(`File not found: ${filename}`);
|
||||||
|
|
||||||
|
const transformed = babel.transform(files[filename], {
|
||||||
|
presets: ['env'],
|
||||||
|
filename
|
||||||
|
}).code;
|
||||||
|
|
||||||
|
const deps = [];
|
||||||
|
const requireRegex = /require\(['"](.*?)['"]\)/g;
|
||||||
|
let match;
|
||||||
|
|
||||||
|
while ((match = requireRegex.exec(transformed)) !== null) {
|
||||||
|
deps.push(match[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
graph[filename] = { code: transformed, deps };
|
||||||
|
await Promise.all(deps.map(dep => traverse(resolvePath(filename, dep))));
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolvePath = (from, to) => {
|
||||||
|
if (to.startsWith('.')) {
|
||||||
|
const fromDir = from.split('/').slice(0, -1).join('/');
|
||||||
|
return `${fromDir}/${to}`.replace(/\/\.\//g, '/').replace(/[^/]+\/\.\.\//g, '');
|
||||||
|
}
|
||||||
|
return to;
|
||||||
|
};
|
||||||
|
|
||||||
|
await traverse(entryFile);
|
||||||
|
|
||||||
|
const modules = Object.entries(graph).map(([id, { code }]) => {
|
||||||
|
return `'${id}': {
|
||||||
|
exports: {},
|
||||||
|
fn: function(require, module, exports) {
|
||||||
|
${code}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
}).join(',');
|
||||||
|
|
||||||
|
return `(function() {
|
||||||
|
const modules = {${modules}};
|
||||||
|
const cache = {};
|
||||||
|
|
||||||
|
function require(moduleId) {
|
||||||
|
if (cache[moduleId]) return cache[moduleId].exports;
|
||||||
|
const module = cache[moduleId] = modules[moduleId];
|
||||||
|
module.fn(require, module, module.exports);
|
||||||
|
return module.exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
return require('${entryFile}');
|
||||||
|
})();`;
|
||||||
|
};
|
||||||
|
export default bundleApp;
|
||||||
92
tests/4_transpiler/outputs/x-ai_grok-4.1-fast.js
Normal file
92
tests/4_transpiler/outputs/x-ai_grok-4.1-fast.js
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
async function bundleApp(entryFile, files) {
|
||||||
|
const babel = await import('https://esm.sh/@babel/standalone@7.24.7');
|
||||||
|
const { transform } = babel;
|
||||||
|
const modules = new Map();
|
||||||
|
const visited = new Set();
|
||||||
|
const reqRe = /require\s*\(\s*["']([^"']+)["']\s*\)/g;
|
||||||
|
|
||||||
|
function dirname(file) {
|
||||||
|
const i = file.lastIndexOf('/');
|
||||||
|
return i === -1 ? '' : file.slice(0, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolvePath(from, imp) {
|
||||||
|
const dirSegments = dirname(from).split('/');
|
||||||
|
const impSegments = imp.split('/').filter(s => s !== '' && s !== '.');
|
||||||
|
const resSegments = [...dirSegments];
|
||||||
|
for (const seg of impSegments) {
|
||||||
|
if (seg === '..') {
|
||||||
|
resSegments.pop();
|
||||||
|
} else {
|
||||||
|
resSegments.push(seg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resSegments.join('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeRegExp(str) {
|
||||||
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeStr(str) {
|
||||||
|
return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function process(file) {
|
||||||
|
if (visited.has(file)) return;
|
||||||
|
visited.add(file);
|
||||||
|
const code = files[file];
|
||||||
|
if (code === undefined) throw new Error(`Missing file: ${file}`);
|
||||||
|
const res = transform(code, {
|
||||||
|
presets: [['env', { modules: 'commonjs' }]],
|
||||||
|
filename: file
|
||||||
|
});
|
||||||
|
if (res.error) throw new Error(`Babel error in ${file}: ${res.error}`);
|
||||||
|
let tcode = res.code;
|
||||||
|
const deps = new Set();
|
||||||
|
let match;
|
||||||
|
while ((match = reqRe.exec(tcode)) !== null) {
|
||||||
|
deps.add(match[1]);
|
||||||
|
}
|
||||||
|
const rdeps = new Set([...deps].map(d => resolvePath(file, d)));
|
||||||
|
for (const orig of deps) {
|
||||||
|
const resolved = resolvePath(file, orig);
|
||||||
|
const re = new RegExp(`require\\s*\\(\\s*["']${escapeRegExp(orig)}["']\\s*\\)`, 'g');
|
||||||
|
tcode = tcode.replace(re, `require("${resolved}")`);
|
||||||
|
}
|
||||||
|
modules.set(file, tcode);
|
||||||
|
await Promise.all(Array.from(rdeps).map(process));
|
||||||
|
}
|
||||||
|
|
||||||
|
const entryId = resolvePath('index.js', entryFile);
|
||||||
|
await process(entryId);
|
||||||
|
|
||||||
|
const sortedModules = Array.from(modules.entries()).sort(([a], [b]) => a.localeCompare(b));
|
||||||
|
const bundleParts = [
|
||||||
|
'(function(){',
|
||||||
|
'var modules={'
|
||||||
|
];
|
||||||
|
for (const [id, code] of sortedModules) {
|
||||||
|
bundleParts.push(
|
||||||
|
`'${escapeStr(id)}':function(r,m,e){`,
|
||||||
|
code,
|
||||||
|
'},'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
bundleParts.pop();
|
||||||
|
bundleParts.push(
|
||||||
|
'};',
|
||||||
|
'var cache={};',
|
||||||
|
'function req(id){',
|
||||||
|
'if(cache[id])return cache[id].exports;',
|
||||||
|
'var m={exports:{}};',
|
||||||
|
'cache[id]=m;',
|
||||||
|
'modules[id].call(m.exports,req,m,m.exports);',
|
||||||
|
'return m.exports;',
|
||||||
|
'}',
|
||||||
|
`return req('${escapeStr(entryId)}');`,
|
||||||
|
'})()'
|
||||||
|
);
|
||||||
|
return bundleParts.join('');
|
||||||
|
}
|
||||||
|
export default bundleApp;
|
||||||
Reference in New Issue
Block a user