Skip to content

Commit 28de4e2

Browse files
committed
JSX: Regexp optimisation + handle spread operator as a whole
1 parent 8fc1b03 commit 28de4e2

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

components/prism-jsx.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
var javascript = Prism.util.clone(Prism.languages.javascript);
44

55
Prism.languages.jsx = Prism.languages.extend('markup', javascript);
6-
Prism.languages.jsx.tag.pattern= /<\/?[\w\.:-]+\s*(?:\s+(?:[\w\.:-]+(?:=(?:("|')(\\?[\s\S])*?\1|[^\s'">=]+|(\{[\s\S]*?\})))?|\{\.{3}\w+\}))*\s*\/?>/i;
6+
Prism.languages.jsx.tag.pattern= /<\/?[\w.:-]+\s*(?:\s+(?:[\w\.:-]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+|(?:\{[^}]*\})))?|\{\.{3}\w+\}))*\s*\/?>/i;
77

8-
Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:('|")[\s\S]*?(\1)|[^\s>]+)/i;
8+
Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">]+)/i;
99

1010
Prism.languages.insertBefore('inside', 'attr-name', {
1111
'spread': {
1212
pattern: /\{\.{3}\w+\}/,
1313
inside: {
14-
'punctuation': /\{|\}|\./,
14+
'punctuation': /[{}]|\.{3}/,
1515
'attr-value': /\w+/
1616
}
1717
}
1818
}, Prism.languages.jsx.tag);
1919

2020
var jsxExpression = Prism.util.clone(Prism.languages.jsx);
2121

22-
delete jsxExpression.punctuation
22+
delete jsxExpression.punctuation;
2323

2424
jsxExpression = Prism.languages.insertBefore('jsx', 'operator', {
2525
'punctuation': /=(?={)|[{}[\];(),.:]/

components/prism-jsx.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/jsx/tag_feature.test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ var myElement = <MyComponent someProperty={true} />;
4949
]],
5050
["spread", [
5151
["punctuation", "{"],
52-
["punctuation", "."],
53-
["punctuation", "."],
54-
["punctuation", "."],
52+
["punctuation", "..."],
5553
["attr-value", "foo"],
5654
["punctuation", "}"]
5755
]],

0 commit comments

Comments
 (0)