Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/sema/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::config_options::{Declaration, In, converted, is_enum, is_file_path, i
use crate::json::{Json, TsConfigSourceFile};
use crate::resolve::{
Host, Options, ancestors, combine_paths, contains_path, displayed_path,
equate_string_case_insensitive, extra_supported_extensions, file_extension_is_one_of,
get_base_file_name, get_path_components, get_relative_path_from_directory, inside,
is_rooted_disk_path, is_same_path, join, known_extension, remove_file_extension,
equate_string_case_insensitive, extra_supported_extensions, get_base_file_name,
get_path_components, get_relative_path_from_directory, inside, is_rooted_disk_path,
is_same_path, join, known_extension, remove_file_extension, supported_extension_is,
supported_extensions, to_lowercase_unicode_15, to_path, typescript_path,
};
use crate::session::Session;
Expand Down Expand Up @@ -280,7 +280,7 @@ impl Roots {
.extension_groups
.iter()
.any(|group| group.iter().any(|it| has_extension(it)))
|| self.extra_extensions.iter().any(|it| has_extension(it));
|| (self.extra_extensions.iter()).any(|it| supported_extension_is(path, it));
Comment thread
robobun marked this conversation as resolved.
Resolved
let whole = PathParts {
directory,
name: b"",
Expand Down Expand Up @@ -1702,7 +1702,9 @@ fn match_files(
Listed {
files: files
.into_iter()
.filter(|file| file_extension_is_one_of(file, self.extensions))
.filter(|file| {
(self.extensions.iter()).any(|it| supported_extension_is(file, it))
Comment thread
robobun marked this conversation as resolved.
Resolved
})
.filter_map(|file| {
let name = &file[..];
let index = self.files.matches_file(PathParts { directory, name })?;
Expand Down
9 changes: 9 additions & 0 deletions src/sema/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,15 @@ pub(crate) fn file_extension_is(path: &[u8], extension: &[u8]) -> bool {
path.len() > extension.len() && path.ends_with(extension)
}

/// `file_extension_is` for an extension that may be one of `extra_supported_extensions`. The `""` of `--loader :ts`
/// is a name with no extension, as `Host::script_kind` reads it: as a suffix it would be every name.
pub(crate) fn supported_extension_is(path: &[u8], extension: &[u8]) -> bool {
if extension.is_empty() {
return bun_paths::extension(path).is_empty();
}
file_extension_is(path, extension)
}

/// `FileExtensionIsOneOf`
pub(crate) fn file_extension_is_one_of(path: &[u8], extensions: &[&[u8]]) -> bool {
(extensions.iter()).any(|e| file_extension_is(path, e))
Expand Down
15 changes: 15 additions & 0 deletions test/cli/check/entry-points.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ const entries: Entry[] = [
[`types${extension}`]: `export type N = number;\nexport const n: N = ${value(isCorrect)};\n`,
}),
})),
{
// `""` is the extension of a name with no `.`, not a suffix of every name: `include` doesn't match `notes.txt`.
name: "--loader for files without an extension",
wrong: "imported",
isIncluded: true,
loader: ["", "ts"],
// `Bun.build` drops the `""` key.
commands: withLoader.filter(command => command !== "Bun.build"),
main: () => ["main.ts"],
files: (isCorrect, pathsImport) => ({
"main.ts": `${pathsImport}import { n } from "./imported";\nexport const m: number = n;\n${run}`,
"imported": `export const n: number = ${value(isCorrect)};\n`,
"notes.txt": `not a script\n`,
}),
},
{
// Without `allowJs`.
name: "a JavaScript file with its declaration file",
Expand Down
Loading