This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 268674

Summary: ES6 String Templates: Incorrect parsing & syntax highlighting for a placeholder expression containing an Object literal.
Product: javascript Reporter: akaScooter
Component: EditorAssignee: Petr Pisl <ppisl>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: P3    
Version: 8.2   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:
Attachments: Screencaps of current (incorrect) highlighting vs correct highlighting
Screencap of mismatched brackets due to incorrect parsing

Description akaScooter 2016-10-25 11:09:28 UTC
Created attachment 162624 [details]
Screencaps of current (incorrect) highlighting vs correct highlighting

When an Object literal is used within an ES6 template literal, the syntax highlighting indicating the embedded expression (within placeholder delimiters “${…}”) incorrectly stops at the closing brace of the expression's Object literal — not at the closing brace of the expression's placeholder delimiters — with the rest of the expression highlighted as a String.

Example:
    /**
     * @returns {String} source string with '<','>','&','"' replaced with their HTML/XML entities.
     */
1:    function h ( s )
2:    {
3:        return s.replace(/[<>&"]/g, function(c){
4:            return `&${{'<':'lt','>':'gt','&':'amp','"':'quot'}[c]};`;
5:        });
6:    }

template literal in line #4: String syntax incorrectly resumes with the opening bracket at “[c];”, but String syntax should not resume until after the final closing curly bracket of the expression placeholder's delimiters (only the final “;” character should be highlighted as String syntax).
Comment 1 akaScooter 2016-10-25 12:42:01 UTC
Just noticed: not just syntax highlighting — also syntax parsing. Causes mismatched brackets which create erroneous syntax errors later in code.
Comment 2 akaScooter 2016-10-25 12:43:12 UTC
Created attachment 162625 [details]
Screencap of mismatched brackets due to incorrect parsing
Comment 3 akaScooter 2016-10-25 13:01:14 UTC
Umm… after editing the file a bit more, then undoing all the changes to go back to the state at which this error appeared, the example I provided is now parsing perfectly correctly.

So uncertain now how to reproduce it.
Comment 4 Petr Pisl 2016-10-27 13:47:00 UTC
I can not reproduce it as well now. Marking as works for me, please reopen, if you run in it again. Thanks.