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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parcel throws error for static initialization blocks. #7838

Closed
sandyboon opened this issue Mar 17, 2022 · 0 comments 路 Fixed by #7839
Closed

Parcel throws error for static initialization blocks. #7838

sandyboon opened this issue Mar 17, 2022 · 0 comments 路 Fixed by #7839

Comments

@sandyboon
Copy link

馃悰 bug report

In the following class, I have a simple static initialization block that sets a static property. When I run parcel build, it throws compilation error, coming out of parcel transformer.

  export default class MyClass {
    static prop = "somevalue";
    static {
      console.log("I am in static block");
      MyClass.prop = "changing the val";
    }

    static printVal = () => {
    console.log(`Value is : ${MyClass.prop}`);
  };
}

The error being thrown is -
脳 Build failed.

@parcel/transformer-js: Unexpected token {. Expected identifier, string literal, numeric literal or [ for the computed key

C:\dev\parcelstatic\staticClass.js:4:10
3 |

4 | static {
| ^
5 | console.log("I am in static block");
6 | MyClass.prop = "changing the val";

馃帥 Configuration (.babelrc, package.json, cli command)

{
  "name": "parcelstatic",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "parcel build index.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel": "^2.3.2"
  }
}

馃 Expected Behavior

I should be able to use static initialization blocks.

馃槸 Current Behavior

Using static initialization blocks in your class breaks the build.

馃拋 Possible Solution

馃敠 Context

馃捇 Code Sample

馃實 Your Environment

Software Version(s)
Parcel 2.3.2
Node v14.18.1
npm/Yarn npm
Operating System Win 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant