diff options
author | 2022-01-22 18:31:45 -0800 | |
---|---|---|
committer | 2022-01-22 18:31:45 -0800 | |
commit | 1576d183c9cd5d5df0722897e5df89c94b17fa00 (patch) | |
tree | 22080858a80daa9ef910ffa8d8c4567ce0746054 | |
parent | 0e0bfe91d050fc7fa645c8a1169db600a2ecd0ed (diff) | |
download | bun-1576d183c9cd5d5df0722897e5df89c94b17fa00.tar.gz bun-1576d183c9cd5d5df0722897e5df89c94b17fa00.tar.zst bun-1576d183c9cd5d5df0722897e5df89c94b17fa00.zip |
Instead of 4 loops, we can do one switch statement
Diffstat (limited to '')
-rw-r--r-- | src/resolver/resolver.zig | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index aa0b28107..bbb697d92 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -701,18 +701,13 @@ pub const Resolver = struct { // If you use mjs or mts, then you're using esm // If you use cjs or cts, then you're using cjs // This should win out over the module type from package.json - if (!kind.isFromCSS() and module_type == .unknown) { - getter: { - if (strings.eqlAnyComptime(path.name.ext, &.{ ".mjs", ".mts" })) { - module_type = .esm; - break :getter; - } - - if (strings.eqlAnyComptime(path.name.ext, &.{ ".cjs", ".cts" })) { - module_type = .cjs; - break :getter; - } - } + if (!kind.isFromCSS() and module_type == .unknown and path.name.ext.len == 4) { + const FourLetterMatcher = strings.ExactSizeMatcher(4); + module_type = switch (FourLetterMatcher.match(path.name.ext)) { + FourLetterMatcher.case(".mjs"), FourLetterMatcher.case(".mts") => .esm, + FourLetterMatcher.case(".cjs"), FourLetterMatcher.case(".cts") => .cjs, + else => .unknown, + }; } if (dir.getEntries()) |entries| { |