mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
fix(bundler): bundling invalid html / export star as / react refresh fixes (#17685)
This commit is contained in:
@@ -79,7 +79,11 @@ pub fn scan(this: *HTMLScanner, input: []const u8) !void {
|
||||
try processor.run(this, input);
|
||||
}
|
||||
|
||||
pub fn HTMLProcessor(comptime T: type, comptime visit_head_and_body: bool) type {
|
||||
pub fn HTMLProcessor(
|
||||
comptime T: type,
|
||||
/// If the visitor should visit html, head, body
|
||||
comptime visit_document_tags: bool,
|
||||
) type {
|
||||
return struct {
|
||||
const TagHandler = struct {
|
||||
/// CSS selector to match elements
|
||||
@@ -151,12 +155,6 @@ pub fn HTMLProcessor(comptime T: type, comptime visit_head_and_body: bool) type
|
||||
.url_attribute = "href",
|
||||
.kind = .url,
|
||||
},
|
||||
// Catch-all for other links with href
|
||||
.{
|
||||
.selector = "link:not([rel~='stylesheet']):not([rel~='modulepreload']):not([rel~='manifest']):not([rel~='icon']):not([rel~='apple-touch-icon'])[href]",
|
||||
.url_attribute = "href",
|
||||
.kind = .url,
|
||||
},
|
||||
// Images with src
|
||||
.{
|
||||
.selector = "img[src]",
|
||||
@@ -231,7 +229,7 @@ pub fn HTMLProcessor(comptime T: type, comptime visit_head_and_body: bool) type
|
||||
var builder = lol.HTMLRewriter.Builder.init();
|
||||
defer builder.deinit();
|
||||
|
||||
var selectors: std.BoundedArray(*lol.HTMLSelector, tag_handlers.len + if (visit_head_and_body) 2 else 0) = .{};
|
||||
var selectors: std.BoundedArray(*lol.HTMLSelector, tag_handlers.len + if (visit_document_tags) 3 else 0) = .{};
|
||||
defer for (selectors.slice()) |selector| {
|
||||
selector.deinit();
|
||||
};
|
||||
@@ -254,36 +252,23 @@ pub fn HTMLProcessor(comptime T: type, comptime visit_head_and_body: bool) type
|
||||
);
|
||||
}
|
||||
|
||||
if (visit_head_and_body) {
|
||||
const head_selector = try lol.HTMLSelector.parse("head");
|
||||
selectors.appendAssumeCapacity(head_selector);
|
||||
try builder.addElementContentHandlers(
|
||||
head_selector,
|
||||
T,
|
||||
T.onHeadTag,
|
||||
this,
|
||||
void,
|
||||
null,
|
||||
null,
|
||||
void,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
const body_selector = try lol.HTMLSelector.parse("body");
|
||||
selectors.appendAssumeCapacity(body_selector);
|
||||
try builder.addElementContentHandlers(
|
||||
body_selector,
|
||||
T,
|
||||
T.onBodyTag,
|
||||
this,
|
||||
void,
|
||||
null,
|
||||
null,
|
||||
void,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
if (visit_document_tags) {
|
||||
inline for (.{ "body", "head", "html" }, &.{ T.onBodyTag, T.onHeadTag, T.onHtmlTag }) |tag, cb| {
|
||||
const head_selector = try lol.HTMLSelector.parse(tag);
|
||||
selectors.appendAssumeCapacity(head_selector);
|
||||
try builder.addElementContentHandlers(
|
||||
head_selector,
|
||||
T,
|
||||
cb,
|
||||
this,
|
||||
void,
|
||||
null,
|
||||
null,
|
||||
void,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const memory_settings = lol.MemorySettings{
|
||||
|
||||
Reference in New Issue
Block a user