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

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

[elpa] master d82f357 199/271: Merge branch 'feature/name-nodes' into de


From: Jackson Ray Hamilton
Subject: [elpa] master d82f357 199/271: Merge branch 'feature/name-nodes' into develop
Date: Thu, 05 Feb 2015 18:31:11 +0000

branch: master
commit d82f357968c13f98afaef37593ed8dbec7b3cc2f
Merge: eba74ae 1f06301
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Merge branch 'feature/name-nodes' into develop
---
 context-coloring.el              |   20 ++++++-----------
 test/context-coloring-test.el    |   43 ++++++++++++++++++++++++++++++++++++-
 test/fixtures/key-names.js       |    6 +++++
 test/fixtures/property-lookup.js |    5 ++++
 4 files changed, 59 insertions(+), 15 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index ea62a28..283bddd 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -227,6 +227,7 @@ END (exclusive) with the face corresponding to LEVEL."
 
 ;;; js2-mode colorization
 
+;; TODO: Consider `js2-node-top-level-decl-p' as an optimization.
 (defsubst context-coloring-js2-scope-level (scope)
   "Gets the level of SCOPE."
   (let ((level 0)
@@ -243,23 +244,16 @@ END (exclusive) with the face corresponding to LEVEL."
       (setq scope enclosing-scope))
     level))
 
-;; Adapted from js2-refactor.el/js2r-vars.el.
-;; FIXME: This fails if there is whitespace between the name and the colon.
 (defsubst context-coloring-js2-local-name-node-p (node)
   "Determines if NODE is a js2-name-node representing a local
 variable."
   (and (js2-name-node-p node)
-       (let ((start (js2-node-abs-pos node)))
-         (and
-          (let ((end (+ start (js2-node-len node))))
-            (not (string-match "[\n\t ]*:" (buffer-substring-no-properties
-                                            end
-                                            (+ end 1)))))
-          (not (string-match "\\.[\n\t ]*" (buffer-substring-no-properties
-                                            (max 1 (- start 1)) ; 0 throws an
-                                                                ; error. "" 
will
-                                                                ; fail the 
test.
-                                            start)))))))
+       (let ((parent (js2-node-parent node)))
+         (not (or (js2-object-prop-node-p parent)
+                  (and (js2-prop-get-node-p parent)
+                       ;; For nested property lookup, the node on the left is a
+                       ;; `js2-prop-get-node', so this always works.
+                       (eq node (js2-prop-get-node-right parent))))))))
 
 (defsubst context-coloring-js2-colorize-node (node level)
   "Colors NODE with the color for LEVEL."
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 88b556e..3fa7953 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -94,8 +94,8 @@ invoke when it is done."
                                                                          
(match-beginning 1)
                                                                          
(match-end 1))))
                          (= level actual-level)))))
-          (ert-fail (format "Expected level at point %s to be %s; was %s"
-                            point level actual-level))))
+          (ert-fail (format "Expected level in region [%s, %s), which is 
\"%s\", to be %s; but at point %s, it was %s"
+                            start end (buffer-substring-no-properties start 
end) level point actual-level))))
       (setq i (+ i 1)))))
 
 (defun context-coloring-test-assert-message (expected)
@@ -196,4 +196,43 @@ invoke when it is done."
    "./fixtures/catch.js"
    (context-coloring-test-js-catch)))
 
+(defun context-coloring-test-js-key-names ()
+  (context-coloring-test-assert-region-level 20 63 1))
+
+(ert-deftest-async context-coloring-test-js-mode-key-names (done)
+  (context-coloring-test-js-mode
+   "./fixtures/key-names.js"
+   (lambda (teardown)
+     (unwind-protect
+         (context-coloring-test-js-key-names)
+       (funcall teardown))
+     (funcall done))))
+
+(ert-deftest context-coloring-test-js2-mode-key-names ()
+  (context-coloring-test-js2-mode
+   "./fixtures/key-names.js"
+   (context-coloring-test-js-key-names)))
+
+(defun context-coloring-test-js-property-lookup ()
+  (context-coloring-test-assert-region-level 20 26 0)
+  (context-coloring-test-assert-region-level 26 38 1)
+  (context-coloring-test-assert-region-level 38 44 0)
+  (context-coloring-test-assert-region-level 44 52 1)
+  (context-coloring-test-assert-region-level 57 63 0)
+  (context-coloring-test-assert-region-level 63 74 1))
+
+(ert-deftest-async context-coloring-test-js-mode-property-lookup (done)
+  (context-coloring-test-js-mode
+   "./fixtures/property-lookup.js"
+   (lambda (teardown)
+     (unwind-protect
+         (context-coloring-test-js-property-lookup)
+       (funcall teardown))
+     (funcall done))))
+
+(ert-deftest context-coloring-test-js2-mode-property-lookup ()
+  (context-coloring-test-js2-mode
+   "./fixtures/property-lookup.js"
+   (context-coloring-test-js-property-lookup)))
+
 (provide 'context-coloring-test)
diff --git a/test/fixtures/key-names.js b/test/fixtures/key-names.js
new file mode 100644
index 0000000..d8ad17c
--- /dev/null
+++ b/test/fixtures/key-names.js
@@ -0,0 +1,6 @@
+(function () {
+    return {
+        a: 0,
+        b : 2
+    };
+}());
diff --git a/test/fixtures/property-lookup.js b/test/fixtures/property-lookup.js
new file mode 100644
index 0000000..4edcb41
--- /dev/null
+++ b/test/fixtures/property-lookup.js
@@ -0,0 +1,5 @@
+(function () {
+    window.foo();
+    window. bar();
+    window.foo.bar();
+}());



reply via email to

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