Merge JS snippets
Merge several JS snippets into one file: separate them with `// --- file: a.js` or `<<<`, and they are joined in order. Identical top-level function / class declarations are kept only once, with the dropped duplicates (and their source segment) listed in a header comment. Wrap as-is, as an IIFE, or as an ES module (exporting the merged function names), and see how many segments were merged and how many items deduplicated. Boundary: dedupe compares declaration text exactly and does not do semantic equivalence.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Result
The result can be copied directly.
Paste several JS snippets to merge them
Characters: 0 · Segments merged: 0 · Deduplicated: 0 · Declarations: 0
What this tool does
- Combine split scripts into one includable file.
- Merge snippets from several sources and drop duplicate functions.
- Wrap loose helpers as an IIFE or ES module.
Example
Input
// --- file: a.js
function a() { return 1; }
function dup() { return 2; }
<<< b.js
function b() { return 3; }
function dup() { return 2; }Output
// 合并 2 段,去重 1 项
// 来源:a.js, b.js
// 已丢弃重复声明:function dup(来自 b.js)
function a() { return 1; }
function dup() { return 2; }
function b() { return 3; }Dedupe only covers top-level `function` / `class` declarations; variable assignments, IIFEs and arrow-function constants are left alone to avoid accidental removal.
Frequently asked questions
How do I write the split markers?
Either `// --- file: a.js` (the `--` and `#` comment forms also work) or a bare line `<<< b.js`. Without markers the whole input is one segment with an auto-generated name.
How is dedupe decided?
By keyword + name + full declaration text (whitespace normalised). So `function dup() { return 2; }` twice keeps the first; same-name functions with different bodies are both kept, never overwritten.
Does the IIFE change behaviour?
Yes, it changes scope: merged declarations no longer leak to the global object, which suits a self-contained script. If you need to expose functions, use the ES module wrap, which emits `export { … }`.
Why do declaration and dedupe counts differ?
The declaration count includes every top-level function / class found in all segments; the dedupe count is how many were dropped as duplicates. Two same-name functions in two segments give declarations 2 and dedupe 1.
Keywords:js mergeIIFE