Skip to content

Commit 1034a47

Browse files
committed
Improved javascript regex regocnizing for extracting js messages
1 parent 4055511 commit 1034a47

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

CHANGES

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Babel Changelog
22
===============
33

4+
Version 2.10.0
5+
--------------
6+
7+
(Feature releaser released on May 22nd 2021)
8+
9+
Improvements
10+
~~~~~~~~~~~~
11+
12+
* Support for javascript template strings
13+
14+
415
Version 2.9.0
516
-------------
617

babel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
negotiate_locale, parse_locale, get_locale_identifier
2222

2323

24-
__version__ = '2.9.0'
24+
__version__ = '2.10.0'

babel/messages/jslexer.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,57 @@
2525
name_re = re.compile(r'[\w$_][\w\d$_]*', re.UNICODE)
2626
dotted_name_re = re.compile(r'[\w$_][\w\d$_.]*[\w\d$_.]', re.UNICODE)
2727
division_re = re.compile(r'/=?')
28-
regex_re = re.compile(r'/(?:[^/\\]*(?:\\.[^/\\]*)*)/[a-zA-Z]*', re.DOTALL)
28+
29+
regex_re = re.compile(
30+
r'''
31+
32+
# Opening slash of the regex
33+
/
34+
35+
(?:
36+
37+
# 1) Blackslashed character
38+
#
39+
# Match a backslash `\` and then it's following character, allowing
40+
# to blackslash the `/` for example.
41+
(?:\\.)?
42+
43+
|
44+
45+
# 2) Regex character class `[a-z]`
46+
#
47+
# Match regex character class, like `[a-z]`. Inside a character
48+
# class, a `/` character may appear, which does not close the
49+
# regex. Therefore we allow it here inside a character class.
50+
\[
51+
(?:
52+
[^\]]*
53+
|
54+
\\\]
55+
)*
56+
\]
57+
58+
|
59+
60+
# 3) Other characters
61+
#
62+
# Match anything except a closing slash `/`, a backslash `\`, or a
63+
# opening bracket `[`. Those last two will be handled by the other
64+
# matchers.
65+
[^/\\\[]*
66+
67+
)*
68+
69+
# Closing slash of the regex
70+
/
71+
72+
# regex flags
73+
[a-zA-Z]*
74+
75+
''',
76+
re.DOTALL + re.VERBOSE
77+
)
78+
2979
line_re = re.compile(r'(\r\n|\n|\r)')
3080
line_join_re = re.compile(r'\\' + line_re.pattern)
3181
uni_escape_re = re.compile(r'[a-fA-F0-9]{1,4}')

0 commit comments

Comments
 (0)