Bug 393633 - kwrite javascript syntax highlighting incorrectly displays as regex
Summary: kwrite javascript syntax highlighting incorrectly displays as regex
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-29 08:33 UTC by Cyp
Modified: 2018-08-23 10:46 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
screenshot of testcase (26.86 KB, image/png)
2018-04-29 08:33 UTC, Cyp
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Cyp 2018-04-29 08:33:30 UTC
Created attachment 112304 [details]
screenshot of testcase

Using javascript syntax highlighting and dividing an identifier ending in a non-ascii character by something, the / is interpreted as the start of a regex.

Testcase, the / in δ/113 is interpreted as the start of a regex:

let regex = /hello.*(world|universe)?/;
let i = 22;
let j = i/7;
let δ = 355;
 let k = δ/113;
let m = 42;
let regex2 = /hello.*(world|universe)?/;
let ouch = true;
Comment 1 Nibaldo G. 2018-08-23 10:46:58 UTC
Git commit ddc165f1bca8e9b74d4f3379affacbc7266f6d1a by Nibaldo González.
Committed on 23/08/2018 at 10:46.
Pushed by ngonzalez into branch 'master'.

JavaScript: add binaries, fix octals, improve escapes & allow Non-ASCII identifiers

Summary:
**Changes:**

* Add binaries: `0b0101` [1]
* Fix octals: the format of octals supported is: `0o1717`, but the HlCOct rule is equivalent to `01717`. [1]
* Improve escapes [2]: HlCStringChar rule does not contain the exact escapes supported by JavaScript:
	* The reserved character escapes are `'"\bfnrtv0`. These are now highlighted in bold (itemData: "Reserved Char. Escape").
	* Hexadecimal escapes in JS only support 2 numbers: `\xNN`, but HlCStringChar admits 1 or 2.
	* The maximum value of octal escape is `\377` (255 in decimal). For example, when typing `\477`, it's only considered as an escape: `\47`.
	* Any character can be escaped (previously, in the templates, the special character "$" for substitutions is not escaped).
* In "JavaScript React" the context "Conditional Expression", which is unnecessary, is eliminated to simplify the code.

* Add identifiers with Non-ASCII characters [3], to avoid highlighting RegExp and numbers after non-ASCII characters. This also applies to the highlighting of objects, functions and JSON properties.

**References:**
* [1] Standard ECMA-262, ECMAScript 2015 Language Specification. [11.8.3] Numeric Literals: https://ecma-international.org/ecma-262/6.0/#sec-literals-numeric-literals
* [2] Standard ECMA-262, ECMAScript 2015 Language Specification. [11.8.4] String Literals: https://ecma-international.org/ecma-262/6.0/#sec-literals-string-literals
* [3] Valid JavaScript variable names in ES2015: https://mathiasbynens.be/notes/javascript-identifiers-es6

Reviewers: dhaumann, cullmann, #framework_syntax_highlighting

Reviewed By: cullmann, #framework_syntax_highlighting

Subscribers: kwrite-devel

Tags: #kate, #frameworks

Differential Revision: https://phabricator.kde.org/D13888

M  +8    -0    autotests/folding/test.js.fold
M  +5    -5    autotests/folding/test.jsx.fold
M  +8    -0    autotests/html/test.js.html
M  +8    -0    autotests/input/test.js
M  +9    -1    autotests/reference/test.js.ref
M  +1    -1    autotests/reference/test.qml.ref
M  +11   -13   data/syntax/javascript-react.xml
M  +35   -16   data/syntax/javascript.xml

https://commits.kde.org/syntax-highlighting/ddc165f1bca8e9b74d4f3379affacbc7266f6d1a