jsfiddle / jsfiddle-users

Discussions, issues and docs for JSFiddle.
https://jsfiddle.net
314 stars 114 forks source link

Operators containing questionmarks not properly supported #1860

Closed pirasleandro closed 6 months ago

pirasleandro commented 6 months ago

In JavaScript mode, when using any of the operators that contain a question mark (??, ??=, and .?), the editor displays them as a syntax error, even though I can run the code without any issues. In Typescript mode, the operators are syntax-highlighted correctly.

image result: { ... }, "5" link to fiddle

Whether in JavaScript or Typescript mode, the formatter introduces additional spaces around each question mark, breaking all of the obove named operators. This is especially confusing when using Typescript, since it's not highlighted as syntax error. The same applies to < and >, rendering generic type declarations in Typescript less readable.

before:

let foo;
foo ??= {};
let bar = null ?? 5;
let baz = new Array<number>();
console.log(foo, bar?.toString(), baz);

after:

let foo;
foo ? ? = {};
let bar = null ? ? 5;
let baz = new Array < number > ();
console.log(foo, bar ? .toString(), baz);
oskarkrawczyk commented 6 months ago

In JavaScript mode, when using any of the operators that contain a question mark (??, ??=, and .?), the editor displays them as a syntax error, even though I can run the code without any issues.

All seems fine as far as I can see:

Screenshot 2024-05-07 at 11 36 19

Same when TypeScript is selected:

Screenshot 2024-05-07 at 11 38 57

Cannot replicate what you're seeing so closing until more details are provided.