summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2016-10-24 15:06:52 +0300
committerGitHub <noreply@github.com>2016-10-24 15:06:52 +0300
commit82cb625829c6f6f2e9efb90bd3f121852fe41a8d (patch)
treefe2ed03d1811782e4d2bc6e07357823b7fdbc540
parentead6ed984fee9019b94700068f553223ad30b012 (diff)
parentbe0d8cb340264c0f11f29efc67c5fb109b429e39 (diff)
downloadbabel-82cb625829c6f6f2e9efb90bd3f121852fe41a8d.tar.gz
Merge pull request #396 from karloskar/feature/evolve-jsx-extraction-pt2
jslexer.py: Change jsx_tag regex again
-rw-r--r--babel/messages/jslexer.py2
-rw-r--r--tests/messages/test_jslexer.py133
2 files changed, 83 insertions, 52 deletions
diff --git a/babel/messages/jslexer.py b/babel/messages/jslexer.py
index 665a86f..a9bab2f 100644
--- a/babel/messages/jslexer.py
+++ b/babel/messages/jslexer.py
@@ -45,7 +45,7 @@ _rules = [
([eE][-+]?\d+)? |
(0x[a-fA-F0-9]+)
)''')),
- ('jsx_tag', re.compile(r'</?[^> ]+', re.I)), # May be mangled in `get_rules`
+ ('jsx_tag', re.compile(r'(?:</?[^>\s]+|/>)', re.I)), # May be mangled in `get_rules`
('operator', re.compile(r'(%s)' % '|'.join(map(re.escape, operators)))),
('template_string', re.compile(r'''`(?:[^`\\]*(?:\\.[^`\\]*)*)`''', re.UNICODE)),
('string', re.compile(r'''(?xs)(
diff --git a/tests/messages/test_jslexer.py b/tests/messages/test_jslexer.py
index e125fec..b70621f 100644
--- a/tests/messages/test_jslexer.py
+++ b/tests/messages/test_jslexer.py
@@ -40,55 +40,86 @@ def test_jsx():
<option value="val2">{ i18n._('String 2') }</option>
<option value="val3">{ i18n._('String 3') }</option>
<component value={i18n._('String 4')} />
+ <comp2 prop={<comp3 />} data={{active: true}}>
+ <btn text={ i18n._('String 5') } />
+ </comp2>
""", jsx=True)) == [
- ('jsx_tag', '<option', 2),
- ('name', 'value', 2),
- ('operator', '=', 2),
- ('string', '"val1"', 2),
- ('operator', '>', 2),
- ('operator', '{', 2),
- ('name', 'i18n._', 2),
- ('operator', '(', 2),
- ('string', "'String1'", 2),
- ('operator', ')', 2),
- ('operator', '}', 2),
- ('jsx_tag', '</option', 2),
- ('operator', '>', 2),
- ('jsx_tag', '<option', 3),
- ('name', 'value', 3),
- ('operator', '=', 3),
- ('string', '"val2"', 3),
- ('operator', '>', 3),
- ('operator', '{', 3),
- ('name', 'i18n._', 3),
- ('operator', '(', 3),
- ('string', "'String 2'", 3),
- ('operator', ')', 3),
- ('operator', '}', 3),
- ('jsx_tag', '</option', 3),
- ('operator', '>', 3),
- ('jsx_tag', '<option', 4),
- ('name', 'value', 4),
- ('operator', '=', 4),
- ('string', '"val3"', 4),
- ('operator', '>', 4),
- ('operator', '{', 4),
- ('name', 'i18n._', 4),
- ('operator', '(', 4),
- ('string', "'String 3'", 4),
- ('operator', ')', 4),
- ('operator', '}', 4),
- ('jsx_tag', '</option', 4),
- ('operator', '>', 4),
- ('jsx_tag', '<component', 5),
- ('name', 'value', 5),
- ('operator', '=', 5),
- ('operator', '{', 5),
- ('name', 'i18n._', 5),
- ('operator', '(', 5),
- ('string', "'String 4'", 5),
- ('operator', ')', 5),
- ('operator', '}', 5),
- ('operator', '/', 5),
- ('operator', '>', 5)
- ]
+ ('jsx_tag', '<option', 2),
+ ('name', 'value', 2),
+ ('operator', '=', 2),
+ ('string', '"val1"', 2),
+ ('operator', '>', 2),
+ ('operator', '{', 2),
+ ('name', 'i18n._', 2),
+ ('operator', '(', 2),
+ ('string', "'String1'", 2),
+ ('operator', ')', 2),
+ ('operator', '}', 2),
+ ('jsx_tag', '</option', 2),
+ ('operator', '>', 2),
+ ('jsx_tag', '<option', 3),
+ ('name', 'value', 3),
+ ('operator', '=', 3),
+ ('string', '"val2"', 3),
+ ('operator', '>', 3),
+ ('operator', '{', 3),
+ ('name', 'i18n._', 3),
+ ('operator', '(', 3),
+ ('string', "'String 2'", 3),
+ ('operator', ')', 3),
+ ('operator', '}', 3),
+ ('jsx_tag', '</option', 3),
+ ('operator', '>', 3),
+ ('jsx_tag', '<option', 4),
+ ('name', 'value', 4),
+ ('operator', '=', 4),
+ ('string', '"val3"', 4),
+ ('operator', '>', 4),
+ ('operator', '{', 4),
+ ('name', 'i18n._', 4),
+ ('operator', '(', 4),
+ ('string', "'String 3'", 4),
+ ('operator', ')', 4),
+ ('operator', '}', 4),
+ ('jsx_tag', '</option', 4),
+ ('operator', '>', 4),
+ ('jsx_tag', '<component', 5),
+ ('name', 'value', 5),
+ ('operator', '=', 5),
+ ('operator', '{', 5),
+ ('name', 'i18n._', 5),
+ ('operator', '(', 5),
+ ('string', "'String 4'", 5),
+ ('operator', ')', 5),
+ ('operator', '}', 5),
+ ('jsx_tag', '/>', 5),
+ ('jsx_tag', '<comp2', 6),
+ ('name', 'prop', 6),
+ ('operator', '=', 6),
+ ('operator', '{', 6),
+ ('jsx_tag', '<comp3', 6),
+ ('jsx_tag', '/>', 6),
+ ('operator', '}', 6),
+ ('name', 'data', 6),
+ ('operator', '=', 6),
+ ('operator', '{', 6),
+ ('operator', '{', 6),
+ ('name', 'active', 6),
+ ('operator', ':', 6),
+ ('name', 'true', 6),
+ ('operator', '}', 6),
+ ('operator', '}', 6),
+ ('operator', '>', 6),
+ ('jsx_tag', '<btn', 7),
+ ('name', 'text', 7),
+ ('operator', '=', 7),
+ ('operator', '{', 7),
+ ('name', 'i18n._', 7),
+ ('operator', '(', 7),
+ ('string', "'String 5'", 7),
+ ('operator', ')', 7),
+ ('operator', '}', 7),
+ ('jsx_tag', '/>', 7),
+ ('jsx_tag', '</comp2', 8),
+ ('operator', '>', 8)
+ ]