diff --git a/babel/messages/extract.py b/babel/messages/extract.py index 153fe5116..ee90afb76 100644 --- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -518,8 +518,13 @@ def extract_javascript(fileobj, keywords, comment_tags, options): encoding = options.get('encoding', 'utf-8') last_token = None call_stack = -1 + dotted = any('.' in kw for kw in keywords) - for token in tokenize(fileobj.read().decode(encoding), jsx=options.get("jsx", True)): + for token in tokenize( + fileobj.read().decode(encoding), + jsx=options.get("jsx", True), + dotted=dotted + ): if token.type == 'operator' and token.value == '(': if funcname: message_lineno = token.lineno diff --git a/babel/messages/jslexer.py b/babel/messages/jslexer.py index 32500676a..e6310cf3f 100644 --- a/babel/messages/jslexer.py +++ b/babel/messages/jslexer.py @@ -22,12 +22,13 @@ escapes = {'b': '\b', 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t'} +name_re = re.compile(r'[\w$_][\w\d$_]*', re.UNICODE) +dotted_name_re = re.compile(r'[\w$_][\w\d$_.]*[\w\d$_.]', re.UNICODE) division_re = re.compile(r'/=?') regex_re = re.compile(r'/(?:[^/\\]*(?:\\.[^/\\]*)*)/[a-zA-Z]*(?s)') line_re = re.compile(r'(\r\n|\n|\r)') line_join_re = re.compile(r'\\' + line_re.pattern) uni_escape_re = re.compile(r'[a-fA-F0-9]{1,4}') -name_re = re.compile(r'(\$+\w*|[^\W\d]\w*)(?u)') Token = namedtuple('Token', 'type value lineno') @@ -36,6 +37,7 @@ (None, re.compile(r'