From 2ebb310ccfe6de3197fd03992bf6a172c6496027 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Fri, 29 Aug 2025 11:00:51 -0700 Subject: [PATCH] fix(haxe): after colon, highlight non-identifiers like numbers and strings previously, numbers and strings were treated as types, which could cause problems with highlighting for anonymous structures, like: var obj = { num: 123.4, str: "hello" }; --- CHANGES.md | 2 ++ src/languages/haxe.js | 4 ++-- test/markup/haxe/default.expect.txt | 31 ++++++++++++++++------------- test/markup/haxe/default.txt | 3 +++ 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b1413c29a5..fe895582d2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ Core Grammars: - enh(json) add json5 support [Kerry Shetline][] - fix(css) `unicode-range` parsing, issue #4253 [Kerry Shetline][] - fix(csharp) Support digit separators [te-ing][] +- fix(haxe) After colon, highlight non-identifiers like numbers and strings [Josh Tynjala][] Documentation: @@ -55,6 +56,7 @@ CONTRIBUTORS [te-ing]: https://github.com/te-ing [Anthony Martin]: https://github.com/anthony-c-martin [NriotHrreion]: https://github.com/NriotHrreion +[Josh Tynjala]: https://github.com/joshtynjala ## Version 11.11.1 diff --git a/src/languages/haxe.js b/src/languages/haxe.js index 084b80263b..46ff15f2d7 100644 --- a/src/languages/haxe.js +++ b/src/languages/haxe.js @@ -74,7 +74,7 @@ export default function(hljs) { }, { className: 'type', // function types - begin: /:[ \t]*/, + begin: ":[ \t]*(?=\\(|" + IDENT_RE + ")", end: /[^A-Za-z0-9_ \t\->]/, excludeBegin: true, excludeEnd: true, @@ -82,7 +82,7 @@ export default function(hljs) { }, { className: 'type', // types - begin: /:[ \t]*/, + begin: ":[ \t]*(?=" + IDENT_RE + ")", end: /\W/, excludeBegin: true, excludeEnd: true diff --git a/test/markup/haxe/default.expect.txt b/test/markup/haxe/default.expect.txt index 72d1b25922..3c2b98a000 100644 --- a/test/markup/haxe/default.expect.txt +++ b/test/markup/haxe/default.expect.txt @@ -98,11 +98,11 @@ // switch statements! var c:Color = Color.Green; var x:Int = switch(c) { - case Red: 0; - case Green: 1; - case Blue: 2; - case Rgb(r, g, b): 3; - case _: -1; + case Red: 0; + case Green: 1; + case Blue: 2; + case Rgb(r, g, b): 3; + case _: -1; } for(i in 0...3) { @@ -139,21 +139,24 @@ private inline function func(a:Int, b:Float, ?c:String, d:Bool=false):Dynamic { return { - x: 0, + x: 0, y: true, z: false, - a: 1.53, - b: 5e10, - c: -12, - d: 1_0_0_0_0, + a: 1.53, + b: 5e10, + c: -12, + d: 1_0_0_0_0, - i: 10000i32, - u: 2147483648u32, - l: 10000000000i64, - f: 5f64, + i: 10000i32, + u: 2147483648u32, + l: 10000000000i64, + f: 5f64, n: null, + + s1: "double", + s2: 'single', }; } diff --git a/test/markup/haxe/default.txt b/test/markup/haxe/default.txt index 4c11b45d2e..689cecf0a6 100644 --- a/test/markup/haxe/default.txt +++ b/test/markup/haxe/default.txt @@ -154,6 +154,9 @@ class Main extends BaseClass implements SomeFunctionality { f: 5f64, n: null, + + s1: "double", + s2: 'single', }; }