Skip to content

Optional chaining suport in Javascript #34776

@zalishchuk

Description

@zalishchuk
  • VSCode Version: Code 1.16.1 (27492b6, 2017-09-14T16:24:39.530Z)
  • OS Version: Darwin x64 16.7.0
  • Extensions:
Extension Author (truncated) Version
EditorConfig Edi 0.10.1
sharecode Rol 0.4.1
vscode-caniuse aka 0.5.3
path-intellisense chr 1.4.2
vscode-eslint dba 1.3.2
python don 0.7.0
prettier-vscode esb 0.23.1
auto-rename-tag for 0.0.14
docthis joe 0.4.8
vscode-styled-components jpo 0.0.8
vscode-puglint mrm 2.3.0
atom-keybindings ms- 3.0.2
color-highlight nau 2.3.0
vetur oct 0.9.7
vscode-icons rob 7.13.0
vscode-nginx sha 0.3.1
language-stylus sys 1.7.3
vscode-todo-highlight way 0.5.11
JavaScriptSnippets xab 1.4.1

(3 theme extensions excluded)


Steps to Reproduce:

Support optional chaining syntax in javascript/javascriptreact languages.

Seems like VS Code parses ? as a ternary operator and expects : symbol further.

Screenshots:
Broken syntax
Works as it should

Code:

const a = {
  b: {
    c: {
      d: {
        e: 1,
        g: [1, 2, 3],
      },
    },
    f: null,
  },
};

const brokenSyntaxHighlighting = () => {
  const array = a?.b?.c?.d?.g;

  /**
   * No TypeEror, but syntax highlighting is broken
   */
  const test = a?.b?.f?.f;

  for (let i = 0; i < array.length; i++) {
    console.log(array[i]);
  }
};

brokenSyntaxHighlighting();

Reproduces without extensions: Yes

Metadata

Metadata

Assignees

Labels

grammarSyntax highlighting grammarjavascriptJavaScript support issuesupstreamIssue identified as 'upstream' component related (exists outside of VS Code)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions