git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC PATCH 1/1] userdiff: add javascript diff driver

From
Johannes Sixt <j6t@kdbg.org>
Date
Jun 5, 2025, 05:51 UTC
Message-ID
<4deb24c2-98f2-40f8-b50c-c74485ebc10d@kdbg.org>
In-Reply-To
<20250604094100.80598-2-derick.william.moraes@gmail.com>

Thank you for your contribution. We have had a number of submissions for Javascript or Typescript drivers in the past, but none of them were followed through to be integrated.

Typescript:

https://lore.kernel.org/git/20240404163827.5855-1-utsavp0213@gmail.com/ https://lore.kernel.org/git/pull.1746.git.git.1721061218993.gitgitgadget@gmail.com/

Javascript:

https://lore.kernel.org/git/20240301074048.188835-1-sergiusnyah@gmail.com/ https://lore.kernel.org/git/20220403132508.28196-1-a97410985new@gmail.com/

Please review these submission and the responses that they received. Perhaps you can find inspiration for improvement from them.

Since this patch is marked as [GSoC], I'll comment on the style a bit, but do not go into the depth of the patch itself too far, yet. Please let us know if one of the earlier submissions can be revived or reused in some way.

Am 04.06.25 um 11:35 schrieb Derick W. de M. Frias:
> Add a userdiff pattern for javascript, and 13 test cases for instances
> of function declarations in javascript.

This is written in imperative mood, which is good. A minor recommendation: Don't mention the number of test cases here; it might go stale if the patch is updated.

Show 43 quoted lines
> 
> 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

We avoid incomplete last lines in this code base if it is not mandated for some reason.

Here and in the later test cases, the word "ChangeMe" is missing. How did these ever pass the tests?

Show 146 quoted lines
> 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",
The following lines are indented by spaces. We use TAB here.
Show 27 quoted lines
> +     /* 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}=|=>"),

You do not have to include single-character punctuation; these are recognized as words automatically.

Personally I prefer |===| over |={3}| (and similar for the others) because it is easier to understand.

>  PATTERNS("kotlin",
>  	 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
>  	 /* -- */
-- Hannes
Previous: D. Ben KnobleNext: Derick W. de M. Frias
Message 4 of 11 in “userdiff: add javascript diff driver”
  1. 0/1 userdiff: add javascript diff driverDerick W. de M. Frias, Jun 4, 2025
  2. 1/1 userdiff: add javascript diff driverDerick W. de M. Frias, Jun 4, 2025
  3. D. Ben KnobleJun 4, 2025
  4. Johannes SixtJun 5, 2025
  5. 0/4 diff: create pattern for javascript languageDerick W. de M. Frias, Jun 23, 2025
  6. 2/4 t4034: add tests for javascript word literalsDerick W. de M. Frias, Jun 23, 2025
  7. 3/4 t4018: add tests for recognizing javascript function syntaxDerick W. de M. Frias, Jun 23, 2025
  8. 1/4 userdiff: add javascript diff driverDerick W. de M. Frias, Jun 23, 2025
  9. Junio C HamanoJun 23, 2025
  10. 4/4 t4018: add tests for javascript export type function declarationsDerick W. de M. Frias, Jun 23, 2025
  11. Johannes SixtJun 26, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.