Skip to content

Commit

Permalink
es6 function support closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktasia committed Apr 26, 2016
1 parent 320f336 commit 5313ef6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dumb-jump.el
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@
:regex "(service|factory)\\\((['\\\"])JJJ\\2" :tags ("angular")
:tests ("module.factory(\\'test\\', [\\'$rootScope\\', function($rootScope) {"))

(:type "function" :language "javascript"
:regex "\\bJJJ\\s*[=:]\\s*\\\([^\\\)]*\\\)\\s+\\=>" :tags ("es6")
:tests ("const test = (foo) => " "test: (foo) => {" " test: (foo) => {"))

(:type "function" :language "javascript"
:regex "\\bJJJ\\s*\\\([^\\\)]*\\\)\\s*{" :tags ("es6")
:tests ("test(foo) {" "test (foo){" "test(foo){"))

;; javascript
(:type "variable" :language "javascript"
:regex "\\s*\\bJJJ\\s*=[^=]+?$" :tests ("test = 1234") :not ("if (test === 1234)"))
Expand Down
25 changes: 25 additions & 0 deletions test/data/proj1/src/js/es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let funcName1 = (foo) => "bar";

const funcName2 = (foo) => "bar";

const funcName3 = (foo) => {
return "bar";
}

const obj = {
funcName4 : (foo) => {
return "bar";
}
}

const obj = {
funcName5(foo) {
return "bar";
}
}

funcName1();
funcName2();
funcName3();
funcName4();
funcName5();
46 changes: 46 additions & 0 deletions test/dumb-jump-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,52 @@
(mock (dumb-jump-goto-file-line * 7 35))
(should (string= js-file (dumb-jump-go)))))))

(ert-deftest dumb-jump-go-js-es6a-test ()
(let ((js-file (f-join test-data-dir-proj1 "src" "js" "es6.js")))
(with-current-buffer (find-file-noselect js-file t)
(goto-char (point-min))
(forward-line 20)
(with-mock
(mock (dumb-jump-goto-file-line * 1 4))
(should (string= js-file (dumb-jump-go)))))))

(ert-deftest dumb-jump-go-js-es6b-test ()
(let ((js-file (f-join test-data-dir-proj1 "src" "js" "es6.js")))
(with-current-buffer (find-file-noselect js-file t)
(goto-char (point-min))
(forward-line 21)
(with-mock
(mock (dumb-jump-goto-file-line * 3 6))
(should (string= js-file (dumb-jump-go)))))))

(ert-deftest dumb-jump-go-js-es6c-test ()
(let ((js-file (f-join test-data-dir-proj1 "src" "js" "es6.js")))
(with-current-buffer (find-file-noselect js-file t)
(goto-char (point-min))
(forward-line 22)
(with-mock
(mock (dumb-jump-goto-file-line * 5 6))
(should (string= js-file (dumb-jump-go)))))))

(ert-deftest dumb-jump-go-js-es6d-test ()
(let ((js-file (f-join test-data-dir-proj1 "src" "js" "es6.js")))
(with-current-buffer (find-file-noselect js-file t)
(goto-char (point-min))
(forward-line 23)
(with-mock
(mock (dumb-jump-goto-file-line * 10 2))
(should (string= js-file (dumb-jump-go)))))))

(ert-deftest dumb-jump-go-js-es6e-test ()
(let ((js-file (f-join test-data-dir-proj1 "src" "js" "es6.js")))
(with-current-buffer (find-file-noselect js-file t)
(goto-char (point-min))
(forward-line 24)
(with-mock
(mock (dumb-jump-goto-file-line * 16 2))
(should (string= js-file (dumb-jump-go)))))))


(ert-deftest dumb-jump-go-sig-def-test ()
(let ((js-file (f-join test-data-dir-proj1 "src" "js" "fake2.js")))
(with-current-buffer (find-file-noselect js-file t)
Expand Down

0 comments on commit 5313ef6

Please sign in to comment.