userdiff: add javascript diff driver
cover userdiff: add javascript diff driver
Hi, I'm Derick and this is one of my first contributions. I'm a CS undergrad student and I'm really excited to start learning more about Git's internals.
As it is in 2025, javascript is amongst the most prevalent programming languages and yet it it not beeing supported by a diff driver in Git. I do believe that the addition of this functionality is a good contribution that will benefit tons of developers that work with javascript.
For me, it was a surprise to discover that javascript isn't supported yet, so the first thing that came to mind was if someone had already tried to work on the problem. Searching at Git's lore, I found some previous atempts at tacking it and I tried to learn from them and to guide my work along what I believe were good paths taken.
The pattern I added to userdiff.c to recognize functions groups them in some categories, that are: conventional functions (Those that are declared in outer scope, and not assigned to any variable), assigned functions (those that ARE assigned to a variable), arrow functions and functions declared inside classes or objects.
For js literals, the regex matches valid alphanumerical literals that are valid in javascript. It also matches numerical literals in binary, octal, decimal and hexadecimal bases, and punctuations.
I also added test cases for instances of function declarations.
I tried to keep things simple, my idea is to make it work well while thinking 'vanilla' javascript-first. I'm quite sure the contribution still can be improved so I'm looking foward for feedback on what is important/interesting to be made.
Derick W. de M. Frias (1):
userdiff: add javascript diff driver
.../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
Signature · 1 line
2.50.0.rc0.62.g658f0ae201.dirty
PATCH 1/1 userdiff: add javascript diff driver
Add a userdiff pattern for javascript, and 13 test cases for instances of function declarations in javascript.
--- .../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
t/t4018/javascript-anonymous-function-assigned new file +4 -0
@@ -0,0 +1,4 @@ +const RIGHT = function (a, b) { + + return a + b; +};
t/t4018/javascript-arrow-function-assigned new file +4 -0
@@ -0,0 +1,4 @@ +const RIGHT = (a, b) => { + + return a + b; +};
t/t4018/javascript-arrow-function-assigned-2 new file +1 -0
@@ -0,0 +1 @@ +const RIGHT = a => a+1;
t/t4018/javascript-async-function new file +4 -0
@@ -0,0 +1,4 @@ +async function RIGHT (a, b) { + + return a + b; +};
t/t4018/javascript-async-function-assigned new file +4 -0
@@ -0,0 +1,4 @@ +const RIGHT = async function (a, b) { + + return a + b; +};
t/t4018/javascript-class-function new file +6 -0
@@ -0,0 +1,6 @@ +class Test { + RIGHT() { + let a = 1; + let b = Value; + } +}
t/t4018/javascript-function new file +4 -0
@@ -0,0 +1,4 @@ +function RIGHT (a, b) { + + return a + b; +};
t/t4018/javascript-function-assigned new file +4 -0
@@ -0,0 +1,4 @@ +const RIGHT = function test (a, b) { + + return a + b; +};
t/t4018/javascript-generator-function new file +5 -0
@@ -0,0 +1,5 @@ +function* RIGHT() { + + yield 1; + yield 2; +}
t/t4018/javascript-generator-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +function *RIGHT() { + + yield 1; + yield 2; +}
t/t4018/javascript-generator-function-assigned new file +5 -0
@@ -0,0 +1,5 @@ +const RIGHT = function* (){ + + yield 1; + yield 2; +}
t/t4018/javascript-generator-function-assigned-2 new file +5 -0
@@ -0,0 +1,5 @@ +const RIGHT = function *(){ + + yield 1; + yield 2; +}
t/t4018/javascript-method-function new file +6 -0
@@ -0,0 +1,6 @@ +const Test = { + RIGHT() { + let a = 1; + let b = Value; + } +}
userdiff.c +28 -0
@@ -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]+.*)$",/* -- */
Signature · 1 line
2.50.0.rc0.62.g658f0ae201.dirty
Quoted 3 lines · Derick W. de M. Frias
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?
Quoted 38 lines
Signed-off-by Derick W. de M. Frias <[email protected]>--- .../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-functiont/t4018/javascript-anonymous-function-assigned new file +0
-0
t/t4018/javascript-anonymous-function-assigned line 4
Quoted 5 lines
t/t4018/javascript-anonymous-function-assigned new file +4
-0@@ -0,0 +1,4 @@ +const RIGHT = function (a, b) { + + return a + b; +};
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.
Quoted 146 lines
t/t4018/javascript-arrow-function-assigned new file +4
-0@@ -0,0 +1,4 @@ +const RIGHT = (a, b) => { + + return a + b; +};t/t4018/javascript-arrow-function-assigned-2 new file +1
-0@@ -0,0 +1 @@ +const RIGHT = a => a+1;t/t4018/javascript-async-function new file +4
-0@@ -0,0 +1,4 @@ +async function RIGHT (a, b) { + + return a + b; +};t/t4018/javascript-async-function-assigned new file +4
-0@@ -0,0 +1,4 @@ +const RIGHT = async function (a, b) { + + return a + b; +};t/t4018/javascript-class-function new file +6
-0@@ -0,0 +1,6 @@ +class Test { + RIGHT() { + let a = 1; + let b = Value; + } +}t/t4018/javascript-function new file +4
-0@@ -0,0 +1,4 @@ +function RIGHT (a, b) { + + return a + b; +};t/t4018/javascript-function-assigned new file +4
-0@@ -0,0 +1,4 @@ +const RIGHT = function test (a, b) { + + return a + b; +};t/t4018/javascript-generator-function new file +5
-0@@ -0,0 +1,5 @@ +function* RIGHT() { + + yield 1; + yield 2; +}t/t4018/javascript-generator-function-2 new file +5
-0@@ -0,0 +1,5 @@ +function *RIGHT() { + + yield 1; + yield 2; +}t/t4018/javascript-generator-function-assigned new file +5
-0@@ -0,0 +1,5 @@ +const RIGHT = function* (){ + + yield 1; + yield 2; +}t/t4018/javascript-generator-function-assigned-2 new file +5
-0@@ -0,0 +1,5 @@ +const RIGHT = function *(){ + + yield 1; + yield 2; +}t/t4018/javascript-method-function new file +6
-0@@ -0,0 +1,6 @@ +const Test = { + RIGHT() { + let a = 1; + let b = Value; + } +}userdiff.c +1
-0@@ -237,6 +237,34 @@ PATTERNS("java","|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" "|[-+*/<>%&^|=!]=" "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), +PATTERNS("javascript",
userdiff.c PATTERNS("java", · line 250
Quoted 10 lines
userdiff.c +10
-0+/* 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.
Quoted 24 lines
userdiff.c +17
-1+ "([$_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
Signature · 1 line
D. Ben Knoble
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/[email protected]/
https://lore.kernel.org/git/[email protected]/
Javascript:
https://lore.kernel.org/git/[email protected]/
https://lore.kernel.org/git/[email protected]/
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:
Quoted 2 lines
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.
Quoted 38 lines
Signed-off-by Derick W. de M. Frias <[email protected]>--- .../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-functiont/t4018/javascript-anonymous-function-assigned new file +0
-0
t/t4018/javascript-anonymous-function-assigned line 4
Quoted 5 lines
t/t4018/javascript-anonymous-function-assigned new file +4
-0@@ -0,0 +1,4 @@ +const RIGHT = function (a, b) { + + return a + b; +};
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?
Quoted 142 lines
t/t4018/javascript-arrow-function-assigned new file +4
-0@@ -0,0 +1,4 @@ +const RIGHT = (a, b) => { + + return a + b; +};t/t4018/javascript-arrow-function-assigned-2 new file +1
-0@@ -0,0 +1 @@ +const RIGHT = a => a+1;t/t4018/javascript-async-function new file +4
-0@@ -0,0 +1,4 @@ +async function RIGHT (a, b) { + + return a + b; +};t/t4018/javascript-async-function-assigned new file +4
-0@@ -0,0 +1,4 @@ +const RIGHT = async function (a, b) { + + return a + b; +};t/t4018/javascript-class-function new file +6
-0@@ -0,0 +1,6 @@ +class Test { + RIGHT() { + let a = 1; + let b = Value; + } +}t/t4018/javascript-function new file +4
-0@@ -0,0 +1,4 @@ +function RIGHT (a, b) { + + return a + b; +};t/t4018/javascript-function-assigned new file +4
-0@@ -0,0 +1,4 @@ +const RIGHT = function test (a, b) { + + return a + b; +};t/t4018/javascript-generator-function new file +5
-0@@ -0,0 +1,5 @@ +function* RIGHT() { + + yield 1; + yield 2; +}t/t4018/javascript-generator-function-2 new file +5
-0@@ -0,0 +1,5 @@ +function *RIGHT() { + + yield 1; + yield 2; +}t/t4018/javascript-generator-function-assigned new file +5
-0@@ -0,0 +1,5 @@ +const RIGHT = function* (){ + + yield 1; + yield 2; +}t/t4018/javascript-generator-function-assigned-2 new file +5
-0@@ -0,0 +1,5 @@ +const RIGHT = function *(){ + + yield 1; + yield 2; +}t/t4018/javascript-method-function new file +6
-0@@ -0,0 +1,6 @@ +const Test = { + RIGHT() { + let a = 1; + let b = Value; + } +}userdiff.c +0
-0
userdiff.c PATTERNS("java", · line 240
Quoted 4 lines
userdiff.c +1
-0@@ -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.
Quoted 17 lines
userdiff.c +17
-0+/* 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?|"
userdiff.c PATTERNS("java", · line 267
Quoted 10 lines
userdiff.c +10
-0+/* 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.
userdiff.c PATTERNS("java", · line 270
Quoted 3 lines
userdiff.c +0
-0PATTERNS("kotlin", "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",/* -- */
-- Hannes
v2 cover diff: create pattern for javascript language
I'm sending a new version of the diff driver. I tried to expand recognition of functions to more possible cases, improved tests in t4018 for function matching of the pattern and tried to add test t4034 for the matching of words.
I added a lot more test for t4018, so much that I got caught up if I was exaggerating. I was not trying to exhaust all possibilities, I just think that javascript has a lot of different valid syntaxes for declaring functions and I was trying to make a somewhat complete coverage of that. Let me know if perhaps I'm going too far along this direction.
I also tried to incorporate your feedbacks, thanks!
Quoted 9 lines
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/[email protected]/
https://lore.kernel.org/git/[email protected]/
Quoted 7 lines
Javascript:
https://lore.kernel.org/git/[email protected]/
https://lore.kernel.org/git/[email protected]/Please review these submission and the responses that they received. Perhaps you can find inspiration for improvement from them.
It has beeing great fun :)! I took a deep dive into the suggested submissions. For clarity purposes, I'll be addressing them for the following index, and sometimes for the contributor's name:
[1] Utsav Parmar: https://lore.kernel.org/git/[email protected]/
[2] Mattew Hughes: https://lore.kernel.org/git/[email protected]/
[3] Sergius Nyah: https://lore.kernel.org/git/[email protected]/
[4] Xing Zhi Jiang: https://lore.kernel.org/git/[email protected]/
From contributions [1], [2] and [3] I did not found many things that are worth noting.
Previous to sending the v1, I had already searched through the lore and stumbled across Xing Zhi Jiang's[4] contribution. He had a lot of things worked out, including well recognized nested functions, that is something still not supported here in v2. Also the discutions around it brought up interesting points that I took into consideration:
- ESModules syntax for exporting functions (export function FUNCNAME...)
- 'exports.' and 'module.exports.' syntax from commonJS.
- What should and what should not be supported.
I called 'vanillaJS' javascript as it is defined by ECMAScript's specs, or what you will find if you are working with JS without things like React, Vue, jQuery, Axios. I noticed that I used this term in the last submission but had not explained what I was talking about. There I said I wanted to be "vanillaJS" first, as I believe ECMAs specs should be the focal point of a tool like this one.
This is important, because some things that live outside 'vanillaJS', like 'commonJS' for example, which is a thing in Node, add syntax to valid function declarations in their own context. Exhausting those syntaxes might be impossible, and I belive it's not the way to go here. Also, it would be huge work and I don't believe that I have JS knowledge extensive enough to do so.
As it was pointed out inside [4] discutions, it would be nice if a heavilly spread syntax like 'export.' and 'module.export.' from 'commonJS' were supported, even thought it is not ECMA, because it would benefit users in more diverse situations, which I agree. That is why I tried adding support to recognize them.
Xing tried to add in v3 patterns for supporting jQuery. As I don't have experience working, it is not added here. Like in the above paragraph, I think it would greatly benefit a lot of developers if jQuery was supported, but that raised the discussion:
What this pattern should aim to give support to outside vanillaJS, if it should? And if yes, where do we draw the line to define what is widespread enough to be supported? I want to know your toughts on it.
Quoted 5 lines
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.
In userdiff.c, I cleaned from the pattern the single character punctuation identifiers and I improved the syntax of some other identifiers (Like ={3} --> ===). For scaped punctuations, I kept the syntax with {} as I believe it reads more clearly (Like \\.{3} instead of \\.\\.\\.}.
Quoted 2 lines
I didn't see any test cases dealing with nested functions, which might add some value?
I agree it would add value. As I said, [4] had it working and for the moment but I still could not understand the strategy and what part of the regex dealt with it. In his v1, Xing talks about 3 negations rules he added to the matching pattern. I think that this is the part responsible for solving the problem, but I don't understand how. I would appreciate if someone took a little time to maybe figure it out.
Quoted 2 lines
We avoid incomplete last lines in this code base if it is not mandated for some reason.
I put a blank line at the end of all files in this submission.
Quoted 2 lines
Here and in the later test cases, the word "ChangeMe" is missing. How did these ever pass the tests?
Here Johannes was reffering to the t4018 test cases which were missing "ChangeMe", it was a mistake from my part. This time I added "ChangeMe" to the t4018 tests.
Derick W. de M. Frias (4):
userdiff: add javascript diff driver
t4034: add tests for javascript word literals
t4018: add tests for recognizing javascript function syntax
t4018: add tests for javascript 'exports.', 'module.exports' and
'export' type functions
Documentation/gitattributes.adoc | 2 + .../javascript-anonymous-assigned-function | 4 ++ t/t4018/javascript-arrow-assigned-function | 4 ++ t/t4018/javascript-arrow-assigned-function-2 | 5 ++ t/t4018/javascript-arrow-assigned-function-3 | 1 + t/t4018/javascript-assigned-function | 4 ++ t/t4018/javascript-async-assigned-function | 4 ++ t/t4018/javascript-async-function | 4 +- t/t4018/javascript-class-get-function | 5 ++ t/t4018/javascript-class-set-function | 5 ++ t/t4018/javascript-class-static-function | 5 ++ t/t4018/javascript-class-unprefixed-function | 6 ++ ...ascript-dotexpors-async-anonymous-function | 3 + .../javascript-dotexports-anonymous-function | 3 + t/t4018/javascript-dotexports-arrow-function | 4 ++ .../javascript-dotexports-arrow-function-2 | 4 ++ .../javascript-dotexports-arrow-function-3 | 1 + .../javascript-dotexports-assigned-function | 1 + ...javascript-dotexports-async-arrow-function | 3 + ...vascript-dotexports-async-arrow-function-2 | 4 ++ ...vascript-dotexports-async-arrow-function-3 | 1 + t/t4018/javascript-dotexports-async-function | 4 ++ ...exports-async-generator-anonymous-function | 5 ++ ...ports-async-generator-anonymous-function-2 | 5 ++ ...script-dotexports-async-generator-function | 5 ++ ...ript-dotexports-async-generator-function-2 | 5 ++ t/t4018/javascript-dotexports-function | 4 ++ ...pt-dotexports-generator-anonymous-function | 5 ++ ...-dotexports-generator-anonymous-function-2 | 5 ++ .../javascript-dotexports-generator-function | 5 ++ ...javascript-dotexports-generator-function-2 | 5 ++ t/t4018/javascript-export-arrow-function | 4 ++ ...t-export-async-anonymous-assigned-function | 4 ++ .../javascript-export-async-arrow-function | 4 ++ t/t4018/javascript-export-async-function | 4 ++ ...sync-generator-anonymous-assigned-function | 4 ++ ...nc-generator-anonymous-assigned-function-2 | 4 ++ ...t-export-async-generator-assigned-function | 5 ++ ...export-async-generator-assigned-function-2 | 5 ++ ...javascript-export-async-generator-function | 5 ++ ...vascript-export-async-generator-function-2 | 5 ++ t/t4018/javascript-export-function | 4 ++ ...ascript-export-generator-assigned-function | 6 ++ ...cript-export-generator-assigned-function-2 | 6 ++ t/t4018/javascript-export-generator-function | 5 ++ .../javascript-export-generator-function-2 | 5 ++ t/t4018/javascript-function | 4 +- .../javascript-generator-assigned-function | 5 ++ .../javascript-generator-assigned-function-2 | 5 ++ t/t4018/javascript-generator-function | 4 +- t/t4018/javascript-generator-function-2 | 4 +- t/t4018/javascript-method-unprefixed-function | 6 ++ ...cript-module-dotexports-anonymous-function | 3 + ...avascript-module-dotexports-arrow-function | 4 ++ ...ascript-module-dotexports-arrow-function-2 | 4 ++ ...ascript-module-dotexports-arrow-function-3 | 1 + ...script-module-dotexports-assigned-function | 1 + ...ipt-module-dotexports-async-arrow-function | 3 + ...t-module-dotexports-async-arrow-function-2 | 4 ++ ...t-module-dotexports-async-arrow-function-3 | 1 + ...avascript-module-dotexports-async-function | 4 ++ ...exports-async-generator-anonymous-function | 5 ++ ...ports-async-generator-anonymous-function-2 | 5 ++ ...module-dotexports-async-generator-function | 5 ++ ...dule-dotexports-async-generator-function-2 | 5 ++ t/t4018/javascript-module-dotexports-function | 4 ++ ...le-dotexports-generator-anonymous-function | 5 ++ ...-dotexports-generator-anonymous-function-2 | 5 ++ ...cript-module-dotexports-generator-function | 5 ++ ...ipt-module-dotexports-generator-function-2 | 5 ++ t/t4018/javascript-skip-function-calls | 7 +++ t/t4018/javascript-skip-reserved-words | 38 ++++++++++++ t/t4034-diff-words.sh | 1 + t/t4034/javascript/expect | 26 ++++++-- t/t4034/javascript/post | 16 +++-- t/t4034/javascript/pre | 16 +++-- userdiff.c | 62 +++++++++++-------- 77 files changed, 408 insertions(+), 46 deletions(-) create mode 100644 t/t4018/javascript-anonymous-assigned-function create mode 100644 t/t4018/javascript-arrow-assigned-function create mode 100644 t/t4018/javascript-arrow-assigned-function-2 create mode 100644 t/t4018/javascript-arrow-assigned-function-3 create mode 100644 t/t4018/javascript-assigned-function create mode 100644 t/t4018/javascript-async-assigned-function create mode 100644 t/t4018/javascript-class-get-function create mode 100644 t/t4018/javascript-class-set-function create mode 100644 t/t4018/javascript-class-static-function create mode 100644 t/t4018/javascript-class-unprefixed-function create mode 100644 t/t4018/javascript-dotexpors-async-anonymous-function create mode 100644 t/t4018/javascript-dotexports-anonymous-function create mode 100644 t/t4018/javascript-dotexports-arrow-function create mode 100644 t/t4018/javascript-dotexports-arrow-function-2 create mode 100644 t/t4018/javascript-dotexports-arrow-function-3 create mode 100644 t/t4018/javascript-dotexports-assigned-function create mode 100644 t/t4018/javascript-dotexports-async-arrow-function create mode 100644 t/t4018/javascript-dotexports-async-arrow-function-2 create mode 100644 t/t4018/javascript-dotexports-async-arrow-function-3 create mode 100644 t/t4018/javascript-dotexports-async-function create mode 100644 t/t4018/javascript-dotexports-async-generator-anonymous-function create mode 100644 t/t4018/javascript-dotexports-async-generator-anonymous-function-2 create mode 100644 t/t4018/javascript-dotexports-async-generator-function create mode 100644 t/t4018/javascript-dotexports-async-generator-function-2 create mode 100644 t/t4018/javascript-dotexports-function create mode 100644 t/t4018/javascript-dotexports-generator-anonymous-function create mode 100644 t/t4018/javascript-dotexports-generator-anonymous-function-2 create mode 100644 t/t4018/javascript-dotexports-generator-function create mode 100644 t/t4018/javascript-dotexports-generator-function-2 create mode 100644 t/t4018/javascript-export-arrow-function create mode 100644 t/t4018/javascript-export-async-anonymous-assigned-function create mode 100644 t/t4018/javascript-export-async-arrow-function create mode 100644 t/t4018/javascript-export-async-function create mode 100644 t/t4018/javascript-export-async-generator-anonymous-assigned-function create mode 100644 t/t4018/javascript-export-async-generator-anonymous-assigned-function-2 create mode 100644 t/t4018/javascript-export-async-generator-assigned-function create mode 100644 t/t4018/javascript-export-async-generator-assigned-function-2 create mode 100644 t/t4018/javascript-export-async-generator-function create mode 100644 t/t4018/javascript-export-async-generator-function-2 create mode 100644 t/t4018/javascript-export-function create mode 100644 t/t4018/javascript-export-generator-assigned-function create mode 100644 t/t4018/javascript-export-generator-assigned-function-2 create mode 100644 t/t4018/javascript-export-generator-function create mode 100644 t/t4018/javascript-export-generator-function-2 create mode 100644 t/t4018/javascript-generator-assigned-function create mode 100644 t/t4018/javascript-generator-assigned-function-2 create mode 100644 t/t4018/javascript-method-unprefixed-function create mode 100644 t/t4018/javascript-module-dotexports-anonymous-function create mode 100644 t/t4018/javascript-module-dotexports-arrow-function create mode 100644 t/t4018/javascript-module-dotexports-arrow-function-2 create mode 100644 t/t4018/javascript-module-dotexports-arrow-function-3 create mode 100644 t/t4018/javascript-module-dotexports-assigned-function create mode 100644 t/t4018/javascript-module-dotexports-async-arrow-function create mode 100644 t/t4018/javascript-module-dotexports-async-arrow-function-2 create mode 100644 t/t4018/javascript-module-dotexports-async-arrow-function-3 create mode 100644 t/t4018/javascript-module-dotexports-async-function create mode 100644 t/t4018/javascript-module-dotexports-async-generator-anonymous-function create mode 100644 t/t4018/javascript-module-dotexports-async-generator-anonymous-function-2 create mode 100644 t/t4018/javascript-module-dotexports-async-generator-function create mode 100644 t/t4018/javascript-module-dotexports-async-generator-function-2 create mode 100644 t/t4018/javascript-module-dotexports-function create mode 100644 t/t4018/javascript-module-dotexports-generator-anonymous-function create mode 100644 t/t4018/javascript-module-dotexports-generator-anonymous-function-2 create mode 100644 t/t4018/javascript-module-dotexports-generator-function create mode 100644 t/t4018/javascript-module-dotexports-generator-function-2 create mode 100644 t/t4018/javascript-skip-function-calls create mode 100644 t/t4018/javascript-skip-reserved-words
Signature · 1 line
2.50.0.rc0.62.g658f0ae201.dirty
PATCH v2 1/4 userdiff: add javascript diff driver
Add diff pattern for JavaScript programming language and documentation.
--- Documentation/gitattributes.adoc | 2 ++ userdiff.c | 62 ++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 26 deletions(-)
Documentation/gitattributes.adoc +2 -0
@@ -891,6 +891,8 @@ patterns are available: - `java` suitable for source code in the Java language. +- `javascript` suitable for source code in the JavaScript language. + - `kotlin` suitable for source code in the Kotlin language. - `markdown` suitable for Markdown documents.
userdiff.c +36 -26
69 lines not on this page · raw message
Signature · 1 line
2.50.0.rc0.62.g658f0ae201.dirty
userdiff.c PATTERNS("java", · line 242
Quoted 8 lines · Derick W. de M. Frias
userdiff.c +0
-2@@ -238,33 +238,43 @@ PATTERNS("java","|[-+*/<>%&^|=!]=" "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), PATTERNS("javascript", -/* conventional named functions */ - "^[ \t]*(async[ \t]+)?function[ \t]*\\*?[ \t]*([$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*\\(.*$|"
Curious to see that anything needs to be removed from "javascript" section, when we do not have any patterns for the language in the file. Which version of Git is this patch meant to apply to?
PATCH v2 2/4 t4034: add tests for javascript word literals
In reply to Derick W. de M. FriasAdd tests for javascript word pattern.
--- t/t4034-diff-words.sh | 1 + t/t4034/javascript/expect | 26 ++++++++++++++++++++++---- t/t4034/javascript/post | 16 ++++++++++++---- t/t4034/javascript/pre | 16 ++++++++++++---- 4 files changed, 47 insertions(+), 12 deletions(-)
t/t4034-diff-words.sh +1 -0
@@ -328,6 +328,7 @@ test_language_driver dts test_language_driver fortran test_language_driver html test_language_driver java +test_language_driver javascript test_language_driver kotlin test_language_driver matlab test_language_driver objc
t/t4034/javascript/expect +22 -4
@@ -43,12 +43,30 @@ <GREEN>0B0010<RESET> <GREEN>0b0001_1101_0011<RESET> <GREEN>0b11111111111111000011111111111111111n<RESET> +// Floating point and exponent notation<RESET> +<RED>3.14<RESET> +<RED>0.5<RESET> +<RED>1.23e3<RESET> +<RED>4.56e-2<RESET> +<RED>7.89E4<RESET> +<RED>0.12E-1<RESET> +<RED>5e2<RESET> +<RED>7e-3<RESET> +<RED>6E3<RESET> +<RED>9E-3<RESET> +<GREEN>3.15<RESET> +<GREEN>0.75<RESET> +<GREEN>1.23e4<RESET> +<GREEN>4.96e-3<RESET> +<GREEN>7.89E8<RESET> +<GREEN>0.11E-2<RESET> +<GREEN>6e3<RESET> +<GREEN>8e-2<RESET> +<GREEN>7E4<RESET> +<GREEN>2E-6<RESET> // punctuations<RESET> -{<RED>a<RESET><GREEN>b<RESET>} (<RED>a<RESET><GREEN>b<RESET>) -<RED>a<RESET><GREEN>b<RESET>; -[<RED>1,<RESET>2<GREEN>,3<RESET>] [<RED>1, 2,<RESET> ...<RED>params<RESET><GREEN>params_v2<RESET> ] a<RED><=<RESET><GREEN>=<RESET>2 a<RED>>=<RESET><GREEN>=<RESET>2 a<RED>==<RESET><GREEN>=<RESET>2 a<RED>!=<RESET><GREEN>=<RESET>2 a<RED>===<RESET><GREEN>=<RESET>2 a<RED>!==<RESET><GREEN>=<RESET>2 a<RED>^=<RESET><GREEN>=<RESET>2 a<RED>=><RESET><GREEN>=<RESET>2 a<RED>+=<RESET><GREEN>-=<RESET>b a<RED>*=<RESET><GREEN>%=<RESET>b a<RED>**=<RESET><GREEN>&&=<RESET>b a<RED>||=<RESET><GREEN>|=<RESET>b b<RED>+<RESET><GREEN>-<RESET>c a<RED>--<RESET><GREEN>++<RESET> a<RED>>><RESET><GREEN><<<RESET>b a<RED>>>><RESET><GREEN>>>>=<RESET>b a<RED>>>=<RESET><GREEN><<=<RESET>b -a<RED>&&<RESET><GREEN>&<RESET>b a<RED>||<RESET><GREEN>|<RESET>b a<RED>&&=<RESET><GREEN>??=<RESET>b +a<RED>&&<RESET><GREEN>&<RESET>b a<RED>||<RESET><GREEN>|<RESET>b a<RED>&&=<RESET><GREEN>??=<RESET>b
t/t4034/javascript/post +12 -4
@@ -22,12 +22,20 @@ 0B0010 0b0001_1101_0011 0b11111111111111000011111111111111111n +// Floating point and exponent notation +3.15 +0.75 +1.23e4 +4.96e-3 +7.89E8 +0.11E-2 +6e3 +8e-2 +7E4 +2E-6 // punctuations -{b} (b) -b; -[2,3] [ ...params_v2 ] a=2 a=2 a=2 a=2 a=2 a=2 a=2 a=2 a-=b a%=b a&&=b a|=b b-c a++ a<<b a>>>=b a<<=b -a&b a|b a??=b +a&b a|b a??=b
t/t4034/javascript/pre +12 -4
@@ -22,12 +22,20 @@ 0B0110 0b0001_1001_0011 0b1111111111111111111111111111111111111n +// Floating point and exponent notation +3.14 +0.5 +1.23e3 +4.56e-2 +7.89E4 +0.12E-1 +5e2 +7e-3 +6E3 +9E-3 // punctuations -{a} (a) -a; -[1,2] [ 1, 2, ...params ] a<=2 a>=2 a==2 a!=2 a===2 a!==2 a^=2 a=>2 a+=b a*=b a**=b a||=b b+c a-- a>>b a>>>b a>>=b -a&&b a||b a&&=b +a&&b a||b a&&=b
Signature · 1 line
2.50.0.rc0.62.g658f0ae201.dirty
PATCH v2 3/4 t4018: add tests for recognizing javascript function syntax
In reply to Derick W. de M. FriasAdd tests for javascript function declarations as in ECMAScript ES5.1<
--- .../javascript-anonymous-assigned-function | 4 ++ t/t4018/javascript-arrow-assigned-function | 4 ++ t/t4018/javascript-arrow-assigned-function-2 | 5 +++ t/t4018/javascript-arrow-assigned-function-3 | 1 + t/t4018/javascript-assigned-function | 4 ++ t/t4018/javascript-async-assigned-function | 4 ++ t/t4018/javascript-async-function | 4 +- t/t4018/javascript-class-get-function | 5 +++ t/t4018/javascript-class-set-function | 5 +++ t/t4018/javascript-class-static-function | 5 +++ t/t4018/javascript-class-unprefixed-function | 6 +++ t/t4018/javascript-function | 4 +- .../javascript-generator-assigned-function | 5 +++ .../javascript-generator-assigned-function-2 | 5 +++ t/t4018/javascript-generator-function | 4 +- t/t4018/javascript-generator-function-2 | 4 +- t/t4018/javascript-method-unprefixed-function | 6 +++ t/t4018/javascript-skip-function-calls | 7 ++++ t/t4018/javascript-skip-reserved-words | 38 +++++++++++++++++++ 19 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 t/t4018/javascript-anonymous-assigned-function create mode 100644 t/t4018/javascript-arrow-assigned-function create mode 100644 t/t4018/javascript-arrow-assigned-function-2 create mode 100644 t/t4018/javascript-arrow-assigned-function-3 create mode 100644 t/t4018/javascript-assigned-function create mode 100644 t/t4018/javascript-async-assigned-function create mode 100644 t/t4018/javascript-class-get-function create mode 100644 t/t4018/javascript-class-set-function create mode 100644 t/t4018/javascript-class-static-function create mode 100644 t/t4018/javascript-class-unprefixed-function create mode 100644 t/t4018/javascript-generator-assigned-function create mode 100644 t/t4018/javascript-generator-assigned-function-2 create mode 100644 t/t4018/javascript-method-unprefixed-function create mode 100644 t/t4018/javascript-skip-function-calls create mode 100644 t/t4018/javascript-skip-reserved-words
t/t4018/javascript-anonymous-assigned-function new file +4 -0
@@ -0,0 +1,4 @@ +const RIGHT = function (a, b) { + + return a + b; //ChangeMe +};
t/t4018/javascript-arrow-assigned-function new file +4 -0
@@ -0,0 +1,4 @@ +const RIGHT = (a, b) => { + + return a + b; //ChangeMe +};
t/t4018/javascript-arrow-assigned-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +const RIGHT = a => { + + return a + 1; //ChangeMe +}; +
t/t4018/javascript-arrow-assigned-function-3 new file +1 -0
@@ -0,0 +1 @@ +const RIGHT = a => a+1; //ChangeMe
t/t4018/javascript-assigned-function new file +4 -0
@@ -0,0 +1,4 @@ +const RIGHT = function test (a, b) { + + return a + b; //ChangeMe +};
t/t4018/javascript-async-assigned-function new file +4 -0
@@ -0,0 +1,4 @@ +const RIGHT = async function (a, b) { + + return a + b; //ChangeMe +};
t/t4018/javascript-async-function +2 -2
@@ -1,4 +1,4 @@ async function RIGHT (a, b) { - return a + b; -}; + return a + b; //ChangeMe +};
t/t4018/javascript-class-get-function new file +5 -0
@@ -0,0 +1,5 @@ +class ChangeMe { + get RIGHT() { + return 1; + } +}
t/t4018/javascript-class-set-function new file +5 -0
@@ -0,0 +1,5 @@ +class ChangeMe { + set RIGHT() { + return 1; + } +}
t/t4018/javascript-class-static-function new file +5 -0
@@ -0,0 +1,5 @@ +class ChangeMe { + static RIGHT(a, b) { + return a + b; + } +}
t/t4018/javascript-class-unprefixed-function new file +6 -0
@@ -0,0 +1,6 @@ +class Test { + RIGHT() { + let a = 1; + let b = ChangeMe; + } +}
t/t4018/javascript-function +2 -2
@@ -1,4 +1,4 @@ function RIGHT (a, b) { - return a + b; -}; + return a + b; //ChangeMe +};
t/t4018/javascript-generator-assigned-function new file +5 -0
@@ -0,0 +1,5 @@ +const RIGHT = function* (){ + + yield 1; + yield 2; //ChangeMe +}
t/t4018/javascript-generator-assigned-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +const RIGHT = function *(){ + + yield 1; + yield 2; //ChangeMe +}
t/t4018/javascript-generator-function +2 -2
@@ -1,5 +1,5 @@ function* RIGHT() { yield 1; - yield 2; -} + yield 2; //ChangeMe +}
t/t4018/javascript-generator-function-2 +2 -2
@@ -1,5 +1,5 @@ function *RIGHT() { yield 1; - yield 2; -} + yield 2; //ChangeMe +}
t/t4018/javascript-method-unprefixed-function new file +6 -0
@@ -0,0 +1,6 @@ +const Test = { + RIGHT() { + let a = 1; + let b = ChangeMe; + } +}
t/t4018/javascript-skip-function-calls new file +7 -0
@@ -0,0 +1,7 @@ +class Test { + static RIGHT() { + call_to_skip(); + call_to_skip2(); + let a = ChangeMe; + } +}
t/t4018/javascript-skip-reserved-words new file +38 -0
@@ -0,0 +1,38 @@ +function RIGHT(a, b) { + import("./async1") + + if (a > 1) { + // ... + } + do { + // ... + } + while (i < 5){ + // + }; + for (const element of array1) { + console.log(element) + } + with(o) { + console.log(x) + } + switch (expr) { + case 'a': + // ... + break; + case 'b': + // ... + break; + default: + // ... + } + try { + // ... + return (a + c) + } + catch (error) { + // ... + } + + return a + b; // ChangeMe +}
Signature · 1 line
2.50.0.rc0.62.g658f0ae201.dirty
PATCH v2 4/4 t4018: add tests for javascript export type function declarations
In reply to Derick W. de M. FriasAdd tests for javascript export function declarations as in ECMAScript ES6 and CommonJS.
--- t/t4018/javascript-dotexpors-async-anonymous-function | 3 +++ t/t4018/javascript-dotexports-anonymous-function | 3 +++ t/t4018/javascript-dotexports-arrow-function | 4 ++++ t/t4018/javascript-dotexports-arrow-function-2 | 4 ++++ t/t4018/javascript-dotexports-arrow-function-3 | 1 + t/t4018/javascript-dotexports-assigned-function | 1 + t/t4018/javascript-dotexports-async-arrow-function | 3 +++ t/t4018/javascript-dotexports-async-arrow-function-2 | 4 ++++ t/t4018/javascript-dotexports-async-arrow-function-3 | 1 + t/t4018/javascript-dotexports-async-function | 4 ++++ ...javascript-dotexports-async-generator-anonymous-function | 5 +++++ ...vascript-dotexports-async-generator-anonymous-function-2 | 5 +++++ t/t4018/javascript-dotexports-async-generator-function | 5 +++++ t/t4018/javascript-dotexports-async-generator-function-2 | 5 +++++ t/t4018/javascript-dotexports-function | 4 ++++ t/t4018/javascript-dotexports-generator-anonymous-function | 5 +++++ .../javascript-dotexports-generator-anonymous-function-2 | 5 +++++ t/t4018/javascript-dotexports-generator-function | 5 +++++ t/t4018/javascript-dotexports-generator-function-2 | 5 +++++ t/t4018/javascript-export-arrow-function | 4 ++++ t/t4018/javascript-export-async-anonymous-assigned-function | 4 ++++ t/t4018/javascript-export-async-arrow-function | 4 ++++ t/t4018/javascript-export-async-function | 4 ++++ ...cript-export-async-generator-anonymous-assigned-function | 4 ++++ ...ipt-export-async-generator-anonymous-assigned-function-2 | 4 ++++ t/t4018/javascript-export-async-generator-assigned-function | 5 +++++ .../javascript-export-async-generator-assigned-function-2 | 5 +++++ t/t4018/javascript-export-async-generator-function | 5 +++++ t/t4018/javascript-export-async-generator-function-2 | 5 +++++ t/t4018/javascript-export-function | 4 ++++ t/t4018/javascript-export-generator-assigned-function | 6 ++++++ t/t4018/javascript-export-generator-assigned-function-2 | 6 ++++++ t/t4018/javascript-export-generator-function | 5 +++++ t/t4018/javascript-export-generator-function-2 | 5 +++++ t/t4018/javascript-module-dotexports-anonymous-function | 3 +++ t/t4018/javascript-module-dotexports-arrow-function | 4 ++++ t/t4018/javascript-module-dotexports-arrow-function-2 | 4 ++++ t/t4018/javascript-module-dotexports-arrow-function-3 | 1 + t/t4018/javascript-module-dotexports-assigned-function | 1 + t/t4018/javascript-module-dotexports-async-arrow-function | 3 +++ t/t4018/javascript-module-dotexports-async-arrow-function-2 | 4 ++++ t/t4018/javascript-module-dotexports-async-arrow-function-3 | 1 + t/t4018/javascript-module-dotexports-async-function | 4 ++++ ...ipt-module-dotexports-async-generator-anonymous-function | 5 +++++ ...t-module-dotexports-async-generator-anonymous-function-2 | 5 +++++ .../javascript-module-dotexports-async-generator-function | 5 +++++ .../javascript-module-dotexports-async-generator-function-2 | 5 +++++ t/t4018/javascript-module-dotexports-function | 4 ++++ ...avascript-module-dotexports-generator-anonymous-function | 5 +++++ ...ascript-module-dotexports-generator-anonymous-function-2 | 5 +++++ t/t4018/javascript-module-dotexports-generator-function | 5 +++++ t/t4018/javascript-module-dotexports-generator-function-2 | 5 +++++ 52 files changed, 211 insertions(+) create mode 100644 t/t4018/javascript-dotexpors-async-anonymous-function create mode 100644 t/t4018/javascript-dotexports-anonymous-function create mode 100644 t/t4018/javascript-dotexports-arrow-function create mode 100644 t/t4018/javascript-dotexports-arrow-function-2 create mode 100644 t/t4018/javascript-dotexports-arrow-function-3 create mode 100644 t/t4018/javascript-dotexports-assigned-function create mode 100644 t/t4018/javascript-dotexports-async-arrow-function create mode 100644 t/t4018/javascript-dotexports-async-arrow-function-2 create mode 100644 t/t4018/javascript-dotexports-async-arrow-function-3 create mode 100644 t/t4018/javascript-dotexports-async-function create mode 100644 t/t4018/javascript-dotexports-async-generator-anonymous-function create mode 100644 t/t4018/javascript-dotexports-async-generator-anonymous-function-2 create mode 100644 t/t4018/javascript-dotexports-async-generator-function create mode 100644 t/t4018/javascript-dotexports-async-generator-function-2 create mode 100644 t/t4018/javascript-dotexports-function create mode 100644 t/t4018/javascript-dotexports-generator-anonymous-function create mode 100644 t/t4018/javascript-dotexports-generator-anonymous-function-2 create mode 100644 t/t4018/javascript-dotexports-generator-function create mode 100644 t/t4018/javascript-dotexports-generator-function-2 create mode 100644 t/t4018/javascript-export-arrow-function create mode 100644 t/t4018/javascript-export-async-anonymous-assigned-function create mode 100644 t/t4018/javascript-export-async-arrow-function create mode 100644 t/t4018/javascript-export-async-function create mode 100644 t/t4018/javascript-export-async-generator-anonymous-assigned-function create mode 100644 t/t4018/javascript-export-async-generator-anonymous-assigned-function-2 create mode 100644 t/t4018/javascript-export-async-generator-assigned-function create mode 100644 t/t4018/javascript-export-async-generator-assigned-function-2 create mode 100644 t/t4018/javascript-export-async-generator-function create mode 100644 t/t4018/javascript-export-async-generator-function-2 create mode 100644 t/t4018/javascript-export-function create mode 100644 t/t4018/javascript-export-generator-assigned-function create mode 100644 t/t4018/javascript-export-generator-assigned-function-2 create mode 100644 t/t4018/javascript-export-generator-function create mode 100644 t/t4018/javascript-export-generator-function-2 create mode 100644 t/t4018/javascript-module-dotexports-anonymous-function create mode 100644 t/t4018/javascript-module-dotexports-arrow-function create mode 100644 t/t4018/javascript-module-dotexports-arrow-function-2 create mode 100644 t/t4018/javascript-module-dotexports-arrow-function-3 create mode 100644 t/t4018/javascript-module-dotexports-assigned-function create mode 100644 t/t4018/javascript-module-dotexports-async-arrow-function create mode 100644 t/t4018/javascript-module-dotexports-async-arrow-function-2 create mode 100644 t/t4018/javascript-module-dotexports-async-arrow-function-3 create mode 100644 t/t4018/javascript-module-dotexports-async-function create mode 100644 t/t4018/javascript-module-dotexports-async-generator-anonymous-function create mode 100644 t/t4018/javascript-module-dotexports-async-generator-anonymous-function-2 create mode 100644 t/t4018/javascript-module-dotexports-async-generator-function create mode 100644 t/t4018/javascript-module-dotexports-async-generator-function-2 create mode 100644 t/t4018/javascript-module-dotexports-function create mode 100644 t/t4018/javascript-module-dotexports-generator-anonymous-function create mode 100644 t/t4018/javascript-module-dotexports-generator-anonymous-function-2 create mode 100644 t/t4018/javascript-module-dotexports-generator-function create mode 100644 t/t4018/javascript-module-dotexports-generator-function-2
t/t4018/javascript-dotexpors-async-anonymous-function new file +3 -0
@@ -0,0 +1,3 @@ +exports.RIGHT = async function(a, b) { + return a + b; // ChangeMe +};
t/t4018/javascript-dotexports-anonymous-function new file +3 -0
@@ -0,0 +1,3 @@ +exports.RIGHT = function(a, b) { + return a + b; //ChangeMe +};
t/t4018/javascript-dotexports-arrow-function new file +4 -0
@@ -0,0 +1,4 @@ +exports.RIGHT = (a, b) => { + + return a+b; //ChangeMe +};
t/t4018/javascript-dotexports-arrow-function-2 new file +4 -0
@@ -0,0 +1,4 @@ +exports.RIGHT = a => { + + return a+1; //ChangeMe +};
t/t4018/javascript-dotexports-arrow-function-3 new file +1 -0
@@ -0,0 +1 @@ +exports.RIGHT = a => a+1; //ChangeMe
t/t4018/javascript-dotexports-assigned-function new file +1 -0
@@ -0,0 +1 @@ +exports.RIGHT = PreviousFunction; //ChangeMe
t/t4018/javascript-dotexports-async-arrow-function new file +3 -0
@@ -0,0 +1,3 @@ +exports.RIGHT = async (a, b) => { + return a + b; // ChangeMe +};
t/t4018/javascript-dotexports-async-arrow-function-2 new file +4 -0
@@ -0,0 +1,4 @@ +exports.RIGHT = async a => { + + return a + 1; // ChangeMe +};
t/t4018/javascript-dotexports-async-arrow-function-3 new file +1 -0
@@ -0,0 +1 @@ +exports.RIGHT = async a => a + 1; // ChangeMe
t/t4018/javascript-dotexports-async-function new file +4 -0
@@ -0,0 +1,4 @@ +exports.RIGHT = async function ChangeMe(a, b) { + + return a + b; // ChangeMe +}
t/t4018/javascript-dotexports-async-generator-anonymous-function new file +5 -0
@@ -0,0 +1,5 @@ +exports.RIGHT = async function* () { + + yield 1; + yield 2; // ChangeMe +};
t/t4018/javascript-dotexports-async-generator-anonymous-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +exports.RIGHT = async function *() { + + yield 1; + yield 2; // ChangeMe +};
t/t4018/javascript-dotexports-async-generator-function new file +5 -0
@@ -0,0 +1,5 @@ +exports.RIGHT = async function* ChangeMe() { + + yield 1; + yield 2; +}
t/t4018/javascript-dotexports-async-generator-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +exports.RIGHT = async function *ChangeMe() { + + yield 1; + yield 2; +}
t/t4018/javascript-dotexports-function new file +4 -0
@@ -0,0 +1,4 @@ +exports.RIGHT = function ChangeMe(a, b) { + + return a + b; +};
t/t4018/javascript-dotexports-generator-anonymous-function new file +5 -0
@@ -0,0 +1,5 @@ +exports.RIGHT = function* () { + + yield 1; + yield 2; // ChangeMe +}
t/t4018/javascript-dotexports-generator-anonymous-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +exports.RIGHT = function *() { + + yield 1; + yield 2; // ChangeMe +};
t/t4018/javascript-dotexports-generator-function new file +5 -0
@@ -0,0 +1,5 @@ +exports.RIGHT = function* ChangeMe() { + + yield 1; + yield 2; +}
t/t4018/javascript-dotexports-generator-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +exports.RIGHT = function *ChangeMe() { + + yield 1; + yield 2; +}
t/t4018/javascript-export-arrow-function new file +4 -0
@@ -0,0 +1,4 @@ +export const RIGHT = (a, b) => { + + return a + b; // ChangeMe +};
t/t4018/javascript-export-async-anonymous-assigned-function new file +4 -0
@@ -0,0 +1,4 @@ +export const RIGHT = async function(a, b) { + + return a + b; //ChangeMe +};
t/t4018/javascript-export-async-arrow-function new file +4 -0
@@ -0,0 +1,4 @@ +export const RIGHT = async (a, b) => { + + return a + b; // ChangeMe +};
t/t4018/javascript-export-async-function new file +4 -0
@@ -0,0 +1,4 @@ +export async function RIGHT(a, b) { + + return a + b; // ChangeMe +}
t/t4018/javascript-export-async-generator-anonymous-assigned-function new file +4 -0
@@ -0,0 +1,4 @@ +export const RIGHT = async function* () { + yield 1; + yield 2; // ChangeMe +};
t/t4018/javascript-export-async-generator-anonymous-assigned-function-2 new file +4 -0
@@ -0,0 +1,4 @@ +export const RIGHT = async function *() { + yield 1; + yield 2; // ChangeMe +};
t/t4018/javascript-export-async-generator-assigned-function new file +5 -0
@@ -0,0 +1,5 @@ +export const RIGHT = async function* ChangeMe() { + + yield 1; + yield 2; +};
t/t4018/javascript-export-async-generator-assigned-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +export const RIGHT = async function *ChangeMe() { + + yield 1; + yield 2; +};
t/t4018/javascript-export-async-generator-function new file +5 -0
@@ -0,0 +1,5 @@ +export async function* RIGHT() { + + yield 1; + yield 2; // ChangeMe +}
t/t4018/javascript-export-async-generator-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +export async function *RIGHT() { + + yield 1; + yield 2; // ChangeMe +}
t/t4018/javascript-export-function new file +4 -0
@@ -0,0 +1,4 @@ +export function RIGHT(a, b) { + + return a + b; // ChangeMe +}
t/t4018/javascript-export-generator-assigned-function new file +6 -0
@@ -0,0 +1,6 @@ +export const RIGHT = function* () { + + yield 1; + yield 2; // ChangeMe + +};
t/t4018/javascript-export-generator-assigned-function-2 new file +6 -0
@@ -0,0 +1,6 @@ +export const RIGHT = function *() { + + yield 1; + yield 2; // ChangeMe + +};
t/t4018/javascript-export-generator-function new file +5 -0
@@ -0,0 +1,5 @@ +export function* RIGHT() { + + yield 1; + yield 2; // ChangeMe +}
t/t4018/javascript-export-generator-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +export function *RIGHT() { + + yield 1; + yield 2; // ChangeMe +}
t/t4018/javascript-module-dotexports-anonymous-function new file +3 -0
@@ -0,0 +1,3 @@ +module.exports.RIGHT = function(a, b) { + return a + b; //ChangeMe +};
t/t4018/javascript-module-dotexports-arrow-function new file +4 -0
@@ -0,0 +1,4 @@ +module.exports.RIGHT = (a, b) => { + + return a+b; //ChangeMe +};
t/t4018/javascript-module-dotexports-arrow-function-2 new file +4 -0
@@ -0,0 +1,4 @@ +module.exports.RIGHT = a => { + + return a+1; //ChangeMe +};
t/t4018/javascript-module-dotexports-arrow-function-3 new file +1 -0
@@ -0,0 +1 @@ +module.exports.RIGHT = a => a+1; //ChangeMe
t/t4018/javascript-module-dotexports-assigned-function new file +1 -0
@@ -0,0 +1 @@ +module.exports.RIGHT = PreviousFunction; //ChangeMe
t/t4018/javascript-module-dotexports-async-arrow-function new file +3 -0
@@ -0,0 +1,3 @@ +module.exports.RIGHT = async (a, b) => { + return a + b; // ChangeMe +};
t/t4018/javascript-module-dotexports-async-arrow-function-2 new file +4 -0
@@ -0,0 +1,4 @@ +module.exports.RIGHT = async a => { + + return a + 1; // ChangeMe +};
t/t4018/javascript-module-dotexports-async-arrow-function-3 new file +1 -0
@@ -0,0 +1 @@ +module.exports.RIGHT = async a => a + 1; // ChangeMe
t/t4018/javascript-module-dotexports-async-function new file +4 -0
@@ -0,0 +1,4 @@ +module.exports.RIGHT = async function ChangeMe(a, b) { + + return a + b; // ChangeMe +}
t/t4018/javascript-module-dotexports-async-generator-anonymous-function new file +5 -0
@@ -0,0 +1,5 @@ +module.exports.RIGHT = async function* () { + + yield 1; + yield 2; // ChangeMe +};
t/t4018/javascript-module-dotexports-async-generator-anonymous-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +module.exports.RIGHT = async function *() { + + yield 1; + yield 2; // ChangeMe +};
t/t4018/javascript-module-dotexports-async-generator-function new file +5 -0
@@ -0,0 +1,5 @@ +module.exports.RIGHT = async function* ChangeMe() { + + yield 1; + yield 2; +}
t/t4018/javascript-module-dotexports-async-generator-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +module.exports.RIGHT = async function *ChangeMe() { + + yield 1; + yield 2; +}
t/t4018/javascript-module-dotexports-function new file +4 -0
@@ -0,0 +1,4 @@ +module.exports.RIGHT = function ChangeMe(a, b) { + + return a + b; +};
t/t4018/javascript-module-dotexports-generator-anonymous-function new file +5 -0
@@ -0,0 +1,5 @@ +module.exports.RIGHT = function* () { + + yield 1; + yield 2; // ChangeMe +}
t/t4018/javascript-module-dotexports-generator-anonymous-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +module.exports.RIGHT = function *() { + + yield 1; + yield 2; // ChangeMe +};
t/t4018/javascript-module-dotexports-generator-function new file +5 -0
@@ -0,0 +1,5 @@ +module.exports.RIGHT = function* ChangeMe() { + + yield 1; + yield 2; +}
t/t4018/javascript-module-dotexports-generator-function-2 new file +5 -0
@@ -0,0 +1,5 @@ +module.exports.RIGHT = function *ChangeMe() { + + yield 1; + yield 2; +}
Signature · 1 line
2.50.0.rc0.62.g658f0ae201.dirty
Re: [PATCH v2 4/4] t4018: add tests for javascript export type function declarations
Many of the cases are not valid tests. In particular the word "ChangeMe" must occur *only once* and *after* the line with "RIGHT" and there must be at least one unchanged line before it. (I wonder how these tests could have passed. Do we have a flaw in the test driver?)
t/t4018/javascript-dotexpors-async-anonymous-function line 3
Quoted 9 lines
t/t4018/javascript-dotexpors-async-anonymous-function new file +3
-0@@ -0,0 +1,3 @@ +exports.RIGHT = async function(a, b) { + return a + b; // ChangeMe +};
Here.
t/t4018/javascript-dotexports-anonymous-function line 3
Quoted 9 lines
t/t4018/javascript-dotexports-anonymous-function new file +3
-0@@ -0,0 +1,3 @@ +exports.RIGHT = function(a, b) { + return a + b; //ChangeMe +};
Here.
t/t4018/javascript-dotexports-arrow-function-3 line 1
Quoted 7 lines
t/t4018/javascript-dotexports-arrow-function-3 new file +1
-0@@ -0,0 +1 @@ +exports.RIGHT = a => a+1; //ChangeMe
Here.
And many more. You see the pattern.
t/t4018/javascript-dotexports-arrow-function-3 line 5
Quoted 8 lines
+++ b/t/t4018/javascript-module-dotexports-generator-function
t/t4018/javascript-dotexports-arrow-function-3 new file +5
-0@@ -0,0 +1,5 @@ +module.exports.RIGHT = function* ChangeMe() { + + yield 1; + yield 2; +}
An incomplete last line, again. Please look at the patch text that you are going to submit. Don't depend on reviewers' to notice such obvious glitches.
I haven't found enough time for a complete review, yet. Please submit a patch series that does not depend on an earlier round.
Splitting the test cases in separate patches is a good idea. I think you have chosen a split that excercises different hunk header patterns. But in this case, it would also be feasible and helpful to exclude the pattern from the earlier patch and add the pattern and the corresponding test cases in the same commit.
-- Hannes