Skip to content

Commit bf7fb56

Browse files
authored
Merge pull request #278 from kwonoj/fix-issues-277
2 parents 0933eb7 + fe6d1f2 commit bf7fb56

File tree

12 files changed

+44
-14
lines changed

12 files changed

+44
-14
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ resolver = "2"
1212
#lto = true
1313

1414
[workspace.dependencies]
15-
istanbul-oxide = { path = "./packages/istanbul-oxide", version = "0.0.30" }
15+
istanbul-oxide = { path = "./packages/istanbul-oxide", version = "0.0.31" }
1616
swc-coverage-instrument = { path = "./packages/swc-coverage-instrument" }
1717

1818
getrandom = { version = "0.2.15" }

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swc-plugin-coverage-instrument",
3-
"version": "0.0.30",
3+
"version": "0.0.31",
44
"description": "SWC coverage instrumentation plugin",
55
"main": "./target/wasm32-wasip1/release/swc_plugin_coverage.wasm",
66
"napi": {

packages/istanbul-oxide/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "MIT"
66
name = "istanbul-oxide"
77
repository = "https://github.com/kwonoj/swc-coverage-instrument"
8-
version = "0.0.30"
8+
version = "0.0.31"
99

1010
[dependencies]
1111
indexmap = { workspace = true, features = ["serde"] }

packages/swc-coverage-instrument/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "MIT"
66
name = "swc-coverage-instrument"
77
repository = "https://github.com/kwonoj/swc-coverage-instrument"
8-
version = "0.0.30"
8+
version = "0.0.31"
99

1010
[dependencies]
1111
istanbul-oxide = { workspace = true }

packages/swc-coverage-instrument/src/visitors/coverage_visitor.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ impl<C: Clone + Comments, S: SourceMapper> VisitMut for CoverageVisitor<C, S> {
160160
ModuleItem::ModuleDecl(decl) => self.on_enter(decl),
161161
ModuleItem::Stmt(stmt) => self.on_enter(stmt),
162162
};
163+
164+
// https://github.com/kwonoj/swc-plugin-coverage-instrument/issues/277
165+
// Add statement counter for export const declarations to match istanbul behavior
166+
// Istanbul treats export const and export var differently:
167+
// - export const: adds statement counter for the export declaration
168+
// - export var: only instruments the initializer, no separate export counter
169+
if let ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(export_decl)) = &item {
170+
if let Decl::Var(var_decl) = &export_decl.decl {
171+
if var_decl.kind == VarDeclKind::Const {
172+
self.mark_prepend_stmt_counter(&export_decl.span);
173+
}
174+
}
175+
}
176+
163177
item.visit_mut_children_with(self);
164178

165179
new_items.extend(self.before.drain(..).map(|v| ModuleItem::Stmt(v)));

packages/swc-plugin-coverage/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "MIT"
66
name = "swc-plugin-coverage"
77
repository = "https://github.com/kwonoj/swc-coverage-instrument"
8-
version = "0.0.30"
8+
version = "0.0.31"
99

1010
[lib]
1111
crate-type = ["cdylib"]

spec/fixtures/issue-277.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: export const statements coverage (issue 277)
3+
code: |
4+
export const sayHi = () => 'hi';
5+
6+
export const sayHii = () => 'hii';
7+
instrumentOpts:
8+
esModules: true
9+
tests:
10+
- name: export const coverage
11+
lines: {'1': 1, '3': 1}
12+
statements: {'0': 1, '1': 0, '2': 1, '3': 0}
13+
functions: {'0': 0, '1': 0}

spec/swc-coverage-custom-transform/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)