Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a848bf7
Coverage lists a line where only an object literal starts
dylan-conway Oct 20, 2026
472cf44
Shorten a comment
dylan-conway Oct 20, 2026
bd33378
Test each character an object literal can follow, a branch that is no…
dylan-conway Oct 20, 2026
1cc552e
The text of a line comment is not what a brace follows
dylan-conway Oct 20, 2026
d885782
Slashes in a string do not hide what a brace follows
dylan-conway Oct 20, 2026
2ecdf15
Merge commit '9b4284f788f20e3d6ec8358daf62ad10694b158a' into claude/c…
dylan-conway Oct 21, 2026
984edc8
The brace of a block is not listed after a number that ends in a peri…
dylan-conway Oct 21, 2026
cace517
Coverage takes which brace is code from the printer instead of from t…
dylan-conway Oct 21, 2026
9d70e48
Bump the version of the transpiler cache, share the collector of a so…
dylan-conway Oct 21, 2026
5bf196b
Two comments say what the code does, and an object pattern in an assi…
dylan-conway Oct 21, 2026
321cefa
The test that a word in a source map maps to the same word no longer …
dylan-conway Oct 21, 2026
4a9bf3b
Merge remote-tracking branch 'origin/main' into claude/coverage-objec…
dylan-conway Oct 21, 2026
0b3bf68
Coverage takes the braces from the source map only if the printer mad…
dylan-conway Oct 21, 2026
498d880
Merge remote-tracking branch 'origin/main' into claude/coverage-objec…
dylan-conway Oct 21, 2026
9d31e5c
The source map tests decode each map once, and the { after finally ha…
dylan-conway Oct 21, 2026
22636ad
Say what the comments mean, assert the counts of an object's braces, …
dylan-conway Oct 21, 2026
f771382
Coverage prints each text once more for a source map of its own, an o…
dylan-conway Oct 21, 2026
6c01175
The printer marks the braces of object literals in the source map for…
dylan-conway Oct 21, 2026
55cce26
A mark has the positions of its mapping so that reading the marks dec…
dylan-conway Oct 21, 2026
cef2f35
A // @bun file is parsed and printed for its marks only with --covera…
dylan-conway Oct 21, 2026
2205822
Merge main, and the cache version is 40
dylan-conway Oct 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/ast/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct Property {
pub struct Object {
pub properties: crate::StoreSlice<Property>,
pub is_single_line: bool,
pub close_brace_loc: crate::Loc,
}
// No `impl Default` on purpose: only `is_single_line` has a sensible default;
// `properties` does not, so every constructor must supply it.
Expand Down
1 change: 1 addition & 0 deletions src/ast/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl Binding {
E::Object {
properties: G::PropertyList::from_bump_vec(properties),
is_single_line: b.is_single_line,
close_brace_loc: b.close_brace_loc,
..Default::default()
},
loc,
Expand Down
2 changes: 2 additions & 0 deletions src/ast/s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub struct If {
pub test: ExprNodeIndex,
pub yes: StmtNodeIndex,
pub no: Option<StmtNodeIndex>,
/// Where the `else` of `no` is. `Loc::EMPTY` in an `if` that the parser did not make.
pub else_loc: crate::Loc,
}

pub struct For {
Expand Down
1 change: 1 addition & 0 deletions src/bundler/linker_context/generateCodeForFileInChunkJS.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ pub fn generate_code_for_file_in_chunk_js<'r, 'src>(
kept.into_bump_slice_mut(),
),
is_single_line: object.get().is_single_line,
close_brace_loc: object.get().close_brace_loc,
},
binding.loc,
)
Expand Down
3 changes: 3 additions & 0 deletions src/bundler/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,8 @@ impl<'a> Transpiler<'a> {
// @bun annotation
opts.features.dont_bundle_twice = this_parse.dont_bundle_twice;

opts.features.code_coverage = self.options.code_coverage;

opts.features.commonjs_at_runtime = this_parse.allow_commonjs;

opts.features.inlining = self.options.inlining;
Expand Down Expand Up @@ -2423,6 +2425,7 @@ impl<'a> Transpiler<'a> {
minify_whitespace: self.options.minify_whitespace,
minify_syntax: self.options.minify_syntax,
minify_identifiers: self.options.minify_identifiers,
code_coverage: self.options.code_coverage,
module_type: if IS_BUN && self.options.transform_only {
// this is for when using `bun build --no-bundle`
// it should copy what was passed for the cli
Expand Down
2 changes: 2 additions & 0 deletions src/js_parser/p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
B::Object {
properties: bun_ast::StoreSlice::from_bump(items_hmr),
is_single_line: false,
close_brace_loc: bun_ast::Loc::EMPTY,
},
bun_ast::Loc::EMPTY,
);
Expand Down Expand Up @@ -3992,6 +3993,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
B::Object {
properties: bun_ast::StoreSlice::new_mut(properties.into_bump_slice_mut()),
is_single_line: ex.is_single_line,
close_brace_loc: ex.close_brace_loc,
},
expr.loc,
));
Expand Down
2 changes: 2 additions & 0 deletions src/js_parser/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
if p.lexer.has_newline_before {
is_single_line = false;
}
let close_brace_loc = p.lexer.loc();
p.lexer.expect(T::TCloseBrace)?;

return Ok(p.b(
Expand All @@ -1161,6 +1162,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
properties.into_bump_slice_mut(),
),
is_single_line,
close_brace_loc,
},
loc,
));
Expand Down
2 changes: 2 additions & 0 deletions src/js_parser/parse/parse_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ impl<'a> Options<'a> {
auto_polyfill_require: f.auto_polyfill_require,
replace_exports: Default::default(),
dont_bundle_twice: f.dont_bundle_twice,
code_coverage: f.code_coverage,
unwrap_commonjs_packages: f.unwrap_commonjs_packages,
commonjs_at_runtime: f.commonjs_at_runtime,
unwrap_commonjs_to_esm: f.unwrap_commonjs_to_esm,
Expand Down Expand Up @@ -2165,6 +2166,7 @@ impl<'a> Parser<'a> {
B::Object {
properties,
is_single_line: false,
close_brace_loc: bun_ast::Loc::EMPTY,
},
bun_ast::Loc::EMPTY,
);
Expand Down
2 changes: 2 additions & 0 deletions src/js_parser/parse/parse_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
test,
yes,
no: None,
else_loc: bun_ast::Loc::EMPTY,
},
current_loc,
);
Expand All @@ -249,6 +250,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
return Ok(root_if.unwrap());
}

