Skip to content

Commit

Permalink
Improved JS function pattern (#1736)
Browse files Browse the repository at this point in the history
Allows for spaces around the punctuations of function invocation via `apply`, `bind`, or `call`.
  • Loading branch information
RunDevelopment authored Feb 28, 2019
1 parent 64dc049 commit 8378ac8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
],
'number': /\b(?:(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+)n?|\d+n|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
'function': /[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\(|\.(?:apply|bind|call)\()/,
'function': /[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
});

Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

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

2 changes: 1 addition & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
],
'number': /\b(?:(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+)n?|\d+n|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
'function': /[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\(|\.(?:apply|bind|call)\()/,
'function': /[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
});

Expand Down
2 changes: 2 additions & 0 deletions tests/languages/javascript/function_feature.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
foo()
foo ()
foo . call ()
foo_bar()
foo_bar ( )
f42()
Expand All @@ -16,6 +17,7 @@ foo({ y: fun() })
[
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
["function", "foo"], ["punctuation", "."], ["function", "call"], ["punctuation", "("], ["punctuation", ")"],
["function", "foo_bar"], ["punctuation", "("], ["punctuation", ")"],
["function", "foo_bar"], ["punctuation", "("], ["punctuation", ")"],
["function", "f42"], ["punctuation", "("], ["punctuation", ")"],
Expand Down

0 comments on commit 8378ac8

Please sign in to comment.