summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-08-23 04:46:01 +0000
committerFangrui Song <maskray@google.com>2019-08-23 04:46:01 +0000
commit8798c8de9a8a4abf597cd370da57ebefaa4d951d (patch)
tree0c973efd715b7f4045a88d2a0c4e55b9cc4664f7
parent6c9dc12caaffc4bb2d9d836b890dc27b7a8c167a (diff)
downloadbcm5719-llvm-8798c8de9a8a4abf597cd370da57ebefaa4d951d.tar.gz
bcm5719-llvm-8798c8de9a8a4abf597cd370da57ebefaa4d951d.zip
[clang-format] Recognize ECMAScript module .mjs as JavaScript
PR43085. Recognize .mjs files as JavaScript. .mjs is the extension for ECMAScript modules. A specific extension (and associated content type javascript/esm) is introduced to differentiate it from CommonJS modules and solve some interoperability problems. Differential Revision: https://reviews.llvm.org/D66584 Patch by Fergal Daly llvm-svn: 369732
-rw-r--r--clang/lib/Format/Format.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 4fbaee470fa..175807edfb4 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2411,8 +2411,9 @@ const char *StyleOptionHelpDescription =
static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
if (FileName.endswith(".java"))
return FormatStyle::LK_Java;
- if (FileName.endswith_lower(".js") || FileName.endswith_lower(".ts"))
- return FormatStyle::LK_JavaScript; // JavaScript or TypeScript.
+ if (FileName.endswith_lower(".js") || FileName.endswith_lower(".mjs") ||
+ FileName.endswith_lower(".ts"))
+ return FormatStyle::LK_JavaScript; // (module) JavaScript or TypeScript.
if (FileName.endswith(".m") || FileName.endswith(".mm"))
return FormatStyle::LK_ObjC;
if (FileName.endswith_lower(".proto") ||
OpenPOWER on IntegriCloud