Skip to content

Optional chaining (?.) in code causes error #38

@culhantr

Description

@culhantr

Installed product versions

  • Visual Studio: 2019 Professional 16.9.5
  • This extension: 2.1.47

Description

Running Prettier on a file that includes the Optional chaining operator (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) causes a syntax error

Steps to recreate

  1. Create a file which uses the optional chaining operator (Note: My file is .tsx - not sure if this is relevant)
  2. Run Prettier

Current behavior

The file is not prettified and there is an error in the Output:

11/17/2021 11:18:07 AM: [error] stdin: SyntaxError: Expression expected. (146:20)
[error]   144 |         (c) =>
[error]   145 |           c.value &&
[error] > 146 |           (c.value?.toString() === value ||
[error]       |                    ^
[error]   147 |             parseFloat(c.value?.toString()) === parseFloat(value))
[error]   148 |       ) !== index
[error]   149 |     ) {

(Because I'm not sure the text will line up properly here, I want to point out that in the output the caret is pointing to the period after the question mark in "(c.value?.toString()")

Expected behavior

Prettier properly parses the code and makes it pretty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions