Skip to content

"optional" does not exist on computed optional class property with variable #1019

Closed
@sosukesuzuki

Description

@sosukesuzuki

(This issue related on prettier/prettier#6569)

What code were you trying to parse?

// Put your code here
const bar = "bar";
class Foo {
    [bar]?;
}

What did you expect to happen?

{
  "type": "ClassProperty",
  "key": {
    "type": "Identifier",
    "name": "bar",
    "range": [36, 39],
    "loc": {
      "start": {
        "line": 4,
        "column": 5
      },
      "end": {
        "line": 4,
        "column": 8
      }
    }
  },
  "value": null,
  "computed": true,
  "static": false,
  "range": [35, 42],
  "loc": {
    "start": {
      "line": 4,
      "column": 4
    },
    "end": {
      "line": 4,
      "column": 11
    }
  },
  "optional": true // This "optional" should exist
}

What actually happened?

{
  "type": "ClassProperty",
  "key": {
    "type": "Identifier",
    "name": "bar",
    "range": [36, 39],
    "loc": {
      "start": {
        "line": 4,
        "column": 5
      },
      "end": {
        "line": 4,
        "column": 8
      }
    }
  },
  "value": null,
  "computed": true,
  "static": false,
  "range": [35, 42],
  "loc": {
    "start": {
      "line": 4,
      "column": 4
    },
    "end": {
      "line": 4,
      "column": 11
    }
  }
}

It works fine for computed optional properties that do not use variables.

class Foo {
  ["bar"]?;
  [1]?;
}

Versions

package version
@typescript-eslint/typescript-estree 2.3.1
TypeScript 3.4.1
node 12.10.0
npm 6.11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas prthere is a PR raised to close thispackage: typescript-estreeIssues related to @typescript-eslint/typescript-estree

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions