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

JS Extras #1743

Merged
merged 11 commits into from
Feb 28, 2019
Merged

JS Extras #1743

merged 11 commits into from
Feb 28, 2019

Conversation

RunDevelopment
Copy link
Member

This PR adds extras for Javascript.
It's based on @atomiks's comment and heavily modified by me.

All languages extending Javascript (expect for JSX) are loaded before JS Extras and therefore unaffected.

By default, this only changes the highlighting of known variables and previously undetected known class names.

Features

Keyword groupings

Some keywords get new aliases which might be useful for highlighting:

  • as, default, export, from, and import get the module alias.
  • null and undefined get the nil alias.

It's implemented in a way that is not (currently) testable (unfortunately) to be compatible with the Highlight Keywords plugin which only checks the token name.

Known class names

All JS standard built types and all error types will be recognized.

Known variables

Some variables in JS are fixed. Here are some of them:

  • document, location, navigator, performance, localStorage, sessionStorage, and window get the dom and variable classes.
  • console gets the console and class-name classes.

Special operators

Some operators will get their own token name:

  • => gets arrow.
  • ... gets spread.

Property accesses

All accesses of an object property using literals like foo.bar, String.raw, foo.bar.baz but not including accesses via computed keys like foo['bar'].

Methods

Methods are functions with are being accessed from an object. This also includes the static methods of a class.
E.g.: console.log(), foo.bar(), String.fromCodePoint(72334)

This also includes variables like foo.bar = function() { this.baz = true; }.

All methods are also property accesses.

Maybe class names

These are names which we are pretty sure are class names but not quite 100% sure, thus maybe class names. All names with start with an upper case letter are assumed to may be class names.

All property-access and function tokens are checked for maybe class names.

Not included

There are some features for @atomiks work I didn't include.

  • Some keyword groupings I did not include because they didn't seem useful to me.
  • (Property) definitions (e.g. { a: 1, b: 2 }, here a and b) I couldn't include because I couldn't find a way to fix false positives caused by the conditional operator (e.g. cond ? foo: bar).
    My basic approach was to say that a property definition has to be preceded by either { or ,. That works great but not with comments.
    {
        foo: null, // explain foo
        bar: false // not preceded by ','
    }
    If we ever get something which allows us to ignore comments, this will work. Until then, it's not included.

@RunDevelopment RunDevelopment merged commit bb62860 into PrismJS:master Feb 28, 2019
@RunDevelopment RunDevelopment deleted the js-extras branch February 28, 2019 19:19
@RunDevelopment
Copy link
Member Author

The failed tests, failed because of git clone...
2/4 node versions and my local system all passed the tests.

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

Successfully merging this pull request may close these issues.

2 participants