diff options
-rw-r--r-- | src/bun.js/module_loader.zig | 25 | ||||
-rw-r--r-- | test/js/bun/test/jest-extended.test.js | 2 | ||||
-rw-r--r-- | test/transpiler/async-transpiler-entry.js | 1 | ||||
-rw-r--r-- | test/transpiler/handlebars.hbs | 6 | ||||
-rw-r--r-- | test/transpiler/runtime-transpiler.test.ts | 6 |
5 files changed, 34 insertions, 6 deletions
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index c3aeaa9ce..ca6071d0d 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -1665,6 +1665,12 @@ pub const ModuleLoader = struct { out.* = ZigString.fromUTF8(name); } + defer { + if (is_main) { + jsc_vm.has_loaded = true; + } + } + if (jsc_vm.isWatcherEnabled()) { var resolved_source = jsc_vm.refCountedResolvedSource(printer.ctx.written, input_specifier, path.text, null, false); @@ -2058,7 +2064,10 @@ pub const ModuleLoader = struct { &display_specifier, ); const path = Fs.Path.init(specifier); - const loader: options.Loader = jsc_vm.bundler.options.loaders.get(path.name.ext) orelse options.Loader.js; + + // Deliberately optional. + // The concurrent one only handles javascript-like loaders right now. + const loader: ?options.Loader = jsc_vm.bundler.options.loaders.get(path.name.ext); // We only run the transpiler concurrently when we can. // Today, that's: @@ -2067,7 +2076,8 @@ pub const ModuleLoader = struct { // Import Expressions (import('foo')) // if (comptime bun.FeatureFlags.concurrent_transpiler) { - if (allow_promise and loader.isJavaScriptLike() and + const concurrent_loader = loader orelse .file; + if (allow_promise and (jsc_vm.has_loaded or jsc_vm.is_in_preload) and concurrent_loader.isJavaScriptLike() and // Plugins make this complicated, // TODO: allow running concurrently when no onLoad handlers match a plugin. jsc_vm.plugin_runner == null and jsc_vm.transpiler_store.enabled) @@ -2083,6 +2093,15 @@ pub const ModuleLoader = struct { } } + const synchronous_loader = loader orelse + // Unknown extensions are to be treated as file loader + if (jsc_vm.has_loaded or jsc_vm.is_in_preload) + options.Loader.file + else + // Unless it's potentially the main module + // This is important so that "bun run ./foo-i-have-no-extension" works + options.Loader.js; + var promise: ?*JSC.JSInternalPromise = null; ret.* = ErrorableResolvedSource.ok( ModuleLoader.transpileSourceCode( @@ -2092,7 +2111,7 @@ pub const ModuleLoader = struct { referrer_slice.slice(), specifier_ptr.*, path, - loader, + synchronous_loader, &log, null, ret, diff --git a/test/js/bun/test/jest-extended.test.js b/test/js/bun/test/jest-extended.test.js index 30527e157..2cdec75fa 100644 --- a/test/js/bun/test/jest-extended.test.js +++ b/test/js/bun/test/jest-extended.test.js @@ -135,7 +135,7 @@ describe("jest-extended", () => { expect("").not.toBeArrayOfSize(1); expect(0).not.toBeArrayOfSize(1); }); - + // test('toIncludeAllMembers()') // test('toIncludeAllPartialMembers()') // test('toIncludeAnyMembers()') diff --git a/test/transpiler/async-transpiler-entry.js b/test/transpiler/async-transpiler-entry.js index 179a4e6a8..191c7c8a7 100644 --- a/test/transpiler/async-transpiler-entry.js +++ b/test/transpiler/async-transpiler-entry.js @@ -1 +1,2 @@ export { default } from "./async-transpiler-imported.js"; +export { default as hbs } from "./handlebars.hbs"; diff --git a/test/transpiler/handlebars.hbs b/test/transpiler/handlebars.hbs new file mode 100644 index 000000000..be5830357 --- /dev/null +++ b/test/transpiler/handlebars.hbs @@ -0,0 +1,6 @@ +<!DOCTYPE html> +<html> +<head> + <title>{{title}}</title> +</head> +</html>
\ No newline at end of file diff --git a/test/transpiler/runtime-transpiler.test.ts b/test/transpiler/runtime-transpiler.test.ts index b3f545719..c1881ee67 100644 --- a/test/transpiler/runtime-transpiler.test.ts +++ b/test/transpiler/runtime-transpiler.test.ts @@ -8,13 +8,15 @@ describe("// @bun", () => { }); test("async transpiler", async () => { - const { default: value } = await import("./async-transpiler-entry"); + const { default: value, hbs } = await import("./async-transpiler-entry"); expect(value).toBe(42); + expect(hbs).toBeString(); }); test("require()", async () => { - const { default: value } = require("./async-transpiler-entry"); + const { default: value, hbs } = require("./async-transpiler-entry"); expect(value).toBe(42); + expect(hbs).toBeString(); }); test("synchronous", async () => { |