Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support class static blocks (stage-4) #15016

Closed
35 of 36 tasks
aladdin-add opened this issue Sep 1, 2021 · 12 comments
Closed
35 of 36 tasks

support class static blocks (stage-4) #15016

aladdin-add opened this issue Sep 1, 2021 · 12 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint new syntax This issue is related to new syntax that has reached stage 4

Comments

@aladdin-add
Copy link
Member

aladdin-add commented Sep 1, 2021

What is the name of the syntax to implement?
class static blocks

Please provide the TC39 URL for the syntax proposal:
https://github.com/tc39/proposal-class-static-block

Please provide some example code for the new syntax:

// with static blocks:
class C {
  static x = ...;
  static y;
  static z;
  static {
    try {
      const obj = doSomethingWith(this.x);
      this.y = obj.y;
      this.z = obj.z;
    }
    catch {
      this.y = ...;
      this.z = ...;
    }
  }
}

Implementation Checklist

Please check off all items that have already been completed. Be sure to paste the pull request URLs next to each item so we can verify the work as done.

Are you willing to submit a pull request to implement this syntax?
y

@aladdin-add aladdin-add added core Relates to ESLint's core APIs and features new syntax This issue is related to new syntax that has reached stage 4 labels Sep 1, 2021
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Sep 1, 2021
@aladdin-add aladdin-add changed the title support class static initialization blocks(stage-4) support class static blocks (stage-4) Sep 1, 2021
@nzakas nzakas moved this from Needs Triage to Blocked in Triage Sep 2, 2021
@nzakas nzakas pinned this issue Sep 2, 2021
@nzakas
Copy link
Member

nzakas commented Sep 2, 2021

This looks like it will need a new scope in eslint-scope and a new code path type.

@mdjermanovic
Copy link
Member

This looks like it will need a new scope in eslint-scope and a new code path type.

Yes, I think the same.

@nzakas nzakas added this to Planned in Public Roadmap via automation Sep 4, 2021
@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint labels Sep 14, 2021
aladdin-add added a commit to eslint/espree that referenced this issue Sep 16, 2021
acorn has been upgraded in ee1d3ec, this commit
simiply added some tests. The tests were copied from test262, refs: tc39/test262@afe217b
aladdin-add added a commit to eslint/espree that referenced this issue Sep 16, 2021
acorn has been upgraded in ee1d3ec, this commit
simiply added some tests. The tests were copied from test262, refs: tc39/test262@afe217b
aladdin-add added a commit to eslint/espree that referenced this issue Sep 16, 2021
acorn has been upgraded in ee1d3ec, this commit
simiply added some tests. The tests were copied from test262, refs: tc39/test262@afe217b
aladdin-add added a commit to eslint/espree that referenced this issue Sep 16, 2021
acorn has been upgraded in ee1d3ec, this commit
simiply added some tests. The tests were copied from test262, refs: tc39/test262@afe217b
@aladdin-add aladdin-add moved this from Blocked to Ready to Implement in Triage Sep 27, 2021
@mdjermanovic
Copy link
Member

I unchecked espree because it also re-exports visitor keys. I don't think we're using espree.VisitorKeys in ESLint, but espree itself would be incomplete without updating eslint-visitor-keys dependency.

@mdjermanovic
Copy link
Member

I added an initial list of rules that should be updated. A couple of them may need only docs/tests update. Note that class static blocks do not have directive prologue.

mdjermanovic added a commit that referenced this issue Nov 10, 2021
Class static blocks are implicit functions. Therefore, they should be treated as separate code paths. This adds `class-static-block` code paths. Each `StaticBlock` node will start a new `class-static-block` code path.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 10, 2021
Updates `omitLastInOneLineBlock` option to apply to class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 11, 2021
Updates the `no-extra-semi` rule to report semicolons after class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 17, 2021
Updates the `no-redeclare` rule to report redeclarations in class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 17, 2021
Fixes false positives at the top level of class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 17, 2021
Fixes false negatives at the top level of class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 17, 2021
Class static blocks are implicit functions. Therefore, they should be treated as separate code paths. This adds `class-static-block` code paths. Each `StaticBlock` node will start a new `class-static-block` code path.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 17, 2021
Updates the `complexity` rule to apply to class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 18, 2021
Updates the `padded-blocks` rule to apply to class static blocks.

Refs #15016
@mdjermanovic mdjermanovic moved this from Ready to Implement to Pull Request Opened in Triage Nov 18, 2021
mdjermanovic added a commit that referenced this issue Nov 18, 2021
Fixes false negatives at the top level of class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 19, 2021
Updates the `max-statements` rule so that it does not apply to class static blocks and does not count statements in them as statements in the enclosing function.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 19, 2021
* feat: update brace-style for class static blocks

Updates the `brace-style` rule to apply to braces of class static blocks.

Refs #15016

* Add note about indentation
mdjermanovic added a commit that referenced this issue Nov 19, 2021
Updates the `lines-around-comment` rule so that options `"allowBlockStart"` and `"allowBlockEnd"` apply to class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 19, 2021
Updates the `indent` rule to apply to class static blocks.

Adds `StaticBlock.body` option that enforces indentation level for the body of a class static block.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 19, 2021
Updates the `complexity` rule to apply to class static blocks.

Refs #15016
mdjermanovic added a commit that referenced this issue Nov 19, 2021
Updates the `padded-blocks` rule to apply to class static blocks.

Refs #15016
btmills pushed a commit that referenced this issue Nov 21, 2021
Updates the `max-depth` rule to treat class static blocks as separate contexts when calculating depth.

Refs #15016
btmills pushed a commit that referenced this issue Nov 21, 2021
Updates the `no-inner-declarations` rule to allow declarations at the top level of class static blocks.

Refs #15016
btmills pushed a commit that referenced this issue Nov 21, 2021
Updates the `no-redeclare` rule to report redeclarations in class static blocks.

Refs #15016
btmills pushed a commit that referenced this issue Nov 21, 2021
Fixes false positive in the `semi-style` rule: the last statement in a class static block should be allowed to have its semicolon on the same line when the option is `first`.

Refs #15016
btmills pushed a commit that referenced this issue Nov 21, 2021
Fixes the `vars-on-top` rule to allow `var` declarations at the top of class static blocks.

Refs #15016
btmills pushed a commit that referenced this issue Nov 21, 2021
Updates logic related to class definition evaluation with class static blocks.

Refs #15016
@btmills
Copy link
Member

btmills commented Nov 21, 2021

All currently-known work to implement class static blocks just shipped in ESLint v8.3.0!

@btmills btmills closed this as completed Nov 21, 2021
Public Roadmap automation moved this from Planned to Complete Nov 21, 2021
Triage automation moved this from Pull Request Opened to Complete Nov 21, 2021
@btmills btmills unpinned this issue Nov 21, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators May 21, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint new syntax This issue is related to new syntax that has reached stage 4
Projects
Public Roadmap
  
Complete
Archived in project
Triage
Complete
Development

No branches or pull requests

5 participants