Skip to content

Commit

Permalink
fix(js/ts) Float32Array higlighted incorrectly (#3353)
Browse files Browse the repository at this point in the history
* fix(js/ts) Float32Array higlighted incorrectly
* add JSON as an exception
  • Loading branch information
joshgoebel committed Oct 12, 2021
1 parent 1a258a3 commit 1c79370
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -12,6 +12,7 @@ Parser:

Grammars:

- fix(js/ts) `Float32Array` highlighted incorrectly (#3353) [Josh Goebel][]
- fix(css) single-colon psuedo-elements no longer break highlighting (#3240) [Josh Goebel][]
- fix(scss) single-colon psuedo-elements no longer break highlighting (#3240) [Josh Goebel][]
- enh(fsharp) rewrite most of the grammar, with many improvements [Melvyn Laïly][]
Expand Down
12 changes: 11 additions & 1 deletion src/languages/javascript.js
Expand Up @@ -254,7 +254,17 @@ export default function(hljs) {

const CLASS_REFERENCE = {
relevance: 0,
match: /\b[A-Z][a-z]+([A-Z][a-z]+)*/,
match:
regex.either(
// Hard coded exceptions
/\bJSON/,
// Float32Array
/\b[A-Z][a-z]+([A-Z][a-z]+|\d)*/,
// CSSFactory
/\b[A-Z]{2,}([A-Z][a-z]+|\d)+/,
// BLAH
// this will be flagged as a UPPER_CASE_CONSTANT instead
),
className: "title.class",
keywords: {
_: [
Expand Down
63 changes: 40 additions & 23 deletions src/languages/lib/ecmascript.js
Expand Up @@ -51,44 +51,61 @@ const LITERALS = [
"Infinity"
];

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
export const TYPES = [
"Intl",
"DataView",
"Number",
"Math",
"Date",
"String",
"RegExp",
// Fundamental objects
"Object",
"Function",
"Boolean",
"Error",
"Symbol",
"Set",
"Map",
"WeakSet",
"WeakMap",
"Proxy",
"Reflect",
"JSON",
"Promise",
// numbers and dates
"Math",
"Date",
"Number",
"BigInt",
// text
"String",
"RegExp",
// Indexed collections
"Array",
"Float32Array",
"Float64Array",
"Int8Array",
"Uint8Array",
"Uint8ClampedArray",
"Int16Array",
"Int32Array",
"Int8Array",
"Uint16Array",
"Uint32Array",
"Float32Array",
"Array",
"Uint8Array",
"Uint8ClampedArray",
"ArrayBuffer",
"BigInt64Array",
"BigUint64Array",
"BigInt"
// Keyed collections
"Set",
"Map",
"WeakSet",
"WeakMap",
// Structured data
"ArrayBuffer",
"SharedArrayBuffer",
"Atomics",
"DataView",
"JSON",
// Control abstraction objects
"Promise",
"Generator",
"GeneratorFunction",
"AsyncFunction",
// Reflection
"Reflect",
"Proxy",
// Internationalization
"Intl",
// WebAssembly
"WebAssembly"
];

export const ERROR_TYPES = [
"Error",
"EvalError",
"InternalError",
"RangeError",
Expand Down
7 changes: 7 additions & 0 deletions test/markup/javascript/class.expect.txt
Expand Up @@ -26,3 +26,10 @@
<span class="hljs-keyword">if</span>(value) {}
<span class="hljs-keyword">switch</span>(value) {}
<span class="hljs-keyword">try</span> {} <span class="hljs-keyword">catch</span>(err) {}

<span class="hljs-title class_">Car</span>
<span class="hljs-title class_">Vehicle</span>
<span class="hljs-title class_">SelfDrivingTruck</span>
<span class="hljs-title class_">CSSParser</span>
<span class="hljs-title class_">Float32Array</span>
<span class="hljs-title class_">BigInt64Array</span>
7 changes: 7 additions & 0 deletions test/markup/javascript/class.txt
Expand Up @@ -26,3 +26,10 @@ while(value) {}
if(value) {}
switch(value) {}
try {} catch(err) {}

Car
Vehicle
SelfDrivingTruck
CSSParser
Float32Array
BigInt64Array

0 comments on commit 1c79370

Please sign in to comment.