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

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

[elpa] master 55ca15a 23/28: Guard against excessively lenghty nodes.


From: Jackson Ray Hamilton
Subject: [elpa] master 55ca15a 23/28: Guard against excessively lenghty nodes.
Date: Tue, 05 May 2015 11:10:25 +0000

branch: master
commit 55ca15a37bf816abdc63b02d2ea6f24e835dd2df
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Guard against excessively lenghty nodes.
---
 context-coloring.el                   |   69 ++++++++++++++++++---------------
 test/context-coloring-test.el         |    6 +++
 test/fixtures/unterminated-comment.js |    6 +++
 3 files changed, 50 insertions(+), 31 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index d7071c9..c55e6e3 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -244,47 +244,54 @@ variable."
                        ;; `js2-prop-get-node', so this always works.
                        (eq node (js2-prop-get-node-right parent))))))))
 
+(defvar-local context-coloring-point-max nil
+  "Cached value of `point-max'.")
+
 (defsubst context-coloring-js2-colorize-node (node level)
   "Color NODE with the color for LEVEL."
   (let ((start (js2-node-abs-pos node)))
     (context-coloring-colorize-region
      start
-     (+ start (js2-node-len node)) ; End
+     (min
+      ;; End
+      (+ start (js2-node-len node))
+      ;; Somes nodes (like the ast when there is an unterminated multiline
+      ;; comment) will stretch to the value of `point-max'.
+      context-coloring-point-max)
      level)))
 
 (defun context-coloring-js2-colorize ()
   "Color the current buffer using the abstract syntax tree
 generated by `js2-mode'."
-  ;; Don't bother trying to color a mangled tree.
-  (when (= 0 (length js2-parsed-errors))
-    ;; Reset the hash table; the old one could be obsolete.
-    (setq context-coloring-js2-scope-level-hash-table (make-hash-table :test 
'eq))
-    (with-silent-modifications
-      (js2-visit-ast
-       js2-mode-ast
-       (lambda (node end-p)
-         (when (null end-p)
-           (cond
-            ((js2-scope-p node)
-             (context-coloring-js2-colorize-node
-              node
-              (context-coloring-js2-scope-level node)))
-            ((context-coloring-js2-local-name-node-p node)
-             (let* ((enclosing-scope (js2-node-get-enclosing-scope node))
-                    (defining-scope (js2-get-defining-scope
-                                     enclosing-scope
-                                     (js2-name-node-name node))))
-               ;; The tree seems to be walked lexically, so an entire scope 
will
-               ;; be colored, including its name nodes, before they are 
reached.
-               ;; Coloring the nodes defined in that scope would be redundant, 
so
-               ;; don't do it.
-               (when (not (eq defining-scope enclosing-scope))
-                 (context-coloring-js2-colorize-node
-                  node
-                  (context-coloring-js2-scope-level defining-scope))))))
-           ;; The `t' indicates to search children.
-           t)))
-      (context-coloring-maybe-colorize-comments-and-strings))))
+  ;; Reset the hash table; the old one could be obsolete.
+  (setq context-coloring-js2-scope-level-hash-table (make-hash-table :test 
'eq))
+  (setq context-coloring-point-max (point-max))
+  (with-silent-modifications
+    (js2-visit-ast
+     js2-mode-ast
+     (lambda (node end-p)
+       (when (null end-p)
+         (cond
+          ((js2-scope-p node)
+           (context-coloring-js2-colorize-node
+            node
+            (context-coloring-js2-scope-level node)))
+          ((context-coloring-js2-local-name-node-p node)
+           (let* ((enclosing-scope (js2-node-get-enclosing-scope node))
+                  (defining-scope (js2-get-defining-scope
+                                   enclosing-scope
+                                   (js2-name-node-name node))))
+             ;; The tree seems to be walked lexically, so an entire scope will
+             ;; be colored, including its name nodes, before they are reached.
+             ;; Coloring the nodes defined in that scope would be redundant, so
+             ;; don't do it.
+             (when (not (eq defining-scope enclosing-scope))
+               (context-coloring-js2-colorize-node
+                node
+                (context-coloring-js2-scope-level defining-scope))))))
+         ;; The `t' indicates to search children.
+         t)))
+    (context-coloring-maybe-colorize-comments-and-strings)))
 
 
 ;;; Shell command scopification / colorization
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 8600e06..e220954 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -985,6 +985,12 @@ see that function."
 (context-coloring-test-deftest-js2-mode syntactic-strings
   :fixture-name comments-and-strings)
 
+;; As long as `add-text-properties' doesn't signal an error, this test passes.
+(defun context-coloring-test-js-unterminated-comment ()
+  "Test unterminated multiline comments.")
+
+(context-coloring-test-deftest-js2-mode unterminated-comment)
+
 (provide 'context-coloring-test)
 
 ;;; context-coloring-test.el ends here
diff --git a/test/fixtures/unterminated-comment.js 
b/test/fixtures/unterminated-comment.js
new file mode 100644
index 0000000..94d4703
--- /dev/null
+++ b/test/fixtures/unterminated-comment.js
@@ -0,0 +1,6 @@
+function a() {
+    /*
+    function b() {
+
+    }
+}



reply via email to

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