summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>2019-04-08 07:47:37 -0700
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>2019-04-08 22:48:24 -0700
commit3eadf1eff43c84a1095094334549a1e0d1e75d80 (patch)
tree5685d1280968cf57b35c7aeb642370a29962fe61 /lisp
parente48306f84f1aeb4409cc02ae864f33e7af657288 (diff)
downloademacs-3eadf1eff43c84a1095094334549a1e0d1e75d80.tar.gz
Identify JSX strings (for js2-mode)
* lisp/progmodes/js.el (js-jsx--syntax-propertize-tag): Derived modes like js2-mode may use font-lock-syntactic-face-function to apply faces to JSX strings (and only JSX strings). Apply the js-jsx-string text property to such strings so they can be distinctly identified. (js-jsx--text-properties): Ensure the js-jsx-string text property gets cleaned up, too.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/js.el13
1 files changed, 9 insertions, 4 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index a1de3ef7959..b1068bfc7b8 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -2165,9 +2165,14 @@ testing for syntax only valid as JSX."
;; JSXExpressionContainer here will be parsed in the
;; next iteration of the loop.
(if (memq (char-after) '(?\" ?\' ?\`))
- (condition-case nil
- (forward-sexp)
- (scan-error (throw 'stop nil)))
+ (progn
+ ;; Record the string’s position so derived modes
+ ;; applying syntactic fontification atypically
+ ;; (e.g. js2-mode) can recognize it as part of JSX.
+ (put-text-property (point) (1+ (point)) 'js-jsx-string t)
+ (condition-case nil
+ (forward-sexp)
+ (scan-error (throw 'stop nil))))
;; Save JSXAttribute’s beginning in case we find a
;; JSXExpressionContainer as the JSXAttribute’s value which
;; we should associate with the JSXAttribute.
@@ -2195,7 +2200,7 @@ testing for syntax only valid as JSX."
(defconst js-jsx--text-properties
(list
'js-jsx-tag-beg nil 'js-jsx-tag-end nil 'js-jsx-close-tag-pos nil
- 'js-jsx-tag-name nil 'js-jsx-attribute-name nil
+ 'js-jsx-tag-name nil 'js-jsx-attribute-name nil 'js-jsx-string nil
'js-jsx-text nil 'js-jsx-expr nil 'js-jsx-expr-attribute nil)
"Plist of text properties added by `js-syntax-propertize'.")