* [GSoC PATCH 0/1] userdiff: add javascript diff driver @ 2025-06-04 9:35 Derick W. de M. Frias 2025-06-04 9:35 ` [GSoC PATCH 1/1] " Derick W. de M. Frias 0 siblings, 1 reply; 11+ messages in thread From: Derick W. de M. Frias @ 2025-06-04 9:35 UTC (permalink / raw) To: git 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 -- 2.50.0.rc0.62.g658f0ae201.dirty ^ permalink raw reply [flat|nested] 11+ messages in thread
* [GSoC PATCH 1/1] userdiff: add javascript diff driver 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 2025-06-04 21:19 ` D. Ben Knoble 2025-06-05 5:51 ` Johannes Sixt 0 siblings, 2 replies; 11+ messages in thread From: Derick W. de M. Frias @ 2025-06-04 9:35 UTC (permalink / raw) To: git 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 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [GSoC PATCH 1/1] userdiff: add javascript diff driver 2025-06-04 9:35 ` [GSoC PATCH 1/1] " Derick W. de M. Frias @ 2025-06-04 21:19 ` D. Ben Knoble 2025-06-05 5:51 ` Johannes Sixt 1 sibling, 0 replies; 11+ messages in thread From: D. Ben Knoble @ 2025-06-04 21:19 UTC (permalink / raw) To: Derick W. de M. Frias; +Cc: git 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? > > 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 > 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. > + "([$_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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [GSoC PATCH 1/1] userdiff: add javascript diff driver 2025-06-04 9:35 ` [GSoC PATCH 1/1] " Derick W. de M. Frias 2025-06-04 21:19 ` 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 1 sibling, 1 reply; 11+ messages in thread From: Johannes Sixt @ 2025-06-05 5:51 UTC (permalink / raw) To: Derick W. de M. Frias; +Cc: git 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. > > 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? > 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. > + /* 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 0/4] diff: create pattern for javascript language 2025-06-05 5:51 ` Johannes Sixt @ 2025-06-23 6:35 ` Derick W. de M. Frias 2025-06-23 6:35 ` [PATCH v2 1/4] userdiff: add javascript diff driver Derick W. de M. Frias ` (3 more replies) 0 siblings, 4 replies; 11+ messages in thread From: Derick W. de M. Frias @ 2025-06-23 6:35 UTC (permalink / raw) To: j6t; +Cc: derick.william.moraes, git 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! > 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. 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/20240404163827.5855-1-utsavp0213@gmail.com/ [2] Mattew Hughes: https://lore.kernel.org/git/pull.1746.git.git.1721061218993.gitgitgadget@gmail.com/ [3] Sergius Nyah: https://lore.kernel.org/git/20240301074048.188835-1-sergiusnyah@gmail.com/ [4] Xing Zhi Jiang: https://lore.kernel.org/git/20220403132508.28196-1-a97410985new@gmail.com/ 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. > 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 \\.\\.\\.}. > 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. > 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. > 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 -- 2.50.0.rc0.62.g658f0ae201.dirty ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 1/4] userdiff: add javascript diff driver 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 ` 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 ` (2 subsequent siblings) 3 siblings, 1 reply; 11+ messages in thread From: Derick W. de M. Frias @ 2025-06-23 6:35 UTC (permalink / raw) To: j6t; +Cc: derick.william.moraes, git Add diff pattern for JavaScript programming language and documentation. Signed-off-by: Derick W. de M. Frias <derick.william.moraes@gmail.com> --- Documentation/gitattributes.adoc | 2 ++ userdiff.c | 62 ++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Documentation/gitattributes.adoc b/Documentation/gitattributes.adoc index f20041a323..b7075ccb29 100644 --- a/Documentation/gitattributes.adoc +++ b/Documentation/gitattributes.adoc @@ -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. diff --git a/userdiff.c b/userdiff.c index 94134e5b09..0d352bc722 100644 --- a/userdiff.c +++ b/userdiff.c @@ -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]*\\(.*$|" - /* 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|" + /* don't match reserved expressions that have function-like syntax */ + "!^[ \t]*(if|do|while|for|with|switch|catch|import|return)\n" + /* matches conventional named functions, that can also be async and/or have export */ + "^[ \t]*(export[ \t]+)?(async[ \t]+)?function[ \t]*\\*?[ \t]*" + "([$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*\\(.*$" + /* matches assigned exports */ + "|^[ \t]*export[ \t]*(const|default)[ \t]*([$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*=" + /* matches 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]*\\{?.*$" + /* matches 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]*\\{.*$" + /* matches functions created or assigned in 'exports.' or 'module.exports.' context*/ + "|^[ \t]*(module.)?exports.([$_a-zA-Z][$_a-zA-Z0-9]*)[ \t]*=" + "([ \t]*(async[ \t]+)?(function)?[ \t]*\\*?[ \t]*" + "([$_a-zA-Z][$_a-zA-Z0-9]*)?[ \t]*\\(.*$" + "|[ \t]*([$_a-zA-Z][$_a-zA-Z0-9]*);" + "|[ \t]*(async[ \t]+)?([$_a-zA-Z][$_a-zA-Z0-9]*)[ \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}=|=>"), + "|\\.{3}|<=|>=|==|!=|===|!==|\\*{2}|\\+{2}|--|<<|>>|>>>|&&|\\|{2}|\\?{2}|\\+=|-=" + "|\\*=|%=|\\*{2}=|<<=|>>=|>>>=|&=|\\|=|\\^=|&&=|\\|{2}=|\\?{2}=|=>"), PATTERNS("kotlin", "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$", /* -- */ -- 2.50.0.rc0.62.g658f0ae201.dirty ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/4] userdiff: add javascript diff driver 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 0 siblings, 0 replies; 11+ messages in thread From: Junio C Hamano @ 2025-06-23 18:09 UTC (permalink / raw) To: Derick W. de M. Frias; +Cc: j6t, git "Derick W. de M. Frias" <derick.william.moraes@gmail.com> writes: > --- a/userdiff.c > +++ b/userdiff.c > @@ -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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 2/4] t4034: add tests for javascript word literals 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 6:35 ` 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 3 siblings, 0 replies; 11+ messages in thread From: Derick W. de M. Frias @ 2025-06-23 6:35 UTC (permalink / raw) To: j6t; +Cc: derick.william.moraes, git Add tests for javascript word pattern. Signed-off-by: Derick W. de M. Frias <derick.william.moraes@gmail.com> --- 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(-) diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index 0be647c2fb..5bf1294f27 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -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 diff --git a/t/t4034/javascript/expect b/t/t4034/javascript/expect index cc5e1253f6..98b057c48a 100644 --- a/t/t4034/javascript/expect +++ b/t/t4034/javascript/expect @@ -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 \ No newline at end of file +a<RED>&&<RESET><GREEN>&<RESET>b a<RED>||<RESET><GREEN>|<RESET>b a<RED>&&=<RESET><GREEN>??=<RESET>b diff --git a/t/t4034/javascript/post b/t/t4034/javascript/post index 9d66c9dc91..12165198ad 100644 --- a/t/t4034/javascript/post +++ b/t/t4034/javascript/post @@ -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 \ No newline at end of file +a&b a|b a??=b diff --git a/t/t4034/javascript/pre b/t/t4034/javascript/pre index 9876514042..43d5908e09 100644 --- a/t/t4034/javascript/pre +++ b/t/t4034/javascript/pre @@ -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 \ No newline at end of file +a&&b a||b a&&=b -- 2.50.0.rc0.62.g658f0ae201.dirty ^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 3/4] t4018: add tests for recognizing javascript function syntax 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 6:35 ` [PATCH v2 2/4] t4034: add tests for javascript word literals Derick W. de M. Frias @ 2025-06-23 6:35 ` 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 3 siblings, 0 replies; 11+ messages in thread From: Derick W. de M. Frias @ 2025-06-23 6:35 UTC (permalink / raw) To: j6t; +Cc: derick.william.moraes, git Add tests for javascript function declarations as in ECMAScript ES5.1< Signed-off-by: Derick W. de M. Frias <derick.william.moraes@gmail.com> --- .../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 diff --git a/t/t4018/javascript-anonymous-assigned-function b/t/t4018/javascript-anonymous-assigned-function new file mode 100644 index 0000000000..c9127e231d --- /dev/null +++ b/t/t4018/javascript-anonymous-assigned-function @@ -0,0 +1,4 @@ +const RIGHT = function (a, b) { + + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-arrow-assigned-function b/t/t4018/javascript-arrow-assigned-function new file mode 100644 index 0000000000..3182197aee --- /dev/null +++ b/t/t4018/javascript-arrow-assigned-function @@ -0,0 +1,4 @@ +const RIGHT = (a, b) => { + + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-arrow-assigned-function-2 b/t/t4018/javascript-arrow-assigned-function-2 new file mode 100644 index 0000000000..b5732967c0 --- /dev/null +++ b/t/t4018/javascript-arrow-assigned-function-2 @@ -0,0 +1,5 @@ +const RIGHT = a => { + + return a + 1; //ChangeMe +}; + diff --git a/t/t4018/javascript-arrow-assigned-function-3 b/t/t4018/javascript-arrow-assigned-function-3 new file mode 100644 index 0000000000..98ee879dd2 --- /dev/null +++ b/t/t4018/javascript-arrow-assigned-function-3 @@ -0,0 +1 @@ +const RIGHT = a => a+1; //ChangeMe diff --git a/t/t4018/javascript-assigned-function b/t/t4018/javascript-assigned-function new file mode 100644 index 0000000000..170d54db4f --- /dev/null +++ b/t/t4018/javascript-assigned-function @@ -0,0 +1,4 @@ +const RIGHT = function test (a, b) { + + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-async-assigned-function b/t/t4018/javascript-async-assigned-function new file mode 100644 index 0000000000..1c1923b336 --- /dev/null +++ b/t/t4018/javascript-async-assigned-function @@ -0,0 +1,4 @@ +const RIGHT = async function (a, b) { + + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-async-function b/t/t4018/javascript-async-function index 7f99b8c89a..740e5304aa 100644 --- a/t/t4018/javascript-async-function +++ b/t/t4018/javascript-async-function @@ -1,4 +1,4 @@ async function RIGHT (a, b) { - return a + b; -}; \ No newline at end of file + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-class-get-function b/t/t4018/javascript-class-get-function new file mode 100644 index 0000000000..e27fa81478 --- /dev/null +++ b/t/t4018/javascript-class-get-function @@ -0,0 +1,5 @@ +class ChangeMe { + get RIGHT() { + return 1; + } +} diff --git a/t/t4018/javascript-class-set-function b/t/t4018/javascript-class-set-function new file mode 100644 index 0000000000..ba747db7c7 --- /dev/null +++ b/t/t4018/javascript-class-set-function @@ -0,0 +1,5 @@ +class ChangeMe { + set RIGHT() { + return 1; + } +} diff --git a/t/t4018/javascript-class-static-function b/t/t4018/javascript-class-static-function new file mode 100644 index 0000000000..b3c8f1ff2a --- /dev/null +++ b/t/t4018/javascript-class-static-function @@ -0,0 +1,5 @@ +class ChangeMe { + static RIGHT(a, b) { + return a + b; + } +} diff --git a/t/t4018/javascript-class-unprefixed-function b/t/t4018/javascript-class-unprefixed-function new file mode 100644 index 0000000000..675c787995 --- /dev/null +++ b/t/t4018/javascript-class-unprefixed-function @@ -0,0 +1,6 @@ +class Test { + RIGHT() { + let a = 1; + let b = ChangeMe; + } +} diff --git a/t/t4018/javascript-function b/t/t4018/javascript-function index d11ad34aff..bd7945ca2b 100644 --- a/t/t4018/javascript-function +++ b/t/t4018/javascript-function @@ -1,4 +1,4 @@ function RIGHT (a, b) { - return a + b; -}; \ No newline at end of file + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-generator-assigned-function b/t/t4018/javascript-generator-assigned-function new file mode 100644 index 0000000000..c5ff9d89b5 --- /dev/null +++ b/t/t4018/javascript-generator-assigned-function @@ -0,0 +1,5 @@ +const RIGHT = function* (){ + + yield 1; + yield 2; //ChangeMe +} diff --git a/t/t4018/javascript-generator-assigned-function-2 b/t/t4018/javascript-generator-assigned-function-2 new file mode 100644 index 0000000000..8ce7567987 --- /dev/null +++ b/t/t4018/javascript-generator-assigned-function-2 @@ -0,0 +1,5 @@ +const RIGHT = function *(){ + + yield 1; + yield 2; //ChangeMe +} diff --git a/t/t4018/javascript-generator-function b/t/t4018/javascript-generator-function index af7cbb50a3..9a24ae7d08 100644 --- a/t/t4018/javascript-generator-function +++ b/t/t4018/javascript-generator-function @@ -1,5 +1,5 @@ function* RIGHT() { yield 1; - yield 2; -} \ No newline at end of file + yield 2; //ChangeMe +} diff --git a/t/t4018/javascript-generator-function-2 b/t/t4018/javascript-generator-function-2 index d40b395f5c..bac71e362c 100644 --- a/t/t4018/javascript-generator-function-2 +++ b/t/t4018/javascript-generator-function-2 @@ -1,5 +1,5 @@ function *RIGHT() { yield 1; - yield 2; -} \ No newline at end of file + yield 2; //ChangeMe +} diff --git a/t/t4018/javascript-method-unprefixed-function b/t/t4018/javascript-method-unprefixed-function new file mode 100644 index 0000000000..eb6300dda3 --- /dev/null +++ b/t/t4018/javascript-method-unprefixed-function @@ -0,0 +1,6 @@ +const Test = { + RIGHT() { + let a = 1; + let b = ChangeMe; + } +} diff --git a/t/t4018/javascript-skip-function-calls b/t/t4018/javascript-skip-function-calls new file mode 100644 index 0000000000..cc9699a9f5 --- /dev/null +++ b/t/t4018/javascript-skip-function-calls @@ -0,0 +1,7 @@ +class Test { + static RIGHT() { + call_to_skip(); + call_to_skip2(); + let a = ChangeMe; + } +} \ No newline at end of file diff --git a/t/t4018/javascript-skip-reserved-words b/t/t4018/javascript-skip-reserved-words new file mode 100644 index 0000000000..d12fe587a8 --- /dev/null +++ b/t/t4018/javascript-skip-reserved-words @@ -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 +} -- 2.50.0.rc0.62.g658f0ae201.dirty ^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 4/4] t4018: add tests for javascript export type function declarations 2025-06-23 6:35 ` [PATCH v2 0/4] diff: create pattern for javascript language Derick W. de M. Frias ` (2 preceding siblings ...) 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 ` Derick W. de M. Frias 2025-06-26 6:21 ` Johannes Sixt 3 siblings, 1 reply; 11+ messages in thread From: Derick W. de M. Frias @ 2025-06-23 6:35 UTC (permalink / raw) To: j6t; +Cc: derick.william.moraes, git Add tests for javascript export function declarations as in ECMAScript ES6 and CommonJS. Signed-off-by: Derick W. de M. Frias <derick.william.moraes@gmail.com> --- 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 diff --git a/t/t4018/javascript-dotexpors-async-anonymous-function b/t/t4018/javascript-dotexpors-async-anonymous-function new file mode 100644 index 0000000000..9f970a2343 --- /dev/null +++ b/t/t4018/javascript-dotexpors-async-anonymous-function @@ -0,0 +1,3 @@ +exports.RIGHT = async function(a, b) { + return a + b; // ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-anonymous-function b/t/t4018/javascript-dotexports-anonymous-function new file mode 100644 index 0000000000..2fa9775c95 --- /dev/null +++ b/t/t4018/javascript-dotexports-anonymous-function @@ -0,0 +1,3 @@ +exports.RIGHT = function(a, b) { + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-arrow-function b/t/t4018/javascript-dotexports-arrow-function new file mode 100644 index 0000000000..a7d9741e90 --- /dev/null +++ b/t/t4018/javascript-dotexports-arrow-function @@ -0,0 +1,4 @@ +exports.RIGHT = (a, b) => { + + return a+b; //ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-arrow-function-2 b/t/t4018/javascript-dotexports-arrow-function-2 new file mode 100644 index 0000000000..f9cd237bb8 --- /dev/null +++ b/t/t4018/javascript-dotexports-arrow-function-2 @@ -0,0 +1,4 @@ +exports.RIGHT = a => { + + return a+1; //ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-arrow-function-3 b/t/t4018/javascript-dotexports-arrow-function-3 new file mode 100644 index 0000000000..cc3f1ec017 --- /dev/null +++ b/t/t4018/javascript-dotexports-arrow-function-3 @@ -0,0 +1 @@ +exports.RIGHT = a => a+1; //ChangeMe diff --git a/t/t4018/javascript-dotexports-assigned-function b/t/t4018/javascript-dotexports-assigned-function new file mode 100644 index 0000000000..308cc37095 --- /dev/null +++ b/t/t4018/javascript-dotexports-assigned-function @@ -0,0 +1 @@ +exports.RIGHT = PreviousFunction; //ChangeMe diff --git a/t/t4018/javascript-dotexports-async-arrow-function b/t/t4018/javascript-dotexports-async-arrow-function new file mode 100644 index 0000000000..01df800f19 --- /dev/null +++ b/t/t4018/javascript-dotexports-async-arrow-function @@ -0,0 +1,3 @@ +exports.RIGHT = async (a, b) => { + return a + b; // ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-async-arrow-function-2 b/t/t4018/javascript-dotexports-async-arrow-function-2 new file mode 100644 index 0000000000..453da8fcb4 --- /dev/null +++ b/t/t4018/javascript-dotexports-async-arrow-function-2 @@ -0,0 +1,4 @@ +exports.RIGHT = async a => { + + return a + 1; // ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-async-arrow-function-3 b/t/t4018/javascript-dotexports-async-arrow-function-3 new file mode 100644 index 0000000000..74b028cf1c --- /dev/null +++ b/t/t4018/javascript-dotexports-async-arrow-function-3 @@ -0,0 +1 @@ +exports.RIGHT = async a => a + 1; // ChangeMe diff --git a/t/t4018/javascript-dotexports-async-function b/t/t4018/javascript-dotexports-async-function new file mode 100644 index 0000000000..88b3539544 --- /dev/null +++ b/t/t4018/javascript-dotexports-async-function @@ -0,0 +1,4 @@ +exports.RIGHT = async function ChangeMe(a, b) { + + return a + b; // ChangeMe +} diff --git a/t/t4018/javascript-dotexports-async-generator-anonymous-function b/t/t4018/javascript-dotexports-async-generator-anonymous-function new file mode 100644 index 0000000000..9e90bdf489 --- /dev/null +++ b/t/t4018/javascript-dotexports-async-generator-anonymous-function @@ -0,0 +1,5 @@ +exports.RIGHT = async function* () { + + yield 1; + yield 2; // ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-async-generator-anonymous-function-2 b/t/t4018/javascript-dotexports-async-generator-anonymous-function-2 new file mode 100644 index 0000000000..efe2abe4f7 --- /dev/null +++ b/t/t4018/javascript-dotexports-async-generator-anonymous-function-2 @@ -0,0 +1,5 @@ +exports.RIGHT = async function *() { + + yield 1; + yield 2; // ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-async-generator-function b/t/t4018/javascript-dotexports-async-generator-function new file mode 100644 index 0000000000..5d352b5f29 --- /dev/null +++ b/t/t4018/javascript-dotexports-async-generator-function @@ -0,0 +1,5 @@ +exports.RIGHT = async function* ChangeMe() { + + yield 1; + yield 2; +} diff --git a/t/t4018/javascript-dotexports-async-generator-function-2 b/t/t4018/javascript-dotexports-async-generator-function-2 new file mode 100644 index 0000000000..cddc4f9628 --- /dev/null +++ b/t/t4018/javascript-dotexports-async-generator-function-2 @@ -0,0 +1,5 @@ +exports.RIGHT = async function *ChangeMe() { + + yield 1; + yield 2; +} diff --git a/t/t4018/javascript-dotexports-function b/t/t4018/javascript-dotexports-function new file mode 100644 index 0000000000..4c0c622d13 --- /dev/null +++ b/t/t4018/javascript-dotexports-function @@ -0,0 +1,4 @@ +exports.RIGHT = function ChangeMe(a, b) { + + return a + b; +}; diff --git a/t/t4018/javascript-dotexports-generator-anonymous-function b/t/t4018/javascript-dotexports-generator-anonymous-function new file mode 100644 index 0000000000..4899abbb7b --- /dev/null +++ b/t/t4018/javascript-dotexports-generator-anonymous-function @@ -0,0 +1,5 @@ +exports.RIGHT = function* () { + + yield 1; + yield 2; // ChangeMe +} diff --git a/t/t4018/javascript-dotexports-generator-anonymous-function-2 b/t/t4018/javascript-dotexports-generator-anonymous-function-2 new file mode 100644 index 0000000000..1f1e9995b2 --- /dev/null +++ b/t/t4018/javascript-dotexports-generator-anonymous-function-2 @@ -0,0 +1,5 @@ +exports.RIGHT = function *() { + + yield 1; + yield 2; // ChangeMe +}; diff --git a/t/t4018/javascript-dotexports-generator-function b/t/t4018/javascript-dotexports-generator-function new file mode 100644 index 0000000000..837646cacc --- /dev/null +++ b/t/t4018/javascript-dotexports-generator-function @@ -0,0 +1,5 @@ +exports.RIGHT = function* ChangeMe() { + + yield 1; + yield 2; +} diff --git a/t/t4018/javascript-dotexports-generator-function-2 b/t/t4018/javascript-dotexports-generator-function-2 new file mode 100644 index 0000000000..0cc3729220 --- /dev/null +++ b/t/t4018/javascript-dotexports-generator-function-2 @@ -0,0 +1,5 @@ +exports.RIGHT = function *ChangeMe() { + + yield 1; + yield 2; +} diff --git a/t/t4018/javascript-export-arrow-function b/t/t4018/javascript-export-arrow-function new file mode 100644 index 0000000000..098b457924 --- /dev/null +++ b/t/t4018/javascript-export-arrow-function @@ -0,0 +1,4 @@ +export const RIGHT = (a, b) => { + + return a + b; // ChangeMe +}; diff --git a/t/t4018/javascript-export-async-anonymous-assigned-function b/t/t4018/javascript-export-async-anonymous-assigned-function new file mode 100644 index 0000000000..0a36b97838 --- /dev/null +++ b/t/t4018/javascript-export-async-anonymous-assigned-function @@ -0,0 +1,4 @@ +export const RIGHT = async function(a, b) { + + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-export-async-arrow-function b/t/t4018/javascript-export-async-arrow-function new file mode 100644 index 0000000000..557bcd1c23 --- /dev/null +++ b/t/t4018/javascript-export-async-arrow-function @@ -0,0 +1,4 @@ +export const RIGHT = async (a, b) => { + + return a + b; // ChangeMe +}; diff --git a/t/t4018/javascript-export-async-function b/t/t4018/javascript-export-async-function new file mode 100644 index 0000000000..169f4eeed3 --- /dev/null +++ b/t/t4018/javascript-export-async-function @@ -0,0 +1,4 @@ +export async function RIGHT(a, b) { + + return a + b; // ChangeMe +} \ No newline at end of file diff --git a/t/t4018/javascript-export-async-generator-anonymous-assigned-function b/t/t4018/javascript-export-async-generator-anonymous-assigned-function new file mode 100644 index 0000000000..11ee37b2bc --- /dev/null +++ b/t/t4018/javascript-export-async-generator-anonymous-assigned-function @@ -0,0 +1,4 @@ +export const RIGHT = async function* () { + yield 1; + yield 2; // ChangeMe +}; \ No newline at end of file diff --git a/t/t4018/javascript-export-async-generator-anonymous-assigned-function-2 b/t/t4018/javascript-export-async-generator-anonymous-assigned-function-2 new file mode 100644 index 0000000000..6bff23ed2b --- /dev/null +++ b/t/t4018/javascript-export-async-generator-anonymous-assigned-function-2 @@ -0,0 +1,4 @@ +export const RIGHT = async function *() { + yield 1; + yield 2; // ChangeMe +}; \ No newline at end of file diff --git a/t/t4018/javascript-export-async-generator-assigned-function b/t/t4018/javascript-export-async-generator-assigned-function new file mode 100644 index 0000000000..3d5b1e0879 --- /dev/null +++ b/t/t4018/javascript-export-async-generator-assigned-function @@ -0,0 +1,5 @@ +export const RIGHT = async function* ChangeMe() { + + yield 1; + yield 2; +}; diff --git a/t/t4018/javascript-export-async-generator-assigned-function-2 b/t/t4018/javascript-export-async-generator-assigned-function-2 new file mode 100644 index 0000000000..31c674f150 --- /dev/null +++ b/t/t4018/javascript-export-async-generator-assigned-function-2 @@ -0,0 +1,5 @@ +export const RIGHT = async function *ChangeMe() { + + yield 1; + yield 2; +}; diff --git a/t/t4018/javascript-export-async-generator-function b/t/t4018/javascript-export-async-generator-function new file mode 100644 index 0000000000..548589e597 --- /dev/null +++ b/t/t4018/javascript-export-async-generator-function @@ -0,0 +1,5 @@ +export async function* RIGHT() { + + yield 1; + yield 2; // ChangeMe +} diff --git a/t/t4018/javascript-export-async-generator-function-2 b/t/t4018/javascript-export-async-generator-function-2 new file mode 100644 index 0000000000..99167142d7 --- /dev/null +++ b/t/t4018/javascript-export-async-generator-function-2 @@ -0,0 +1,5 @@ +export async function *RIGHT() { + + yield 1; + yield 2; // ChangeMe +} diff --git a/t/t4018/javascript-export-function b/t/t4018/javascript-export-function new file mode 100644 index 0000000000..32f38c36c6 --- /dev/null +++ b/t/t4018/javascript-export-function @@ -0,0 +1,4 @@ +export function RIGHT(a, b) { + + return a + b; // ChangeMe +} diff --git a/t/t4018/javascript-export-generator-assigned-function b/t/t4018/javascript-export-generator-assigned-function new file mode 100644 index 0000000000..30398cd805 --- /dev/null +++ b/t/t4018/javascript-export-generator-assigned-function @@ -0,0 +1,6 @@ +export const RIGHT = function* () { + + yield 1; + yield 2; // ChangeMe + +}; \ No newline at end of file diff --git a/t/t4018/javascript-export-generator-assigned-function-2 b/t/t4018/javascript-export-generator-assigned-function-2 new file mode 100644 index 0000000000..04d2021af5 --- /dev/null +++ b/t/t4018/javascript-export-generator-assigned-function-2 @@ -0,0 +1,6 @@ +export const RIGHT = function *() { + + yield 1; + yield 2; // ChangeMe + +}; \ No newline at end of file diff --git a/t/t4018/javascript-export-generator-function b/t/t4018/javascript-export-generator-function new file mode 100644 index 0000000000..2ad38ff088 --- /dev/null +++ b/t/t4018/javascript-export-generator-function @@ -0,0 +1,5 @@ +export function* RIGHT() { + + yield 1; + yield 2; // ChangeMe +} diff --git a/t/t4018/javascript-export-generator-function-2 b/t/t4018/javascript-export-generator-function-2 new file mode 100644 index 0000000000..56709a8ae9 --- /dev/null +++ b/t/t4018/javascript-export-generator-function-2 @@ -0,0 +1,5 @@ +export function *RIGHT() { + + yield 1; + yield 2; // ChangeMe +} diff --git a/t/t4018/javascript-module-dotexports-anonymous-function b/t/t4018/javascript-module-dotexports-anonymous-function new file mode 100644 index 0000000000..56c1641edb --- /dev/null +++ b/t/t4018/javascript-module-dotexports-anonymous-function @@ -0,0 +1,3 @@ +module.exports.RIGHT = function(a, b) { + return a + b; //ChangeMe +}; diff --git a/t/t4018/javascript-module-dotexports-arrow-function b/t/t4018/javascript-module-dotexports-arrow-function new file mode 100644 index 0000000000..32dc4f865d --- /dev/null +++ b/t/t4018/javascript-module-dotexports-arrow-function @@ -0,0 +1,4 @@ +module.exports.RIGHT = (a, b) => { + + return a+b; //ChangeMe +}; diff --git a/t/t4018/javascript-module-dotexports-arrow-function-2 b/t/t4018/javascript-module-dotexports-arrow-function-2 new file mode 100644 index 0000000000..24d35f8d9e --- /dev/null +++ b/t/t4018/javascript-module-dotexports-arrow-function-2 @@ -0,0 +1,4 @@ +module.exports.RIGHT = a => { + + return a+1; //ChangeMe +}; diff --git a/t/t4018/javascript-module-dotexports-arrow-function-3 b/t/t4018/javascript-module-dotexports-arrow-function-3 new file mode 100644 index 0000000000..333b6c6ff4 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-arrow-function-3 @@ -0,0 +1 @@ +module.exports.RIGHT = a => a+1; //ChangeMe diff --git a/t/t4018/javascript-module-dotexports-assigned-function b/t/t4018/javascript-module-dotexports-assigned-function new file mode 100644 index 0000000000..fc43431c77 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-assigned-function @@ -0,0 +1 @@ +module.exports.RIGHT = PreviousFunction; //ChangeMe diff --git a/t/t4018/javascript-module-dotexports-async-arrow-function b/t/t4018/javascript-module-dotexports-async-arrow-function new file mode 100644 index 0000000000..b7e3341c93 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-async-arrow-function @@ -0,0 +1,3 @@ +module.exports.RIGHT = async (a, b) => { + return a + b; // ChangeMe +}; diff --git a/t/t4018/javascript-module-dotexports-async-arrow-function-2 b/t/t4018/javascript-module-dotexports-async-arrow-function-2 new file mode 100644 index 0000000000..715d3e9560 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-async-arrow-function-2 @@ -0,0 +1,4 @@ +module.exports.RIGHT = async a => { + + return a + 1; // ChangeMe +}; diff --git a/t/t4018/javascript-module-dotexports-async-arrow-function-3 b/t/t4018/javascript-module-dotexports-async-arrow-function-3 new file mode 100644 index 0000000000..3a8ec728a9 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-async-arrow-function-3 @@ -0,0 +1 @@ +module.exports.RIGHT = async a => a + 1; // ChangeMe diff --git a/t/t4018/javascript-module-dotexports-async-function b/t/t4018/javascript-module-dotexports-async-function new file mode 100644 index 0000000000..b931331c1b --- /dev/null +++ b/t/t4018/javascript-module-dotexports-async-function @@ -0,0 +1,4 @@ +module.exports.RIGHT = async function ChangeMe(a, b) { + + return a + b; // ChangeMe +} diff --git a/t/t4018/javascript-module-dotexports-async-generator-anonymous-function b/t/t4018/javascript-module-dotexports-async-generator-anonymous-function new file mode 100644 index 0000000000..66e0acf178 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-async-generator-anonymous-function @@ -0,0 +1,5 @@ +module.exports.RIGHT = async function* () { + + yield 1; + yield 2; // ChangeMe +}; diff --git a/t/t4018/javascript-module-dotexports-async-generator-anonymous-function-2 b/t/t4018/javascript-module-dotexports-async-generator-anonymous-function-2 new file mode 100644 index 0000000000..c1cc0c1fce --- /dev/null +++ b/t/t4018/javascript-module-dotexports-async-generator-anonymous-function-2 @@ -0,0 +1,5 @@ +module.exports.RIGHT = async function *() { + + yield 1; + yield 2; // ChangeMe +}; diff --git a/t/t4018/javascript-module-dotexports-async-generator-function b/t/t4018/javascript-module-dotexports-async-generator-function new file mode 100644 index 0000000000..9e1dbb5b65 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-async-generator-function @@ -0,0 +1,5 @@ +module.exports.RIGHT = async function* ChangeMe() { + + yield 1; + yield 2; +} diff --git a/t/t4018/javascript-module-dotexports-async-generator-function-2 b/t/t4018/javascript-module-dotexports-async-generator-function-2 new file mode 100644 index 0000000000..c886c6357b --- /dev/null +++ b/t/t4018/javascript-module-dotexports-async-generator-function-2 @@ -0,0 +1,5 @@ +module.exports.RIGHT = async function *ChangeMe() { + + yield 1; + yield 2; +} diff --git a/t/t4018/javascript-module-dotexports-function b/t/t4018/javascript-module-dotexports-function new file mode 100644 index 0000000000..6b30d5ea98 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-function @@ -0,0 +1,4 @@ +module.exports.RIGHT = function ChangeMe(a, b) { + + return a + b; +}; diff --git a/t/t4018/javascript-module-dotexports-generator-anonymous-function b/t/t4018/javascript-module-dotexports-generator-anonymous-function new file mode 100644 index 0000000000..c77f32ac64 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-generator-anonymous-function @@ -0,0 +1,5 @@ +module.exports.RIGHT = function* () { + + yield 1; + yield 2; // ChangeMe +} diff --git a/t/t4018/javascript-module-dotexports-generator-anonymous-function-2 b/t/t4018/javascript-module-dotexports-generator-anonymous-function-2 new file mode 100644 index 0000000000..318be0c172 --- /dev/null +++ b/t/t4018/javascript-module-dotexports-generator-anonymous-function-2 @@ -0,0 +1,5 @@ +module.exports.RIGHT = function *() { + + yield 1; + yield 2; // ChangeMe +}; diff --git a/t/t4018/javascript-module-dotexports-generator-function b/t/t4018/javascript-module-dotexports-generator-function new file mode 100644 index 0000000000..839a6f16dc --- /dev/null +++ b/t/t4018/javascript-module-dotexports-generator-function @@ -0,0 +1,5 @@ +module.exports.RIGHT = function* ChangeMe() { + + yield 1; + yield 2; +} \ No newline at end of file diff --git a/t/t4018/javascript-module-dotexports-generator-function-2 b/t/t4018/javascript-module-dotexports-generator-function-2 new file mode 100644 index 0000000000..a70100a26b --- /dev/null +++ b/t/t4018/javascript-module-dotexports-generator-function-2 @@ -0,0 +1,5 @@ +module.exports.RIGHT = function *ChangeMe() { + + yield 1; + yield 2; +} -- 2.50.0.rc0.62.g658f0ae201.dirty ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 4/4] t4018: add tests for javascript export type function declarations 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 0 siblings, 0 replies; 11+ messages in thread From: Johannes Sixt @ 2025-06-26 6:21 UTC (permalink / raw) To: Derick W. de M. Frias; +Cc: git 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?) > diff --git a/t/t4018/javascript-dotexpors-async-anonymous-function b/t/t4018/javascript-dotexpors-async-anonymous-function > new file mode 100644 > index 0000000000..9f970a2343 > --- /dev/null > +++ b/t/t4018/javascript-dotexpors-async-anonymous-function > @@ -0,0 +1,3 @@ > +exports.RIGHT = async function(a, b) { > + return a + b; // ChangeMe > +}; Here. > diff --git a/t/t4018/javascript-dotexports-anonymous-function b/t/t4018/javascript-dotexports-anonymous-function > new file mode 100644 > index 0000000000..2fa9775c95 > --- /dev/null > +++ b/t/t4018/javascript-dotexports-anonymous-function > @@ -0,0 +1,3 @@ > +exports.RIGHT = function(a, b) { > + return a + b; //ChangeMe > +}; Here. > diff --git a/t/t4018/javascript-dotexports-arrow-function-3 b/t/t4018/javascript-dotexports-arrow-function-3 > new file mode 100644 > index 0000000000..cc3f1ec017 > --- /dev/null > +++ b/t/t4018/javascript-dotexports-arrow-function-3 > @@ -0,0 +1 @@ > +exports.RIGHT = a => a+1; //ChangeMe Here. And many more. You see the pattern. > +++ b/t/t4018/javascript-module-dotexports-generator-function > @@ -0,0 +1,5 @@ > +module.exports.RIGHT = function* ChangeMe() { > + > + yield 1; > + yield 2; > +} > \ No newline at end of file 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-06-26 6:21 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-06-04 9:35 [GSoC PATCH 0/1] userdiff: add javascript diff driver Derick W. de M. Frias 2025-06-04 9:35 ` [GSoC PATCH 1/1] " Derick W. de M. Frias 2025-06-04 21:19 ` 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
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).