]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
jslexer.py: Change jsx_tag regex again 396/head
authorKO. Mattsson <karloskar@ponty.se>
Mon, 25 Apr 2016 12:46:06 +0000 (14:46 +0200)
committerKO. Mattsson <karloskar@ponty.se>
Mon, 24 Oct 2016 07:47:01 +0000 (09:47 +0200)
We've had some syntactic variations that my previous PR, #392, did not
account for. One case had a component as a prop that tripped up the
regex.

babel/messages/jslexer.py
tests/messages/test_jslexer.py

index 665a86fb1393d2f87619cf20debdf6ff6e6de97d..a9bab2f2bbd60e110ce40301a8430f9268077dbf 100644 (file)
@@ -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)(
index e125fec7a84a801b73301a6d28d6956f6cdaa254..b70621fc61538746bde8cc315caaa4519c742423 100644 (file)
@@ -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)
+    ]