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

Added babel parser support for javascript parsing #72

Closed
wants to merge 2 commits into from

Conversation

ziemenz
Copy link
Contributor

@ziemenz ziemenz commented Dec 14, 2019

Added new parameter for cli --parser(auto by default)
When parser is auto gettext-extract try parse with use acorn parser. If acorn finished with error, then try parse with babel parser with using project config(e.g @babel/plugin-proposal-optional-chaining)

Copy link
Contributor

@vperron vperron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and useful addition ! I have made a few comments that are easy to resolve. But I will not accept a PR that adds a feature without additional tests though.

Can you add a test that ensure the feature, well, works ?


Parser.extend(stage3).parse(script, ACORN_OPTIONS);
break;
case 'babel':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-pick: indentation

return getGettextEntriesFromScript(script, 'acorn');
} catch (e) {
return getGettextEntriesFromScript(script, 'babel');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd very much rather have 2 sub-functions, one that parses with babel, another that parses with acorn, and that you call them instead of having the function calling itself with different arguments.

Also, in the switch statemnt you could just leave this calling of the two parsers as default instead of using the 'auto' keyword :)

function extractStringsFromJavascript(filename, script) {
const gettextEntries = getGettextEntriesFromScript(script);
function extractStringsFromJavascript(filename, script, parser = 'auto') {
const gettextEntries = getGettextEntriesFromScript(script, parser);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could avoid adding a parser argument to getGettextEntriesFromScript and just directly call one or both of the parsing submethods (let's call them parseJSGettextWithAcorn() and parseJSGettextWithBabel() directly here. It would make a clearer separation of abstraction levels.

case 'auto':
try {
return getGettextEntriesFromScript(script, 'acorn');
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should log something so that the user sees that we just switched the parser.

@@ -30,7 +30,7 @@ yarn add --dev easygettext
##### HTML token extraction

Simply invoke the tool on the templates you want to extract a POT dictionary template from.
The optional '--ouput' argument enables you to directly output to a file.
The optional '--output' argument enables you to directly output to a file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should document somewhere that we now support something more, don't you think ?

@Knogobert
Copy link
Contributor

This would be very nice to implement, it would allow babel to parse future specs just like #84 and more. It seems like all is needed is a few tests and updated documentation, correct @vperron ?

@vperron
Copy link
Contributor

vperron commented Aug 24, 2020

Exactly. I d'ont have time to do it though, but feel free since I doubt @ziemenz has got time enough on their hands for that :)

Knogobert added a commit to Knogobert/easygettext that referenced this pull request Sep 1, 2020
@Knogobert
Copy link
Contributor

Heads up @vperron @ziemenz , I'm currently working on rebasing this PR to version 2.14.0, implementing some of Victor's comments and adding tests & documentation. I'm doing this on my own fork, as I'm not able to commit to this PR. But @ziemenz will still be signed to those two commits.
I'm not sure I will be able to test the CLI argument passing part, but perhaps that also doesn't really need a test? As that would be testing another thing than what this package is about.

@vperron
Copy link
Contributor

vperron commented Sep 2, 2020

Yes, one of the original design choices was to keep the CLI part as simple as possible so that it does not need so much testing. The issue being that testing it requires some integration testing to run external processes and collect the output, which isn't an easy thing to do and automate.
That's why I personnally recommend to put as much code as possible in the non-CLI part and test it heavily :)

@Knogobert
Copy link
Contributor

@vperron I hate to be a reminder for open source projects, but now that a month has passed, have you had time to look over the PR #92 yet? It is supposed to take all of your suggestions in account.

@vperron
Copy link
Contributor

vperron commented Oct 3, 2020 via email

@vperron
Copy link
Contributor

vperron commented Oct 5, 2020

ASAP meaning tomorrow, I'm still on vacation with no computer today ^^

@vperron
Copy link
Contributor

vperron commented Oct 6, 2020

Done ! @Knogobert I'll make you a permanent contributor after your rebase & my merge ^^

@Knogobert
Copy link
Contributor

Thanks @vperron , hope you had a nice vacation! 🌴

I'll fix those issues you mentioned before letting you merge

Knogobert added a commit to Knogobert/easygettext that referenced this pull request Oct 6, 2020
Knogobert added a commit to Knogobert/easygettext that referenced this pull request Oct 6, 2020
vperron pushed a commit that referenced this pull request Oct 6, 2020
@vperron
Copy link
Contributor

vperron commented Oct 6, 2020

Thanks a lot @Knogobert , I made you a contributor permanently and am closing this PR now !

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

Successfully merging this pull request may close these issues.

None yet

3 participants