Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions babel/messages/jslexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _tokenize(
# if we don't have a match we don't give up yet, but check for
# division operators or regular expression literals, based on
# the status of `may_divide` which is determined by the last
# processed non-whitespace token using `_indicates_division`.
# processed non-comment, non-whitespace token using `_indicates_division`.
else:
if may_divide:
match = division_re.match(source, pos)
Expand All @@ -220,7 +220,8 @@ def _tokenize(
token_value = match.group()
if token_type is not None:
token = Token(token_type, token_value, lineno)
may_divide = _indicates_division(token)
if token_type not in ('linecomment', 'multilinecomment'):
may_divide = _indicates_division(token)
yield token
lineno += len(line_re.findall(token_value))
pos = match.end()
Expand Down
12 changes: 12 additions & 0 deletions tests/messages/test_js_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def test_message_with_multiline_comment():
assert messages[0][3] == ['NOTE: hello', 'and bonjour', ' and servus']


@pytest.mark.parametrize('comment', [b'/* total for the day */', b'// total for the day'])
def test_division_after_comment(comment):
buf = BytesIO(
b'const average = total ' + comment + b'\n'
b' / count;\n'
b'const label = gettext("Average");\n'
b'const pattern = /avg/;'
)
messages = list(extract.extract('javascript', buf, extract.DEFAULT_KEYWORDS, [], {}))
assert messages == [(3, 'Average', [], None)]


def test_ignore_function_definitions():
buf = BytesIO(b"""\
function gettext(value) {
Expand Down