[gtksourceview] language-specs: fix JS string templates



commit ef4ac8c1a98346e64f12d03f1ff623061b209459
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 85ba01ea..42ba602d 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;
@@ -47,7 +49,16 @@ let bigIntConst = BigInt('1234513123123');
 
 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]