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

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

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Jun 4, 2025, 21:19 UTC
Message-ID
<CALnO6CBx0ZBXXq9wX_T_YPUYjJESTR28WX-DG5d351FBA2py9g@mail.gmail.com>
In-Reply-To
<20250604094100.80598-2-derick.william.moraes@gmail.com>

On Wed, Jun 4, 2025 at 5:44 AM Derick W. de M. Frias <derick.william.moraes@gmail.com> wrote:

>
> Add a userdiff pattern for javascript, and 13 test cases for instances
> of function declarations in javascript.

I didn't see any test cases dealing with nested functions, which might add some value?

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

Notice these files don't match the *nix convention of having a newline at the end. I find that some editors like VS Code have broken defaults [1] and require a settings change to get this correct, but notably Git's diff machinery will reliably warn you.

[1]: https://stackoverflow.com/q/44704968/4400820
Show 156 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",
> +     /* 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]*"

I didn't see any test cases using these modifiers, either, not that we have to test 100% of all cases.

Show 24 quoted lines
> +     "([$_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
>
>
-- 
D. Ben Knoble
Previous: Derick W. de M. FriasNext: Johannes Sixt
Message 3 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.