[PATCH] D121906: [clang-format] Indent import statements in JavaScript.

sstwcw via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 18 04:58:13 PDT 2022


sstwcw marked an inline comment as done.
sstwcw added inline comments.


================
Comment at: clang/lib/Format/ContinuationIndenter.cpp:631
+      Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash &&
       Previous.is(tok::hash) && State.FirstIndent > 0 &&
       (State.Line->Type == LT_PreprocessorDirective ||
----------------
MyDeveloperDay wrote:
> can I check? is this case really firing? i mean isn't it
> 
> `# import`
> 
> why would javascript be seeing that?
In Javascript import statements also need some special handling. So the line is intentionally labeled as LT_ImportStatement. In `AnnotatingParser::parseLine` there is this.
```
    if (Style.isJavaScript() && CurrentToken->is(Keywords.kw_import))
      ImportStatement = true;
```
I don't know why the line type isn't printed in `TokenAnnotator::printDebugInfo`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121906/new/

https://reviews.llvm.org/D121906



More information about the cfe-commits mailing list