Skip to content

Commit

Permalink
Merge pull request #93 from rtts/regular-expression-literals
Browse files Browse the repository at this point in the history
Fix javascript regular expression literals
  • Loading branch information
JaapJoris authored Mar 16, 2023
2 parents d95ea63 + 9a7a17b commit 47f33ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions djhtml/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ class DjJS(DjTXT):
r"//.*",
r"/\*",
r"[$\w-]+:",
r'"(?:\\.|[^\\"])*"', # "string"
r"'(?:\\.|[^\\'])*'", # 'string'
r"`(?:\\.|[^\\`])*`", # `string`
r"/(?:\\.|[^\\/ \n])*/", # /string/ (but without spaces)
r'"(?:\\.|[^"])*"', # "string"
r"'(?:\\.|[^'])*'", # 'string'
r"`(?:\\.|[^`])*`", # `string`
r"/(?=[^ ])(?:\\.|[^/\n])*/", # /[^ ]string/
r"[{[()\]}]",
r"var ",
r"let ",
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = djhtml
version = 3.0.5
version = 3.0.6
description = Django/Jinja template indenter
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
6 changes: 3 additions & 3 deletions tests/suite/js.html
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@
foo = /([{/
bar = /\/{/
baz = //{//
xizzy = /{/

// The following is known to be broken
// The following is no longer broken \o/
/function() {/
return
}
return
</script>
10 changes: 5 additions & 5 deletions tests/suite/js.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Expression literals ', mode
Line([Text('<', mode=DjHTML), Text('script', mode=InsideHTMLTag, absolute=8), Open('>', mode=DjHTML)])
Line([Text(' re = ', mode=DjJS), Text('/ab+c/', mode=DjJS, relative=1)], level=1)
Line([Text(' space_re = / foo /', mode=DjJS)], level=1)
Line([Text(' single_re = /foo\\/ + bar/', mode=DjJS)], level=1)
Line([Text(' single_re = ', mode=DjJS), Text('/foo\\/ + bar/', mode=DjJS, relative=1)], level=1)
Line([Text(' double_re = ', mode=DjJS), Text('/foo/', mode=DjJS, relative=1), Text(' + ', mode=DjJS), Text('/bar/', mode=DjJS)], level=1)
Line([Text(' looks_like_comment = ', mode=DjJS), Text('/\\(/', mode=DjJS, relative=1), Text('/', mode=DjJS)], level=1)
Line([])
Expand All @@ -446,10 +446,10 @@ Line([])
Line([Text(' foo = ', mode=DjJS), Text('/([{/', mode=DjJS, relative=1)], level=1)
Line([Text(' bar = ', mode=DjJS), Text('/\\/{/', mode=DjJS, relative=1)], level=1)
Line([Text(' baz = ', mode=DjJS), Text('//{//', mode=DjJS, ignore=True)], level=1)
Line([Text(' xizzy = ', mode=DjJS), Text('/{/', mode=DjJS, relative=1)], level=1)
Line([])
Line([Text(' ', mode=DjJS), Text('// The following is known to be broken', mode=DjJS, ignore=True)], level=1, ignore=True)
Line([Text(' /function', mode=DjJS), Open('(', mode=DjJS, level=1), Close(')', mode=DjJS), Text(' ', mode=DjJS), Open('{', mode=DjJS, level=1), Text('/', mode=DjJS)], level=1)
Line([Text(' return', mode=DjJS)], level=2)
Line([Text(' ', mode=DjJS), Close('}', mode=DjJS)], level=1)
Line([Text(' ', mode=DjJS), Text('// The following is no longer broken \\o/', mode=DjJS, ignore=True)], level=1, ignore=True)
Line([Text(' ', mode=DjJS), Text('/function() {/', mode=DjJS)], level=1)
Line([Text(' return', mode=DjJS)], level=1)
Line([Close('</script>', mode=DjHTML)])
Line([])

0 comments on commit 47f33ed

Please sign in to comment.