diff options
author | sstwcw <f0gukp2nk@protonmail.com> | 2022-03-30 23:17:27 +0000 |
---|---|---|
committer | sstwcw <f0gukp2nk@protonmail.com> | 2022-03-30 23:17:27 +0000 |
commit | f6740fe483e9fa0c76aa9f176ff68f51f47a1302 (patch) | |
tree | 146d8fe5b09705ffd41eca6ef289184a53d88153 /clang/unittests/Format/FormatTestJS.cpp | |
parent | a114ec0c6dc052832ec3dc1f65c9e221e3272925 (diff) | |
download | llvm-f6740fe483e9fa0c76aa9f176ff68f51f47a1302.zip llvm-f6740fe483e9fa0c76aa9f176ff68f51f47a1302.tar.gz llvm-f6740fe483e9fa0c76aa9f176ff68f51f47a1302.tar.bz2 |
[clang-format] Indent import statements in JavaScript.
[clang-format] Indent import statements in JavaScript.
Take for example this piece of code found at
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import>.
```
for (const link of document.querySelectorAll("nav > a")) {
link.addEventListener("click", e => {
e.preventDefault();
import('/modules/my-module.js')
.then(module => {
module.loadPageInto(main);
})
.catch(err => {
main.textContent = err.message;
});
});
}
```
Previously the import line would be unindented, looking like this.
```
for (const link of document.querySelectorAll("nav > a")) {
link.addEventListener("click", e => {
e.preventDefault();
import('/modules/my-module.js')
.then(module => {
module.loadPageInto(main);
})
.catch(err => {
main.textContent = err.message;
});
});
}
```
Actually we were going to fix this along with fixing Verilog import
statements. But the patch got too big.
Reviewed By: MyDeveloperDay, curdeius
Differential Revision: https://reviews.llvm.org/D121906
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 6077d21..9883aae 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1875,6 +1875,11 @@ TEST_F(FormatTestJS, Modules) { " myX} from 'm';"); verifyFormat("import * as lib from 'some/module.js';"); verifyFormat("var x = {import: 1};\nx.import = 2;"); + // Ensure an import statement inside a block is at the correct level. + verifyFormat("function() {\n" + " var x;\n" + " import 'some/module.js';\n" + "}"); verifyFormat("export function fn() {\n" " return 'fn';\n" |