From: Dhruv Arora via GitGitGadget Date: Sat, 28 Mar 2026 21:40:04 GMT Subject: [PATCH 2/2] fix(userdiff): sorted pattern and tests Message-ID: In-Reply-To: From: Dhruv Arora - 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 --- 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 { + 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