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

[PATCH 2/2] fix(userdiff): sorted pattern and tests

From
DGDhruv Arora via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 28, 2026, 21:40 UTC
Message-ID
<d684d938fb794fd858d49665e2b5b03aa0319f06.1774734004.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2251.git.git.1774734004.gitgitgadget@gmail.com>
From: Dhruv Arora <a_dhruv@outlook.com>
- Typescript pattern was not in alphabetical order, causing failing tests.
- Added 3 new typescript tests.
- Fixed pattern bug - incorrectly identifying const|let|var instead of
function or class.
Signed-off-by: Dhruv Arora <a_dhruv@outlook.com>
---
 t/t4018/typescript-class-method         |  7 +++++++
 t/t4018/typescript-export-default-class |  7 +++++++
 t/t4018/typescript-export-function      |  7 +++++++
 userdiff.c                              | 28 +++++++++++++------------
 4 files changed, 36 insertions(+), 13 deletions(-)
 create mode 100644 t/t4018/typescript-class-method
 create mode 100644 t/t4018/typescript-export-default-class
 create mode 100644 t/t4018/typescript-export-function
diff --git a/t/t4018/typescript-class-method b/t/t4018/typescript-class-method
new file mode 100644
index 0000000000..6de6eff2e7
--- /dev/null
+++ b/t/t4018/typescript-class-method
@@ -0,0 +1,7 @@
+export class RIGHT {
+    unique = 0
+    constructor () {
+        this.doNothing()
+    }
+    function ChangeMe() { }
+}
diff --git a/t/t4018/typescript-export-default-class b/t/t4018/typescript-export-default-class
new file mode 100644
index 0000000000..aaede0dce3
--- /dev/null
+++ b/t/t4018/typescript-export-default-class
@@ -0,0 +1,7 @@
+export default class RIGHT {
+	private x = 0;
+	private y = 0;
+	private z = 0;
+	// ChangeMe
+	render() {}
+}
diff --git a/t/t4018/typescript-export-function b/t/t4018/typescript-export-function
new file mode 100644
index 0000000000..ba5bf71e80
--- /dev/null
+++ b/t/t4018/typescript-export-function
@@ -0,0 +1,7 @@
+export async function RIGHT(url: string): Promise<string> {
+	const a = 1;
+	const b = 2;
+	const c = 3;
+	ChangeMe
+	return url;
+}
diff --git a/userdiff.c b/userdiff.c
index 086e3fa002..7f5cadb30b 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -337,19 +337,6 @@ 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]+[^;]*)$",
 	 /* -- */
@@ -367,6 +354,21 @@ PATTERNS("scheme",
 	 "|([^][)(}{[ \t])+"),
 PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
 	 "\\\\[a-zA-Z@]+|\\\\.|([a-zA-Z0-9]|[^\x01-\x7f])+"),
+PATTERNS("typescript",
+	/* Starting with optional whitespace */
+	"^[ \t]*"
+	"("
+	/* Followed by an optional export and/or async and/or default keyword */
+	"(export[ \t]+)?(default[ \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 */
+	"^(const|let|var)[ \\t]+[a-zA-Z_][a-zA-Z0-9_]*[ \\t]*="
+	")",
+	/* -- */
+	"[a-zA-Z_][a-zA-Z0-9_]*"),
 { .name = "default", .binary = -1 },
 };
 #undef PATTERNS
-- 
gitgitgadget
Previous: Dhruv Arora via GitGitGadgetNext: Junio C Hamano
Message 3 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.