From dabec2061cef8752f2c27c548f1c61e87f2f66f1 Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 10 Sep 2026 12:19:58 +0530 Subject: [PATCH] Fix TypeScript division highlighting --- runtime/syntax/typescript.yaml | 2 +- runtime/typescript_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 runtime/typescript_test.go diff --git a/runtime/syntax/typescript.yaml b/runtime/syntax/typescript.yaml index 958a7dbb81..c0b9185c7f 100644 --- a/runtime/syntax/typescript.yaml +++ b/runtime/syntax/typescript.yaml @@ -18,7 +18,7 @@ rules: - type: "\\b(Number|Object|RegExp|String|Symbol)\\b" - type: "\\b(any|unknown|boolean|never|number|string|symbol)\\b" - statement: "[-+/*=<>!~%?:&|]" - - constant: "/[^*]([^/]|(\\\\/))*[^\\\\]/[gim]*" + # - constant: "/[^*]([^/]|(\\\\/))*[^\\\\]/[gim]*" - constant: "\\\\[0-7][0-7]?[0-7]?|\\\\x[0-9a-fA-F]+|\\\\[bfnrt'\"\\?\\\\]" - comment: start: "//" diff --git a/runtime/typescript_test.go b/runtime/typescript_test.go new file mode 100644 index 0000000000..2aedbeff33 --- /dev/null +++ b/runtime/typescript_test.go @@ -0,0 +1,28 @@ +package config + +import ( + "testing" + + "github.com/micro-editor/micro/v2/pkg/highlight" +) + +func TestTypeScriptDivisionIsNotRegexp(t *testing.T) { + data, err := Asset("syntax/typescript.yaml") + if err != nil { + t.Fatal(err) + } + file, err := highlight.ParseFile(data) + if err != nil { + t.Fatal(err) + } + def, err := highlight.ParseDef(file, nil) + if err != nil { + t.Fatal(err) + } + + for _, group := range highlight.NewHighlighter(def).HighlightString("const n = 10 / 5 / 2;")[0] { + if group.String() == "constant" { + t.Fatal("division highlighted as a regular expression") + } + } +}