[clang] 56ab56c - [clang-format] Add support for `.cjs` as JavaScript file extension (#118188)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 09:03:55 PST 2024
Author: Jim B
Date: 2024-12-03T09:03:51-08:00
New Revision: 56ab56c85729976f29d5de2fd73912449cb6da7c
URL: https://github.com/llvm/llvm-project/commit/56ab56c85729976f29d5de2fd73912449cb6da7c
DIFF: https://github.com/llvm/llvm-project/commit/56ab56c85729976f29d5de2fd73912449cb6da7c.diff
LOG: [clang-format] Add support for `.cjs` as JavaScript file extension (#118188)
Node uses `.cjs` as an extension for 'common javascript' modules.
Added:
Modified:
clang/docs/ClangFormat.rst
clang/lib/Format/Format.cpp
clang/tools/clang-format/ClangFormat.cpp
clang/tools/clang-format/git-clang-format
Removed:
################################################################################
diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index e17d741b0a00eb..c8f1d7f5a77581 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -49,7 +49,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
supported:
CSharp: .cs
Java: .java
- JavaScript: .mjs .js .ts
+ JavaScript: .js .mjs .cjs .ts
Json: .json
Objective-C: .m .mm
Proto: .proto .protodevel
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ee52972ce66f4a..dcaac4b0d42cc5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3950,6 +3950,7 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
return FormatStyle::LK_Java;
if (FileName.ends_with_insensitive(".js") ||
FileName.ends_with_insensitive(".mjs") ||
+ FileName.ends_with_insensitive(".cjs") ||
FileName.ends_with_insensitive(".ts")) {
return FormatStyle::LK_JavaScript; // (module) JavaScript or TypeScript.
}
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index 5481bb6b87503c..28610052b9b74a 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -87,7 +87,7 @@ static cl::opt<std::string> AssumeFileName(
"supported:\n"
" CSharp: .cs\n"
" Java: .java\n"
- " JavaScript: .mjs .js .ts\n"
+ " JavaScript: .js .mjs .cjs .ts\n"
" Json: .json\n"
" Objective-C: .m .mm\n"
" Proto: .proto .protodevel\n"
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index 6a2a2a22ec5c2b..a322d4abf0ec22 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -94,7 +94,7 @@ def main():
# Other languages that clang-format supports
'proto', 'protodevel', # Protocol Buffers
'java', # Java
- 'mjs', 'js', # JavaScript
+ 'js', 'mjs', 'cjs', # JavaScript
'ts', # TypeScript
'cs', # C Sharp
'json', # Json
More information about the cfe-commits
mailing list