Skip to content

[Bug]: preset-typescript + plugin-proposal-class-properties tries to assign statics to ambient declarations #13853

@forivall

Description

@forivall

💻

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

Babel REPL

declare class Foo {
  static bar;
}

Configuration file name

babel.config.js

Configuration

module.exports = {
  compact: false,
  presets: [
    ['@babel/preset-typescript'],
  ],
  plugins: [
    '@babel/plugin-proposal-class-properties',
  ],
}

Current and expected behavior

Current behaviour: (omitting helpers - happens with import-helpers or when they are inline.)

_defineProperty(Foo, "bar", void 0);

Expected behaviour:

// no "defineProperty" for the static class prop

Environment

  • System:
    • OS: macOS 10.15.7
  • Binaries:
    • Node: 16.9.1 - ~/.nvm/versions/node/v16.9.1/bin/node
    • Yarn: 3.0.0 - /usr/local/bin/yarn
    • npm: 7.21.1 - ~/.nvm/versions/node/v16.9.1/bin/npm
  • Monorepos:
    • Yarn Workspaces: 3.0.0
  • npmPackages:
    • eslint: ^7.30.0 => 7.30.0
    • jest: ^27.0.6 => 27.2.5
    • webpack: ^5.52.0 => 5.58.1

Possible solution

Either bail out of the Class visitor in @babel/helper-create-class-features-plugin when the class is annotated with declare, or ensure that the typescript transform in an earlier different plugin pass than the class features plugin so that the fields init nodes. I'll be submitting a PR for the first option momentarily.

Additional context

No response

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