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*-?)(%\})', diff --git a/tests/test_djangojavascript_lexer.py b/tests/test_djangojavascript_lexer.py new file mode 100644 index 0000000000..a8fb197b59 --- /dev/null +++ b/tests/test_djangojavascript_lexer.py @@ -0,0 +1,41 @@ +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): + """ + Test to make sure the lexer doesn't mistake + {* ... *} to be a django comment + """ + 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 + )