atom / language-javascript

JavaScript language package for Atom
Other
194 stars 237 forks source link

Nullish Coalescing Operator (??) #680

Open Ephellon opened 3 years ago

Ephellon commented 3 years ago

Prerequisites

Description

Atom does not take ?? (Nullish Coalescing Operator) into account when highlighting/folding

Steps to Reproduce

  1. Use the JavaScript syntax highlighter
  2. Copy/Paste

    // ...
    // Notifications
    NOTIFICATIONS = $('[data-test-selector="onsite-notifications-toast-manager"i] [data-test-selector^="onsite-notification-toast"i]', true).map(
    element => {
        let streamer = {
            live: true,
            href: $('a', false, element)?.href,
            icon: $('figure img', false, element)?.src,
            name: $('figure img', false, element)?.alt,
        };
    
        if(!defined(streamer.name))
            return;
    
        element.setAttribute('draggable', true);
        element.setAttribute('twitch-tools-streamer-data', JSON.stringify(streamer));
        element.ondragstart ??= event => {
            let { currentTarget } = event;
    
            event.dataTransfer.setData('application/twitch-tools-streamer', currentTarget.getAttribute('twitch-tools-streamer-data'));
            event.dataTransfer.dropEffect = 'move';
        };
    }
    );
    // ...
  3. Attempt to fold line 17 (it should be matched with line 22 but isn't)

Expected Behavior

  1. The JavaScript syntax highlighter should distinguish between ?? and ? ...: ...
  2. The highlighter should also allow the correct code-folding for ??

Actual Behavior

  1. The syntax highlighter ignores ?? and treats it as ? ...: ...
  2. Code-folding currently mismatches {} [] and () due to it thinking ??? ...: ...

Reproduces how often:

100%

Versions

Additional Information

Screenshots

Incorrect pair being matched (line 17line 23)

image

Correct pair being matched (line 17line 22)

image

Emrio commented 3 years ago

This also breaks syntax highlighting in Javascript and Typescript (although people may say true developers do not need syntax highlighting, seeing the wrong colors is disturbing xD)

Bildschirmfoto 2021-08-20 um 00 51 23
djcaesar9114 commented 2 years ago

Will this be solved in a future release? I'm considering using VisualStudio because the syntax highlighting in Atom becomes ugly when using xxx ?? yyy or xxx?.yyy