emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/js2-mode 7480c79691: Recognize escaped $ inside templat


From: ELPA Syncer
Subject: [elpa] externals/js2-mode 7480c79691: Recognize escaped $ inside template literal
Date: Sun, 9 Oct 2022 18:57:42 -0400 (EDT)

branch: externals/js2-mode
commit 7480c796917a18d7236414ce3cdf44b5be578d2a
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    Recognize escaped $ inside template literal
    
    Fixes #592
---
 NEWS.md         |  5 +++++
 js2-mode.el     | 11 ++++++-----
 tests/parser.el |  3 +++
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index 09f4993fb7..15b276a867 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,10 @@
 # History of user-visible changes
 
+## Next
+
+* Fix for escaping inside template literal
+  ([#592](https://github.com/mooz/js2-mode/issues/592)).
+
 ## 2022-07-10
 
 * Fix for node position of `js2-new-node`
diff --git a/js2-mode.el b/js2-mode.el
index 15662f6b20..754c6d15b0 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -6341,15 +6341,16 @@ its relevant fields and puts it into `js2-ti-tokens'."
     (catch 'break
       (while (/= c quote-char)
         (catch 'continue
-          (when (eq c js2-EOF_CHAR)
+          (cond
+           ((eq c js2-EOF_CHAR)
             (js2-unget-char)
             (js2-report-error "msg.unterminated.string.lit")
             (throw 'break nil))
-          (when (and (eq c ?\n) (not (eq quote-char ?`)))
+           ((and (eq c ?\n) (not (eq quote-char ?`)))
             (js2-unget-char)
             (js2-report-error "msg.unterminated.string.lit")
             (throw 'break nil))
-          (when (eq c ?\\)
+           ((eq c ?\\)
             ;; We've hit an escaped character
             (setq c (js2-get-char))
             (cl-case c
@@ -6427,10 +6428,10 @@ its relevant fields and puts it into `js2-ti-tokens'."
                            c (js2-get-char))))
                  (js2-unget-char)
                  (setq c val)))))
-          (when (and (eq quote-char ?`) (eq c ?$))
+           ((and (eq quote-char ?`) (eq c ?$))
             (when (eq (setq nc (js2-get-char)) ?\{)
               (throw 'break nil))
-            (js2-unget-char))
+            (js2-unget-char)))
           (js2-add-to-string c)
           (setq c (js2-get-char)))))
     (js2-set-string-from-buffer token)
diff --git a/tests/parser.el b/tests/parser.el
index 015eb02768..8233d00044 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -995,6 +995,9 @@ the test."
 (js2-deftest-parse tagged-template
   "foo.args`${++x, \"o\"}k`;")
 
+(js2-deftest-parse template-with-escapes
+  "const valid = `\\${${a}}`;")
+
 ;;; Classes
 
 (js2-deftest-parse parse-harmony-class-statement



reply via email to

[Prev in Thread] Current Thread [Next in Thread]