Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix punctuation not labeled in function definition in TypeScript #1511

Merged
merged 3 commits into from Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygments/lexers/javascript.py
Expand Up @@ -508,7 +508,7 @@ class TypeScriptLexer(RegexLexer):
(r'(super)(\s*)(\([\w,?.$\s]+\s*\))',
bygroups(Keyword.Reserved, Text), 'slashstartsregex'),
# Match stuff like: function() {...}
(r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'),
(r'([a-zA-Z_?.$][\w?.$]*)(?=\(\) \{)', Name.Other, 'slashstartsregex'),
# Match stuff like: (function: return type)
(r'([\w?.$][\w?.$]*)(\s*:\s*)([\w?.$][\w?.$]*)',
bygroups(Name.Other, Text, Keyword.Type)),
Expand Down
24 changes: 23 additions & 1 deletion tests/test_javascript.py
Expand Up @@ -9,7 +9,7 @@

import pytest

from pygments.lexers import CoffeeScriptLexer
from pygments.lexers import CoffeeScriptLexer, TypeScriptLexer
from pygments.token import Token

COFFEE_SLASH_GOLDEN = [
Expand Down Expand Up @@ -83,3 +83,25 @@ def test_beware_infinite_loop(lexer):
(Token.Text, '\n'),
]
assert list(lexer.get_tokens(fragment)) == tokens

@pytest.fixture(scope='module')
def ts_lexer():
yield TypeScriptLexer()

def test_function_definition(ts_lexer):
fragment = u'async function main() {\n}'
tokens = [
(Token.Keyword, u'async'),
(Token.Text, u' '),
(Token.Keyword.Declaration, u'function'),
(Token.Text, u' '),
(Token.Name.Other, u'main'),
(Token.Punctuation, u'('),
(Token.Punctuation, u')'),
(Token.Text, u' '),
(Token.Punctuation, u'{'),
(Token.Text, u'\n'),
(Token.Punctuation, u'}'),
(Token.Text, u'\n'),
]
assert list(ts_lexer.get_tokens(fragment)) == tokens