Skip to content

Commit 55f9b3c

Browse files
committed
userdiff: adding typescript pattern
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>
1 parent 6e8d538 commit 55f9b3c

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

userdiff.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,19 @@ 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_]*"),
340353
PATTERNS("rust",
341354
"^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl|macro_rules!)[< \t]+[^;]*)$",
342355
/* -- */

0 commit comments

Comments
 (0)