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
4 changes: 3 additions & 1 deletion babel/messages/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,12 @@ def parse_template_string(
if level:
expression_contents += character
if not inside_str:
if character == '{' and prev_character == '$':
# start of new template string or object definition
if character == '{':
Comment on lines +838 to +839
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would this handle something like

hello(`there is {nothing} to worry about`)

?
AISI, nothing would then be passed to extract_javascript?

level += 1
elif level and character == '}':
level -= 1
# end of template string
if level == 0 and expression_contents:
expression_contents = expression_contents[0:-1]
fake_file_obj = io.BytesIO(expression_contents.encode())
Expand Down
10 changes: 10 additions & 0 deletions tests/messages/test_js_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,13 @@ def test_inside_nested_template_string():
)

assert messages == [(1, 'Greetings!', [], None), (1, 'This is a lovely evening.', [], None), (1, 'The day is really nice!', [], None)]


def test_template_string_with_parameters() -> None:
buf = BytesIO(
b'`${gettext("text %(param)s", { param: myVar })}`;',
)
messages = list(extract.extract("javascript", buf, {"gettext": None}, [], {"parse_template_string": True}))
assert messages == [
(1, "text %(param)s", [], None),
]
Loading