From: Bruno Haible Date: Wed, 8 Jan 2025 14:15:41 +0000 (+0100) Subject: xgettext: JavaScript: Parse recursive JSX expressions correctly. X-Git-Tag: v0.24~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1605149adc78736c7fde0ef58aa6863aa8b266e1;p=thirdparty%2Fgettext.git xgettext: JavaScript: Parse recursive JSX expressions correctly. Reported by at . * gettext-tools/src/x-javascript.c (phase5_get): Treat a '<' character in level type level_embedded_js_in_xml like in the other level types. * gettext-tools/tests/xgettext-javascript-6: Add another test case. * NEWS: Mention the fix. --- diff --git a/NEWS b/NEWS index cf25593f1..a9886bfe7 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ Version 0.24 - January 2025 * The contents of the po/ directory has been changed: - A file Makefile.in replaces the old Makefile.in.in. # Programming languages support: + * JavaScript: + - xgettext now parses recursive JSX expressions correctly. * C++: - A new example 'hello-c++-gnome3' has been added. * Ruby: diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index 07b6034b3..ed1d1fbe6 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -1478,12 +1478,10 @@ phase5_get (token_ty *tp) case '<': { /* We assume: - - XMLMarkup and XMLElement are not allowed after an expression, - - embedded JavaScript expressions in XML do not recurse. + XMLMarkup and XMLElement are not allowed after an expression. */ if (level_type () == level_xml_element - || (level_type () != level_embedded_js_in_xml - && ! is_after_expression ())) + || ! is_after_expression ()) { /* Recognize XML markup: XML comment, CDATA, Processing Instruction. */ diff --git a/gettext-tools/tests/xgettext-javascript-6 b/gettext-tools/tests/xgettext-javascript-6 index e4df485f9..de68018fe 100755 --- a/gettext-tools/tests/xgettext-javascript-6 +++ b/gettext-tools/tests/xgettext-javascript-6 @@ -64,6 +64,13 @@ var s16 = { a: 1, b:
_("Expected translation string #18")
}end`; var s19 = _("Expected translation string #19"); +const s20 = () => ( + _("Expected translation string #21")} + a3={_("Expected translation string #22")} + /> +); EOF : ${XGETTEXT=xgettext} @@ -149,6 +156,15 @@ msgstr "" msgid "Expected translation string #19" msgstr "" + +msgid "Expected translation string #20" +msgstr "" + +msgid "Expected translation string #21" +msgstr "" + +msgid "Expected translation string #22" +msgstr "" EOF : ${DIFF=diff}