Compare commits

...

1 Commits

Author SHA1 Message Date
Dylan Conway
d88e3bfd3b maybe fix 2024-11-08 18:06:37 -08:00
3 changed files with 11 additions and 1 deletions

View File

@@ -2347,6 +2347,10 @@ pub const ModuleLoader = struct {
break :loader options.Loader.tsx;
}
if (strings.hasPrefixComptime(path.name.dir, "data:")) {
break :loader options.Loader.tsx;
}
// Unknown extensions are to be treated as file loader
break :loader options.Loader.file;
} else {

View File

@@ -1301,7 +1301,7 @@ pub const Bundler = struct {
break :brk logger.Source.initPathString(path.text, "");
}
if (strings.startsWith(path.text, "data:")) {
if (strings.hasPrefixComptime(path.text, "data:")) {
const data_url = DataURL.parseWithoutCheck(path.text) catch |err| {
bundler.log.addErrorFmt(null, logger.Loc.Empty, bundler.allocator, "{s} parsing data url \"{s}\"", .{ @errorName(err), path.text }) catch {};
return null;

View File

@@ -14,6 +14,12 @@ test("should import and execute ES module from string (base64)", async () => {
expect(result).toEqual(2);
});
test("can import module with '.' in source code", async () => {
const code = `export default 1.1;`;
const mod = await import("data:text/javascript," + code).then(mode => mode.default);
expect(mod).toBe(1.1);
});
test("should throw when importing malformed string (base64)", async () => {
expect(() => import("data:text/javascript;base64,asdasdasd")).toThrowError("Base64DecodeError");
});