Skip to content

Commit

Permalink
Fix bugs in #1446 and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RexSkz committed Jul 12, 2018
1 parent 5cf3b3d commit 55248b5
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 58 deletions.
5 changes: 2 additions & 3 deletions components/prism-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
]
});
Prism.languages.flow['function-variable'].pattern = /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:function\b|(?:\([^()]*\)(?:\s*:\s*\w+)?|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i;
delete Prism.languages.flow['es5-function-parameter'];
delete Prism.languages.flow['es6-function-parameter'];
delete Prism.languages.flow['parameter'];

Prism.languages.insertBefore('flow', 'operator', {
'flow-punctuation': {
Expand All @@ -33,4 +32,4 @@
lookbehind: true
}
);
}(Prism));
}(Prism));
2 changes: 1 addition & 1 deletion components/prism-flow.min.js

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

36 changes: 19 additions & 17 deletions components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ Prism.languages.insertBefore('javascript', 'keyword', {
},
// This must be declared before keyword because we use "function" inside the look-forward
'function-variable': {
pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:async\s*)?(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i,
pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:async(?:(?:\s*(?=\())|\s+))?(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i,
alias: 'function'
},
'es5-function-parameter': {
pattern: /(function\s*)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*(\([^()]*\))/,
lookbehind: true,
inside: Prism.languages.javascript,
alias: 'parameter'
},
'es6-function-parameter': {
pattern: /(\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)(?=\s*=>)/,
inside: Prism.languages.javascript,
alias: 'parameter'
},
'es6-class-method-parameter': {
pattern: /\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)(\([^()]*\))(?=\s*\{)/,
inside: Prism.languages.javascript,
alias: 'parameter'
},
'parameter': [
{
pattern: /(function)(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*(\([^()]*\))/,
lookbehind: true,
inside: Prism.languages.javascript,
alias: 'parameter'
},
{
pattern: /(\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)(?=\s*=>)/,
inside: Prism.languages.javascript,
alias: 'parameter'
},
{
pattern: /\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)(\([^()]*\))(?=\s*\{)/,
inside: Prism.languages.javascript,
alias: 'parameter'
}
],
'constant': /\b[A-Z][A-Z\d_]*\b/
});

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.

36 changes: 19 additions & 17 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,25 +737,27 @@ Prism.languages.insertBefore('javascript', 'keyword', {
},
// This must be declared before keyword because we use "function" inside the look-forward
'function-variable': {
pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:async\s*)?(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i,
pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:async(?:(?:\s*(?=\())|\s+))?(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i,
alias: 'function'
},
'es5-function-parameter': {
pattern: /(function\s*)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*(\([^()]*\))/,
lookbehind: true,
inside: Prism.languages.javascript,
alias: 'parameter'
},
'es6-function-parameter': {
pattern: /(\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)(?=\s*=>)/,
inside: Prism.languages.javascript,
alias: 'parameter'
},
'es6-class-method-parameter': {
pattern: /\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)(\([^()]*\))(?=\s*\{)/,
inside: Prism.languages.javascript,
alias: 'parameter'
},
'parameter': [
{
pattern: /(function)(?:\s+[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*(\([^()]*\))/,
lookbehind: true,
inside: Prism.languages.javascript,
alias: 'parameter'
},
{
pattern: /(\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)(?=\s*=>)/,
inside: Prism.languages.javascript,
alias: 'parameter'
},
{
pattern: /\b(?!await|delete|export|for|if|new|return|switch|throw|typeof|while|yield)(?:[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)(\([^()]*\))(?=\s*\{)/,
inside: Prism.languages.javascript,
alias: 'parameter'
}
],
'constant': /\b[A-Z][A-Z\d_]*\b/
});

Expand Down
6 changes: 3 additions & 3 deletions tests/languages/javascript/class-method_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Test {
["class-name", ["Test"]],
["punctuation", "{"],

["es6-class-method-parameter", [
["parameter", [
["function", "foo"],
["punctuation", "("],
"x",
Expand All @@ -25,7 +25,7 @@ class Test {
["punctuation", "}"],

["keyword", "async"],
["es6-class-method-parameter", [
["parameter", [
["function", "bar"],
["punctuation", "("],
"x",
Expand All @@ -38,7 +38,7 @@ class Test {
["punctuation", "{"],
["punctuation", "}"],

["es6-class-method-parameter", [
["parameter", [
["function", "_"],
["punctuation", "("],
["punctuation", ")"]
Expand Down
25 changes: 18 additions & 7 deletions tests/languages/javascript/function-variable_feature.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
foo = function ( x, y) {}
bar = async function baz (x ) {}
baz = async(x) => x
fooBar = x => x
fooBar = (x, y) => x
ಠ_ಠ = () => {}
Expand All @@ -11,7 +12,7 @@ fooBar = (x, y) => x
["function-variable", "foo"],
["operator", "="],
["keyword", "function"],
["es5-function-parameter", [
["parameter", [
["punctuation", "("],
" x",
["punctuation", ","],
Expand All @@ -25,7 +26,7 @@ fooBar = (x, y) => x
["operator", "="],
["keyword", "async"],
["keyword", "function"],
["es5-function-parameter", [
["parameter", [
["function", "baz"],
["punctuation", "("],
"x ",
Expand All @@ -34,16 +35,26 @@ fooBar = (x, y) => x
["punctuation", "{"],
["punctuation", "}"],

["function-variable", "baz"],
["operator", "="],
["keyword", "async"],
["parameter", [
["punctuation", "("],
"x",
["punctuation", ")"]
]],
["operator", "=>"], " x\r\n",

["function-variable", "fooBar"],
["operator", "="],
["es6-function-parameter", [
["parameter", [
"x"
]],
["operator", "=>"], " x\r\n",

["function-variable", "fooBar"],
["operator", "="],
["es6-function-parameter", [
["parameter", [
["punctuation", "("],
"x",
["punctuation", ","],
Expand All @@ -54,7 +65,7 @@ fooBar = (x, y) => x

["function-variable", "ಠ_ಠ"],
["operator", "="],
["es6-function-parameter", [
["parameter", [
["punctuation", "("],
["punctuation", ")"]
]],
Expand All @@ -65,7 +76,7 @@ fooBar = (x, y) => x
["function-variable", "Ƞȡ_҇"],
["operator", "="],
["keyword", "async"],
["es6-function-parameter", [
["parameter", [
["punctuation", "("],
"ಠ",
["punctuation", ","],
Expand All @@ -81,4 +92,4 @@ fooBar = (x, y) => x

----------------------------------------------------

Checks for variables obviously containing functions.
Checks for variables obviously containing functions.
4 changes: 3 additions & 1 deletion tests/languages/javascript/function_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _()
$()
ಠ_ಠ()
Ƞȡ_҇()
if(notAFunction)

----------------------------------------------------

Expand All @@ -19,7 +20,8 @@ $()
["function", "_"], ["punctuation", "("], ["punctuation", ")"],
["function", "$"], ["punctuation", "("], ["punctuation", ")"],
["function", "ಠ_ಠ"], ["punctuation", "("], ["punctuation", ")"],
["function", "Ƞȡ_҇"], ["punctuation", "("], ["punctuation", ")"]
["function", "Ƞȡ_҇"], ["punctuation", "("], ["punctuation", ")"],
["keyword", "if"], ["punctuation", "("], "notAFunction", ["punctuation", ")"]
]

----------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/languages/jsx/issue1294.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default () => (
[
["keyword", "export"],
["keyword", "default"],
["es6-function-parameter", [["punctuation", "("], ["punctuation", ")"]]],
["parameter", [["punctuation", "("], ["punctuation", ")"]]],
["operator", "=>"], ["punctuation", "("],
["tag", [
["tag", [
Expand Down Expand Up @@ -67,4 +67,4 @@ export default () => (

----------------------------------------------------

See #1294.
See #1294.
4 changes: 2 additions & 2 deletions tests/languages/jsx/issue1335.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
["script", [
["script-punctuation", "="],
["punctuation", "{"],
["es6-function-parameter", [
["parameter", [
["punctuation", "("],
"e",
["punctuation", ")"]
Expand Down Expand Up @@ -123,4 +123,4 @@

----------------------------------------------------

Handles nested pairs of curly braces inside tag attribute. See #1335
Handles nested pairs of curly braces inside tag attribute. See #1335
4 changes: 2 additions & 2 deletions tests/languages/jsx/issue1421.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Columns extends React.Component {
["keyword", "extends"],
["class-name", ["React", ["punctuation", "."], "Component"]],
["punctuation", "{"],
["es6-class-method-parameter", [
["parameter", [
["function", "render"],
["punctuation", "("], ["punctuation", ")"]
]],
Expand Down Expand Up @@ -57,4 +57,4 @@ class Columns extends React.Component {
]

----------------------------------------------------
Checks for fragments short syntax. See #1421
Checks for fragments short syntax. See #1421
4 changes: 2 additions & 2 deletions tests/languages/tsx/tag_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Test extends Component {
["keyword", "extends"],
["class-name", ["Component"]],
["punctuation", "{"],
["es6-class-method-parameter", [
["parameter", [
["function", "render"],
["punctuation", "("],
["punctuation", ")"]
Expand Down Expand Up @@ -104,4 +104,4 @@ class Test extends Component {

----------------------------------------------------

Checks for TSX tags.
Checks for TSX tags.

0 comments on commit 55248b5

Please sign in to comment.