﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7704	JS comments put after statements break make-messages.py output	Robby Dermody	Ned Batchelder	"{{{
#!rst

To test, make a JS file (say ``myfile.js``) with the following valid JS content:

.. code-block:: js

    var a = 1;
    if(a != 2 && a != 5) //this comment breaks the file
    {
	//this does not
	alert(gettext(""foobar""));
    }

Running ``make-messages.py -d djangojs -a`` will then yield the following output for that (in the ``myfile.js.py`` intermediate file it produces):

.. code-block:: js

    var a = 1;
    if(a != 2 && a != 5) //this comment breaks the file
    {
    #this does not
	alert(gettext(""foobar""));
    }


As you can see, the comment after the if statement was not replaced, and since ``xgettext`` is then run in Perl mode, it seems to choke on that input.
The result depends on the exact code: This example will cause only that next ``gettext(""foobar"")`` not to be generated (ones further down in the code will).
With other code I had that had a similar line, nothing was generated. The failure is silent and the only way to know is by checking the gettext output (or lack thereof :).

This is due to the regexp in make-messages: ``pythonize_re = re.compile(r'\n\s*//')``
and then the replacement code: ``src = pythonize_re.sub('\n#', src)``

That assumes that comments come after newlines. I'm not submitting a patch right now because I'm unsure about the best regexp to use for this that will get all the valid JS comment cases (or if that is even something the django devs want to do). At the very least, if you all choose not to address this in the code, there should be a note in the documentation telling folks to always put JS comments on their own lines.

As ``make-messages.py`` is now included in django-admin AFAIK, I've categorized it to that.

}}}"	Bug	closed	Internationalization	1.0	Normal	fixed	djangojs, make-messages	robbyd@… ned@… ionel.mc@…	Accepted	1	0	0	1	1	0
