git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] userdiff: adding typescript pattern

From
DGDhruv Arora via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 28, 2026, 21:40 UTC
Message-ID
<f3bb69dbfc628d88075ee9a5a9b549e73cb487fe.1774734004.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2251.git.git.1774734004.gitgitgadget@gmail.com>
From: Dhruv Arora <a_dhruv@outlook.com>

Add builtin userdiff pattern for TypeScript files. Recognizes function declarations, class definitions, arrow functions, and method definitions.

Handles common modifiers like export, async, static, etc..
Signed-off-by: Dhruv Arora <a_dhruv@outlook.com>
---
 userdiff.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/userdiff.c b/userdiff.c
index fe710a68bf..086e3fa002 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -337,6 +337,19 @@ PATTERNS("ruby",
 	 "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
 	 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
 	 "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
+PATTERNS("typescript",
+	/* Starting with optional whitespace */
+	"^[ \t]*"
+	/* Followed by an optional export and/or async keyword */
+	"((export[ \t]+)?(async[ \t]+)?"
+	/* Followed by either a function or class declaration */
+	"((function|class)[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[^{]*)"
+	/* or */
+	"|"
+	/* a variable declaration with const, let, or var */
+	"([ \t]*(const|let|var)[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=))",
+	/* -- */
+	"[a-zA-Z_][a-zA-Z0-9_]*"),
 PATTERNS("rust",
 	 "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl|macro_rules!)[< \t]+[^;]*)$",
 	 /* -- */
-- 
gitgitgadget
Previous: Dhruv Arora via GitGitGadgetNext: Dhruv Arora via GitGitGadget
Message 2 of 6 in “[GSoC] userdiff: adding typescript pattern”
  1. 0/2 [GSoC] userdiff: adding typescript patternDhruv Arora via GitGitGadget, Mar 28, 2026
  2. 1/2 userdiff: adding typescript patternDhruv Arora via GitGitGadget, Mar 28, 2026
  3. 2/2 fix(userdiff): sorted pattern and testsDhruv Arora via GitGitGadget, Mar 28, 2026
  4. Junio C HamanoMar 29, 2026
  5. Johannes SixtMar 29, 2026
  6. Spelling JavaScript (was: Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern)Ben Knoble, Mar 29, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.