chore: create ecma base for use in js and ts which fixes jsx issues

This commit is contained in:
kiyan 2021-03-09 23:14:27 +01:00 committed by Kiyan
parent ec41db9511
commit 3b8c2ea492
15 changed files with 411 additions and 412 deletions

19
queries/ecma/folds.scm Normal file
View file

@ -0,0 +1,19 @@
[
(for_in_statement)
(for_statement)
(while_statement)
(arrow_function)
(function)
(function_declaration)
(class_declaration)
(method_definition)
(do_statement)
(with_statement)
(switch_statement)
(switch_case)
(import_statement)
(if_statement)
(try_statement)
(catch_clause)
(object)
] @fold

271
queries/ecma/highlights.scm Normal file
View file

@ -0,0 +1,271 @@
; Types
; Javascript
; Variables
;-----------
(identifier) @variable
; Properties
;-----------
(property_identifier) @property
(shorthand_property_identifier) @property
; Special identifiers
;--------------------
((identifier) @constructor
(#match? @constructor "^[A-Z]"))
((identifier) @constant
(#vim-match? @constant "^[A-Z_][A-Z\\d_]+$"))
((shorthand_property_identifier) @constant
(#vim-match? @constant "^[A-Z_][A-Z\\d_]+$"))
((identifier) @variable.builtin
(#vim-match? @variable.builtin "^(arguments|module|console|window|document)$"))
((identifier) @function.builtin
(#eq? @function.builtin "require"))
; Function and method definitions
;--------------------------------
(function
name: (identifier) @function)
(function_declaration
name: (identifier) @function)
(method_definition
name: (property_identifier) @method)
(pair
key: (property_identifier) @method
value: (function))
(pair
key: (property_identifier) @method
value: (arrow_function))
(assignment_expression
left: (member_expression
property: (property_identifier) @method)
right: (arrow_function))
(assignment_expression
left: (member_expression
property: (property_identifier) @method)
right: (function))
(variable_declarator
name: (identifier) @function
value: (arrow_function))
(variable_declarator
name: (identifier) @function
value: (function))
(assignment_expression
left: (identifier) @function
right: (arrow_function))
(assignment_expression
left: (identifier) @function
right: (function))
; Function and method calls
;--------------------------
(call_expression
function: (identifier) @function)
(call_expression
function: (member_expression
property: (property_identifier) @method))
; Variables
;----------
(formal_parameters (identifier) @parameter)
(formal_parameters
(rest_parameter
(identifier) @parameter))
; ({ a }) => null
(formal_parameters
(object_pattern
(shorthand_property_identifier) @parameter))
; ({ a: b }) => null
(formal_parameters
(object_pattern
(pair
value: (identifier) @parameter)))
; ([ a ]) => null
(formal_parameters
(array_pattern
(identifier) @parameter))
; a => null
(variable_declarator
value: (arrow_function
parameter: (identifier) @parameter))
; optional parameters
(formal_parameters
(assignment_pattern
(shorthand_property_identifier) @parameter))
; Variables
;----------
(namespace_import
(identifier) @namespace)
; Literals
;---------
(this) @variable.builtin
(super) @variable.builtin
(true) @boolean
(false) @boolean
(null) @constant.builtin
(comment) @comment
(string) @string
(regex) @punctuation.delimiter
(regex_pattern) @string.regex
(template_string) @string
(number) @number
; Punctuation
;------------
(template_substitution
"${" @punctuation.special
"}" @punctuation.special) @none
"..." @punctuation.special
";" @punctuation.delimiter
"." @punctuation.delimiter
"," @punctuation.delimiter
"?." @punctuation.delimiter
(pair ":" @punctuation.delimiter)
[
"--"
"-"
"-="
"&&"
"+"
"++"
"+="
"&="
"/="
"**="
"<<="
"<"
"<="
"<<"
"="
"=="
"==="
"!="
"!=="
"=>"
">"
">="
">>"
"||"
"%"
"%="
"*"
"**"
">>>"
"&"
"|"
"^"
"??"
"*="
">>="
">>>="
"^="
"|="
"&&="
"||="
"??="
] @operator
(binary_expression "/" @operator)
(ternary_expression ["?" ":"] @operator)
(unary_expression ["!" "~" "-" "+" "delete" "void" "typeof"] @operator)
"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
; Keywords
;----------
[
"if"
"else"
"switch"
"case"
"default"
] @conditional
[
"import"
"from"
"as"
] @include
[
"for"
"of"
"do"
"while"
"continue"
] @repeat
[
"async"
"await"
"break"
"class"
"const"
"debugger"
"export"
"extends"
"function"
"get"
"in"
"instanceof"
"let"
"return"
"set"
"static"
"switch"
"target"
"typeof"
"var"
"void"
"with"
"yield"
] @keyword
[
"new"
"delete"
] @keyword.operator
[
"throw"
"try"
"catch"
"finally"
] @exception

30
queries/ecma/indents.scm Normal file
View file

@ -0,0 +1,30 @@
[
(object)
(array)
(arguments)
(statement_block)
(object_pattern)
(class_body)
(method_definition)
(named_imports)
(binary_expression)
(return_statement)
(template_substitution)
(expression_statement (call_expression))
(export_clause)
] @indent
[
(arguments (object))
"("
")"
"{"
"}"
"["
"]"
] @branch
[
(comment)
(template_string)
] @ignore

View file

@ -0,0 +1,20 @@
((comment) @jsdoc)
((regex_pattern) @regex)
(call_expression
function: ((identifier) @language)
arguments: ((template_string) @content
(#offset! @content 0 1 0 -1)))
(call_expression
function: ((identifier) @_name
(#eq? @_name "gql"))
arguments: ((template_string) @graphql
(#offset! @graphql 0 1 0 -1)))
(call_expression
function: ((identifier) @_name
(#eq? @_name "hbs"))
arguments: ((template_string) @glimmer
(#offset! @glimmer 0 1 0 -1)))

61
queries/ecma/locals.scm Normal file
View file

@ -0,0 +1,61 @@
; Scopes
;-------
(statement_block) @scope
(function) @scope
(arrow_function) @scope
(function_declaration) @scope
(method_definition) @scope
(for_statement) @scope
(for_in_statement) @scope
(catch_clause) @scope
; Definitions
;------------
(formal_parameters
(identifier) @definition.parameter)
(formal_parameters
(object_pattern
(identifier) @definition.parameter))
; function(arg = []) {
(formal_parameters
(assignment_pattern
(shorthand_property_identifier) @definition.parameter))
; x => x
(arrow_function
parameter: (identifier) @definition.parameter)
(formal_parameters
(object_pattern
(shorthand_property_identifier) @definition.parameter))
(formal_parameters
(array_pattern
(identifier) @definition.parameter))
(formal_parameters
(rest_parameter
(identifier) @definition.parameter))
(variable_declarator
name: (identifier) @definition.var)
(import_specifier
(identifier) @definition.import)
(namespace_import
(identifier) @definition.import)
(function_declaration
((identifier) @definition.var)
(#set! definition.var.scope parent))
; References
;------------
(identifier) @reference
(shorthand_property_identifier) @reference

View file

@ -1,20 +1 @@
; inherits: (jsx)
[
(for_in_statement)
(for_statement)
(while_statement)
(arrow_function)
(function)
(function_declaration)
(class_declaration)
(method_definition)
(do_statement)
(with_statement)
(switch_statement)
(switch_case)
(import_statement)
(if_statement)
(try_statement)
(catch_clause)
(object)
] @fold
; inherits: ecma,jsx

View file

@ -1,272 +1 @@
; inherits: (jsx)
; Types
; Javascript
; Variables
;-----------
(identifier) @variable
; Properties
;-----------
(property_identifier) @property
(shorthand_property_identifier) @property
; Special identifiers
;--------------------
((identifier) @constructor
(#match? @constructor "^[A-Z]"))
((identifier) @constant
(#vim-match? @constant "^[A-Z_][A-Z\\d_]+$"))
((shorthand_property_identifier) @constant
(#vim-match? @constant "^[A-Z_][A-Z\\d_]+$"))
((identifier) @variable.builtin
(#vim-match? @variable.builtin "^(arguments|module|console|window|document)$"))
((identifier) @function.builtin
(#eq? @function.builtin "require"))
; Function and method definitions
;--------------------------------
(function
name: (identifier) @function)
(function_declaration
name: (identifier) @function)
(method_definition
name: (property_identifier) @method)
(pair
key: (property_identifier) @method
value: (function))
(pair
key: (property_identifier) @method
value: (arrow_function))
(assignment_expression
left: (member_expression
property: (property_identifier) @method)
right: (arrow_function))
(assignment_expression
left: (member_expression
property: (property_identifier) @method)
right: (function))
(variable_declarator
name: (identifier) @function
value: (arrow_function))
(variable_declarator
name: (identifier) @function
value: (function))
(assignment_expression
left: (identifier) @function
right: (arrow_function))
(assignment_expression
left: (identifier) @function
right: (function))
; Function and method calls
;--------------------------
(call_expression
function: (identifier) @function)
(call_expression
function: (member_expression
property: (property_identifier) @method))
; Variables
;----------
(formal_parameters (identifier) @parameter)
(formal_parameters
(rest_parameter
(identifier) @parameter))
; ({ a }) => null
(formal_parameters
(object_pattern
(shorthand_property_identifier) @parameter))
; ({ a: b }) => null
(formal_parameters
(object_pattern
(pair
value: (identifier) @parameter)))
; ([ a ]) => null
(formal_parameters
(array_pattern
(identifier) @parameter))
; a => null
(variable_declarator
value: (arrow_function
parameter: (identifier) @parameter))
; optional parameters
(formal_parameters
(assignment_pattern
(shorthand_property_identifier) @parameter))
; Variables
;----------
(namespace_import
(identifier) @namespace)
; Literals
;---------
(this) @variable.builtin
(super) @variable.builtin
(true) @boolean
(false) @boolean
(null) @constant.builtin
(comment) @comment
(string) @string
(regex) @punctuation.delimiter
(regex_pattern) @string.regex
(template_string) @string
(number) @number
; Punctuation
;------------
(template_substitution
"${" @punctuation.special
"}" @punctuation.special) @none
"..." @punctuation.special
";" @punctuation.delimiter
"." @punctuation.delimiter
"," @punctuation.delimiter
"?." @punctuation.delimiter
(pair ":" @punctuation.delimiter)
[
"--"
"-"
"-="
"&&"
"+"
"++"
"+="
"&="
"/="
"**="
"<<="
"<"
"<="
"<<"
"="
"=="
"==="
"!="
"!=="
"=>"
">"
">="
">>"
"||"
"%"
"%="
"*"
"**"
">>>"
"&"
"|"
"^"
"??"
"*="
">>="
">>>="
"^="
"|="
"&&="
"||="
"??="
] @operator
(binary_expression "/" @operator)
(ternary_expression ["?" ":"] @operator)
(unary_expression ["!" "~" "-" "+" "delete" "void" "typeof"] @operator)
"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
; Keywords
;----------
[
"if"
"else"
"switch"
"case"
"default"
] @conditional
[
"import"
"from"
"as"
] @include
[
"for"
"of"
"do"
"while"
"continue"
] @repeat
[
"async"
"await"
"break"
"class"
"const"
"debugger"
"export"
"extends"
"function"
"get"
"in"
"instanceof"
"let"
"return"
"set"
"static"
"switch"
"target"
"typeof"
"var"
"void"
"with"
"yield"
] @keyword
[
"new"
"delete"
] @keyword.operator
[
"throw"
"try"
"catch"
"finally"
] @exception
; inherits: ecma,jsx

View file

@ -1,32 +1 @@
; inherits: (jsx)
[
(object)
(array)
(arguments)
(statement_block)
(object_pattern)
(class_body)
(method_definition)
(named_imports)
(binary_expression)
(return_statement)
(template_substitution)
(expression_statement (call_expression))
(export_clause)
] @indent
[
(arguments (object))
"("
")"
"{"
"}"
"["
"]"
] @branch
[
(comment)
(template_string)
] @ignore
; inherits: ecma,jsx

View file

@ -1,20 +1 @@
((comment) @jsdoc)
((regex_pattern) @regex)
(call_expression
function: ((identifier) @language)
arguments: ((template_string) @content
(#offset! @content 0 1 0 -1)))
(call_expression
function: ((identifier) @_name
(#eq? @_name "gql"))
arguments: ((template_string) @graphql
(#offset! @graphql 0 1 0 -1)))
(call_expression
function: ((identifier) @_name
(#eq? @_name "hbs"))
arguments: ((template_string) @glimmer
(#offset! @glimmer 0 1 0 -1)))
; inherits: ecma,jsx

View file

@ -1,63 +1 @@
; inherits: (jsx)
; Scopes
;-------
(statement_block) @scope
(function) @scope
(arrow_function) @scope
(function_declaration) @scope
(method_definition) @scope
(for_statement) @scope
(for_in_statement) @scope
(catch_clause) @scope
; Definitions
;------------
(formal_parameters
(identifier) @definition.parameter)
(formal_parameters
(object_pattern
(identifier) @definition.parameter))
; function(arg = []) {
(formal_parameters
(assignment_pattern
(shorthand_property_identifier) @definition.parameter))
; x => x
(arrow_function
parameter: (identifier) @definition.parameter)
(formal_parameters
(object_pattern
(shorthand_property_identifier) @definition.parameter))
(formal_parameters
(array_pattern
(identifier) @definition.parameter))
(formal_parameters
(rest_parameter
(identifier) @definition.parameter))
(variable_declarator
name: (identifier) @definition.var)
(import_specifier
(identifier) @definition.import)
(namespace_import
(identifier) @definition.import)
(function_declaration
((identifier) @definition.var)
(#set! definition.var.scope parent))
; References
;------------
(identifier) @reference
(shorthand_property_identifier) @reference
; inherits: ecma,jsx

View file

@ -1,4 +1,4 @@
; inherits: javascript
; inherits: ecma
[
(interface_declaration)

View file

@ -1,4 +1,4 @@
; inherits: javascript
; inherits: ecma
[
"abstract"
"declare"

View file

@ -1,4 +1,4 @@
; inherits: javascript
; inherits: ecma
[
(enum_declaration)

View file

@ -1 +1 @@
; inherits: javascript
; inherits: ecma

View file

@ -1,4 +1,4 @@
; inherits: javascript
; inherits: ecma
(required_parameter (identifier) @definition)
(optional_parameter (identifier) @definition)