Skip to content

Commit

Permalink
fix tests, don't return empty chunk when handling error in link
Browse files Browse the repository at this point in the history
  • Loading branch information
snoglobe committed Sep 27, 2024
1 parent a187e39 commit b3ea2ef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/bundler/bundle_v2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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});
Expand Down
2 changes: 1 addition & 1 deletion src/js_ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/bundler/esbuild/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
},
});
Expand Down

0 comments on commit b3ea2ef

Please sign in to comment.