oxc-coverage-instrument 0.2.16 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +8 -8
  2. package/vitest.js +33 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-coverage-instrument",
3
- "version": "0.2.16",
3
+ "version": "0.3.0",
4
4
  "description": "Istanbul-compatible JavaScript/TypeScript coverage instrumentation using the Oxc AST. 8-48x faster than istanbul-lib-instrument.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -61,12 +61,12 @@
61
61
  "test": "node test.mjs"
62
62
  },
63
63
  "optionalDependencies": {
64
- "@oxc-coverage-instrument/binding-darwin-arm64": "0.2.16",
65
- "@oxc-coverage-instrument/binding-darwin-x64": "0.2.16",
66
- "@oxc-coverage-instrument/binding-linux-x64-gnu": "0.2.16",
67
- "@oxc-coverage-instrument/binding-linux-arm64-gnu": "0.2.16",
68
- "@oxc-coverage-instrument/binding-linux-x64-musl": "0.2.16",
69
- "@oxc-coverage-instrument/binding-win32-x64-msvc": "0.2.16",
70
- "@oxc-coverage-instrument/binding-win32-arm64-msvc": "0.2.16"
64
+ "@oxc-coverage-instrument/binding-darwin-arm64": "0.3.0",
65
+ "@oxc-coverage-instrument/binding-darwin-x64": "0.3.0",
66
+ "@oxc-coverage-instrument/binding-linux-x64-gnu": "0.3.0",
67
+ "@oxc-coverage-instrument/binding-linux-arm64-gnu": "0.3.0",
68
+ "@oxc-coverage-instrument/binding-linux-x64-musl": "0.3.0",
69
+ "@oxc-coverage-instrument/binding-win32-x64-msvc": "0.3.0",
70
+ "@oxc-coverage-instrument/binding-win32-arm64-msvc": "0.3.0"
71
71
  }
72
72
  }
package/vitest.js CHANGED
@@ -40,8 +40,29 @@ function createOxcInstrumenter(options) {
40
40
  const ignoreClassMethods = options.ignoreClassMethods || [];
41
41
  const reportLogic = options.reportLogic || false;
42
42
 
43
- let _lastSourceMap = null;
43
+ // Raw JSON strings from the last instrument call — parsed lazily on first access.
44
+ let _lastCoverageMapJson = null;
45
+ let _lastSourceMapJson = null;
46
+ // Parsed objects — null until actually read via lastFileCoverage()/lastSourceMap().
44
47
  let _lastFileCoverage = null;
48
+ let _lastSourceMap = null;
49
+ // Dirty flags — set to true after each instrumentSync to invalidate cached parses.
50
+ let _coverageDirty = false;
51
+ let _sourceMapDirty = false;
52
+
53
+ function ensureCoverageParsed() {
54
+ if (_coverageDirty && _lastCoverageMapJson !== null) {
55
+ _lastFileCoverage = JSON.parse(_lastCoverageMapJson);
56
+ _coverageDirty = false;
57
+ }
58
+ }
59
+
60
+ function ensureSourceMapParsed() {
61
+ if (_sourceMapDirty && _lastSourceMapJson !== null) {
62
+ _lastSourceMap = JSON.parse(_lastSourceMapJson);
63
+ _sourceMapDirty = false;
64
+ }
65
+ }
45
66
 
46
67
  return {
47
68
  instrumentSync(code, filename, inputSourceMap) {
@@ -53,22 +74,30 @@ function createOxcInstrumenter(options) {
53
74
  ignoreClassMethods,
54
75
  });
55
76
 
56
- _lastFileCoverage = JSON.parse(result.coverageMap);
57
- _lastSourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : null;
77
+ // Store raw JSON — defer parsing until actually needed.
78
+ _lastCoverageMapJson = result.coverageMap;
79
+ _lastSourceMapJson = result.sourceMap || null;
80
+ _coverageDirty = true;
81
+ _sourceMapDirty = true;
58
82
 
59
- return result.code;
83
+ // result.code is a Buffer (zero-copy from Rust); convert to string for
84
+ // istanbul-lib-instrument compatibility (instrumentSync must return string).
85
+ return result.code.toString();
60
86
  },
61
87
 
62
88
  lastSourceMap() {
89
+ ensureSourceMapParsed();
63
90
  return _lastSourceMap;
64
91
  },
65
92
 
66
93
  lastFileCoverage() {
94
+ ensureCoverageParsed();
67
95
  return _lastFileCoverage;
68
96
  },
69
97
 
70
98
  // Property alias used by vite-plugin-istanbul (vs lastFileCoverage() method used by Vitest)
71
99
  get fileCoverage() {
100
+ ensureCoverageParsed();
72
101
  return _lastFileCoverage;
73
102
  },
74
103
  };