From: "Derick W. de M. Frias" <derick.william.moraes@gmail.com>
To: git@vger.kernel.org
Subject: [GSoC PATCH 1/1] userdiff: add javascript diff driver
Date: Wed, 4 Jun 2025 06:35:46 -0300 [thread overview]
Message-ID: <20250604094100.80598-2-derick.william.moraes@gmail.com> (raw)
In-Reply-To: <20250604094100.80598-1-derick.william.moraes@gmail.com>
Add a userdiff pattern for javascript, and 13 test cases for instances
of function declarations in javascript.
Signed-off-by: Derick W. de M. Frias <derick.william.moraes@gmail.com>
---
.../javascript-anonymous-function-assigned | 4 +++
t/t4018/javascript-arrow-function-assigned | 4 +++
t/t4018/javascript-arrow-function-assigned-2 | 1 +
t/t4018/javascript-async-function | 4 +++
t/t4018/javascript-async-function-assigned | 4 +++
t/t4018/javascript-class-function | 6 ++++
t/t4018/javascript-function | 4 +++
t/t4018/javascript-function-assigned | 4 +++
t/t4018/javascript-generator-function | 5 ++++
t/t4018/javascript-generator-function-2 | 5 ++++
.../javascript-generator-function-assigned | 5 ++++
.../javascript-generator-function-assigned-2 | 5 ++++
t/t4018/javascript-method-function | 6 ++++
userdiff.c | 28 +++++++++++++++++++
14 files changed, 85 insertions(+)
create mode 100644 t/t4018/javascript-anonymous-function-assigned
create mode 100644 t/t4018/javascript-arrow-function-assigned
create mode 100644 t/t4018/javascript-arrow-function-assigned-2
create mode 100644 t/t4018/javascript-async-function
create mode 100644 t/t4018/javascript-async-function-assigned
create mode 100644 t/t4018/javascript-class-function
create mode 100644 t/t4018/javascript-function
create mode 100644 t/t4018/javascript-function-assigned
create mode 100644 t/t4018/javascript-generator-function
create mode 100644 t/t4018/javascript-generator-function-2
create mode 100644 t/t4018/javascript-generator-function-assigned
create mode 100644 t/t4018/javascript-generator-function-assigned-2
create mode 100644 t/t4018/javascript-method-function
diff --git a/t/t4018/javascript-anonymous-function-assigned b/t/t4018/javascript-anonymous-function-assigned
new file mode 100644
index 0000000000..d3c1728dd8
--- /dev/null
+++ b/t/t4018/javascript-anonymous-function-assigned
@@ -0,0 +1,4 @@
+const RIGHT = function (a, b) {
+
+ return a + b;
+};
\ No newline at end of file
diff --git a/t/t4018/javascript-arrow-function-assigned b/t/t4018/javascript-arrow-function-assigned
new file mode 100644
index 0000000000..5f0b056f61
--- /dev/null
+++ b/t/t4018/javascript-arrow-function-assigned
@@ -0,0 +1,4 @@
+const RIGHT = (a, b) => {
+
+ return a + b;
+};
\ No newline at end of file
diff --git a/t/t4018/javascript-arrow-function-assigned-2 b/t/t4018/javascript-arrow-function-assigned-2
new file mode 100644
index 0000000000..9e923f4261
--- /dev/null
+++ b/t/t4018/javascript-arrow-function-assigned-2
@@ -0,0 +1 @@
+const RIGHT = a => a+1;
\ No newline at end of file
diff --git a/t/t4018/javascript-async-function b/t/t4018/javascript-async-function
new file mode 100644
index 0000000000..7f99b8c89a
--- /dev/null
+++ b/t/t4018/javascript-async-function
@@ -0,0 +1,4 @@
+async function RIGHT (a, b) {
+
+ return a + b;
+};
\ No newline at end of file
diff --git a/t/t4018/javascript-async-function-assigned b/t/t4018/javascript-async-function-assigned
new file mode 100644
index 0000000000..9a01d9701f
--- /dev/null
+++ b/t/t4018/javascript-async-function-assigned
@@ -0,0 +1,4 @@
+const RIGHT = async function (a, b) {
+
+ return a + b;
+};
\ No newline at end of file
diff --git a/t/t4018/javascript-class-function b/t/t4018/javascript-class-function
new file mode 100644
index 0000000000..9f216d7174
--- /dev/null
+++ b/t/t4018/javascript-class-function
@@ -0,0 +1,6 @@
+class Test {
+ RIGHT() {
+ let a = 1;
+ let b = Value;
+ }
+}
\ No newline at end of file
diff --git a/t/t4018/javascript-function b/t/t4018/javascript-function
new file mode 100644
index 0000000000..d11ad34aff
--- /dev/null
+++ b/t/t4018/javascript-function
@@ -0,0 +1,4 @@
+function RIGHT (a, b) {
+
+ return a + b;
+};
\ No newline at end of file
diff --git a/t/t4018/javascript-function-assigned b/t/t4018/javascript-function-assigned
new file mode 100644
index 0000000000..38eaecafc6
--- /dev/null
+++ b/t/t4018/javascript-function-assigned
@@ -0,0 +1,4 @@
+const RIGHT = function test (a, b) {
+
+ return a + b;
+};
\ No newline at end of file
diff --git a/t/t4018/javascript-generator-function b/t/t4018/javascript-generator-function
new file mode 100644
index 0000000000..af7cbb50a3
--- /dev/null
+++ b/t/t4018/javascript-generator-function
@@ -0,0 +1,5 @@
+function* RIGHT() {
+
+ yield 1;
+ yield 2;
+}
\ No newline at end of file
diff --git a/t/t4018/javascript-generator-function-2 b/t/t4018/javascript-generator-function-2
new file mode 100644
index 0000000000..d40b395f5c
--- /dev/null
+++ b/t/t4018/javascript-generator-function-2
@@ -0,0 +1,5 @@
+function *RIGHT() {
+
+ yield 1;
+ yield 2;
+}
\ No newline at end of file
diff --git a/t/t4018/javascript-generator-function-assigned b/t/t4018/javascript-generator-function-assigned
new file mode 100644
index 0000000000..b45d069949
--- /dev/null
+++ b/t/t4018/javascript-generator-function-assigned
@@ -0,0 +1,5 @@
+const RIGHT = function* (){
+
+ yield 1;
+ yield 2;
+}
\ No newline at end of file
diff --git a/t/t4018/javascript-generator-function-assigned-2 b/t/t4018/javascript-generator-function-assigned-2
new file mode 100644
index 0000000000..2c4bc271ab
--- /dev/null
+++ b/t/t4018/javascript-generator-function-assigned-2
@@ -0,0 +1,5 @@
+const RIGHT = function *(){
+
+ yield 1;
+ yield 2;
+}
\ No newline at end of file
diff --git a/t/t4018/javascript-method-function b/t/t4018/javascript-method-function
new file mode 100644
index 0000000000..37e380cc6f
--- /dev/null
+++ b/t/t4018/javascript-method-function
@@ -0,0 +1,6 @@
+const Test = {
+ RIGHT() {
+ let a = 1;
+ let b = Value;
+ }
+}
\ No newline at end of file
diff --git a/userdiff.c b/userdiff.c
index 05776ccd10..94134e5b09 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -237,6 +237,34 @@ PATTERNS("java",
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
"|[-+*/<>%&^|=!]="
"|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
+PATTERNS("javascript",
+ /* conventional named functions */
+ "^[ \t]*(async[ \t]+)?function[ \t]*\\*?[ \t]*([$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*\\(.*$|"
+ /* assigned functions */
+ "^[ \t]*(const|let|var)[ \t]+([$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*="
+ "[ \t]*(async[ \t]+)?function[ \t]*\\*?[ \t]*([$_a-zA-Z][$_a-zA-Z0-9]*)?[ \t]*\\(.*$|"
+ /* arrow functions */
+ "^[ \t]*(const|let|var)[ \t]+([$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*="
+ "[ \t]*(\\([^\\)]*\\)|[$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*=>[ \t]*\\{?.*$|"
+ /* functions declared inside classes and objects */
+ "^[ \t]*(static[ \t]+)?(async[ \t]+)?(get[ \t]+|set[ \t]+)?\\*?[ \t]*"
+ "([$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*\\([^)]*\\)[ \t]*\\{.*$",
+ /* identifiers */
+ "[$_A-Za-z][$_A-Za-z0-9]*|"
+ /* hexadecimal and big hexadecimal */
+ "0[xX](?:[0-9a-fA-F](?:_?[0-9a-fA-F])*)n?|"
+ /* octa and big octa */
+ "0[oO](?:[0-7](?:_?[0-7])*)n?|"
+ /* binary and big binary */
+ "0[bB](?:[01](?:_?[01])*)n?|"
+ /* decimal, floting point and exponent notation (eE) */
+ "(?:0|[1-9](?:_?[0-9])*)(?:\\.(?:[0-9](?:_?[0-9])*))?(?:[eE][+-]?(?:[0-9](?:_?[0-9])*))?|"
+ /* big decimal */
+ "(?:0|[1-9](?:_?[0-9])*)n|"
+ /* punctuation */
+ "\\{|\\}|\\(|\\)|\\.|\\.{3}|;|,|<|>|<=|>=|==|!=|={3}|!==|\\+|-|\\*|/|%|\\*{2}|"
+ "\\+{2}|--|<<|>>|>>>|&|\\||\\^|!|~|&&|\\|{2}|\\?{1,2}|:|=|\\+=|-=|\\*=|%=|\\*{2}=|"
+ "<<=|>>=|>>>=|&=|\\|=|\\^=|&&=|\\|{2}=|\\?{2}=|=>"),
PATTERNS("kotlin",
"^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
/* -- */
--
2.50.0.rc0.62.g658f0ae201.dirty
next prev parent reply other threads:[~2025-06-04 9:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-04 9:35 [GSoC PATCH 0/1] userdiff: add javascript diff driver Derick W. de M. Frias
2025-06-04 9:35 ` Derick W. de M. Frias [this message]
2025-06-04 21:19 ` [GSoC PATCH 1/1] " D. Ben Knoble
2025-06-05 5:51 ` Johannes Sixt
2025-06-23 6:35 ` [PATCH v2 0/4] diff: create pattern for javascript language Derick W. de M. Frias
2025-06-23 6:35 ` [PATCH v2 1/4] userdiff: add javascript diff driver Derick W. de M. Frias
2025-06-23 18:09 ` Junio C Hamano
2025-06-23 6:35 ` [PATCH v2 2/4] t4034: add tests for javascript word literals Derick W. de M. Frias
2025-06-23 6:35 ` [PATCH v2 3/4] t4018: add tests for recognizing javascript function syntax Derick W. de M. Frias
2025-06-23 6:35 ` [PATCH v2 4/4] t4018: add tests for javascript export type function declarations Derick W. de M. Frias
2025-06-26 6:21 ` Johannes Sixt
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=20250604094100.80598-2-derick.william.moraes@gmail.com \
--to=derick.william.moraes@gmail.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;
as well as URLs for NNTP newsgroup(s).