Skip to content
New issue

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

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

Already on GitHub? # to your account

JSX/regexp ambiguity in jslexer #640

Open
remram44 opened this issue May 9, 2019 · 4 comments
Open

JSX/regexp ambiguity in jslexer #640

remram44 opened this issue May 9, 2019 · 4 comments

Comments

@remram44
Copy link

remram44 commented May 9, 2019

After a regular expression like />/, Babel ignores all messages until the next one.

Mapping:

[javascript: **.js]
encoding = utf-8
extract_messages = gettext

Source file:

alert(gettext("First message"));
var expr = />/g;
alert(gettext("Second message"));
var expr2 = /'/g;
alert(gettext("Third message"));

Result POT:

"Generated-By: Babel 2.6.0\n"

#: test.js:1
msgid "First message"
msgstr ""

#: test.js:5
msgid "Third message"
msgstr ""
remram44 added a commit to remram44/taguette that referenced this issue May 13, 2019
@akx
Copy link
Member

akx commented May 27, 2019

The JavaScript lexer in Babel is far from perfect, unfortunately...
If you feel like trying to hack at the lexer to fix this, by all means please do!

It might be a good idea for a future version to use e.g. https://github.com/Kronuz/esprima-python when it's available (i.e. an optional dependency) for more robust parsing.

@remram44
Copy link
Author

remram44 commented May 29, 2019

Thanks, I might take a look. I am low on time unfortunately right now.

For reference, lexer is jslexer.py

@remram44
Copy link
Author

Seems that /> gets recognized as a JSX tag.

@remram44
Copy link
Author

remram44 commented Jun 15, 2019

I don't see how to fix this. The tokenizer can't possibly tell if /> is the start of a regexp or the end of a JSX tag, they are the same tokens. The Javascript grammar is too ambiguous for this to be decided at the tokenizer level.

A parser would be able to tell if it's currently in a JSX tag or not and resolve the ambiguity, but there is no such parsing being done in Babel. Simply keeping track of JSX open/close tokens wouldn't be enough because regexps can appear inside JSX tags (<hr class={ /\w+/.exec(var)[0] }/>).

I think I'll have to leave that alone, sorry!

Wrote a test:
def test_regex():
    assert list(jslexer.tokenize('''
        re = />/g;
    ''')) == [
        ('name', 're', 2),
        ('operator', '=', 2),
        ('regexp', '/>/', 2),
        ('operator', ';', 2),
    ]

@remram44 remram44 changed the title Babel gets confused by JavaScript regular expressions JSX/regexp ambiguity in jslexer Jun 15, 2019
spdegabrielle pushed a commit to spdegabrielle/taguette that referenced this issue Jul 28, 2020
LucasLefevre added a commit to odoo/o-spreadsheet that referenced this issue Jun 15, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791
robodoo pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes #1444

Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

X-original-commit: df307ed
robodoo pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes #1461

X-original-commit: df307ed
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
LucasLefevre added a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791
robodoo pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes #1462

Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

X-original-commit: d711ad2
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

X-original-commit: d711ad2
fw-bot pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

X-original-commit: d711ad2
robodoo pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes #1465

X-original-commit: d711ad2
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
robodoo pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes #1464

X-original-commit: d711ad2
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
robodoo pushed a commit to odoo/o-spreadsheet that referenced this issue Jun 24, 2022
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes #1463

X-original-commit: d711ad2
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Topdev97 added a commit to Topdev97/o-spreadsheet that referenced this issue Nov 18, 2024
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes odoo/o-spreadsheet#1461

X-original-commit: df307ed6a0e79370a8405b902df1e909671fb035
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Topdev97 added a commit to Topdev97/o-spreadsheet that referenced this issue Nov 18, 2024
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes odoo/o-spreadsheet#1464

X-original-commit: d711ad2cb1ef220d8a02853243859a4572748d61
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Topdev97 added a commit to Topdev97/o-spreadsheet that referenced this issue Nov 18, 2024
There's an issue in odoo when extracing translatable source terms
from the bundled library file `o_spreadsheet.js`. Some terms are not
extracted.

Babel doesn't correctly tokenize the regex /"/
As a result, all following tokens are fucked up and source terms are no longer
exported after this point.

It seems to be known that babel js lexer isn't perfect.
python-babel/babel#467
python-babel/babel#616
python-babel/babel#640
python-babel/babel#791

closes odoo/o-spreadsheet#1463

X-original-commit: d711ad2cb1ef220d8a02853243859a4572748d61
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants