Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1061 JSX spread operator break #1094

Merged
merged 2 commits into from
Feb 8, 2017
Merged

fixes #1061 JSX spread operator break #1094

merged 2 commits into from
Feb 8, 2017

Conversation

vkbansal
Copy link
Contributor

@vkbansal vkbansal commented Feb 7, 2017

No description provided.

@@ -3,10 +3,20 @@
var javascript = Prism.util.clone(Prism.languages.javascript);

Prism.languages.jsx = Prism.languages.extend('markup', javascript);
Prism.languages.jsx.tag.pattern= /<\/?[\w\.:-]+\s*(?:\s+[\w\.:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+|(\{[\w\W]*?\})))?\s*)*\/?>/i;
Prism.languages.jsx.tag.pattern= /<\/?[\w\.:-]+\s*(?:\s+[\w\.:-]*(?:=?(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+|(\{[\w\W]*?\})))?\s*)*\/?>/i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain that change a bit? There seems to be a large part of the regexp that would now be able to match only whitespaces... I'm afraid this could increase the amount of backtracking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is that it was previously matching a word followed by = and it was compulsory. I just made the word and = optional by replacing + with * for the word and adding ? after =.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consequence is that you are allowing a whole bunch of weird stuff doing this. With the new regexp, <div ""> would match, for example.

I'd prefer a more explicit version, that allows the spread operator. Something like...

/<\/?[\w\.:-]+\s*(?:\s+(?:[\w\.:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+|(\{[\w\W]*?\})))?|\{\.{3}\w+\})\s*)*\/?>/i

or if you want to combine the spread part with the existing part using curly braces, then something like:

/<\/?[\w\.:-]+\s*(?:\s+(?:[\w\.:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?|(?:[\w\.:-]+=)?\{[\w\W]*?\})\s*)*\/?>/i

though I think the first one is a little bit more readable, and might backtrack a bit less.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too like the first approach. I'll update the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Golmote Golmote merged commit 561bceb into PrismJS:gh-pages Feb 8, 2017
@Golmote
Copy link
Contributor

Golmote commented Feb 8, 2017

Thanks!

@vkbansal vkbansal deleted the jsx-spread-fix branch February 8, 2017 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants