Skip to content

Commit

Permalink
Bash: Accept hyphens in function names (#2832)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Marr authored Mar 26, 2021
1 parent 772d42b commit e4ad22a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions components/prism-bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
// but not “foo {”
{
// a) and c)
pattern: /(\bfunction\s+)\w+(?=(?:\s*\(?:\s*\))?\s*\{)/,
pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,
lookbehind: true,
alias: 'function'
},
{
// b)
pattern: /\b\w+(?=\s*\(\s*\)\s*\{)/,
pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/,
alias: 'function'
}
],
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bash.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/languages/bash/function-name_feature.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function foo { :; }
function foo-bar { :; }
bar() { :; }
function foo() { :; }
# Not a function:
Expand All @@ -13,6 +14,12 @@ bar { :; }
["builtin", ":"],
["punctuation", ";"],
["punctuation", "}"],
["keyword", "function"],
["function-name", "foo-bar"],
["punctuation", "{"],
["builtin", ":"],
["punctuation", ";"],
["punctuation", "}"],
["function-name", "bar"],
["punctuation", "("],
["punctuation", ")"],
Expand Down

0 comments on commit e4ad22a

Please sign in to comment.