Skip to content

feat(coverage): support --experimental-strip-types via acorn-typescript#151

Open
sohil-kshirsagar wants to merge 2 commits intomainfrom
sohil/feat/strip-types-coverage
Open

feat(coverage): support --experimental-strip-types via acorn-typescript#151
sohil-kshirsagar wants to merge 2 commits intomainfrom
sohil/feat/strip-types-coverage

Conversation

@sohil-kshirsagar
Copy link
Copy Markdown
Contributor

Add TypeScript coverage support for Node.js --experimental-strip-types (and the stable --experimental-transform-types in Node 23+).

Problem

When a project runs .ts files directly via node --experimental-strip-types server.ts, V8 reports coverage against the .ts files. Our coverage processor uses acorn to parse the source AST, but acorn can't handle TypeScript syntax (type annotations, import type, etc.), causing the file to be silently skipped. This resulted in coverage showing only tuskDriftInit.ts (2/2 lines, 100%) while the actual server code was completely missing.

Fix

Added acorn-typescript as a dependency. When processing a .ts/.tsx/.mts/.cts file, the parser uses acorn.Parser.extend(tsPlugin()) to handle TypeScript syntax. Falls back to plain acorn if the plugin isn't available.

The TypeScript detection is based on file extension — only .ts/.tsx files use the plugin. Regular .js files continue using plain acorn with no overhead.

Testing

Tested against drift-node-demo which uses --experimental-strip-types:

  • Before: 100.0% lines (2/2) across 1 file (only tuskDriftInit.ts)
  • After: 85.5% lines (59/69) across 2 files (server.ts at 85.1% + tuskDriftInit.ts at 100%)

Also verified no regression on CJS/ESM repos (example-express-server, example-express-ts-server).

…n-typescript

V8 runs .ts files directly with --experimental-strip-types, but acorn
can't parse TypeScript syntax. Added acorn-typescript plugin for .ts/.tsx
files so coverage works for projects using Node's native TS support.
@sohil-kshirsagar sohil-kshirsagar marked this pull request as ready for review April 8, 2026 04:55
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/core/coverageProcessor.ts">

<violation number="1" location="src/core/coverageProcessor.ts:244">
P2: CJS TypeScript files that use `import type` (a very common pattern) will be misidentified as ESM here. `import type` is TypeScript-only syntax that Node.js strips before execution, but acorn-typescript still rejects `import` declarations in `sourceType: "script"` mode. This causes the script parse to throw, falling through to the module parse with `isCJS` remaining `false`.

Since Node.js `--experimental-strip-types` determines CJS vs ESM from `package.json`/file extension (not from syntax), it still wraps CJS files with the ~62-byte wrapper. With `isCJS = false`, the `wrapperLength` offset won't be applied, silently misaligning all V8 byte offsets and producing incorrect line-level coverage data.

Consider detecting CJS via file extension (`.cts`) or `package.json` type field rather than relying solely on parse success for TypeScript files.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@tusk-dev
Copy link
Copy Markdown

tusk-dev bot commented Apr 8, 2026

No tests generated

View output

Tip

New to Tusk Unit Tests? Learn more here.

View check history

Commit Status Output Created (UTC)
1633799 Generated 1 test - 1 passed Tests Apr 8, 2026 4:55AM
217bfdc No tests generated Output Apr 8, 2026 5:14AM

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/core/coverageProcessor.ts">

<violation number="1" location="src/core/coverageProcessor.ts:252">
P2: For `.ts` files, parsing `script` first can misclassify ESM-with-type-only-imports as CJS, causing an incorrect CommonJS `wrapperLength` offset.

(Based on your team's feedback about treating `import type` TypeScript files as ESM for wrapper offset handling.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 217bfdc. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant