[gtksourceview/gtksourceview-4-2] language-specs: fix JS string templates
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gtksourceview-4-2] language-specs: fix JS string templates
- Date: Thu, 26 Sep 2019 22:30:02 +0000 (UTC)
commit e8af7bcba17b068af266d189ea6fe1525a4db861
Author: Nuno Martins <nunocastromartins protonmail com>
Date: Thu Sep 26 22:28:05 2019 +0000
language-specs: fix JS string templates
Fixes JS string templates with interpolations that contain other string
templates, e.g.:
```js
const str = `some ${a ? `a${aa}` : 'b'}`;
```
data/language-specs/javascript.lang | 9 ++++++++-
tests/syntax-highlighting/file.js | 11 +++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/data/language-specs/javascript.lang b/data/language-specs/javascript.lang
index 1ced13e7..d9627cbf 100644
--- a/data/language-specs/javascript.lang
+++ b/data/language-specs/javascript.lang
@@ -785,13 +785,20 @@
<keyword>public</keyword>
</context>
- <context id="template-string" style-ref="string">
+ <context id="template-string" style-ref="string" class="string" class-disabled="no-spell-check">
<start>`</start>
<end>`</end>
<include>
+ <context ref="escape"/>
+ <context ref="def:line-continue"/>
+
+ <!-- FIXME: syntax highlight should go back to none here -->
<context id="template-expression" style-ref="function">
<start>\$\{</start>
<end>\}</end>
+ <include>
+ <context ref="js:*"/>
+ </include>
</context>
</include>
</context>
diff --git a/tests/syntax-highlighting/file.js b/tests/syntax-highlighting/file.js
index 7897808a..df1cc72e 100644
--- a/tests/syntax-highlighting/file.js
+++ b/tests/syntax-highlighting/file.js
@@ -26,6 +26,8 @@ x = a /b/ c / d;
"\u00a9" // Unicode escape
'\u{1D306}' // Unicode code point escape
/\cJ/ // Control escape
+'\
+' // Newline escape
// ES2015 binary and octal numbers:
let binary1 = 0b1010;
@@ -41,7 +43,16 @@ let octal2 = 0O4567;
console.log(`The sum of 2 and 2 is ${2 + 2}`);
+// Interpolation inside interpolation
+let interp = `Hello ${
+ Math.random() > 0.5
+ ? 'World!'
+ : `${Math.random() > 0.5 ? 'Alice' : 'Bob'}!`
+}`;
+
let y = 8;
let my_string = `This is a multiline
string that also contains
a template ${y + (4.1 - 2.2)}`;
+let escaped = `\b\f\`\\\u00a8\u{12345}\
+`;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]