diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7702f11 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM ubuntu:bionic + +RUN apt-get update && apt-get install -y \ + curl \ + emacs \ + git \ + make \ + python \ + && rm -rf /var/lib/apt/lists/* + +RUN cd /tmp \ + && curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python \ + && rm -rf /tmp/* + +ENV PATH="/root/.cask/bin:${PATH}" diff --git a/README.md b/README.md index 0cb7263..16b181e 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,25 @@ to `false`: `tsc --pretty false`. However, doing this does more than just turning off the colors. It also causes `tsc` to produce less elaborate error messages. +# Contributing + +To run the tests you can run: +```bash +make test +``` + +Alternatively, you may run the tests with the provided `Dockerfile` by running: +```bash +# build the container (only needed the first time) +docker build -t typescript.el . + +# run the tests +docker run --rm \ + -v $(pwd):/home/typescript.el \ + typescript.el \ + bash -c 'cd /home/typescript.el && make test' +``` + # Other Typescript-packages of interest While `typescript.el` may *not* provide a full kitchen-sink, the good diff --git a/aritest.ts b/aritest.ts new file mode 100644 index 0000000..fa0a0e5 --- /dev/null +++ b/aritest.ts @@ -0,0 +1,33 @@ +type Test = null; +type Foo = null; + +const testme = ''; + +class Fatso {} + +export class AritestComponent extends Fatso { + + foo(test: Test, bar) { + console.log(testme) + } + + footwo(test, bar) { + console.log(testme) + + const thing = param2 => { + // + } + } +} + +function test(me: Test, that: Foo) { + +} + +function testtwo( + me: string, that: Foo +) {} + +function testthree( + me, that +) {} diff --git a/test-files/aritest.ts b/test-files/aritest.ts new file mode 100644 index 0000000..c476ae4 --- /dev/null +++ b/test-files/aritest.ts @@ -0,0 +1,53 @@ +function foo(bar, baz, faz) { + // +} + +function foo2( + bar, baz, faz +) { + // +} + +function bar(bar: string, baz: Bar, faz) { + // +} + +function barz( + bar: string, baz: Bar, faz) { + // +} + +function baz(bar: string, baz: Bar, faz: T) { + // +} + +class Foo { + bar: Map>; + + constructor() { + this.foo(); + this.bar = 'test'; + } + + foo(foo): Promise { + console.log('test me'); + } + + baz( + foo, bar, baz + ) { + // + } + + baz2(foo, bar, baz) { + this.baz(foo, bar, baz); + } +} + +interface Bar { + bar: Map>; + + foo(); + bar(): Promise; + baz(foo: Foo, bar, baz): Promise; +} diff --git a/typescript-mode-general-tests.el b/typescript-mode-general-tests.el index 7185a36..43c8ee1 100644 --- a/typescript-mode-general-tests.el +++ b/typescript-mode-general-tests.el @@ -336,9 +336,28 @@ console.log(this.methodCall())" ("this" . typescript-this-face) ("methodCall" . font-lock-function-name-face) (("string" "boolean" "number" "any") . typescript-primitive-face) - (("endpoint" "data") . nil) + (("endpoint" "data") . font-lock-variable-name-face) (("<" ">" ",") . nil)))) +(ert-deftest font-lock/class-function-params () + "Tests highlighting params of function definitions within classes." + (font-lock-test + "class Foo extends Bar {\n +method1(param1) {}\n +method2(param2, param3) {}\n +method3(param4: string, param5: Bar) {\n +console.log(notAParam)\n +}\n +method4(param6) {}\n +method5(\n +param7: string, param8\n +)\n" + '((("method1" "method2" "method3" "method4" "method5") . font-lock-function-name-face) + (("param1" "param2" "param3" "param4") . font-lock-variable-name-face) + (("param5" "param6" "param7" "param8") . font-lock-variable-name-face) + ("string" . typescript-primitive-face) + ("notAParam" . nil)))) + (ert-deftest font-lock/generics () "Tests that type hints within generics are highlighted properly." (font-lock-test diff --git a/typescript-mode.el b/typescript-mode.el index 66c45bd..bb4390d 100644 --- a/typescript-mode.el +++ b/typescript-mode.el @@ -1524,9 +1524,11 @@ LIMIT defaults to point." (typescript--up-nearby-list) (and (looking-at "(") (progn (forward-symbol -1) - (or (looking-at "function") + (or (typescript--inside-class-list-p) + (looking-at "function") (progn (forward-symbol -1) - (looking-at "function")))))))) + (or (typescript--inside-class-list-p) + (looking-at "function"))))))))) (defun typescript--inside-dojo-class-list-p () "Return non-nil iff point is in a Dojo multiple-inheritance class block." @@ -1540,6 +1542,18 @@ LIMIT defaults to point." (looking-at "\"\\s-*,\\s-*\\[") (eq (match-end 0) (1+ list-begin))))))) +(defun typescript--inside-class-list-p () + "Return non-nil iff point is in a class block." + (ignore-errors + (save-excursion + (typescript--up-nearby-list) + (let ((list-begin (point))) + (forward-line 0) + (and (or (looking-at ".*class.*{") + (looking-at ".*interface.*{")) + (goto-char (match-end 0)) + (eq (match-end 0) (1+ list-begin))))))) + (defun typescript--syntax-begin-function () (when (< typescript--cache-end (point)) (goto-char (max (point-min) typescript--cache-end))) @@ -1877,10 +1891,46 @@ and searches for the next token to be highlighted." '(end-of-line) '(1 font-lock-variable-name-face))) - ;; continued formal parameter list + ("(\\(.*\\))\\s-+=>" + (1 font-lock-constant-face)) + + ;; lambda without argument parenthesis + ,(list + (concat "\\(" typescript--name-re "\\)" "\\s-+=>") + (list 1 'font-lock-constant-face)) + + ;; formal parameters - lambda functions + ;; ,(list + ;; (concat + ;; "(\\s-*" typescript--name-start-re "\\s-*") + ;; (list (concat "\\(" typescript--name-re "\\)\\(\\s-*).*\\)?") + ;; '(backward-char) + ;; '(end-of-line) + ;; '(1 font-lock-variable-name-face))) + ;; ,(list + ;; (concat "\\s-*" typescript--name-start-re "\\s-*") + ;; (list (concat "\\(" typescript--name-re "\\)" "\\s-*" ")?" "\\s-*" "\\(=>\\)") + ;; '(backward-char) + ;; '(end-of-line) + ;; '(1 font-lock-constant-face))) + + ;; continued formal parameters - class functions + ,(list + (concat + "\\(\\s-+" typescript--name-re "\\)?\\s-*\\(<.*>\\)?\\s-*(\\s-*" + typescript--name-start-re) + (list (concat "\\(" typescript--name-re "\\)\\(\\s-*).*\\)?") + '(if (save-excursion (backward-char) + (typescript--inside-param-list-p)) + (forward-symbol -1) + (end-of-line)) + '(end-of-line) + '(1 font-lock-variable-name-face))) + + ;; continued formal parameter list -- multiline parameter list ,(list (concat - "^\\s-*" typescript--name-re "\\s-*[,)]") + "^\\s-*" typescript--name-re "\\s-*[,:)]") (list typescript--name-re '(if (save-excursion (backward-char) (typescript--inside-param-list-p))