Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extracting comments not working in assignment #65

Closed
emabiz opened this issue May 18, 2023 · 3 comments
Closed

extracting comments not working in assignment #65

emabiz opened this issue May 18, 2023 · 3 comments

Comments

@emabiz
Copy link

emabiz commented May 18, 2023

Hi,
it seems that extracting comments is not working properly if the calleName is in an assignment. But not always.
This is what I get:

    let foo;

    function f(){
        foo=/* global foo leading not working */ lan.gettext('global foo leading not working');
        foo= lan.gettext('global foo trailing not working'); /* global foo trailing not working */

        let local_foo=/* local foo leading not working */ lan.gettext('local foo leading not working');
        let local_foo1= lan.gettext('local foo trailing working'); /* local foo trailing working */
    }

How to solve this?
Thank you

Emanuele

@lukasgeiter
Copy link
Owner

Hello Emanuele!

Let me preface this by saying that the comment extraction implementation will never be perfect. Because comments aren't intrinsically associated with a specific statement or expression in your code, gettext-extractor employs some heuristics to try and extract relevant comments. In practice, this means a lot of specific handling for all the different places a call expression can appear in.

Now on to your specific issues...


foo=/* global foo leading not working */ lan.gettext('global foo leading not working');
foo= lan.gettext('global foo trailing not working'); /* global foo trailing not working */

Variable assignments is one of the cases that is not handled yet, but I can add support for that.


let local_foo=/* local foo leading not working */ lan.gettext('local foo leading not working');
let local_foo1= lan.gettext('local foo trailing working'); /* local foo trailing working */

With variable declarations, I've made the decision to extract leading comments that come before the variable declaration as a whole. So the following should be extracted properly:

// comment
let local_foo = lan.gettext('test');
/* comment */ let local_foo = lan.gettext('test');

While it's technically possible to additionally extract leading comments after the equals sign, I'd prefer to keep the complexity down and not do that.

@emabiz
Copy link
Author

emabiz commented May 25, 2023

Hi,
yes it is enough for my purposes.
Actually I was searching one way that works, and I found that putting the comment immediately after the gettext (before the ;) works fine.
It also covers the following pattern:

`Hello ${lan.gettext('World') /* comment world */}`

That it is perfectly fine for me.
Thank you

@lukasgeiter
Copy link
Owner

Comment extraction for variable assignments is fixed in v3.8.0 (not for comments that come after the equals sign though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants