tree-sitter-javascript icon indicating copy to clipboard operation
tree-sitter-javascript copied to clipboard

Static class initialization block

Open madmoizo opened this issue 2 years ago • 2 comments

The following piece of code is valid but it is parsed incorrectly:

The random parsing seems to be a combination of export, static class initialization block and comments.

export class Incorrect {
  static {
    this.foo = true
    this.bar = false
    this.hello = 1
    this.init()
  }
}
export class Incorrect {
  static {
    this.foo= true
    this.bar = false
    this.init()
    this.hello = 1
  }
}
export class Correct {
  static {
    this.foo= true
    this.bar = false
    this.init()
    this.hello = 1
  }
}
export class Incorrect {
  static {
    // This comment affects parsing
    this.foo= true
    this.bar = false
    this.init()
    this.hello = 1
  }
}
// This comment affects parsing
export class Incorrect {
  static {
    this.foo= true
    this.bar = false
    this.init()
    this.hello = 1
  }
}

Functions call only

export class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}
export class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}
export class Incorrect {
  static {
    // This comment affects parsing
    this.init()
    this.init()
    this.init()
  }
}
// This comment does not affects parsing (which is already incorrect)
export class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}

Functions call only no export

class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}
class Correct {
  static {
    this.init()
    this.init()
    this.init()
  }
}
class Incorrect {
  static {
    // This comment does not affects parsing (which is already incorrect)
    this.init()
    this.init()
    this.init()
  }
}
// This comment does not affects parsing (which is already incorrect)
class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}

madmoizo avatar May 26 '22 14:05 madmoizo

Can you drop a link to where this language feature is described in the spec, or somewhere official?

maxbrunsfeld avatar May 31 '22 21:05 maxbrunsfeld

https://tc39.es/ecma262/multipage/ecmascript-language-functions-and-classes.html#prod-ClassStaticBlock

madmoizo avatar Jun 01 '22 00:06 madmoizo

You closed the issue, I assumed it was solved but may you explain why the parsing is still incorrect on my initial post?

madmoizo avatar Feb 23 '23 06:02 madmoizo