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 - ES6 String Templates: Incorrect parsing & syntax highlighting for a placeholder expression containing an Object literal.
Summary: ES6 String Templates: Incorrect parsing & syntax highlighting for a placehold...
Status: RESOLVED WORKSFORME
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.2
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-25 11:09 UTC by akaScooter
Modified: 2016-10-27 13:47 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Screencaps of current (incorrect) highlighting vs correct highlighting (12.06 KB, image/png)
2016-10-25 11:09 UTC, akaScooter
Details
Screencap of mismatched brackets due to incorrect parsing (5.98 KB, image/png)
2016-10-25 12:43 UTC, akaScooter
Details

Note You need to log in before you can comment on or make changes to this bug.
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.