[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() {
+
+ }
+}
- [elpa] master fb53884 17/28: Update README., (continued)
- [elpa] master fb53884 17/28: Update README., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 52da59c 18/28: Bust cache., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 3f63fab 11/28: Add local coverage configuration., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 158fd83 16/28: Test the trimming function., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 0c20edf 14/28: Add coverage for missing lines., Jackson Ray Hamilton, 2015/05/05
- [elpa] master d116055 12/28: Fix original-maximum-face restoration bug., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 1b6f6fb 21/28: Cleanup README., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 5dd3035 19/28: Refactor trim functions., Jackson Ray Hamilton, 2015/05/05
- [elpa] master f8cfd37 22/28: Double-space., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 64852e7 24/28: Update library headers., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 55ca15a 23/28: Guard against excessively lenghty nodes.,
Jackson Ray Hamilton <=
- [elpa] master 8f1af4a 20/28: Update library header., Jackson Ray Hamilton, 2015/05/05
- [elpa] master dbddc45 26/28: Reimplement coverage reporter in elisp., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 6ee3f82 25/28: Refactor coverage., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 283a006 27/28: Version 6.2.1., Jackson Ray Hamilton, 2015/05/05
- [elpa] master 8a083d5 28/28: Merge commit '283a006be8e96c7e011dedddb460b289d335a9fb' from context-coloring, Jackson Ray Hamilton, 2015/05/05