Volume XXII, number 280Wednesday, October 7, 2026Latest message 54 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

patch, 2 parts[GSoC] userdiff: adding typescript pattern

6 messages between Mar 28, 2026 and Mar 29, 2026, from Dhruv Arora via GitGitGadget, Junio C Hamano, Johannes Sixt, Ben Knoble.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Dhruv Arora via GitGitGadgetMar 28, 2026, 21:40 UTC on lore

Description ===========

 * 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
 * Added tests for the typescript pattern in userdiff.
Dhruv Arora (2):
  userdiff: adding typescript pattern
  fix(userdiff): sorted pattern and tests
 t/t4018/typescript-class-method         |  7 +++++++
 t/t4018/typescript-export-default-class |  7 +++++++
 t/t4018/typescript-export-function      |  7 +++++++
 userdiff.c                              | 15 +++++++++++++++
 4 files changed, 36 insertions(+)
 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
base-commit: ce74208c2fa13943fffa58f168ac27a76d0eb789
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2251%2FDhruv-0-Arora%2Fuserdiff%2Ftypescript-pattern-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2251/Dhruv-0-Arora/userdiff/typescript-pattern-v1
Pull-Request: https://github.com/git/git/pull/2251
-- 
gitgitgadget
Dhruv Arora via GitGitGadgetMar 28, 2026, 21:40 UTC in reply to Dhruv Arora via GitGitGadget on lore

[PATCH 1/2] userdiff: adding typescript pattern

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(+)
Show changes to userdiff.c +13 −0
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
Dhruv Arora via GitGitGadgetMar 28, 2026, 21:40 UTC in reply to Dhruv Arora via GitGitGadget on lore

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

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
Show changes to 4 files +36 −13

t/t4018/typescript-class-method, t/t4018/typescript-export-default-class, t/t4018/typescript-export-function, userdiff.c

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
Junio C HamanoMar 29, 2026, 00:42 UTC in reply to Dhruv Arora via GitGitGadget on lore

Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern

"Dhruv Arora via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 13 quoted lines
> Description
> ===========
>
>  * 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
>
>  * Added tests for the typescript pattern in userdiff.
>
> Dhruv Arora (2):
>   userdiff: adding typescript pattern
>   fix(userdiff): sorted pattern and tests

We frown upon a patch series that makes mistakes in an earlier step, only to fix them in a later step. The "git rebase -i" command helps us pretend to be more perfect developers than we actually are, whipping your patch series into a shape that builds one small step on top of another in a logical succession. Such a patch series is easier to understand than a history that faithfully records all the stumbles the developer made until they reached the final solution.

Just have a single patch that adds the right pattern at the right place and add necessary tests.

When/if your reviewers suggest further changes, the way you should work on them is the same. Pretend as if you discarded everything you did, started from scratch, and reached the ideal result without making any mistakes or taking any detours along the way.

Thanks.
Show 14 quoted lines
>  t/t4018/typescript-class-method         |  7 +++++++
>  t/t4018/typescript-export-default-class |  7 +++++++
>  t/t4018/typescript-export-function      |  7 +++++++
>  userdiff.c                              | 15 +++++++++++++++
>  4 files changed, 36 insertions(+)
>  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
>
>
> base-commit: ce74208c2fa13943fffa58f168ac27a76d0eb789
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2251%2FDhruv-0-Arora%2Fuserdiff%2Ftypescript-pattern-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2251/Dhruv-0-Arora/userdiff/typescript-pattern-v1
> Pull-Request: https://github.com/git/git/pull/2251
Johannes SixtMar 29, 2026, 09:31 UTC in reply to Dhruv Arora via GitGitGadget on lore

Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern

Am 28.03.26 um 22:40 schrieb Dhruv Arora via GitGitGadget:
Show 29 quoted lines
> 
> Description
> ===========
> 
>  * 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
> 
>  * Added tests for the typescript pattern in userdiff.
> 
> Dhruv Arora (2):
>   userdiff: adding typescript pattern
>   fix(userdiff): sorted pattern and tests
> 
>  t/t4018/typescript-class-method         |  7 +++++++
>  t/t4018/typescript-export-default-class |  7 +++++++
>  t/t4018/typescript-export-function      |  7 +++++++
>  userdiff.c                              | 15 +++++++++++++++
>  4 files changed, 36 insertions(+)
>  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
> 
> 
> base-commit: ce74208c2fa13943fffa58f168ac27a76d0eb789
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2251%2FDhruv-0-Arora%2Fuserdiff%2Ftypescript-pattern-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2251/Dhruv-0-Arora/userdiff/typescript-pattern-v1
> Pull-Request: https://github.com/git/git/pull/2251

Javascript and Typescript are related languages, if I am not mistaken. It would be appreciated if the new language driver could be used for both. Then the driver's name should be the superset language and the documentation (missing, BTW) should mention that the driver can be used for both languages.

We have had a number of submissions for Javascript or Typescript drivers in the past, but none of them were followed through to be integrated.

Typescript:

https://lore.kernel.org/git/20240404163827.5855-1-utsavp0213@gmail.com/ https://lore.kernel.org/git/pull.1746.git.git.1721061218993.gitgitgadget@gmail.com/

Javascript:

https://lore.kernel.org/git/20240301074048.188835-1-sergiusnyah@gmail.com/ https://lore.kernel.org/git/20220403132508.28196-1-a97410985new@gmail.com/ https://lore.kernel.org/git/20250604094100.80598-1-derick.william.moraes@gmail.com/

Please review these submission and the responses that they received. Perhaps you can find inspiration for improvement from them.

-- Hannes
Ben KnobleMar 29, 2026, 14:39 UTC in reply to Johannes Sixt on lore

Spelling JavaScript (was: Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern)

Show 5 quoted lines
> Le 29 mars 2026 à 05:32, Johannes Sixt <j6t@kdbg.org> a écrit :
> 
> Javascript and Typescript are related languages, if I am not mistaken.
> 
> -- Hannes
FWIW, I believe both languages are officially spelled with a capital S: “JavaScript”, “TypeScript”. At least that is how Wikipedia and official sites present them.
I knew what you meant of course, and will now take my pedant hat off ;)

Back to recent threads