Skip to content

No error thrown for a declare class field that have an initializer #12092

@sosukesuzuki

Description

@sosukesuzuki

Bug Report

  • I would like to work on a fix!

Current behavior

REPL

No error is thrown from parser. We can find an error message for this from source code(ref:

"'declare' class fields cannot have an initializer",
) but it isn't thrown.

We have a test for this but I think it is wrong because the AST have no errors (ref: https://github.com/babel/babel/blob/3628c528676a91cd95bb00d56f799be53185e316/packages/babel-parser/test/fixtures/typescript/class/declare-field-initializer/output.json)

Input Code

class A {
  declare bar: string = "test";
}

Expected behavior
It throw a syntax error "'declare' class fields cannot have an initializer".

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

parse(code, {  plugins: ["typescript", "classProperties"] });

Environment

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