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

Re: [GSoC][PATCH v2] Add a diff driver for JavaScript languages.

From
xing zhi jiang <a97410985new@gmail.com>
Date
Apr 3, 2022, 13:24 UTC
Message-ID
<CAN_FRNLyH4HB-1MbKGCDFingbaBTu4wmQoxUCrhEA0OhxHYkPg@mail.gmail.com>
In-Reply-To
<kl6l8rtayk5o.fsf@chooglen-macbookpro.roam.corp.google.com>
On Wed, 16 Mar 2022 at 05:34, Glen Choo <chooglen@google.com> wrote:
Show 47 quoted lines
>
> Junio C Hamano <gitster@pobox.com> writes:
>
> > Glen Choo <chooglen@google.com> writes:
> >
> >> Interesting, I'll take note. I'm still personally not keen on supporting
> >> CommonJS-only patterns when we are purportedly trying to show diffs for
> >> JavaScript, but if we think this fits the style, I'm happy to oblige.
> >
> > The question is, with these patterns that are aware of CommonJS
> > convention, would your bog-standard-and-boring vanilla JS code be
> > detected incorrectly?  Becoming aware of popular conventions without
> > hurting others would be a good thing.
> >
> > And the "popular conventions" does not have to be limited to
> > CommonJS/Node.
>
> From the perspective of "'exports' is a special name", yes, we could
> detect vanilla JS code 'incorrectly' because, in vanilla JS, the names
> 'exports' or 'module.exports' are not special. So perhaps, one could
> imagine a browser-side script that deals with "imports" and "exports" as
> part of their business:
>
>   const exports = {
>     quantity: 1,
>     type: 'boxes',
>   };
>   exports.getQuantity = () => {
>     foo();
>   };
>
> This diff driver would mistakenly detect `exports.getQuantity = () =>
> {`.
>
> Although, the more I think about it, the spirit of this patch seems to
> be "we want to show headers whenever we think we are in a function", so
> we don't actually need to treat 'exports' or 'module.exports' specially
> at all, e.g. this case should also pass our diff driver tests:
>
>   const foo = {};
>   foo.RIGHT = () => {
>
>     ChangeMe();
>   };
>
> and if we do this, we will correctly handle 'exports' and
> 'module.exports' anyway by virtue of them being plain old JS objects.
The spirit of this patch is to show headers when we are in the
function body(which has a large code block). Because this can help
users understand the context.
And prevent mismatch non-related function. ex:
    function WRONG() {
        // ...
    }
    const foo = {};
    foo.RIGHT = () => {
      ChangeMe();
    };
if we don't match "foo.RIGHT = () => {". It may match the "function
WRONG() {". This would be very misleading.
So the v3 patch. I do not treat `exports` as a special keyword. And
can match the code like "foo.RIGHT = () => {".
The regex would be
"((module\\.)?[$_[:alpha:]][$_[:alnum:]]*\\.[$_[:alpha:]][$_[:alnum:]]*[\t
]*=[\t ]*(\\(.*\\)|[$_[:alpha:]][$_[:alnum:]]*)[\t ]*=>.*)"
Previous: Glen ChooNext: xing zhi jiang
Message 16 of 25 in “userdiff: add buildin diff driver for JavaScript language”
  1. xing zhi jiangMar 4, 2022
  2. [GSoC][PATCH 1/1] Add a diff driver for JavaScript languages.xing zhi jiang, Mar 4, 2022
  3. Johannes SixtMar 5, 2022
  4. xing-zhi jiangMar 7, 2022
  5. Johannes SixtMar 8, 2022
  6. xing zhi jiangMar 12, 2022
  7. Johannes SixtMar 5, 2022
  8. [GSoC][PATCH v2] Add a diff driver for JavaScript languages.xing zhi jiang, Mar 12, 2022
  9. Johannes SixtMar 13, 2022
  10. xing zhi jiangApr 3, 2022
  11. Glen ChooMar 14, 2022
  12. Johannes SixtMar 15, 2022
  13. Glen ChooMar 15, 2022
  14. Junio C HamanoMar 15, 2022
  15. Glen ChooMar 15, 2022
  16. xing zhi jiangApr 3, 2022
  17. xing zhi jiangApr 3, 2022
  18. xing zhi jiangApr 3, 2022
  19. [GSoC][PATCH v3] Add a diff driver for JavaScript languages.xing zhi jiang, Apr 3, 2022
  20. Johannes SixtApr 3, 2022
  21. Ævar Arnfjörð BjarmasonApr 4, 2022
  22. Johannes SixtApr 4, 2022
  23. Junio C HamanoApr 4, 2022
  24. Ævar Arnfjörð BjarmasonApr 5, 2022
  25. Glen ChooApr 4, 2022

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

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