]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: JavaScript: Parse recursive JSX expressions correctly.
authorBruno Haible <bruno@clisp.org>
Wed, 8 Jan 2025 14:15:41 +0000 (15:15 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 8 Jan 2025 14:15:41 +0000 (15:15 +0100)
Reported by <fiurgeist@gmail.com> at <https://savannah.gnu.org/bugs/?66643>.

* 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.

NEWS
gettext-tools/src/x-javascript.c
gettext-tools/tests/xgettext-javascript-6

diff --git a/NEWS b/NEWS
index cf25593f1fff433c8317425e996ec8ec1673c317..a9886bfe7026d1983754d96f7c451bacbefdadf8 100644 (file)
--- 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:
index 07b6034b354ffcc4c9c5ba4cad8760f392c83448..ed1d1fbe67fe5648e115c7a38ee54dd92c93d7b7 100644 (file)
@@ -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.  */
index e4df485f9a16dbe180fa36dfd5455bd7d05bc1ed..de68018fe655be1d10912d8c1c8e6fc4a8b0be3f 100755 (executable)
@@ -64,6 +64,13 @@ var s16 = { a: 1, b: <div className={`${ _("Expected translation string #16") }`
 var s17 = _("Expected translation string #17");
 var s18 = `begin${ <div> _("Expected translation string #18") </div> }end`;
 var s19 = _("Expected translation string #19");
+const s20 = () => (
+  <Foo
+    a1={_("Expected translation string #20")}
+    a2={foo && <div>_("Expected translation string #21")</div>}
+    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}