@@ -442,3 +442,63 @@ library.")
(description
"This package provides a Rust grammar for the Tree-sitter library.")
(license license:expat)))
+
+(define-public tree-sitter-typescript
+ (package (inherit tree-sitter-c)
+ (name "tree-sitter-typescript")
+ (version "0.19.0")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/tree-sitter/tree-sitter-typescript")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32
+ "01pkmwwmbv6kxda0n6g4cfg72ldmpi9gmp11a5gygn472vhrh2xw"))))
+ (native-inputs
+ `(("tree-sitter" ,tree-sitter)
+ ("tree-sitter-javascript" ,tree-sitter-javascript)
+ ("node-nan" ,node-nan)))
+ (arguments
+ (substitute-keyword-arguments (package-arguments tree-sitter-c)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ ;; The parse-example script tries to clone git repositories.
+ (add-after 'unpack 'remove-parse-example
+ (lambda _
+ (substitute* "package.json"
+ ((" && script\\/parse-examples") ""))))
+ (add-after 'build 'build-gyp
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let ((node (assoc-ref inputs "node")))
+ (invoke (string-append node "/lib/node_modules/npm/node_modules"
+ "/node-gyp/bin/node-gyp.js")
+ "build"))))
+ (replace 'make-files-writable
+ (lambda _
+ (for-each make-file-writable
+ (find-files "typescript" ".*"))
+ (for-each make-file-writable
+ (find-files "tsx" ".*"))))
+ (replace 'install-native-lib
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((lib (string-append (assoc-ref outputs "out")
+ "/lib/tree-sitter")))
+ ;; Invoking `tree-sitter test' loads the grammar which
+ ;; compiles it to a .so binary that we install.
+ (with-directory-excursion "typescript"
+ (invoke "tree-sitter" "test"))
+ (with-directory-excursion "tsx"
+ (invoke "tree-sitter" "test"))
+ (mkdir-p lib)
+ (copy-recursively (string-append (getenv "HOME")
+ "/.tree-sitter/bin")
+ lib))))))))
+ (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)))