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

Javascript family leaving 'template' span open after particular earlier syntax #2694

Closed
danopia opened this issue Jan 3, 2021 · 1 comment · Fixed by #2705
Closed

Javascript family leaving 'template' span open after particular earlier syntax #2694

danopia opened this issue Jan 3, 2021 · 1 comment · Fixed by #2705

Comments

@danopia
Copy link

danopia commented Jan 3, 2021

Information

  • Language: Javascript, also Typescript
  • Plugins: Whatever the test page uses, presumably none

Description

I found a highlighting bug in this source code: https://deno.land/std@0.79.0/encoding/toml.ts and when the latest version of PrismJS was tested it showed a different bug. So I'm reporting the bug from latest here, from copying the whole file into Prism's test page.

It seems like particular template literal usage is getting parsed correctly earlier in the file, and then breaking other template tags later in the file. The affected line has its first template tag token ignored which then causes template tag parsing to be inverted for the rest of the file.

It seems there's two different setup lines for this bug that both need to be in a particular order:

  1. One line with a regex containing a single quote, and then a single quote in template quotes. This renders fine.
  2. Anywhere after that, a comment with a template literal in it. This renders fine.
  3. Anywhere after that, a normal basic template literal. This breaks for the rest of the file

Code snippet

Screenshot 2021-01-03 at 18 52 50

Test page

The code being highlighted incorrectly.
// One line with a pattern containing single quote, and then a single quote in template quotes
replace(/'/, `'`)

// Anywhere after that, a comment with template tags in it:
// `load bearing comment`

// Anywhere after that, normal basic template tags are broken
const var3 = `break starts here`;
const var4 = `break ends here`;
@RunDevelopment
Copy link
Member

Thanks for reporting this!

This is a bug in Prism's matching algorithm for greedy rules. I'll try to fix it in the next couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants