From 47bc0a6ecdb37d0bf7e55e27e86297a318c4fbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 31 May 2026 21:25:07 +0900 Subject: [PATCH] lang: Update javascript --- languages.toml | 2 +- runtime/queries/ecma/highlights.scm | 47 ++++++++++++++++++++++- runtime/queries/ecma/injections.scm | 22 +++++++++++ runtime/queries/javascript/highlights.scm | 5 +++ 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/languages.toml b/languages.toml index e5583950..9b810282 100644 --- a/languages.toml +++ b/languages.toml @@ -997,7 +997,7 @@ args = { program = "{0}", skipFiles = [ "/**" ] } [[grammar]] name = "javascript" -source = { git = "https://github.com/tree-sitter/tree-sitter-javascript", rev = "3a837b6f3658ca3618f2022f8707e29739c91364" } +source = { git = "https://github.com/tree-sitter/tree-sitter-javascript", rev = "58404d8cf191d69f2674a8fd507bd5776f46cb11" } [[language]] name = "jsx" diff --git a/runtime/queries/ecma/highlights.scm b/runtime/queries/ecma/highlights.scm index 3a09b282..d575797b 100644 --- a/runtime/queries/ecma/highlights.scm +++ b/runtime/queries/ecma/highlights.scm @@ -264,8 +264,21 @@ ] @constant (#match? @constant "^[A-Z_][A-Z\\d_]+$")) +; Built-in constructors / types +((identifier) @type.builtin + (#any-of? @type.builtin + "Object" "Function" "Boolean" "Symbol" "Number" "BigInt" "String" "RegExp" + "Array" "Map" "Set" "WeakMap" "WeakSet" "WeakRef" "Promise" "Proxy" "Date" + "ArrayBuffer" "SharedArrayBuffer" "DataView" + "Int8Array" "Uint8Array" "Uint8ClampedArray" "Int16Array" "Uint16Array" + "Int32Array" "Uint32Array" "Float32Array" "Float64Array" + "BigInt64Array" "BigUint64Array" + "Error" "EvalError" "RangeError" "ReferenceError" "SyntaxError" "TypeError" + "URIError" "AggregateError") + (#is-not? local)) + ((identifier) @variable.builtin - (#match? @variable.builtin "^(arguments|module|console|window|document)$") + (#match? @variable.builtin "^(arguments|module|console|window|document|globalThis|Math|JSON|Reflect|Intl)$") (#is-not? local)) (call_expression @@ -294,3 +307,35 @@ "clearInterval" "queueMicrotask") (#is-not? local)) + +; Shebang +;-------- + +(hash_bang_line) @keyword.directive + +; Labels +;------- + +(statement_identifier) @label + +; Decorators +;----------- + +(decorator "@" @attribute) +(decorator (identifier) @attribute) +(decorator + (call_expression + function: (identifier) @attribute)) +(decorator + (member_expression + property: (property_identifier) @attribute)) +(decorator + (call_expression + function: (member_expression + property: (property_identifier) @attribute))) + +; Namespace imports/exports: `import * as ns` / `export * as ns` +;---------------------------------------------------------------- + +(namespace_import (identifier) @namespace) +(namespace_export (identifier) @namespace) diff --git a/runtime/queries/ecma/injections.scm b/runtime/queries/ecma/injections.scm index d1bed89b..539a2834 100644 --- a/runtime/queries/ecma/injections.scm +++ b/runtime/queries/ecma/injections.scm @@ -101,3 +101,25 @@ arguments: (arguments (string (string_fragment) @injection.content)) (#set! injection.language "css")) + +; styled-components / emotion: inject CSS into styled template literals. +; `createGlobalStyle``, `keyframes``, `injectGlobal`` +(call_expression + function: (identifier) @_name + (#any-of? @_name "createGlobalStyle" "keyframes" "injectGlobal") + arguments: (template_string (string_fragment) @injection.content) + (#set! injection.language "css")) + +; `styled.div``, `styled.button``, ... +(call_expression + function: (member_expression + object: (identifier) @_styled (#eq? @_styled "styled")) + arguments: (template_string (string_fragment) @injection.content) + (#set! injection.language "css")) + +; `styled(Component)`` +(call_expression + function: (call_expression + function: (identifier) @_styled (#eq? @_styled "styled")) + arguments: (template_string (string_fragment) @injection.content) + (#set! injection.language "css")) diff --git a/runtime/queries/javascript/highlights.scm b/runtime/queries/javascript/highlights.scm index bd09e048..fa70b5f9 100644 --- a/runtime/queries/javascript/highlights.scm +++ b/runtime/queries/javascript/highlights.scm @@ -1,3 +1,8 @@ ; See runtime/queries/ecma/README.md for more info. ; inherits: ecma,_javascript + +; `using` / `await using` resource-management declarations (TC39). Kept here +; rather than in shared ecma/ because the pinned typescript grammar has no +; `using` token yet (move to ecma when typescript gains it). +"using" @keyword.storage.modifier -- 2.51.2