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

Optional chaining operator (?.) in <template> breaks syntax highlighting on GitHub #217

Open
wopian opened this issue May 18, 2022 · 11 comments

Comments

@wopian
Copy link
Contributor

wopian commented May 18, 2022

I don't use Sublime Text (so can't check the new branch), but this issue appears on GitHub which uses this repository for syntax highlighting and is using the latest version of the master branch.

The optional chaining operator (?.) causes the file to stop syntax highlighting the rest of the file when it is used in an attribute inside <template>

With optional chaining operator:

<script setup lang="ts">
  const hello = {}
</script>
<template>
	<div v-if="hello?.world" />
</template>
<style>
	div {
      font-size: 16px;
    }
</style>
Screenshot

Screenshot 2022-05-18 at 17 40 33

Without optional chaining operator:

<script setup lang="ts">
  const hello = {}
</script>
<template>
	<div v-if="hello.world" />
</template>
<style>
	div {
      font-size: 16px;
    }
</style>
@skyronic
Copy link
Collaborator

The .tmLanguage definitions - used by linguist hasn't been updated for a while.

This code snippet isn't broken in sublime though:

CleanShot 2022-05-18 at 12 48@2x

I'll look into if it's possible to update the .tmLanguage but I can't comment on how feasible it is without taking a closer look.

@wopian wopian changed the title Optional chaining operator (?.) in <template> breaks syntax highlighting Optional chaining operator (?.) in <template> breaks syntax highlighting on GitHub May 18, 2022
@odanado
Copy link

odanado commented Aug 22, 2022

I found the same problem too.
vue-syntax-highlight is used for syntax highlighting on GitHub
https://github.com/github/linguist/blob/master/grammars.yml

 2022-08-22 23 57 25

ref: https://github.com/odan-sandbox/vue-github-syntax-highlight-broken/blob/main/src/components/HelloWorld.vue

@Leland
Copy link

Leland commented Oct 14, 2022

@hfhchan-plb
Copy link

+1, it causes all the subsequent CSS to show up as invalid too, as the parser believes it's still in JS mode.

@hfhchan-plb
Copy link

See also: github-linguist/linguist#6001

@sparr
Copy link

sparr commented Feb 21, 2023

Another example in the wild: https://github.com/snapshot-labs/snapshot/blob/3151610c3121d7ffe07cf2b8e811de341c7866ad/src/components/Ui/Avatar.vue

And a shorter test case:

<a>
	<b v-if="c?.d" />
</a>

@kaiarrowood
Copy link

We have numerous instances of this in our repos. The nullish coalescing operator ?? also breaks the syntax highlighting. Vue 3 is pushing heavily towards typescript so instances of this are just going to get more and more common. Has there been any movement on this issue since it's been created?

@KyeRussell
Copy link

If it helps get a sense of severity: just checking in to say that also I've run into this several times.

@RyStanley89
Copy link

This issue continues to affect many users. Any assistance from contributors in resolving this would be greatly appreciated.

@yuichkun
Copy link

Not that it's a fix for this repo, but as to address the breaking syntax on GitHub, I've made a PR to linguist so that they use supposedly newer/maintained vuejs/language-tools for Vue.js grammar source.

It's approved, but won't be there until they make the next release (could be a few months)

@yuichkun
Copy link

It's approved, but won't be there until they make the next release (could be a few months)

It's out now and I've confirmed that it fixed the syntax break on my side 🎉

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

No branches or pull requests

10 participants