Git development
 help / color / mirror / Atom feed
* [PATCH 0/2] [GSoC] userdiff: adding typescript pattern
@ 2026-03-28 21:40 Dhruv Arora via GitGitGadget
  2026-03-28 21:40 ` [PATCH 1/2] " Dhruv Arora via GitGitGadget
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Dhruv Arora via GitGitGadget @ 2026-03-28 21:40 UTC (permalink / raw)
  To: git; +Cc: Dhruv Arora


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] userdiff: adding typescript pattern
  2026-03-28 21:40 [PATCH 0/2] [GSoC] userdiff: adding typescript pattern Dhruv Arora via GitGitGadget
@ 2026-03-28 21:40 ` Dhruv Arora via GitGitGadget
  2026-03-28 21:40 ` [PATCH 2/2] fix(userdiff): sorted pattern and tests Dhruv Arora via GitGitGadget
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Dhruv Arora via GitGitGadget @ 2026-03-28 21:40 UTC (permalink / raw)
  To: git; +Cc: Dhruv Arora, Dhruv Arora

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] fix(userdiff): sorted pattern and tests
  2026-03-28 21:40 [PATCH 0/2] [GSoC] userdiff: adding typescript pattern Dhruv Arora via GitGitGadget
  2026-03-28 21:40 ` [PATCH 1/2] " Dhruv Arora via GitGitGadget
@ 2026-03-28 21:40 ` Dhruv Arora via GitGitGadget
  2026-03-29  0:42 ` [PATCH 0/2] [GSoC] userdiff: adding typescript pattern Junio C Hamano
  2026-03-29  9:31 ` Johannes Sixt
  3 siblings, 0 replies; 6+ messages in thread
From: Dhruv Arora via GitGitGadget @ 2026-03-28 21:40 UTC (permalink / raw)
  To: git; +Cc: Dhruv Arora, Dhruv Arora

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern
  2026-03-28 21:40 [PATCH 0/2] [GSoC] userdiff: adding typescript pattern Dhruv Arora via GitGitGadget
  2026-03-28 21:40 ` [PATCH 1/2] " Dhruv Arora via GitGitGadget
  2026-03-28 21:40 ` [PATCH 2/2] fix(userdiff): sorted pattern and tests Dhruv Arora via GitGitGadget
@ 2026-03-29  0:42 ` Junio C Hamano
  2026-03-29  9:31 ` Johannes Sixt
  3 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2026-03-29  0:42 UTC (permalink / raw)
  To: Dhruv Arora via GitGitGadget; +Cc: git, Dhruv Arora

"Dhruv Arora via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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.

>  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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern
  2026-03-28 21:40 [PATCH 0/2] [GSoC] userdiff: adding typescript pattern Dhruv Arora via GitGitGadget
                   ` (2 preceding siblings ...)
  2026-03-29  0:42 ` [PATCH 0/2] [GSoC] userdiff: adding typescript pattern Junio C Hamano
@ 2026-03-29  9:31 ` Johannes Sixt
  2026-03-29 14:39   ` Spelling JavaScript (was: Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern) Ben Knoble
  3 siblings, 1 reply; 6+ messages in thread
From: Johannes Sixt @ 2026-03-29  9:31 UTC (permalink / raw)
  To: Dhruv Arora; +Cc: Dhruv Arora via GitGitGadget, git

Am 28.03.26 um 22:40 schrieb Dhruv Arora via GitGitGadget:
> 
> 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Spelling JavaScript (was: Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern)
  2026-03-29  9:31 ` Johannes Sixt
@ 2026-03-29 14:39   ` Ben Knoble
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Knoble @ 2026-03-29 14:39 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Dhruv Arora, Dhruv Arora via GitGitGadget, git


> 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 ;)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-29 14:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-28 21:40 [PATCH 0/2] [GSoC] userdiff: adding typescript pattern Dhruv Arora via GitGitGadget
2026-03-28 21:40 ` [PATCH 1/2] " Dhruv Arora via GitGitGadget
2026-03-28 21:40 ` [PATCH 2/2] fix(userdiff): sorted pattern and tests Dhruv Arora via GitGitGadget
2026-03-29  0:42 ` [PATCH 0/2] [GSoC] userdiff: adding typescript pattern Junio C Hamano
2026-03-29  9:31 ` Johannes Sixt
2026-03-29 14:39   ` Spelling JavaScript (was: Re: [PATCH 0/2] [GSoC] userdiff: adding typescript pattern) Ben Knoble

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox