Skip to content

Commit

Permalink
Strip trailing spaces and fix word boundary in JS regex
Browse files Browse the repository at this point in the history
  • Loading branch information
RexSkz committed Jul 12, 2018
1 parent 7205979 commit e7afc73
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Prism.languages.insertBefore('javascript', 'keyword', {
},
'parameter': [
{
pattern: /(function(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)\S[^()]*(?=\s*\))/,
pattern: /(function(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)[^\s()][^()]*?(?=\s*\))/,
lookbehind: true,
inside: Prism.languages.javascript
},
Expand All @@ -28,12 +28,12 @@ Prism.languages.insertBefore('javascript', 'keyword', {
inside: Prism.languages.javascript
},
{
pattern: /(\()[^()]+(?=\)\s*=>)/,
pattern: /(\(\s*)[^\s()][^()]*?(?=\s*\)\s*=>)/,
lookbehind: true,
inside: Prism.languages.javascript
},
{
pattern: /(\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)\S[^()]*(?=\s*\)\s*\{)/,
pattern: /((?:\b|\s|^)(?!(?:await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?![$\w\xA0-\uFFFF]))(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)[^\s()][^()]*?(?=\s*\)\s*\{)/,
lookbehind: true,
inside: Prism.languages.javascript
}
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.

6 changes: 3 additions & 3 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ Prism.languages.insertBefore('javascript', 'keyword', {
},
'parameter': [
{
pattern: /(function(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)\S[^()]*(?=\s*\))/,
pattern: /(function(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)[^\s()][^()]*?(?=\s*\))/,
lookbehind: true,
inside: Prism.languages.javascript
},
Expand All @@ -751,12 +751,12 @@ Prism.languages.insertBefore('javascript', 'keyword', {
inside: Prism.languages.javascript
},
{
pattern: /(\()[^()]+(?=\)\s*=>)/,
pattern: /(\(\s*)[^\s()][^()]*?(?=\s*\)\s*=>)/,
lookbehind: true,
inside: Prism.languages.javascript
},
{
pattern: /(\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)\S[^()]*(?=\s*\)\s*\{)/,
pattern: /((?:\b|\s|^)(?!(?:await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?![$\w\xA0-\uFFFF]))(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*)[^\s()][^()]*?(?=\s*\)\s*\{)/,
lookbehind: true,
inside: Prism.languages.javascript
}
Expand Down
15 changes: 11 additions & 4 deletions tests/languages/javascript/class-method_feature.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Test {
foo(x, y = 0) {}
async bar(x, y = 0) {}
_ ( ) {}
foo( x, y = 0) {}
async bar(x, y = 0 ) {}
$ ( ) {}
asyncFoo(){}
}

----------------------------------------------------
Expand Down Expand Up @@ -38,7 +39,13 @@ class Test {
["punctuation", "{"],
["punctuation", "}"],

["function", "_"],
["function", "$"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["function", "asyncFoo"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
Expand Down
4 changes: 2 additions & 2 deletions tests/languages/javascript/function-variable_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ foo = function ( x, y) {}
bar = async function baz (x ) {}
baz = async(x) => x
fooBar = x => x
fooBar = (x, y) => x
fooBar = ( x, y ) => x
ಠ_ಠ = () => {}
Ƞȡ_҇ = async (ಠ, Ƞ = 2) => {}

Expand All @@ -29,7 +29,7 @@ fooBar = (x, y) => x
["function", "baz"],
["punctuation", "("],
["parameter", [
"x "
"x"
]],
["punctuation", ")"],
["punctuation", "{"],
Expand Down

0 comments on commit e7afc73

Please sign in to comment.