fix tests, don't return empty chunk when handling error in link

This commit is contained in:
snoglobe
2024-09-27 16:31:28 -07:00
parent a187e39457
commit b3ea2efb0e
3 changed files with 10 additions and 8 deletions

View File

@@ -4249,7 +4249,7 @@ pub const LinkerContext = struct {
// Stop now if there were errors
if (this.log.hasErrors()) {
return &[_]Chunk{};
return error.BuildFailed;
}
if (comptime FeatureFlags.help_catch_memory_issues) {
@@ -7611,11 +7611,10 @@ pub const LinkerContext = struct {
}
const imported_pretty_path = c.parse_graph.input_files.items(.source)[source_index].path.pretty;
const text: string = if (strings.eql(imported_pretty_path, tla_pretty_path)) {
std.fmt.allocPrint(c.allocator, "This require call is not allowed because the imported file {s} contains a top-level await", .{imported_pretty_path}) catch bun.outOfMemory();
} else {
std.fmt.allocPrint(c.allocator, "This require call is not allowed because the transitive dependency {s} contains a top-level await", .{tla_pretty_path}) catch bun.outOfMemory();
};
const text: string = if (strings.eql(imported_pretty_path, tla_pretty_path))
std.fmt.allocPrint(c.allocator, "This require call is not allowed because the imported file \"{s}\" contains a top-level await", .{imported_pretty_path}) catch bun.outOfMemory()
else
std.fmt.allocPrint(c.allocator, "This require call is not allowed because the transitive dependency \"{s}\" contains a top-level await", .{tla_pretty_path}) catch bun.outOfMemory();
const source: Logger.Source = c.parse_graph.input_files.items(.source)[source_index];
c.log.addRangeErrorWithNotes(&source, record.range, text, notes.items) catch bun.outOfMemory();
@@ -9572,6 +9571,8 @@ pub const LinkerContext = struct {
const trace = tracer(@src(), "generateChunksInParallel");
defer trace.end();
bun.assert(chunks.len > 0);
{
debug(" START {d} renamers", .{chunks.len});
defer debug(" DONE {d} renamers", .{chunks.len});

View File

@@ -6823,7 +6823,7 @@ pub const Ast = struct {
// that they can be used in log messages. Check to see if "Len > 0".
import_keyword: logger.Range = logger.Range.None, // Does not include TypeScript-specific syntax or "import()"
export_keyword: logger.Range = logger.Range.None, // Does not include TypeScript-specific syntax
top_level_await_keyword: logger.Range,
top_level_await_keyword: logger.Range = logger.Range.None,
/// These are stored at the AST level instead of on individual AST nodes so
/// they can be manipulated efficiently without a full AST traversal

View File

@@ -3512,7 +3512,8 @@ describe("bundler", () => {
"/entry.js": [
'This require call is not allowed because the transitive dependency "c.js" contains a top-level await',
'This require call is not allowed because the transitive dependency "c.js" contains a top-level await',
'This require call is not allowed because the transitive dependency "entry.js" contains a top-level await',
'This require call is not allowed because the transitive dependency "c.js" contains a top-level await',
'This require call is not allowed because the imported file "entry.js" contains a top-level await',
],
},
});