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

Syntax highlighting breaks on optional chaining ?. or nullish coalescing operator ?? #18

Closed
rixo opened this issue Feb 18, 2022 · 0 comments · Fixed by #19
Closed

Syntax highlighting breaks on optional chaining ?. or nullish coalescing operator ?? #18

rixo opened this issue Feb 18, 2022 · 0 comments · Fixed by #19

Comments

@rixo
Copy link
Contributor

rixo commented Feb 18, 2022

When JS is used as the lang for a Svelte component script, either explicitly (<script lang="js">) or implicitly (<script>), presence of ?. or ?? in the script breaks syntax highlighting or the part of the code after the script (with the markup apparently highlighted with JS rules).

For example, this snippet breaks:

<script>
  const x = a?.b
</script>

<div>Hello</div>

Or this one:

<script>
  const x = a ?? b
</script>

<div>Hello</div>

Oh? This even breaks in Github! What grammar are they using?

But with our new grammar this works (not on Github -- what the hell??):

<script lang="ts">
  const x = a ?? b
</script>

<div>Hello</div>

I have confirmed that changing source.js injections to source.ts fixes the problem, so that seems to indicate that the problem originates in the language-javascript grammar. Or maybe an incompatibility between something it contains and Atom's (and Github's?) implementation of TextMate grammars.

So an easy fix would be to change all injections of source.js to source.ts in our grammar. language-typescript is a core grammar bundled with Atom, so everyone should have it. But this fix would mean JS only users would noticeably get a different highlighting of their JS Svelte components and their standard .js files.

Would that be acceptable, at least as a temporary quick fix?

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 a pull request may close this issue.

1 participant