Skip to content

Commit

Permalink
fix(typescript-test): treat foo.d.html.ts as a .d.ts file
Browse files Browse the repository at this point in the history
TypeScript/tests/cases/conformance/nonjsExtensions/declarationFileForHtmlFileWithinDeclarationFile.ts
creates a file called component.d.html.ts. We should interpret it as a
TypeScript definition file.
  • Loading branch information
strager committed Dec 29, 2023
1 parent b7f9349 commit 6c48395
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions test/test-typescript-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ TEST(Test_TypeScript_Test, typescript_definition_file) {
EXPECT_FALSE(options->jsx);
}

TEST(Test_TypeScript_Test, typescript_definition_file_with_weird_extension) {
Padded_String file(
u8"// @filename: example.d.html.ts\n"_sv
u8"export const a;"_sv);
TypeScript_Test_Units units =
extract_units_from_typescript_test(std::move(file), u8"hello.ts");
ASSERT_EQ(units.size(), 1);
std::optional<Linter_Options> options = units[0].get_linter_options();
ASSERT_TRUE(options.has_value());
EXPECT_TRUE(options->typescript);
EXPECT_TRUE(options->typescript_definition);
}

TEST(Test_TypeScript_Test, javascript_file_is_linted) {
{
Padded_String file(
Expand Down
2 changes: 1 addition & 1 deletion tools/test-typescript/typescript-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ std::optional<Linter_Options> TypeScript_Test_Unit::get_linter_options() const {
if (ends_with(String8_View(this->name), u8".json"_sv)) {
return std::nullopt;
}
if (ends_with(String8_View(this->name), u8".d.ts"_sv)) {
if (contains(String8_View(this->name), u8".d."_sv)) {
return Linter_Options{
.jsx = false, .typescript = true, .typescript_definition = true};
}
Expand Down

0 comments on commit 6c48395

Please sign in to comment.