{"id":48551329,"url":"https://github.com/fallow-rs/oxc-coverage-instrument","last_synced_at":"2026-04-13T17:01:17.990Z","repository":{"id":349724208,"uuid":"1203619488","full_name":"fallow-rs/oxc-coverage-instrument","owner":"fallow-rs","description":"Istanbul-compatible JavaScript/TypeScript coverage instrumentation using the Oxc AST","archived":false,"fork":false,"pushed_at":"2026-04-10T12:05:09.000Z","size":405,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-11T15:02:49.408Z","etag":null,"topics":["coverage","istanbul","javascript","oxc","rust","testing","typescript"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fallow-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-07T07:53:35.000Z","updated_at":"2026-04-10T12:05:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"f37ee843-8798-4df3-8af3-b574c5fa5be2","html_url":"https://github.com/fallow-rs/oxc-coverage-instrument","commit_stats":null,"previous_names":["fallow-rs/oxc-coverage-instrument"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/fallow-rs/oxc-coverage-instrument","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallow-rs%2Foxc-coverage-instrument","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallow-rs%2Foxc-coverage-instrument/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallow-rs%2Foxc-coverage-instrument/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallow-rs%2Foxc-coverage-instrument/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fallow-rs","download_url":"https://codeload.github.com/fallow-rs/oxc-coverage-instrument/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallow-rs%2Foxc-coverage-instrument/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31761996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T15:25:13.801Z","status":"ssl_error","status_checked_at":"2026-04-13T15:25:09.162Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coverage","istanbul","javascript","oxc","rust","testing","typescript"],"created_at":"2026-04-08T09:00:18.413Z","updated_at":"2026-04-13T17:01:17.940Z","avatar_url":"https://github.com/fallow-rs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oxc_coverage_instrument\n\n[![CI](https://github.com/fallow-rs/oxc-coverage-instrument/actions/workflows/ci.yml/badge.svg)](https://github.com/fallow-rs/oxc-coverage-instrument/actions/workflows/ci.yml)\n[![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/fallow-rs/oxc-coverage-instrument/badges/coverage.json)](https://github.com/fallow-rs/oxc-coverage-instrument/actions/workflows/coverage.yml)\n[![Crates.io](https://img.shields.io/crates/v/oxc_coverage_instrument.svg)](https://crates.io/crates/oxc_coverage_instrument)\n[![npm](https://img.shields.io/npm/v/oxc-coverage-instrument.svg)](https://www.npmjs.com/package/oxc-coverage-instrument)\n[![docs.rs](https://docs.rs/oxc_coverage_instrument/badge.svg)](https://docs.rs/oxc_coverage_instrument)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nIstanbul-compatible JavaScript/TypeScript coverage instrumentation, built on the [Oxc](https://oxc.rs) parser. **58x faster** than `istanbul-lib-instrument`.\n\n## Why\n\n[`swc-coverage-instrument`](https://github.com/kwonoj/swc-plugin-coverage-instrument) fills this role for SWC. There is no equivalent for the Oxc ecosystem. Any tool built on `oxc_parser` that needs coverage instrumentation currently has to pull in SWC or Babel.\n\nThis crate fills that gap. AST-level instrumentation via `oxc_traverse` + `oxc_codegen` produces correct Istanbul-compatible output, verified against the canonical `istanbul-lib-instrument` on 25 shared fixtures.\n\n## Install\n\n### Rust\n\n```toml\n[dependencies]\noxc_coverage_instrument = \"0.2\"\n```\n\n### Node.js\n\n```bash\nnpm install oxc-coverage-instrument\n```\n\n### CLI\n\n```bash\ncargo install oxc-coverage-instrument-cli\n```\n\n## Usage\n\n### Rust\n\n```rust\nuse oxc_coverage_instrument::{instrument, InstrumentOptions};\n\nlet source = \"function add(a, b) { return a + b; }\";\nlet result = instrument(source, \"add.js\", \u0026InstrumentOptions::default()).unwrap();\n\n// Istanbul-compatible coverage map\nassert_eq!(result.coverage_map.fn_map[\"0\"].name, \"add\");\n\n// Instrumented source with counters injected\nprintln!(\"{}\", result.code);\n```\n\n### Node.js\n\n```javascript\nimport { instrument } from 'oxc-coverage-instrument';\n\nconst result = instrument(source, 'file.js', {\n  coverageVariable: '__coverage__',  // optional\n  sourceMap: true,                    // optional\n});\n\nresult.code;                          // instrumented source\nconst coverageMap = JSON.parse(result.coverageMap);  // Istanbul format\nresult.sourceMap;                     // source map JSON (if enabled)\n```\n\n### CLI\n\n```bash\n# Print instrumented code to stdout\noxc-coverage-instrument src/app.js\n\n# Write to file\noxc-coverage-instrument src/app.js -o dist/app.js\n\n# Print coverage map only\noxc-coverage-instrument src/app.js --coverage-map\n\n# With source map\noxc-coverage-instrument src/app.js -o dist/app.js --source-map\n```\n\n### Vite plugin example\n\n```javascript\nimport { instrument } from 'oxc-coverage-instrument';\n\nexport function coveragePlugin() {\n  return {\n    name: 'coverage-instrument',\n    transform(code, id) {\n      if (process.env.COVERAGE \u0026\u0026 /\\.[jt]sx?$/.test(id) \u0026\u0026 !id.includes('node_modules')) {\n        const result = instrument(code, id, { sourceMap: true });\n        return { code: result.code, map: result.sourceMap ? JSON.parse(result.sourceMap) : undefined };\n      }\n    },\n  };\n}\n```\n\n### Reading existing coverage data\n\n```rust\nuse oxc_coverage_instrument::parse_coverage_map;\n\n// Parse a coverage-final.json file\nlet json = std::fs::read_to_string(\"coverage-final.json\").unwrap();\nlet map = parse_coverage_map(\u0026json).unwrap();\n\nfor (path, coverage) in \u0026map {\n    println!(\"{}: {} statements, {} functions, {} branches\",\n        path, coverage.s.len(), coverage.f.len(), coverage.b.len());\n}\n```\n\n## What it tracks\n\n| Dimension | What gets a counter |\n|:----------|:-------------------|\n| **Statements** | Every executable statement |\n| **Functions** | Declarations, expressions, arrows, class methods |\n| **Branches** | `if`/`else`, ternary, `switch`, `\u0026\u0026`/`\\|\\|`/`??`, `??=`/`\\|\\|=`/`\u0026\u0026=`, `default-arg` |\n| **Pragmas** | `istanbul ignore next/if/else/file`, `v8 ignore`, `c8 ignore` |\n\n## Istanbul conformance\n\nVerified against `istanbul-lib-instrument` on 25 shared fixtures covering all branch types, function forms, and edge cases. 175 automated conformance checks validate:\n\n- Function counts and names match exactly\n- Branch counts, types, and location counts match exactly\n- Statement counts within tolerance\n- JSON structure matches Istanbul's field set\n- Instrumented output re-parses as valid JS\n\n## Performance\n\n| Tool | Throughput | Relative |\n|:-----|:-----------|:---------|\n| **oxc-coverage-instrument** | **50-67 MiB/s** | **58x faster** |\n| istanbul-lib-instrument | 1.1 MiB/s | baseline |\n\nFrom Node.js (via napi): **~19 MiB/s** (18x faster than Istanbul).\n\n## Architecture\n\n```\nsource code (JS/TS)\n    |\n    v\noxc_parser          -- parse to AST\n    |\n    v\nSemanticBuilder     -- build scope tree\n    |\n    v\nCoverageTransform   -- traverse AST, inject ++cov().s[N] counters\n    |\n    v\noxc_codegen         -- emit instrumented code + source map\n    |\n    v\ninstrumented code + coverage map\n```\n\n## Related projects\n\n| Project | AST | Notes |\n|:--------|:----|:------|\n| [`istanbul-lib-instrument`](https://github.com/istanbuljs/istanbuljs) | Babel | The canonical Istanbul instrumenter |\n| [`swc-coverage-instrument`](https://github.com/kwonoj/swc-plugin-coverage-instrument) | SWC | SWC equivalent (~407K monthly npm downloads) |\n| **this crate** | Oxc | First Oxc-native coverage instrumenter, 58x faster |\n\n## Compatibility\n\n- **Rust**: 1.92+ (2024 edition)\n- **Oxc**: 0.124.x\n- **Istanbul**: `coverage-final.json` v3+ format\n- **Node.js**: 18+ (via napi-rs)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffallow-rs%2Foxc-coverage-instrument","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffallow-rs%2Foxc-coverage-instrument","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffallow-rs%2Foxc-coverage-instrument/lists"}