[PATCH] D59292: [clang-format] messes up indentation when using JavaScript private fields and methods

MyDeveloperDay via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 03:53:08 PDT 2019


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: djasper, klimek, JonasToth, reuk, krasimir.
MyDeveloperDay added a project: clang-tools-extra.

Addresses PR40999 https://bugs.llvm.org/show_bug.cgi?id=40999

Private fields and methods  in javasceipt would get incorrectly indented (it sees them as preprocessor directives and hence left aligns them)

In this revision  "#identifier" tokens  tok::hash->tok::identifier are merged into a single new token
tok::identifier with the '#' contained inside the TokenText

  class Example {
    pub = 1;
  #priv = 2;
  
    static pub2 = "foo";
    static #priv2 = "bar";
  
    method() { this.#priv = 5; }
  
    static staticMethod() {
      switch (this.#priv) {
      case '1':
  #priv = 3;
        break;
      }
    }
  
  #privateMethod() {
    this.#privateMethod(); // infinite loop
  }
  
  static #staticPrivateMethod() {}
  }

After this fix the code will be correctly indented

  class Example {
    pub = 1;
    #priv = 2;
  
    static pub2 = "foo";
    static #priv2 = "bar";
  
    method() { this.#priv = 5; }
  
    static staticMethod() {
      switch (this.#priv) {
      case '1':
        #priv = 3;
        break;
      }
    }
  
    #privateMethod() {
      this.#privateMethod(); // infinite loop
    }
  
    static #staticPrivateMethod() {}
  }



NOTE: There might be some Javascript code out there which uses the C processor to preprocess .js files http://www.nongnu.org/espresso/js-cpp.html,  Its not clear how this revision or even private fields and methods would interact.


https://reviews.llvm.org/D59292

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/unittests/Format/FormatTestJS.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59292.190391.patch
Type: text/x-patch
Size: 3926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190313/81ac5988/attachment.bin>


More information about the llvm-commits mailing list