Skip to content

Allow multiple class static block, and follow the document order #12979

@Kingwl

Description

@Kingwl

Bug Report

  • I would like to work on a fix!

Current behavior

According to https://github.com/tc39/proposal-class-static-block

A class may have any number of static {} initialization blocks in its class body.
static {} initialization blocks are evaluated in document order interleaved with static field initializers.

Input Code

class C {
  static  f = 1
  static { console.log(this.f, this.ff) }
  static ff = 2
  static { console.log(this.ff, this.fff) }
  static fff = 3
}

Expected behavior

Multiple block works fine. And the evaluate order follow the document order.

But currently:

Duplicate static block in the same class (5:2)

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "your": { "config": "here" }
}

Environment


  • Babel version(s): [e.g. v7.12.0]
  • Node/npm version: [e.g. Node 12/npm 7]
  • OS: [e.g. macOS 10.15.4, Windows 10]
  • Monorepo: [e.g. yes/no/Lerna]
  • How you are using Babel: [e.g. webpack, rollup, parcel, babel-register]

Possible Solution

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions