vue-syntax-highlight icon indicating copy to clipboard operation
vue-syntax-highlight copied to clipboard

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

Open wopian opened this issue 3 years ago • 11 comments
trafficstars

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>

wopian avatar May 18 '22 16:05 wopian

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.

skyronic avatar May 18 '22 16:05 skyronic

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

odanado avatar Aug 22 '22 14:08 odanado

Chiming in with another instance in the wild on GitHub: https://github.com/divamgupta/diffusionbee-stable-diffusion-ui/blob/b2a2a041757db280e2218a96dd1ca6c06617bfce/electron_app/src/StableDiffusion.vue#L41

Leland avatar Oct 14 '22 03:10 Leland

+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 avatar Jan 19 '23 11:01 hfhchan-plb

See also: https://github.com/github/linguist/issues/6001

hfhchan-plb avatar Jan 19 '23 11:01 hfhchan-plb

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>

sparr avatar Feb 21 '23 20:02 sparr

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?

kaiarrowood avatar Mar 29 '23 16:03 kaiarrowood

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

KyeRussell avatar May 28 '24 06:05 KyeRussell

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

RyStanley89 avatar Aug 27 '24 10:08 RyStanley89