Git development
 help / color / mirror / Atom feed
From: "Dhruv Arora via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Dhruv Arora <a_dhruv@outlook.com>, Dhruv Arora <a_dhruv@outlook.com>
Subject: [PATCH 2/2] fix(userdiff): sorted pattern and tests
Date: Sat, 28 Mar 2026 21:40:04 +0000	[thread overview]
Message-ID: <d684d938fb794fd858d49665e2b5b03aa0319f06.1774734004.git.gitgitgadget@gmail.com> (raw)
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

  parent reply	other threads:[~2026-03-28 21:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-03-29  0:42 ` [PATCH 0/2] [GSoC] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d684d938fb794fd858d49665e2b5b03aa0319f06.1774734004.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=a_dhruv@outlook.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox