Skip to content

Commit a258730

Browse files
committed
fix(userdiff): sorted pattern and tests
- 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>
1 parent 7096154 commit a258730

4 files changed

Lines changed: 36 additions & 13 deletions

File tree

t/t4018/typescript-class-method

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class RIGHT {
2+
unique = 0
3+
constructor () {
4+
this.doNothing()
5+
}
6+
function ChangeMe() { }
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default class RIGHT {
2+
private x = 0;
3+
private y = 0;
4+
private z = 0;
5+
// ChangeMe
6+
render() {}
7+
}

t/t4018/typescript-export-function

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export async function RIGHT(url: string): Promise<string> {
2+
const a = 1;
3+
const b = 2;
4+
const c = 3;
5+
ChangeMe
6+
return url;
7+
}

userdiff.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,6 @@ PATTERNS("ruby",
337337
"(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
338338
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
339339
"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
340-
PATTERNS("typescript",
341-
/* Starting with optional whitespace */
342-
"^[ \t]*"
343-
/* Followed by an optional export and/or async keyword */
344-
"((export[ \t]+)?(async[ \t]+)?"
345-
/* Followed by either a function or class declaration */
346-
"((function|class)[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[^{]*)"
347-
/* or */
348-
"|"
349-
/* a variable declaration with const, let, or var */
350-
"([ \t]*(const|let|var)[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=))",
351-
/* -- */
352-
"[a-zA-Z_][a-zA-Z0-9_]*"),
353340
PATTERNS("rust",
354341
"^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl|macro_rules!)[< \t]+[^;]*)$",
355342
/* -- */
@@ -367,6 +354,21 @@ PATTERNS("scheme",
367354
"|([^][)(}{[ \t])+"),
368355
PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
369356
"\\\\[a-zA-Z@]+|\\\\.|([a-zA-Z0-9]|[^\x01-\x7f])+"),
357+
PATTERNS("typescript",
358+
/* Starting with optional whitespace */
359+
"^[ \t]*"
360+
"("
361+
/* Followed by an optional export and/or async and/or default keyword */
362+
"(export[ \t]+)?(default[ \t]+)?(async[ \t]+)?"
363+
/* Followed by either a function or class declaration */
364+
"((function|class)[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[^{]*)"
365+
/* or */
366+
"|"
367+
/* a variable declaration with const, let, or var */
368+
"^(const|let|var)[ \\t]+[a-zA-Z_][a-zA-Z0-9_]*[ \\t]*="
369+
")",
370+
/* -- */
371+
"[a-zA-Z_][a-zA-Z0-9_]*"),
370372
{ .name = "default", .binary = -1 },
371373
};
372374
#undef PATTERNS

0 commit comments

Comments
 (0)