From 198f5efe505bf67696512a0b63186de3745972f2 Mon Sep 17 00:00:00 2001 From: Sean McElwain Date: Thu, 29 Oct 2020 20:04:20 -0400 Subject: [PATCH 1/3] added test to track djangojavascript lexer fix --- tests/test_djangojavascript_lexer.py | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/test_djangojavascript_lexer.py diff --git a/tests/test_djangojavascript_lexer.py b/tests/test_djangojavascript_lexer.py new file mode 100644 index 0000000000..d4a5f91b57 --- /dev/null +++ b/tests/test_djangojavascript_lexer.py @@ -0,0 +1,37 @@ +import pytest + +from pygments.lexers.templates import JavascriptDjangoLexer +from pygments.token import Comment + + +@pytest.fixture(scope="module") +def lexer(): + yield JavascriptDjangoLexer() + + +def test_do_not_mistake_JSDoc_for_django_comment(lexer): + text = """/** + * @param {*} cool + */ + func = function(cool) { + }; + + /** + * @param {*} stuff + */ + fun = function(stuff) { + };""" + tokens = list(lexer.get_tokens(text)) + assert ( + ( + Comment, + """{*} cool + */ + func = function(cool) { + }; + + /** + * @param {*}""", + ) + not in tokens + ) From 15b13383d5d6001f092472bac2544cfd070aa0be Mon Sep 17 00:00:00 2001 From: Sean McElwain Date: Thu, 29 Oct 2020 20:05:06 -0400 Subject: [PATCH 2/3] removed \'{* ... *}\' as a django comment --- pygments/lexers/templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index a056728e4c..2327589a62 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -338,7 +338,7 @@ class DjangoLexer(RegexLexer): (r'[^{]+', Other), (r'\{\{', Comment.Preproc, 'var'), # jinja/django comments - (r'\{[*#].*?[*#]\}', Comment), + (r'\{#.*?#\}', Comment), # django comments (r'(\{%)(-?\s*)(comment)(\s*-?)(%\})(.*?)' r'(\{%)(-?\s*)(endcomment)(\s*-?)(%\})', From fb8c70e7d5fb5ee7da2a9727ddf471ccff969a7a Mon Sep 17 00:00:00 2001 From: Sean McElwain Date: Thu, 29 Oct 2020 20:08:01 -0400 Subject: [PATCH 3/3] added documentation --- tests/test_djangojavascript_lexer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_djangojavascript_lexer.py b/tests/test_djangojavascript_lexer.py index d4a5f91b57..a8fb197b59 100644 --- a/tests/test_djangojavascript_lexer.py +++ b/tests/test_djangojavascript_lexer.py @@ -10,6 +10,10 @@ def lexer(): def test_do_not_mistake_JSDoc_for_django_comment(lexer): + """ + Test to make sure the lexer doesn't mistake + {* ... *} to be a django comment + """ text = """/** * @param {*} cool */