feat(coverage): support --experimental-strip-types via acorn-typescript#151
Open
sohil-kshirsagar wants to merge 2 commits intomainfrom
Open
feat(coverage): support --experimental-strip-types via acorn-typescript#151sohil-kshirsagar wants to merge 2 commits intomainfrom
sohil-kshirsagar wants to merge 2 commits intomainfrom
Conversation
…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.
Contributor
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Add TypeScript coverage support for Node.js
--experimental-strip-types(and the stable--experimental-transform-typesin Node 23+).Problem
When a project runs
.tsfiles directly vianode --experimental-strip-types server.ts, V8 reports coverage against the.tsfiles. 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 onlytuskDriftInit.ts(2/2 lines, 100%) while the actual server code was completely missing.Fix
Added
acorn-typescriptas a dependency. When processing a.ts/.tsx/.mts/.ctsfile, the parser usesacorn.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/.tsxfiles use the plugin. Regular.jsfiles continue using plain acorn with no overhead.Testing
Tested against
drift-node-demowhich uses--experimental-strip-types:100.0% lines (2/2) across 1 file(only tuskDriftInit.ts)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).