current_if.unwrap().else_loc = p.lexer.loc();
p.lexer.next()?;

// Handle final else
Expand Down
7 changes: 6 additions & 1 deletion src/js_parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ pub mod Runtime {
/// This comment must never be used manually.
pub dont_bundle_twice: bool,

/// Only hashed: `js_printer::Options::code_coverage` changes the source map that is cached.
pub code_coverage: bool,

/// This is a list of packages which even when require() is used, we will
/// instead convert to ESM import statements.
///
Expand Down Expand Up @@ -297,6 +300,7 @@ pub mod Runtime {
auto_polyfill_require: false,
replace_exports: ReplaceableExportMap::default(),
dont_bundle_twice: false,
code_coverage: false,
unwrap_commonjs_packages: &[],
commonjs_at_runtime: false,
unwrap_commonjs_to_esm: false,
Expand Down Expand Up @@ -358,7 +362,7 @@ pub mod Runtime {
pub(crate) fn hash_for_runtime_transpiler(&self, hasher: &mut Wyhash) {
debug_assert!(self.runtime_transpiler_cache.is_some());

let bools: [bool; 17] = [
let bools: [bool; 18] = [
self.top_level_await,
self.auto_import_jsx,
self.allow_runtime,
Expand All @@ -371,6 +375,7 @@ pub mod Runtime {
self.set_breakpoint_on_first_line,
self.trim_unused_imports,
self.dont_bundle_twice,
self.code_coverage,
self.commonjs_at_runtime,
self.emit_decorator_metadata,
self.standard_decorators,
Expand Down
32 changes: 30 additions & 2 deletions src/js_printer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,17 @@ pub trait OnSourceMapChunk {
) -> crate::Result<()>;
}

impl OnSourceMapChunk for Option<SourceMap::Chunk> {
fn on_source_map_chunk(
&mut self,
chunk: SourceMap::Chunk,
_: &bun_ast::Source,
) -> crate::Result<()> {
*self = Some(chunk);
Ok(())
}
}

impl<'a> SourceMapHandler<'a> {
pub(crate) fn on_source_map_chunk(
&self,
Expand Down Expand Up @@ -1346,6 +1357,8 @@ pub struct Options<'a> {
pub minify_identifiers: bool,
pub minify_syntax: bool,
pub print_dce_annotations: bool,
/// Marks the braces of object literals in the source map, see `mark_object_brace`.
pub code_coverage: bool,

pub inline_require_and_import_errors: bool,
/// A bundler renamer named every symbol. Those renamers reserve `NaN`,
Expand Down Expand Up @@ -1425,6 +1438,7 @@ impl<'a> Default for Options<'a> {
minify_identifiers: false,
minify_syntax: false,
print_dce_annotations: true,
code_coverage: false,
inline_require_and_import_errors: true,
has_run_symbol_renamer: false,
require_or_import_meta_for_source_callback: RequireOrImportMetaCallback::default(),
Expand Down Expand Up @@ -2365,6 +2379,7 @@ pub(crate) mod __gated_printer {
temp_bindings.as_mut_slice(),
),
is_single_line: true,
close_brace_loc: bun_ast::Loc::EMPTY,
};
// `from_bump` wraps a `&mut T` as a non-null arena ref; here the
// pointee is a stack local but `print_binding` only reads it and
Expand Down Expand Up @@ -2432,6 +2447,15 @@ pub(crate) mod __gated_printer {
.add_source_mapping(location, self.writer.slice());
}

#[inline]
pub(crate) fn mark_object_brace(&mut self) {
if !GENERATE_SOURCE_MAP || !self.options.code_coverage {
return;
}
self.source_map_builder
.mark_object_brace(self.writer.slice());
}

#[inline]
pub(crate) fn add_source_mapping_for_name(
&mut self,
Expand Down Expand Up @@ -3941,6 +3965,7 @@ pub(crate) mod __gated_printer {
self.print(b"(");
}
self.add_source_mapping(expr.loc);
self.mark_object_brace();
Comment thread
dylan-conway marked this conversation as resolved.
Resolved
self.print(b"{");
let props = e.properties.slice();
if !props.is_empty() {
Expand Down Expand Up @@ -3979,6 +4004,7 @@ pub(crate) mod __gated_printer {
}
if e.close_brace_loc.start > expr.loc.start {
self.add_source_mapping(e.close_brace_loc);
self.mark_object_brace();
}
self.print(b"}");
if wrap {
Expand Down Expand Up @@ -4997,9 +5023,9 @@ pub(crate) mod __gated_printer {
}
ExprData::EString(key_str) => {
let key_str = key_str.flattened(self.bump);
self.add_source_mapping(key.loc);
if key_str.is_utf8() {
self.print_space_before_identifier();
self.add_source_mapping(key.loc);
let mut allow_shorthand = true;
if !IS_JSON && lexer::is_identifier(key_str.slice8()) {
self.print_identifier(key_str.slice8());
Expand Down Expand Up @@ -5044,6 +5070,7 @@ pub(crate) mod __gated_printer {
}
} else if !IS_JSON && self.can_print_identifier_utf16(key_str.slice16()) {
self.print_space_before_identifier();
self.add_source_mapping(key.loc);
self.print_identifier_utf16(key_str.slice16())
.expect("unreachable");

Expand Down Expand Up @@ -5083,6 +5110,7 @@ pub(crate) mod __gated_printer {
}
}
} else {
self.add_source_mapping(key.loc);
let c = Self::best_quote_char_for_e_string(&key_str, false);
self.print(c);
self.print_string_characters_utf16(key_str.slice16(), c);
Expand Down Expand Up @@ -6612,7 +6640,7 @@ pub(crate) mod __gated_printer {
if let Some(no_block) = &s.no {
self.print_semicolon_if_needed();
self.print_space_before_identifier();
self.add_source_mapping(no_block.loc);
self.add_source_mapping(s.else_loc.to_nullable().unwrap_or(no_block.loc));
self.print(b"else");

match &no_block.data {
Expand Down
4 changes: 3 additions & 1 deletion src/jsc/RuntimeTranspilerCache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ bun_core::declare_scope!(cache, visible);
/// an abstract class are mapped elsewhere.
/// Version 37: A JSX spread no longer empties an object `--define`. Older entries can print it as `{}`.
/// Version 38: `finally` is mapped, and the `{` after it is mapped elsewhere.
const EXPECTED_VERSION: u32 = 38;
/// Version 39: `else` and the name of an `async` method are mapped elsewhere, the `}` of a pattern
/// that became an assignment is mapped, and `--coverage` participates in the features hash.
const EXPECTED_VERSION: u32 = 39;

/// Source files smaller than this are not written to / read from the on-disk
/// transpiler cache. Originally 50 KiB, which excluded almost every file in a
Expand Down
4 changes: 2 additions & 2 deletions src/jsc/bindings/InternalModuleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern "C" bool Bun__standaloneInternalModuleBytecode(void* bunVM, uint32_t id,
namespace Bun {

extern "C" bool BunTest__shouldGenerateCodeCoverage(const BunString* sourceURL);
extern "C" void ByteRangeMapping__generate(const BunString* sourceURL, const BunString* code, int sourceID);
extern "C" void ByteRangeMapping__generate(const BunString* sourceURL, const BunString* code, int sourceID, bool alreadyBundled);

static void maybeAddCodeCoverage(JSC::VM& vm, const JSC::SourceCode& code)
{
Expand All @@ -42,7 +42,7 @@ static void maybeAddCodeCoverage(JSC::VM& vm, const JSC::SourceCode& code)
if (shouldGenerateCodeCoverage) {
WTF::String sourceString = code.provider()->source().toStringWithoutCopying();
BunString source = Bun::toString(sourceString);
ByteRangeMapping__generate(&sourceURL, &source, code.provider()->asID());
ByteRangeMapping__generate(&sourceURL, &source, code.provider()->asID(), false);
}
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions src/jsc/bindings/ZigSourceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SourceOrigin toSourceOrigin(const String& sourceURL, bool isBuiltin)
return SourceOrigin(WTF::URL::fileURLWithFileSystemPath(sourceURL));
}

extern "C" void ByteRangeMapping__generate(const BunString* sourceURL, const BunString* code, int sourceID);
extern "C" void ByteRangeMapping__generate(const BunString* sourceURL, const BunString* code, int sourceID, bool alreadyBundled);
extern "C" void ByteRangeMapping__addSourceID(const BunString* sourceURL, const BunString* code, int sourceID);

void addCodeCoverageSourceID(JSC::VM& vm, JSC::SourceProvider& provider)
Expand Down Expand Up @@ -134,7 +134,7 @@ Ref<SourceProvider> SourceProvider::create(
BunString providerURL = Bun::toString(provider->sourceURL());
WTF::String providerSourceString = provider->source().toStringWithoutCopying();
BunString providerSource = Bun::toString(providerSourceString);
ByteRangeMapping__generate(&providerURL, &providerSource, provider->asID());
ByteRangeMapping__generate(&providerURL, &providerSource, provider->asID(), provider->m_alreadyBundled);
}

if (provider->m_alreadyBundled) {
Expand Down
2 changes: 2 additions & 0 deletions src/lint/react_compiler/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ impl<'a> Converter<'a, '_> {
let object = B::Object {
properties: leak(properties),
is_single_line: false,
close_brace_loc: Loc::EMPTY,
};
Binding::alloc(this.arena, object, loc)
}
Expand Down Expand Up @@ -1383,6 +1384,7 @@ impl<'a> Converter<'a, '_> {
test: self.expr(test)?,
yes: self.stmt(yes)?,
no: no.map(|it| self.stmt(it)).transpose()?,
else_loc: Loc::EMPTY,
},
loc,
),
Expand Down
5 changes: 5 additions & 0 deletions src/react_compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ pub(crate) fn codegen_function(
test: if_test,
yes: expr_stmt(call, Loc::EMPTY),
no: None,
else_loc: Loc::EMPTY,
},
Loc::EMPTY,
);
Expand Down Expand Up @@ -866,6 +867,7 @@ fn codegen_reactive_scope(
test: test_condition,
yes,
no,
else_loc: Loc::EMPTY,
},
loc,
);
Expand Down Expand Up @@ -901,6 +903,7 @@ fn codegen_reactive_scope(
loc,
),
no: None,
else_loc: Loc::EMPTY,
},
loc,
));
Expand Down Expand Up @@ -1000,6 +1003,7 @@ fn codegen_terminal(
test: test_expr,
yes: body_stmt(consequent_block, stmt_loc),
no: alternate_stmt,
else_loc: Loc::EMPTY,
},
stmt_loc,
)))
Expand Down Expand Up @@ -3009,6 +3013,7 @@ fn codegen_object_pattern(
b::Object {
properties: StoreSlice::from_bump(properties),
is_single_line: true,
close_brace_loc: Loc::EMPTY,
},
loc,
))
Expand Down
Loading
Loading