* `template_string` -- set to false to disable ES6
template string support.
"""
- from babel.messages.jslexer import tokenize, unquote_string
+ from babel.messages.jslexer import Token, tokenize, unquote_string
funcname = message_lineno = None
messages = []
last_argument = None
template_string=options.get("template_string", True),
dotted=dotted
):
+ if ( # Turn keyword`foo` expressions into keyword("foo") calls:
+ funcname and # have a keyword...
+ (last_token and last_token.type == 'name') and # we've seen nothing after the keyword...
+ token.type == 'template_string' # this is a template string
+ ):
+ message_lineno = token.lineno
+ messages = [unquote_string(token.value)]
+ call_stack = 0
+ token = Token('operator', ')', token.lineno)
+
if token.type == 'operator' and token.value == '(':
if funcname:
message_lineno = token.lineno
)
assert messages == [(1, 'Very template, wow', [], None)]
+
+
+def test_template_string_tag_usage():
+ buf = BytesIO(b"function() { if(foo) msg1 = i18n`Tag template, wow`; }")
+ messages = list(
+ extract.extract('javascript', buf, {"i18n": None}, [], {})
+ )
+
+ assert messages == [(1, 'Tag template, wow', [], None)]