Sublime Forum

[Solved] JavaScript function call formatted like a regex

#1

When I write this JavaScript piece of code in Sublime Text 3, it formats it wrong:

url.split('&').map(a => /^range\=/.test(a) ? a.replace(/\d+\-\d+/g, '\x00') : a);

The character number 25 represents the start of a regular expression, but it is not formated like so. However, the character at position 34 is formated like start of a regex, but it is actually end of a regex. You can see it here.

The syntax of my code is correct, the only problem is because it is wrongly formatted, so it becomes hard to write further code. Is it a bug in Sublime Text 3? I am using the most recent version.

0 Likes

#2

You might not be selecting the correct syntax. Go view -> syntax -> JavaScript -> JavaScript

0 Likes

#3

Thank you for response. My syntax choice from view menu is correct. I again checked view -> syntax -> JavaScript and option JavaScript is already selected (also, my file has extension .js, so it is in JavaScript highlighting by default), so it is not the reason why regex is highlighted incorrectly.

0 Likes

#4

Well that’s weird. I just downloaded Sublime today, and it’s working fine with me:

Which color scheme are you using by the way?

It seems that, your JavaScript.sublime-syntax file is modified or overridden.
AFAIK, there are 2 places of this file.

  1. You find
    Program_file_path\Sublime Text 3\Packages\JavaScript.sublime-package
    copy it somewhere and rename to *.rar. Then unzip to get JavaScript.sublime-syntax.
    This is the default javascript syntax definition.
  2. The user setting folder,
    Windows_User_Folder\AppData\Roaming\Sublime Text 3
    See if you can find JavaScript.sublime-syntax under this folder(subfolders also need to be searched).
    If you can find such a file here, then it probably means the default syntax is overidden.

Try to find these 2 files, and see if there’s anything wrong with them.

0 Likes

#5

After following your steps:

  1. I checked all of the files extracted from JavaScript.sublime-syntax, but found nothing unusual.
  2. No, there is no such a file, which means the default one is not overriden.

My default color scheme is Dawn, I also checked other color schemes, but bug stays. This is my user-preferences file:
{ "color_scheme": "Packages/Color Scheme - Default/Dawn.tmTheme", "tab_size": 2, "word_wrap": true }

This is my JavaScript.sublime-syntax file, can you compare it to yours?

0 Likes

#6

Problem found. Your JavaScript.sublime-syntax file is missing.


Notice that, the file you provided is not a *.sublime-syntax, its the whole package file (*.sublime-package). You need to open the package, as you see in the picture, on the left.
Maybe your version of software is modified?
You can download a new install file from the official website, and get the correct *.sublime-package file. Or, you can give me your email address and I’ll send you my JavaScript.sublime-package where you can find the JavaScript.sublime-syntax within.

1 Like

#7

The official version of the JavaScript package can be found in sublimehq/Packages repository on GitHub; the actual JavaScript part can be found here. (Note: Technically the repository shows the most recent version, which might be *more* recent than the version in the latest published build of Sublime).

That said, this is a package that ships with Sublime text and you say you’re using the most recent version, so my advice would be to put back the official package and not modify it (or stop using whatever modified it on your behalf).

2 Likes

#8

Downloading new package file from GitHub solved the problem. For some weird reason my old file was corrupted. Thank you @huhiha and @OdatNurd for helping.

0 Likes