Subject: [bug#49946] [PATCH v4 24/31] gnu: Add tree-sitter-typescript.

From: Pierre Langlois <[email-masked]>
Date: Fri, 18 Feb 2022 14:39:41 +0000

* gnu/packages/tree-sitter.scm (tree-sitter-typescript): New variable.
---
 gnu/packages/tree-sitter.scm | 69 ++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm
index f4df5c5335..309b38386d 100644
--- a/gnu/packages/tree-sitter.scm
+++ b/gnu/packages/tree-sitter.scm
@@ -731,3 +731,72 @@ (define-public tree-sitter-rust
     (description
       "This package provides a Rust grammar for the Tree-sitter library.")
     (license license:expat)))
+
+(define-public tree-sitter-typescript
+  (let ((commit "111b07762e86efab9a918b7c721f720c37e76b0a")
+        (revision "1"))
+    (package (inherit tree-sitter-c)
+      (name "tree-sitter-typescript")
+      (version (git-version "0.20.0" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/tree-sitter/tree-sitter-typescript")
+                      (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32 "1364bm3wbqqzvp03cvpx1w89bbqynb1v62i46gy7f6rhib9bf63a"))
+                (modules '((guix build utils)))
+                (snippet
+                 '(begin
+                    (delete-file "binding.gyp")
+                    (delete-file-recursively "bindings")
+                    (for-each
+                     (lambda (lang)
+                       (with-directory-excursion lang
+                         (delete-file "src/grammar.json")
+                         (delete-file "src/node-types.json")
+                         (delete-file "src/parser.c")
+                         (delete-file-recursively "src/tree_sitter")))
+                     '("typescript" "tsx"))
+                    #t))))
+      (inputs
+       (list `(,tree-sitter-javascript "js")))
+      (arguments
+       (substitute-keyword-arguments (package-arguments tree-sitter-c)
+        ((#:phases phases)
+         #~(modify-phases #$phases
+             (replace 'build
+               (lambda _
+                 (for-each (lambda (dir)
+                             (with-directory-excursion dir
+                               (invoke "tree-sitter" "generate" "--no-bindings")))
+                           '("typescript" "tsx"))))
+             (replace 'check
+               (lambda _
+                 (for-each (lambda (dir)
+                             (with-directory-excursion dir
+                               (invoke "tree-sitter" "test")))
+                           '("typescript" "tsx"))))
+             (replace 'install
+               (lambda _
+                 (let ((lib (string-append #$output "/lib/tree-sitter/")))
+                   (mkdir-p lib)
+                   (for-each
+                    (lambda (lang)
+                      (invoke #$(cxx-for-target)
+                              "-shared"
+                              "-fPIC"
+                              "-fno-exceptions"
+                              "-O2"
+                              "-g"
+                              "-o" (string-append lib "/" lang ".so")
+                              "-xc" (string-append lang "/src/scanner.c")
+                              "-xc" (string-append lang "/src/parser.c")))
+                    '("typescript" "tsx")))))))))
+      (home-page "https://github.com/tree-sitter/tree-sitter-typescript")
+      (synopsis "Tree-sitter Typescript grammar")
+      (description
+        "This package provides Typescript and TSX grammars for the Tree-sitter
+library.")
+      (license license:expat))))
--
2.34.0