From 8fee76cf39ee4192da534fbafde6ef2e90420429 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 18 Jan 2016 17:09:08 +0200 Subject: [PATCH] JavaScript: Add JSX/E4X tag lexing Fixes #280 --- babel/messages/extract.py | 4 +++- babel/messages/jslexer.py | 25 ++++++++++++++++++++++--- tests/messages/test_js_extract.py | 25 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/babel/messages/extract.py b/babel/messages/extract.py index c2dcd5b99..153fe5116 100644 --- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -506,6 +506,8 @@ def extract_javascript(fileobj, keywords, comment_tags, options): :param comment_tags: a list of translator tags to search for and include in the results :param options: a dictionary of additional options (optional) + Supported options are: + * `jsx` -- set to false to disable JSX/E4X support. """ from babel.messages.jslexer import tokenize, unquote_string funcname = message_lineno = None @@ -517,7 +519,7 @@ def extract_javascript(fileobj, keywords, comment_tags, options): last_token = None call_stack = -1 - for token in tokenize(fileobj.read().decode(encoding)): + for token in tokenize(fileobj.read().decode(encoding), jsx=options.get("jsx", True)): 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 282d294f3..32500676a 100644 --- a/babel/messages/jslexer.py +++ b/babel/messages/jslexer.py @@ -31,7 +31,7 @@ Token = namedtuple('Token', 'type value lineno') -rules = [ +_rules = [ (None, re.compile(r'\s+(?u)')), (None, re.compile(r'