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

fix(js/ts) Float32Array higlighted incorrectly #3353

Merged
merged 5 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
joshgoebel marked this conversation as resolved.
Show resolved Hide resolved
),
className: "title.class",
keywords: {
_: [
Expand Down
63 changes: 40 additions & 23 deletions src/languages/lib/ecmascript.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ while(value) {}
if(value) {}
switch(value) {}
try {} catch(err) {}

Car
Vehicle
SelfDrivingTruck
CSSParser
Float32Array
BigInt64Array