@inthedark/dxlint 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/bin/dxlint +15 -0
- package/bin/dxlint-linux-x64 +0 -0
- package/bin/dxlint-win32-x64.exe +0 -0
- package/package.json +29 -4
- package/rules/conventions.dx +34 -0
- package/rules/correctness.dx +33 -0
- package/rules/es-no-semi.dx +11 -0
- package/rules/format.dx +49 -0
- package/rules/recommended.dx +51 -0
- package/rules/suspicious.dx +31 -0
- package/rules/types.dx +21 -0
- package/std/c.dx +23 -0
- package/std/core/lines.dx +51 -0
- package/std/core/lists.dx +76 -0
- package/std/core.dx +30 -0
- package/std/css.dx +17 -0
- package/std/dx.dx +31 -0
- package/std/json.dx +104 -0
- package/std/markdown.dx +11 -0
- package/std/python.dx +21 -0
- package/std/rust/format.dx +316 -0
- package/std/rust.dx +34 -0
- package/std/toml.dx +19 -0
- package/std/ts/arithmetic.dx +87 -0
- package/std/ts/assertions.dx +477 -0
- package/std/ts/calls.dx +246 -0
- package/std/ts/comments.dx +10 -0
- package/std/ts/conditions.dx +531 -0
- package/std/ts/constants.dx +335 -0
- package/std/ts/deprecation.dx +185 -0
- package/std/ts/directives.dx +60 -0
- package/std/ts/effects.dx +219 -0
- package/std/ts/enums.dx +233 -0
- package/std/ts/expression-fixes.dx +67 -0
- package/std/ts/expressions.dx +270 -0
- package/std/ts/flow.dx +2 -0
- package/std/ts/format.dx +755 -0
- package/std/ts/globals.dx +106 -0
- package/std/ts/grammar.dx +488 -0
- package/std/ts/helpers.dx +102 -0
- package/std/ts/import-attributes.dx +88 -0
- package/std/ts/import-no-deprecated.dx +73 -0
- package/std/ts/indentation.dx +442 -0
- package/std/ts/jsx.dx +646 -0
- package/std/ts/layout/blocks.dx +281 -0
- package/std/ts/layout/calls.dx +79 -0
- package/std/ts/layout/expressions.dx +213 -0
- package/std/ts/layout/literals.dx +114 -0
- package/std/ts/layout/separators.dx +184 -0
- package/std/ts/layout/shared.dx +203 -0
- package/std/ts/layout/text.dx +142 -0
- package/std/ts/layout/types.dx +182 -0
- package/std/ts/layout.dx +9 -0
- package/std/ts/license.dx +54 -0
- package/std/ts/literal-text.dx +3 -0
- package/std/ts/literals.dx +95 -0
- package/std/ts/methods.dx +69 -0
- package/std/ts/modules.dx +268 -0
- package/std/ts/names.dx +348 -0
- package/std/ts/naming.dx +169 -0
- package/std/ts/narrowing.dx +96 -0
- package/std/ts/parentheses.dx +262 -0
- package/std/ts/precedence.dx +25 -0
- package/std/ts/problems/calls.dx +34 -0
- package/std/ts/problems/classes.dx +39 -0
- package/std/ts/problems/control-flow.dx +257 -0
- package/std/ts/problems/declarations.dx +67 -0
- package/std/ts/problems/duplicates.dx +70 -0
- package/std/ts/problems/expressions.dx +154 -0
- package/std/ts/problems/helpers.dx +22 -0
- package/std/ts/problems/imports.dx +43 -0
- package/std/ts/problems/non-null.dx +78 -0
- package/std/ts/problems/numeric-precision.dx +66 -0
- package/std/ts/problems/regexp.dx +66 -0
- package/std/ts/problems/statements.dx +36 -0
- package/std/ts/problems/typescript.dx +55 -0
- package/std/ts/problems/whitespace.dx +40 -0
- package/std/ts/problems.dx +20 -0
- package/std/ts/regex/checks.dx +249 -0
- package/std/ts/regex/findings.dx +209 -0
- package/std/ts/regex/grammar.dx +80 -0
- package/std/ts/regex/suggestions.dx +94 -0
- package/std/ts/regex/values.dx +378 -0
- package/std/ts/regex.dx +5 -0
- package/std/ts/restrictions/comments.dx +76 -0
- package/std/ts/restrictions.dx +811 -0
- package/std/ts/scopes.dx +68 -0
- package/std/ts/scoping/atomic.dx +40 -0
- package/std/ts/scoping/bindings.dx +126 -0
- package/std/ts/scoping/constness.dx +72 -0
- package/std/ts/scoping/globals.dx +52 -0
- package/std/ts/scoping/loops.dx +86 -0
- package/std/ts/scoping/member-uses.dx +111 -0
- package/std/ts/scoping/receivers.dx +107 -0
- package/std/ts/scoping/shadowing.dx +202 -0
- package/std/ts/scoping/usage.dx +393 -0
- package/std/ts/scoping.dx +842 -0
- package/std/ts/selectors.dx +10 -0
- package/std/ts/spreads.dx +97 -0
- package/std/ts/structure/declarations.dx +52 -0
- package/std/ts/structure/lines.dx +79 -0
- package/std/ts/structure/lists.dx +144 -0
- package/std/ts/structure/padding.dx +258 -0
- package/std/ts/structure.dx +963 -0
- package/std/ts/style/classes.dx +157 -0
- package/std/ts/style/comments.dx +75 -0
- package/std/ts/style/declarations.dx +82 -0
- package/std/ts/style/expressions.dx +125 -0
- package/std/ts/style/imports.dx +44 -0
- package/std/ts/style/ordering.dx +192 -0
- package/std/ts/style/returns.dx +152 -0
- package/std/ts/style/signatures.dx +308 -0
- package/std/ts/style/type-exports.dx +62 -0
- package/std/ts/style/type-imports.dx +166 -0
- package/std/ts/style/types.dx +474 -0
- package/std/ts/style.dx +29 -0
- package/std/ts/suggestions/accessors.dx +138 -0
- package/std/ts/suggestions/builtins.dx +110 -0
- package/std/ts/suggestions/comparisons.dx +41 -0
- package/std/ts/suggestions/computed-keys.dx +20 -0
- package/std/ts/suggestions/constructors.dx +54 -0
- package/std/ts/suggestions/control-flow.dx +204 -0
- package/std/ts/suggestions/curly.dx +124 -0
- package/std/ts/suggestions/directives.dx +79 -0
- package/std/ts/suggestions/errors.dx +106 -0
- package/std/ts/suggestions/expressions.dx +230 -0
- package/std/ts/suggestions/functions.dx +260 -0
- package/std/ts/suggestions/globals.dx +187 -0
- package/std/ts/suggestions/helpers.dx +17 -0
- package/std/ts/suggestions/object-shorthand.dx +148 -0
- package/std/ts/suggestions/object-spread.dx +96 -0
- package/std/ts/suggestions/regexp.dx +59 -0
- package/std/ts/suggestions/renames.dx +50 -0
- package/std/ts/suggestions/strings.dx +47 -0
- package/std/ts/suggestions/templates.dx +104 -0
- package/std/ts/suggestions.dx +24 -0
- package/std/ts/template-fixes.dx +22 -0
- package/std/ts/tokens.dx +124 -0
- package/std/ts/type-specifiers.dx +93 -0
- package/std/ts/typed/assignments.dx +154 -0
- package/std/ts/typed/awaitability.dx +157 -0
- package/std/ts/typed/boolean-comparisons.dx +82 -0
- package/std/ts/typed/defaults.dx +97 -0
- package/std/ts/typed/enum-consistency.dx +68 -0
- package/std/ts/typed/enums.dx +52 -0
- package/std/ts/typed/errors.dx +32 -0
- package/std/ts/typed/floating-promises.dx +147 -0
- package/std/ts/typed/for-in-arrays.dx +21 -0
- package/std/ts/typed/includes.dx +102 -0
- package/std/ts/typed/nullish-coalescing.dx +149 -0
- package/std/ts/typed/optional-chains.dx +317 -0
- package/std/ts/typed/promises.dx +205 -0
- package/std/ts/typed/qualifiers.dx +108 -0
- package/std/ts/typed/readonly-members.dx +159 -0
- package/std/ts/typed/readonly-parameters.dx +121 -0
- package/std/ts/typed/redundant-constituents.dx +171 -0
- package/std/ts/typed/regexp-exec.dx +79 -0
- package/std/ts/typed/rejection-handlers.dx +91 -0
- package/std/ts/typed/return-await.dx +116 -0
- package/std/ts/typed/return-this.dx +67 -0
- package/std/ts/typed/strict-void-return.dx +121 -0
- package/std/ts/typed/string-boundaries.dx +153 -0
- package/std/ts/typed/switches.dx +147 -0
- package/std/ts/typed/template-expressions.dx +127 -0
- package/std/ts/typed/template-values.dx +88 -0
- package/std/ts/typed/transfers.dx +106 -0
- package/std/ts/typed/type-arguments.dx +337 -0
- package/std/ts/typed/type-constituents.dx +143 -0
- package/std/ts/typed/type-conversions.dx +82 -0
- package/std/ts/typed/type-parameters.dx +280 -0
- package/std/ts/typed/unbound-method.dx +167 -0
- package/std/ts/typed/unsafe-calls.dx +73 -0
- package/std/ts/typed/unsafe-members.dx +36 -0
- package/std/ts/typed/void-expressions.dx +101 -0
- package/std/ts/typed.dx +585 -0
- package/std/ts/values/arguments.dx +13 -0
- package/std/ts/values/enums.dx +104 -0
- package/std/ts/values/inspection.dx +274 -0
- package/std/ts/values.dx +1217 -0
- package/std/ts.dx +77 -0
- package/std/whitespace.dx +37 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import .ts/modules
|
|
2
|
+
import .ts/comments
|
|
3
|
+
|
|
4
|
+
fn ts_environment(n, key) = {
|
|
5
|
+
value settings: n.ts_environment_settings
|
|
6
|
+
value setting: find_last(settings, item => item.name == key)
|
|
7
|
+
value setting.value
|
|
8
|
+
}
|
|
9
|
+
fn ts_ecma_version(n) = {
|
|
10
|
+
value edition: ts_environment(n, "ecmaVersion")
|
|
11
|
+
value if edition == null || edition == "latest" then 2026
|
|
12
|
+
else if edition >= 6 && edition <= 17 then edition + 2009 else edition
|
|
13
|
+
}
|
|
14
|
+
fn ts_source_type(n) = {
|
|
15
|
+
value selected: ts_environment(n, "sourceType")
|
|
16
|
+
value selected ?? (if ends_with(n.file, ".cjs") || ends_with(n.file, ".cts") then "commonjs"
|
|
17
|
+
else if ts_module_external(n) then "module" else "script")
|
|
18
|
+
}
|
|
19
|
+
fn ts_global_configured(n, key) = {
|
|
20
|
+
value patches: filter(n.ts_environment_settings, item => item.name == "globals")
|
|
21
|
+
value settings: map(patches, item => get(item.value, key))
|
|
22
|
+
value find_last(settings, setting => contains(["readonly", "writable", "off"], setting))
|
|
23
|
+
}
|
|
24
|
+
fn ts_global_comment_owner(entry) = {
|
|
25
|
+
value walk([entry], item => item.parent.node)
|
|
26
|
+
find (item) item is ts_block_comment
|
|
27
|
+
}
|
|
28
|
+
fn ts_global_real_entry(entry) = {
|
|
29
|
+
value comment: ts_global_comment_owner(entry)
|
|
30
|
+
value comment != null && entry.parent.offset == comment.offset + len("/*")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
define {
|
|
34
|
+
in ts_program let ts_environment_settings environment.settings
|
|
35
|
+
in ts_identifier let global {
|
|
36
|
+
value classes: name_role_classes(node, "reference")
|
|
37
|
+
value program: ts_module_program(node)
|
|
38
|
+
value key: ts_module_name(node)
|
|
39
|
+
value if classes != null && contains(classes, "value") && scope_declaration == null
|
|
40
|
+
then ts_global_setting(program, key) else null
|
|
41
|
+
}
|
|
42
|
+
in ts_program let ts_global_editions [
|
|
43
|
+
{edition: 3, names: [
|
|
44
|
+
"Array", "Boolean", "constructor", "Date", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent",
|
|
45
|
+
"Error", "escape", "eval", "EvalError", "Function", "hasOwnProperty", "Infinity", "isFinite", "isNaN",
|
|
46
|
+
"isPrototypeOf", "Math", "NaN", "Number", "Object", "parseFloat", "parseInt", "propertyIsEnumerable", "RangeError",
|
|
47
|
+
"ReferenceError", "RegExp", "String", "SyntaxError", "toLocaleString", "toString", "TypeError", "undefined",
|
|
48
|
+
"unescape", "URIError", "valueOf"
|
|
49
|
+
]},
|
|
50
|
+
{edition: 5, names: ["JSON"]},
|
|
51
|
+
{edition: 2015, names: [
|
|
52
|
+
"ArrayBuffer", "DataView", "Float32Array", "Float64Array", "Int16Array", "Int32Array", "Int8Array", "Intl", "Map",
|
|
53
|
+
"Promise", "Proxy", "Reflect", "Set", "Symbol", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray",
|
|
54
|
+
"WeakMap", "WeakSet"
|
|
55
|
+
]},
|
|
56
|
+
{edition: 2017, names: ["Atomics", "SharedArrayBuffer"]},
|
|
57
|
+
{edition: 2020, names: ["BigInt", "BigInt64Array", "BigUint64Array", "globalThis"]},
|
|
58
|
+
{edition: 2021, names: ["AggregateError", "FinalizationRegistry", "WeakRef"]},
|
|
59
|
+
{edition: 2025, names: ["Float16Array", "Iterator"]},
|
|
60
|
+
{edition: 2026, names: ["AsyncDisposableStack", "DisposableStack", "SuppressedError", "Temporal"]}
|
|
61
|
+
]
|
|
62
|
+
in ts_block_comment match ts_global_directive /\s*globals?\s+/ until /(?=\*\/)/
|
|
63
|
+
in ts_global_directive match ts_global_entry name:/[^\s,:*\/]+/ (/\s*:\s*/ setting:/[^\s,*\/]+/)?
|
|
64
|
+
in ts_block_comment match ts_exported_directive /\s*exported\s+/ until /(?=\*\/)/
|
|
65
|
+
in ts_exported_directive match ts_exported_entry /[^\s,*\/]+/
|
|
66
|
+
in ts_program let ts_global_exported_entries {
|
|
67
|
+
value descendants(ts_exported_entry)
|
|
68
|
+
filter (entry) ts_global_real_entry(entry)
|
|
69
|
+
map (entry) entry.text
|
|
70
|
+
unique
|
|
71
|
+
}
|
|
72
|
+
in ts_program let ts_global_comment_entries {
|
|
73
|
+
value descendants(ts_global_entry)
|
|
74
|
+
filter (entry) ts_global_real_entry(entry)
|
|
75
|
+
map (entry) {
|
|
76
|
+
name: entry.name,
|
|
77
|
+
offset: entry.name.offset,
|
|
78
|
+
comment: ts_global_comment_owner(entry),
|
|
79
|
+
setting: if entry.setting == "true" || entry.setting == "writable" || entry.setting == "writeable" then "writable"
|
|
80
|
+
else if entry.setting == "off" then "off" else "readonly"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
fn ts_global_builtin_setting(n, key) = {
|
|
86
|
+
value edition: find(n.ts_global_editions, row => contains(row.names, key))
|
|
87
|
+
value selected: ts_ecma_version(n)
|
|
88
|
+
value if edition == null then null else if edition.edition <= selected then "readonly" else "off"
|
|
89
|
+
}
|
|
90
|
+
fn ts_global_implicit_setting(n, key) = {
|
|
91
|
+
value configured: ts_global_configured(n, key)
|
|
92
|
+
value source: ts_source_type(n)
|
|
93
|
+
value commonjs: if source == "commonjs" then get({exports: "writable", global: "readonly", module: "readonly", require: "readonly"}, key) else null
|
|
94
|
+
value configured ?? commonjs ?? ts_global_builtin_setting(n, key)
|
|
95
|
+
}
|
|
96
|
+
fn ts_global_mentions(n) = n.ts_global_comment_entries
|
|
97
|
+
fn ts_exported_names(n) = n.ts_global_exported_entries
|
|
98
|
+
fn ts_global_implicit(n, key) = {
|
|
99
|
+
value setting: ts_global_implicit_setting(n, key)
|
|
100
|
+
value setting == "readonly" || setting == "writable"
|
|
101
|
+
}
|
|
102
|
+
fn ts_global_commented(n, key) = any(n.ts_global_comment_entries, mention => mention.name == key)
|
|
103
|
+
fn ts_global_setting(n, key) = {
|
|
104
|
+
value mention: find_last(n.ts_global_comment_entries, item => item.name == key)
|
|
105
|
+
value mention.setting ?? ts_global_implicit_setting(n, key)
|
|
106
|
+
}
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
# Declared JS/TS syntax. Not selected by .ts until oracle and perf gates pass.
|
|
2
|
+
@macro ts_parser_function_header name:type_identifier? (type_parameter:goal(types, type_parameters))? parameter:parameters (":" return_type:goal(types, return_type))?
|
|
3
|
+
@macro ts_parser_variable kind:(text("var") | text("const" not("enum")) | text("let" if(no_in, not(/in|of/), ()) peek(type_identifier | /\[|\{/)) | text("using" if(no_in, (), same_line) peek(not(/in|of/) type_identifier)) | text("await" if(no_in, (), same_line) "using")) cut declaration:ts_declarator ("," declaration:ts_declarator)*
|
|
4
|
+
@macro ts_parser_jsx_header "<" name:jsx_opening_name (type_argument:goal(types, type_arguments))? property:(ts_jsx_spread_attribute | ts_jsx_attribute)*
|
|
5
|
+
@macro ts_parser_signature (type_parameter:type_parameters)? parameter:parameters (":" return_type:return_type)?
|
|
6
|
+
@macro ts_parser_tuple_member (name:type_identifier optional:"?"? ":" type:type_expression | type:type_expression optional:"?"?)
|
|
7
|
+
@macro ts_parser_method_header (kind:/get|set/ peek(accessor_next))? key:property_key optional:"?"? (type_parameter:goal(types, type_parameters))? parameter:parameters (":" return_type:goal(types, return_type))?
|
|
8
|
+
@macro ts_parser_class_header modifier:/declare|abstract/* "class" name:(not(/extends|implements/) type_identifier)? (type_parameter:goal(types, type_parameters))? ("extends" extends:lhs_expression (type_argument:goal(types, type_arguments))?)? ("implements" implements:goal(types, type_expression) ("," implements:goal(types, type_expression))*)?
|
|
9
|
+
@macro ts_parser_class_modifiers (modifier:(text("static") peek(accessor_next) | /public|private|protected|readonly|abstract|override|declare|accessor|async/ same_line peek(accessor_next)))*
|
|
10
|
+
@macro ts_parser_import_kind (kind:"type" peek("{" | "*" | not("from") type_identifier))?
|
|
11
|
+
@macro ts_parser_specifier_kind (kind:"type" peek(not("as") (type_identifier | ts_string)))?
|
|
12
|
+
@macro ts_parser_semi terminator(";", before("}"), newline, eof)
|
|
13
|
+
@macro ts_parser_instantiation_end not(/<|>|\+|-/) (not(same_line) | peek(/instanceof|in|as|satisfies|\?\?|\|\||&&|\||\^|&|==|!=|===|!==|<=|>=|<<|>>|>>>|\*|\/|%|\*\*/) | not(peek(type_identifier | ts_number | ts_bigint | ts_string | ts_template | /\(|\[|\{|!|~|\+\+|--|\/|\/=|@|\.\.\.|#/)))
|
|
14
|
+
@macro ts_parser_arrow_tail same_line operator:"=>" cut body:clear(generator, (clear(no_in, ts_block) | assignment))
|
|
15
|
+
parser ts_syntax in js {
|
|
16
|
+
trivia /\A\u{feff}?#![^\n]*/
|
|
17
|
+
trivia /[ \t\r\n\x0b\x0c\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]+/
|
|
18
|
+
trivia /\/\/[^\r\n\u{2028}\u{2029}]*/
|
|
19
|
+
trivia /\/\*(?:[^*]|\*+[^*/])*\*+\//
|
|
20
|
+
line_break /[\r\n\u{2028}\u{2029}]/
|
|
21
|
+
|
|
22
|
+
flag jsx option
|
|
23
|
+
flag generator
|
|
24
|
+
flag async
|
|
25
|
+
flag no_in
|
|
26
|
+
flag no_cond
|
|
27
|
+
|
|
28
|
+
token keyword /(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|import|in|instanceof|new|null|return|super|switch|this|throw|true|try|typeof|var|void|while|with|yield|let|static|implements|interface|package|private|protected|public|await|async|abstract|declare|type|namespace|module|as|satisfies|keyof|infer|readonly|is|asserts|of|using)/ as ts_keyword
|
|
29
|
+
token word /(?:[A-Za-z_$]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]|\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\}))(?:[A-Za-z0-9_$]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]|\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\}))*/
|
|
30
|
+
token private_name /#(?:[A-Za-z_$]|[^\x00-\x7f])(?:[A-Za-z0-9_$]|[^\x00-\x7f])*/
|
|
31
|
+
token bigint /(?:0[xX][0-9a-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|[0-9][0-9_]*)n/
|
|
32
|
+
token number /(?:0[xX][0-9a-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:[0-9][0-9_]*(?:\.[0-9_]*)?|\.[0-9][0-9_]*)(?:[eE][+-]?[0-9][0-9_]*)?)/
|
|
33
|
+
token string /(?:"(?:\\\r\n|\\[\s\S]|[^"\\\n])*"|'(?:\\\r\n|\\[\s\S]|[^'\\\n])*')/
|
|
34
|
+
token regexp /\/(?:\\[\s\S]|\[(?:\\[\s\S]|[^\]\\\n])*\]|[^\/\\\[\n])+\/(?:[A-Za-z0-9_$\\]|[^\x00-\x7f])*/
|
|
35
|
+
token template /`(?:\\[\s\S]|[^\\`$]|\$+(?:\\[\s\S]|[^\\`{$]))*\$*`/
|
|
36
|
+
token template_head /`(?:\\[\s\S]|[^\\`$]|\$+(?:\\[\s\S]|[^\\`{$]))*\$*\$\{/
|
|
37
|
+
token template_middle /\}(?:\\[\s\S]|[^\\`$]|\$+(?:\\[\s\S]|[^\\`{$]))*\$*\$\{/
|
|
38
|
+
token template_tail /\}(?:\\[\s\S]|[^\\`$]|\$+(?:\\[\s\S]|[^\\`{$]))*\$*`/
|
|
39
|
+
token jsx_name /(?:[A-Za-z_$]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}])(?:[A-Za-z0-9_$-]|[^\x00-\x7f\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}])*/
|
|
40
|
+
token jsx_text /[^<{]+/
|
|
41
|
+
token jsx_string /(?:"[^"]*"|'[^']*')/
|
|
42
|
+
token jsx_value_comment /[ \t\r\n\x0b\x0c\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]*(?:\/\/|\/\*)/
|
|
43
|
+
|
|
44
|
+
token comma "," as ts_comma
|
|
45
|
+
token semicolon ";" as ts_semicolon
|
|
46
|
+
token colon ":" as ts_colon
|
|
47
|
+
token dot "." as ts_dot
|
|
48
|
+
token question "?" as ts_question
|
|
49
|
+
token ellipsis "..." as ts_ellipsis
|
|
50
|
+
token equals "=" as ts_equals
|
|
51
|
+
token open_paren "(" as ts_open_paren
|
|
52
|
+
token close_paren ")" as ts_close_paren
|
|
53
|
+
token open_bracket "[" as ts_open_bracket
|
|
54
|
+
token close_bracket "]" as ts_close_bracket
|
|
55
|
+
token open_brace "{" as ts_open_brace
|
|
56
|
+
token close_brace "}" as ts_close_brace
|
|
57
|
+
token open_angle "<" as ts_open_angle
|
|
58
|
+
token close_angle ">" as ts_close_angle
|
|
59
|
+
token punctuator /(?:\?\.|\?\?=?|={2,3}|=>|!={1,2}|!|\*\*=?|\*=|\*|&&=?|&=?|\|\|=?|\|=?|<<=?|<=|>>>=?|>>=?|>=|\+\+|\+=|\+|--|-=|-|%=|%|\^=|\^|\/=|\/|~|@|#)/ as ts_punctuator
|
|
60
|
+
token type_punctuator /(?:\?\.|\?\?=?|={2,3}|=>|!={1,2}|!|\*\*=?|\*=|\*|&&=?|&=?|\|\|=?|\|=?|<<=?|<=|\+\+|\+=|\+|--|-=|-|%=|%|\^=|\^|\/=|\/|~|@|#)/ as ts_punctuator
|
|
61
|
+
|
|
62
|
+
goal code {
|
|
63
|
+
keyword word private_name bigint number string template template_head
|
|
64
|
+
comma semicolon colon dot question ellipsis equals open_paren close_paren
|
|
65
|
+
open_bracket close_bracket open_brace close_brace open_angle close_angle punctuator
|
|
66
|
+
}
|
|
67
|
+
goal primary {
|
|
68
|
+
keyword word private_name bigint number string regexp template template_head
|
|
69
|
+
comma semicolon colon dot question ellipsis equals open_paren close_paren
|
|
70
|
+
open_bracket close_bracket open_brace close_brace open_angle close_angle punctuator
|
|
71
|
+
}
|
|
72
|
+
goal template_parts { template_middle template_tail }
|
|
73
|
+
goal jsx_body raw { jsx_text open_angle open_brace }
|
|
74
|
+
goal jsx_value { jsx_string open_angle open_brace }
|
|
75
|
+
goal jsx_value_guard raw { jsx_value_comment }
|
|
76
|
+
goal jsx_tag {
|
|
77
|
+
keyword word jsx_name comma semicolon colon dot question ellipsis equals
|
|
78
|
+
open_paren close_paren open_bracket close_bracket open_brace close_brace
|
|
79
|
+
open_angle close_angle punctuator
|
|
80
|
+
}
|
|
81
|
+
goal types {
|
|
82
|
+
keyword word private_name bigint number string template template_head
|
|
83
|
+
comma semicolon colon dot question ellipsis equals open_paren close_paren
|
|
84
|
+
open_bracket close_bracket open_brace close_brace open_angle close_angle type_punctuator
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
node ts_program { body: statement* }
|
|
88
|
+
node ts_block { body: statement* }
|
|
89
|
+
node ts_expression_statement { expression: expression }
|
|
90
|
+
node ts_variable_declaration { kind: text, declaration: ts_declarator+, modifier?: text* }
|
|
91
|
+
node ts_declarator { name: binding, type?: type_expression, init?: assignment }
|
|
92
|
+
node ts_if { test: expression, consequent: statement, alternate?: statement }
|
|
93
|
+
node ts_while { test: expression, body: statement }
|
|
94
|
+
node ts_do_while { body: statement, test: expression }
|
|
95
|
+
node ts_for { modifier?: text, init?: expression | ts_variable_declaration, test?: expression, update?: expression, body: statement }
|
|
96
|
+
node ts_for_in { modifier?: text, left: expression | ts_variable_declaration, right: expression, body: statement }
|
|
97
|
+
node ts_for_of { modifier?: text, left: expression | ts_variable_declaration, right: assignment, body: statement }
|
|
98
|
+
node ts_switch { discriminant: expression, case?: ts_case* }
|
|
99
|
+
node ts_case { test?: expression, body?: statement* }
|
|
100
|
+
node ts_try { block: ts_block, kind?: text, parameter?: binding, type?: type_expression, handler?: ts_block, finalizer?: ts_block }
|
|
101
|
+
node ts_return { argument?: expression }
|
|
102
|
+
node ts_throw { argument?: expression }
|
|
103
|
+
node ts_break { label?: ts_identifier }
|
|
104
|
+
node ts_continue { label?: ts_identifier }
|
|
105
|
+
node ts_empty {}
|
|
106
|
+
node ts_debugger {}
|
|
107
|
+
node ts_labeled { label: ts_identifier, body: statement }
|
|
108
|
+
node ts_with { object: expression, body: statement }
|
|
109
|
+
node ts_function { modifier?: text*, name?: ts_identifier, type_parameter?: ts_type_parameter*, parameter?: ts_parameter*, return_type?: return_type, body?: ts_block }
|
|
110
|
+
node ts_arrow { modifier?: text*, type_parameter?: ts_type_parameter*, parameter?: ts_parameter*, return_type?: return_type, operator: text, body: assignment | ts_block }
|
|
111
|
+
node ts_parameter { decorator?: ts_decorator*, modifier?: text*, name: binding | ts_rest | ts_this, optional?: text, type?: type_expression, init?: assignment }
|
|
112
|
+
node ts_decorator { expression: lhs_expression }
|
|
113
|
+
node ts_class { decorator?: ts_decorator*, modifier?: text*, name?: type_identifier, type_parameter?: ts_type_parameter*, extends?: lhs_expression, type_argument?: type_expression*, implements?: type_expression*, member?: class_member* }
|
|
114
|
+
node ts_method { decorator?: ts_decorator*, modifier?: text*, kind?: text, key: property_key, optional?: text, type_parameter?: ts_type_parameter*, parameter?: ts_parameter*, return_type?: return_type, body?: ts_block }
|
|
115
|
+
node ts_class_property { decorator?: ts_decorator*, modifier?: text*, kind?: text, key: property_key, optional?: text, type?: type_expression, init?: assignment }
|
|
116
|
+
node ts_static_block { body: ts_block }
|
|
117
|
+
node ts_interface { modifier?: text*, name: type_identifier, type_parameter?: ts_type_parameter*, extends?: type_expression*, member?: type_member* }
|
|
118
|
+
node ts_type_alias { modifier?: text*, name: type_identifier, type_parameter?: ts_type_parameter*, type: type_expression }
|
|
119
|
+
node ts_enum { modifier?: text*, name: type_identifier, member?: ts_enum_member* }
|
|
120
|
+
node ts_enum_member { name: property_key, init?: assignment }
|
|
121
|
+
node ts_namespace { modifier?: text*, kind: text, name?: namespace_name, body?: ts_block }
|
|
122
|
+
node ts_import { kind?: text, default_import?: type_identifier, namespace?: type_identifier, specifier?: ts_import_specifier*, from: ts_string }
|
|
123
|
+
node ts_import_specifier { kind?: text, imported: type_identifier | ts_string, local?: type_identifier }
|
|
124
|
+
node ts_import_equals { kind?: text, modifier?: text*, name: type_identifier, value: lhs_expression }
|
|
125
|
+
node ts_export { kind?: text, declaration?: declaration | ts_import | ts_import_equals, specifier?: ts_export_specifier*, namespace?: type_identifier | ts_string, from?: ts_string, expression?: assignment, operator?: text }
|
|
126
|
+
node ts_export_specifier { kind?: text, local: type_identifier | ts_string, exported?: type_identifier | ts_string }
|
|
127
|
+
node ts_export_assignment { expression: expression }
|
|
128
|
+
node ts_object_pattern { property?: ts_pattern_property*, rest?: ts_rest, type?: type_expression }
|
|
129
|
+
node ts_array_pattern { element?: binding_element | ts_rest | ts_hole*, type?: type_expression }
|
|
130
|
+
node ts_pattern_property { key: property_key, value?: binding_element }
|
|
131
|
+
node ts_rest { argument?: binding, name?: ts_identifier, optional?: text, type?: type_expression }
|
|
132
|
+
node ts_identifier {}
|
|
133
|
+
node ts_private_name {}
|
|
134
|
+
node ts_this {}
|
|
135
|
+
node ts_super {}
|
|
136
|
+
node ts_null {}
|
|
137
|
+
node ts_boolean {}
|
|
138
|
+
node ts_number {}
|
|
139
|
+
node ts_bigint {}
|
|
140
|
+
node ts_string literal {}
|
|
141
|
+
node ts_regex literal {}
|
|
142
|
+
node ts_template { quasi: text+, expression?: expression* }
|
|
143
|
+
node ts_tagged_template { tag: expression, type_argument?: type_expression*, quasi: ts_template }
|
|
144
|
+
node ts_array { element?: assignment | ts_spread | ts_hole* }
|
|
145
|
+
node ts_object { property?: ts_property | ts_method | ts_spread* }
|
|
146
|
+
node ts_property { modifier?: text*, kind?: text, key: property_key, value?: assignment | ts_assignment_pattern }
|
|
147
|
+
node ts_assignment_pattern { left?: binding, right: assignment }
|
|
148
|
+
node ts_computed_key { expression: assignment }
|
|
149
|
+
node ts_spread { argument: assignment }
|
|
150
|
+
node ts_hole {}
|
|
151
|
+
node ts_member { object: expression, optional?: text, property: property_name }
|
|
152
|
+
node ts_index { object: expression, optional?: text, index: expression }
|
|
153
|
+
node ts_call { callee: expression, optional?: text, type_argument?: type_expression*, argument?: assignment | ts_spread* }
|
|
154
|
+
node ts_new { callee: new_callee, type_argument?: type_expression*, argument?: assignment | ts_spread* }
|
|
155
|
+
node ts_meta_property {}
|
|
156
|
+
node ts_import_call { argument?: assignment | ts_spread* }
|
|
157
|
+
node ts_unary { operator: text, argument: expression }
|
|
158
|
+
node ts_update { operator: text, argument: expression }
|
|
159
|
+
node ts_await { argument: expression }
|
|
160
|
+
node ts_yield { operator?: text, argument?: assignment }
|
|
161
|
+
node ts_binary { left: expression, operator: text, right: expression }
|
|
162
|
+
node ts_logical { left: expression, operator: text, right: expression }
|
|
163
|
+
node ts_assignment { left: expression, operator: text, right: assignment }
|
|
164
|
+
node ts_conditional { test: expression, consequent: assignment, alternate: assignment }
|
|
165
|
+
node ts_sequence { expression: assignment+ }
|
|
166
|
+
node ts_parenthesized { expression: expression }
|
|
167
|
+
node ts_as { expression: expression, type: type_expression }
|
|
168
|
+
node ts_satisfies { expression: expression, type: type_expression }
|
|
169
|
+
node ts_non_null { expression: expression }
|
|
170
|
+
node ts_instantiation { expression: expression, type_argument?: type_expression* }
|
|
171
|
+
node ts_type_assertion { type: type_expression, expression: unary_expression }
|
|
172
|
+
node ts_jsx_element { opening: ts_jsx_opening, body?: jsx_child*, closing?: ts_jsx_closing }
|
|
173
|
+
node ts_jsx_fragment { opening: ts_jsx_opening, body?: jsx_child*, closing: ts_jsx_closing }
|
|
174
|
+
node ts_jsx_opening { name?: jsx_opening_name, type_argument?: type_expression*, property?: ts_jsx_attribute | ts_jsx_spread_attribute* }
|
|
175
|
+
node ts_jsx_closing { name?: ts_jsx_name }
|
|
176
|
+
node ts_jsx_attribute { name: ts_jsx_name, value?: ts_string | ts_jsx_expression | ts_jsx_element | ts_jsx_fragment }
|
|
177
|
+
node ts_jsx_spread_attribute { argument: assignment }
|
|
178
|
+
node ts_jsx_expression { expression?: expression | ts_spread }
|
|
179
|
+
node ts_jsx_text literal {}
|
|
180
|
+
node ts_jsx_name {}
|
|
181
|
+
node ts_type_reference { name: entity_name, type_argument?: type_expression* }
|
|
182
|
+
node ts_type_keyword {}
|
|
183
|
+
node ts_type_parameter { modifier?: text*, name: ts_identifier, constraint?: type_expression, default?: type_expression }
|
|
184
|
+
node ts_union { type: type_expression+ }
|
|
185
|
+
node ts_intersection { type: type_expression+ }
|
|
186
|
+
node ts_array_type { type: type_expression }
|
|
187
|
+
node ts_parenthesized_type { type: type_expression }
|
|
188
|
+
node ts_qualified_name { left: entity_name, right: type_identifier | ts_private_name }
|
|
189
|
+
node ts_type_operator { operator: text, type: type_operator }
|
|
190
|
+
node ts_indexed_access { object: type_expression, index: type_expression }
|
|
191
|
+
node ts_conditional_type { check: type_union, extends: type_expression, consequent: type_expression, alternate: type_expression }
|
|
192
|
+
node ts_infer { type_parameter: ts_type_parameter }
|
|
193
|
+
node ts_function_type { modifier?: text, kind?: text, type_parameter?: ts_type_parameter*, parameter?: ts_parameter*, return_type: return_type }
|
|
194
|
+
node ts_type_literal { member?: type_member* }
|
|
195
|
+
node ts_property_signature { modifier?: text, key: property_key, optional?: text, type?: type_expression }
|
|
196
|
+
node ts_method_signature { modifier?: text, kind?: text, key: property_key, optional?: text, type_parameter?: ts_type_parameter*, parameter?: ts_parameter*, return_type?: return_type }
|
|
197
|
+
node ts_call_signature { kind?: text, type_parameter?: ts_type_parameter*, parameter?: ts_parameter*, return_type?: return_type }
|
|
198
|
+
node ts_index_signature { decorator?: ts_decorator*, modifier?: text*, parameter: ts_parameter, type?: type_expression }
|
|
199
|
+
node ts_tuple_type { element?: ts_tuple_member | ts_rest* }
|
|
200
|
+
node ts_tuple_member { name?: type_identifier, optional?: text, type: type_expression }
|
|
201
|
+
node ts_type_query { name: entity_query | ts_import_type, type_argument?: type_expression* }
|
|
202
|
+
node ts_import_type { argument: type_expression, qualifier?: entity_name, type_argument?: type_expression* }
|
|
203
|
+
node ts_literal_type { value: ts_number | ts_bigint | ts_string | ts_boolean }
|
|
204
|
+
node ts_template_type { quasi: text+, type?: type_expression* }
|
|
205
|
+
node ts_type_predicate { modifier?: text, name: type_identifier | ts_this, type?: type_expression }
|
|
206
|
+
node ts_mapped_type { modifier?: text, type_parameter: ts_type_parameter, name?: type_expression, optional?: text, type?: type_expression }
|
|
207
|
+
node ts_comma {}
|
|
208
|
+
node ts_semicolon {}
|
|
209
|
+
node ts_colon {}
|
|
210
|
+
node ts_dot {}
|
|
211
|
+
node ts_question {}
|
|
212
|
+
node ts_ellipsis {}
|
|
213
|
+
node ts_equals {}
|
|
214
|
+
node ts_open_paren {}
|
|
215
|
+
node ts_close_paren {}
|
|
216
|
+
node ts_open_bracket {}
|
|
217
|
+
node ts_close_bracket {}
|
|
218
|
+
node ts_open_brace {}
|
|
219
|
+
node ts_close_brace {}
|
|
220
|
+
node ts_open_angle {}
|
|
221
|
+
node ts_close_angle {}
|
|
222
|
+
node ts_keyword {}
|
|
223
|
+
node ts_punctuator {}
|
|
224
|
+
|
|
225
|
+
root ts_program = body:statement* end
|
|
226
|
+
production statement = (
|
|
227
|
+
ts_block | ts_empty | ts_if | ts_while | ts_do_while | ts_return | ts_throw |
|
|
228
|
+
ts_break | ts_continue | ts_debugger | ts_with | ts_switch | ts_try |
|
|
229
|
+
try(ts_for_in) | try(ts_for_of) | ts_for | ts_variable_declaration |
|
|
230
|
+
try(ts_import_equals) | try(ts_import) | try(ts_export_assignment) | decorated_export | ts_export |
|
|
231
|
+
declaration | try(ts_labeled) | ts_expression_statement
|
|
232
|
+
)
|
|
233
|
+
production ts_block = "{" cut body:statement* "}"
|
|
234
|
+
production ts_empty = ";"
|
|
235
|
+
production ts_if = "if" cut "(" test:expression ")" consequent:statement ("else" alternate:statement)?
|
|
236
|
+
production ts_while = "while" cut "(" test:expression ")" body:statement
|
|
237
|
+
production ts_do_while = "do" cut body:statement "while" "(" test:expression ")" ";"?
|
|
238
|
+
production ts_return = "return" cut (same_line argument:expression)? terminator(";", before("}"), newline, eof)
|
|
239
|
+
production ts_throw = "throw" cut (same_line argument:expression)? terminator(";", before("}"), newline, eof)
|
|
240
|
+
production ts_break = "break" cut (same_line label:ts_identifier)? terminator(";", before("}"), newline, eof)
|
|
241
|
+
production ts_continue = "continue" cut (same_line label:ts_identifier)? terminator(";", before("}"), newline, eof)
|
|
242
|
+
production ts_debugger = "debugger" cut terminator(";", before("}"), newline, eof)
|
|
243
|
+
production ts_with = "with" cut "(" object:expression ")" body:statement
|
|
244
|
+
production for_initializer = emit(ts_variable_declaration, @ts_parser_variable) | expression
|
|
245
|
+
production ts_for_in = "for" (modifier:"await")? "(" left:set(no_in, for_initializer) "in" right:clear(no_in, expression) ")" body:statement
|
|
246
|
+
production ts_for_of = "for" (modifier:"await")? "(" left:set(no_in, for_initializer) "of" right:clear(no_in, assignment) ")" body:statement
|
|
247
|
+
production ts_for = "for" cut (modifier:"await")? "(" (init:set(no_in, for_initializer))? ";" test:expression? ";" update:expression? ")" body:statement
|
|
248
|
+
production ts_switch = "switch" cut "(" discriminant:expression ")" "{" case:ts_case* "}"
|
|
249
|
+
production ts_case = ("case" test:expression | "default") ":" body:(not(/case|default|\}/) statement)*
|
|
250
|
+
production ts_try = "try" cut block:ts_block (kind:"catch" ("(" parameter:binding (":" type:goal(types, type_expression))? ")")? handler:ts_block)? ("finally" finalizer:ts_block)?
|
|
251
|
+
production ts_labeled = label:ts_identifier ":" cut body:statement
|
|
252
|
+
production ts_variable_declaration = modifier:"declare"* @ts_parser_variable terminator(";", before("}"), newline, eof)
|
|
253
|
+
production ts_declarator = name:binding "!"? (":" type:goal(types, type_expression))? ("=" init:assignment)?
|
|
254
|
+
production ts_expression_statement = expression:expression terminator(";", before("}"), newline, eof)
|
|
255
|
+
production binding = ts_identifier | ts_object_pattern | ts_array_pattern
|
|
256
|
+
production binding_element precedence binding {
|
|
257
|
+
suffix 1 ("=" right:goal(code, clear(no_in, assignment))) => ts_assignment_pattern(left)
|
|
258
|
+
}
|
|
259
|
+
production ts_object_pattern = "{" (property:ts_pattern_property | rest:ts_rest) ("," (property:ts_pattern_property | rest:ts_rest))* ","? "}" | "{" "}"
|
|
260
|
+
production ts_array_pattern = "[" (element:emit(ts_hole, peek(",")) "," | element:(ts_rest | binding_element) cut ("," | peek("]")))* "]"
|
|
261
|
+
production ts_pattern_property = (key:property_key ":" value:binding_element) | (key:ts_identifier value:ts_assignment_pattern?) | key:property_key
|
|
262
|
+
production ts_rest = "..." argument:binding
|
|
263
|
+
production ts_identifier = not(/(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|import|in|instanceof|new|null|return|super|switch|this|throw|true|try|typeof|var|void|while|with)/) /(?:[A-Za-z_$]|[^\x00-\x7f]|\\u[\s\S]+)(?:[A-Za-z0-9_$]|[^\x00-\x7f]|\\u[\s\S]+)*/
|
|
264
|
+
production property_name = emit(ts_identifier, /(?:[A-Za-z_$]|[^\x00-\x7f]|\\u[\s\S]+)(?:[A-Za-z0-9_$]|[^\x00-\x7f]|\\u[\s\S]+)*/) | ts_private_name
|
|
265
|
+
production ts_private_name = private_name
|
|
266
|
+
production ts_this = "this"
|
|
267
|
+
production ts_super = "super"
|
|
268
|
+
production ts_null = "null"
|
|
269
|
+
production ts_boolean = /true|false/
|
|
270
|
+
production ts_number = number
|
|
271
|
+
production ts_bigint = bigint
|
|
272
|
+
production ts_string = string
|
|
273
|
+
production ts_regex = regexp
|
|
274
|
+
production ts_parenthesized = "(" cut expression:clear(no_in, expression) ")"
|
|
275
|
+
production ts_array = "[" cut clear(no_in, ((element:emit(ts_hole, peek(",")) "," | element:(ts_spread | assignment) cut ("," | peek("]")))*)) "]"
|
|
276
|
+
production ts_spread = "..." cut argument:goal(code, clear(no_in, assignment))
|
|
277
|
+
production ts_object = "{" cut clear(no_in, ((property:(ts_spread | try(object_method) | ts_property) ("," property:(ts_spread | try(object_method) | ts_property))* ","?)?)) "}"
|
|
278
|
+
production property_key = property_name | ts_string | ts_number | ts_bigint | ts_computed_key
|
|
279
|
+
production ts_computed_key = "[" expression:goal(code, clear(no_in, assignment)) "]"
|
|
280
|
+
production ts_property = (modifier:"async" same_line peek(accessor_next))? modifier:"*"? (kind:/get|set/ peek(accessor_next))? key:property_key (":" value:assignment | value:ts_assignment_pattern)?
|
|
281
|
+
production ts_assignment_pattern = "=" right:assignment
|
|
282
|
+
production ts_template = quasi:template | (quasi:template_head expression:clear(no_in, expression) (goal(template_parts, quasi:template_middle) expression:clear(no_in, expression))* goal(template_parts, quasi:template_tail))
|
|
283
|
+
production ts_decorator = "@" expression:lhs_expression
|
|
284
|
+
production ts_parameter = decorator:ts_decorator* (modifier:/public|private|protected|readonly|override/ same_line peek(property_key))* name:(ts_rest | ts_this | binding) (optional:"?")? (":" type:goal(types, type_expression))? ("=" init:goal(code, clear(no_in, assignment)))?
|
|
285
|
+
production parameters = "(" (parameter:ts_parameter ("," parameter:ts_parameter)* ","?)? ")"
|
|
286
|
+
production ts_function = modifier:"declare"* (modifier:"async" same_line)? "function" (modifier:"*" @ts_parser_function_header (body:clear(no_in, set(generator, ts_block)) | @ts_parser_semi) | @ts_parser_function_header (body:clear(no_in, clear(generator, ts_block)) | @ts_parser_semi))
|
|
287
|
+
production ts_arrow = try(
|
|
288
|
+
peek(ts_identifier same_line "=>" | "(" | "<" | "async" same_line (ts_identifier same_line "=>" | "(" | "<"))
|
|
289
|
+
(
|
|
290
|
+
parameter:emit(ts_parameter, name:ts_identifier) @ts_parser_arrow_tail |
|
|
291
|
+
(if(jsx, peek("<" type_identifier ("," | "extends")), ()) type_parameter:goal(types, type_parameters))? parameter:parameters (":" return_type:goal(types, return_type))? @ts_parser_arrow_tail |
|
|
292
|
+
modifier:"async" same_line (
|
|
293
|
+
parameter:emit(ts_parameter, name:ts_identifier) |
|
|
294
|
+
(type_parameter:goal(types, type_parameters))? parameter:parameters (":" return_type:goal(types, return_type))?
|
|
295
|
+
) @ts_parser_arrow_tail
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
production expression precedence assignment {
|
|
300
|
+
left 0 "," => ts_sequence(expression, expression) flatten
|
|
301
|
+
}
|
|
302
|
+
production assignment = goal(code, (ts_arrow | if(generator, ts_yield, fail) | assignment_value))
|
|
303
|
+
production ts_yield = "yield" (same_line operator:"*")? (same_line argument:assignment)?
|
|
304
|
+
production assignment_value precedence binary_expression {
|
|
305
|
+
suffix 1 (operator:/=|\+=|-=|\*=|\/=|%=|\*\*=|<<=|>>=|>>>=|&=|\|=|\^=|&&=|\|\|=|\?\?=/ cut right:assignment) => ts_assignment(left)
|
|
306
|
+
suffix 2 ("?" consequent:clear(no_in, assignment) ":" alternate:assignment) => ts_conditional(test)
|
|
307
|
+
}
|
|
308
|
+
production binary_expression precedence unary_expression {
|
|
309
|
+
left 1 operator:"??" => ts_logical(left, operator, right)
|
|
310
|
+
left 2 operator:"||" => ts_logical(left, operator, right)
|
|
311
|
+
left 3 operator:"&&" => ts_logical(left, operator, right)
|
|
312
|
+
left 4 operator:"|" => ts_binary(left, operator, right)
|
|
313
|
+
left 5 operator:"^" => ts_binary(left, operator, right)
|
|
314
|
+
left 6 operator:"&" => ts_binary(left, operator, right)
|
|
315
|
+
left 7 operator:/==|!=|===|!==/ => ts_binary(left, operator, right)
|
|
316
|
+
left 8 operator:/<|>|<=|>=|instanceof/ => ts_binary(left, operator, right)
|
|
317
|
+
left 8 operator:if(no_in, fail, text("in")) => ts_binary(left, operator, right)
|
|
318
|
+
left 9 operator:/<<|>>|>>>/ => ts_binary(left, operator, right)
|
|
319
|
+
left 10 operator:/\+|-/ => ts_binary(left, operator, right)
|
|
320
|
+
left 11 operator:/\*|\/|%/ => ts_binary(left, operator, right)
|
|
321
|
+
right 12 operator:"**" => ts_binary(left, operator, right)
|
|
322
|
+
suffix 8 (same_line "as" type:goal(types, (emit(ts_type_keyword, "const") | type_expression))) => ts_as(expression)
|
|
323
|
+
suffix 8 (same_line "satisfies" type:goal(types, (emit(ts_type_keyword, "const") | type_expression))) => ts_satisfies(expression)
|
|
324
|
+
}
|
|
325
|
+
production unary_expression precedence (if(jsx, fail, ts_type_assertion) | lhs_expression) {
|
|
326
|
+
prefix 1 operator:/!|~|\+|-|delete|void|typeof/ => ts_unary(operator, argument)
|
|
327
|
+
prefix 1 operator:/\+\+|--/ => ts_update(operator, argument)
|
|
328
|
+
prefix 1 ("await" not(end) not(/\)|\]|\}|,|;|:|=|\.|\?\.|=>|\?/)) => ts_await(argument)
|
|
329
|
+
suffix 2 (same_line operator:/\+\+|--/) => ts_update(argument)
|
|
330
|
+
}
|
|
331
|
+
production lhs_expression precedence goal(primary, primary_expression) {
|
|
332
|
+
suffix 1 ("." property:property_name) => ts_member(object)
|
|
333
|
+
suffix 1 (optional:"?." property:property_name) => ts_member(object)
|
|
334
|
+
suffix 1 ("[" index:clear(no_in, expression) "]") => ts_index(object)
|
|
335
|
+
suffix 1 (optional:"?." "[" index:clear(no_in, expression) "]") => ts_index(object)
|
|
336
|
+
suffix 1 argument:arguments => ts_call(callee)
|
|
337
|
+
suffix 1 try(type_argument:goal(types, type_arguments) argument:arguments) => ts_call(callee)
|
|
338
|
+
suffix 1 (optional:"?." argument:arguments) => ts_call(callee)
|
|
339
|
+
suffix 1 (optional:"?." type_argument:goal(types, type_arguments) argument:arguments) => ts_call(callee)
|
|
340
|
+
suffix 1 (same_line "!") => ts_non_null(expression)
|
|
341
|
+
suffix 1 quasi:ts_template => ts_tagged_template(tag)
|
|
342
|
+
suffix 1 try(type_argument:goal(types, type_arguments) quasi:ts_template) => ts_tagged_template(tag)
|
|
343
|
+
suffix 1 try(type_argument:goal(types, type_arguments) @ts_parser_instantiation_end) => ts_instantiation(expression)
|
|
344
|
+
}
|
|
345
|
+
production arguments = "(" (argument:(ts_spread | clear(no_in, assignment)) ("," argument:(ts_spread | clear(no_in, assignment)))* ","?)? ")"
|
|
346
|
+
production new_callee precedence goal(primary, primary_expression) {
|
|
347
|
+
suffix 1 ("." property:property_name) => ts_member(object)
|
|
348
|
+
suffix 1 ("[" index:clear(no_in, expression) "]") => ts_index(object)
|
|
349
|
+
suffix 1 (same_line "!") => ts_non_null(expression)
|
|
350
|
+
suffix 1 quasi:ts_template => ts_tagged_template(tag)
|
|
351
|
+
}
|
|
352
|
+
production ts_meta_property = /new|import/ "." /[\s\S]+/
|
|
353
|
+
production ts_new = "new" callee:new_callee (try(type_argument:goal(types, type_arguments)))? argument:arguments?
|
|
354
|
+
production ts_import_call = "import" argument:arguments
|
|
355
|
+
production ts_type_assertion = "<" type:goal(types, (emit(ts_type_keyword, "const") | type_expression)) ">" expression:unary_expression
|
|
356
|
+
production primary_expression = if(jsx, goal(jsx_tag, (ts_jsx_fragment | ts_jsx_element)), fail) | ts_this | ts_super | ts_null | ts_boolean | ts_bigint | ts_number | ts_string | ts_regex | ts_template | ts_parenthesized | ts_array | ts_object | try(ts_meta_property) | ts_new | ts_import_call | ts_function | ts_class | ts_private_name | ts_identifier
|
|
357
|
+
|
|
358
|
+
production ts_jsx_fragment = opening:emit(ts_jsx_opening, "<" ">") goal(jsx_body, body:jsx_child*) closing:emit(ts_jsx_closing, "<" "/" ">")
|
|
359
|
+
production ts_jsx_element = (
|
|
360
|
+
try(opening:emit(ts_jsx_opening, @ts_parser_jsx_header "/" ">")) |
|
|
361
|
+
opening:emit(ts_jsx_opening, @ts_parser_jsx_header ">")
|
|
362
|
+
goal(jsx_body, body:jsx_child*)
|
|
363
|
+
closing:emit(ts_jsx_closing, "<" "/" name:ts_jsx_name ">")
|
|
364
|
+
same_text(opening.name, closing.name, /[ \t\r\n\x0b\x0c\u{00a0}\u{1680}\u{2000}-\u{200a}\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]+/)
|
|
365
|
+
)
|
|
366
|
+
production jsx_child = not(peek("<" goal(code, "/"))) (ts_jsx_text | goal(code, ts_jsx_expression) | goal(jsx_tag, (ts_jsx_fragment | ts_jsx_element)))
|
|
367
|
+
production ts_jsx_text = jsx_text
|
|
368
|
+
production jsx_part = /(?:[A-Za-z_$]|[^\x00-\x7f])(?:[A-Za-z0-9_$-]|[^\x00-\x7f])*/
|
|
369
|
+
production ts_jsx_name = jsx_part (("." | ":") jsx_part)*
|
|
370
|
+
production jsx_namespace_name = emit(ts_jsx_name, jsx_part ":" jsx_part)
|
|
371
|
+
production jsx_component_base = ts_this | emit(ts_identifier, jsx_part)
|
|
372
|
+
production jsx_member = emit(ts_member, object:jsx_component_base "." property:emit(ts_identifier, jsx_part))
|
|
373
|
+
production jsx_component_name precedence jsx_member {
|
|
374
|
+
suffix 1 ("." property:emit(ts_identifier, jsx_part)) => ts_member(object)
|
|
375
|
+
}
|
|
376
|
+
production jsx_opening_name = try(jsx_namespace_name) | try(jsx_component_name) | emit(ts_jsx_name, /[a-z][A-Za-z0-9_$-]*|[A-Za-z_$][A-Za-z0-9_$]*-[A-Za-z0-9_$-]*/) | jsx_component_base
|
|
377
|
+
production ts_jsx_attribute = name:emit(ts_jsx_name, jsx_part (":" jsx_part)?) ("=" not(goal(jsx_value_guard, jsx_value_comment)) value:goal(jsx_value, (emit(ts_string, jsx_string) | goal(code, ts_jsx_attribute_expression) | goal(jsx_tag, (ts_jsx_fragment | ts_jsx_element)))))?
|
|
378
|
+
production ts_jsx_spread_attribute = goal(code, ("{" "..." argument:clear(no_in, assignment) "}"))
|
|
379
|
+
production ts_jsx_expression = "{" (expression:(ts_spread | clear(no_in, expression)))? "}"
|
|
380
|
+
production ts_jsx_attribute_expression = emit(ts_jsx_expression, "{" expression:clear(no_in, assignment)? "}")
|
|
381
|
+
|
|
382
|
+
production type_expression = clear(no_cond, type_inner)
|
|
383
|
+
production type_no_conditional = set(no_cond, type_inner)
|
|
384
|
+
production type_inner = try(ts_function_type) | type_conditional
|
|
385
|
+
production type_conditional precedence type_union {
|
|
386
|
+
suffix 0 (same_line if(no_cond, fail, "extends") extends:type_no_conditional "?" consequent:type_expression ":" alternate:type_expression) => ts_conditional_type(check)
|
|
387
|
+
}
|
|
388
|
+
production type_union = emit(ts_union, "|" type:union_members) | type_union_value
|
|
389
|
+
production union_members = type_intersection ("|" type_intersection)*
|
|
390
|
+
production type_union_value precedence type_intersection {
|
|
391
|
+
left 1 "|" => ts_union(type, type) flatten
|
|
392
|
+
}
|
|
393
|
+
production type_intersection = emit(ts_intersection, "&" type:intersection_members) | type_intersection_value
|
|
394
|
+
production intersection_members = type_operator ("&" type_operator)*
|
|
395
|
+
production type_intersection_value precedence type_operator {
|
|
396
|
+
left 2 "&" => ts_intersection(type, type) flatten
|
|
397
|
+
}
|
|
398
|
+
production type_operator precedence (ts_infer | type_postfix) {
|
|
399
|
+
prefix 1 (/keyof|readonly|unique/ not(end) not(/\)|\]|\}|,|;|:|=|>|\||&|\?|\.|=>/)) => ts_type_operator(operator, type)
|
|
400
|
+
}
|
|
401
|
+
production type_postfix precedence type_atom {
|
|
402
|
+
suffix 1 (same_line "[" "]") => ts_array_type(type)
|
|
403
|
+
suffix 1 (same_line "[" index:type_expression "]") => ts_indexed_access(object)
|
|
404
|
+
}
|
|
405
|
+
production type_atom = ts_parenthesized_type | try(ts_mapped_type) | ts_type_literal | ts_tuple_type | ts_literal_type | ts_template_type | ts_type_query | ts_import_type | ts_type_keyword | ts_type_reference
|
|
406
|
+
production ts_parenthesized_type = "(" type:type_expression ")"
|
|
407
|
+
production ts_type_keyword = /any|unknown|never|void|undefined|null|boolean|number|bigint|string|symbol|object|intrinsic|this/ not(".")
|
|
408
|
+
production type_identifier = emit(ts_identifier, /(?:[A-Za-z_$]|[^\x00-\x7f]|\\u[\s\S]+)(?:[A-Za-z0-9_$]|[^\x00-\x7f]|\\u[\s\S]+)*/)
|
|
409
|
+
production entity_name precedence (ts_this | type_identifier) {
|
|
410
|
+
suffix 1 ("." right:type_identifier) => ts_qualified_name(left)
|
|
411
|
+
}
|
|
412
|
+
production entity_query precedence (ts_this | type_identifier) {
|
|
413
|
+
suffix 1 ("." right:(type_identifier | ts_private_name)) => ts_qualified_name(left)
|
|
414
|
+
}
|
|
415
|
+
production ts_type_reference = name:entity_name (same_line type_argument:type_arguments)?
|
|
416
|
+
production type_arguments = "<" (type_expression ("," type_expression)* ","?)? ">"
|
|
417
|
+
production type_parameters = "<" (ts_type_parameter ("," ts_type_parameter)* ","?)? ">"
|
|
418
|
+
production ts_type_parameter = (modifier:/const|in|out/ peek(type_identifier))* name:type_identifier ("extends" constraint:type_expression)? ("=" default:type_expression)?
|
|
419
|
+
production ts_infer = "infer" type_parameter:emit(ts_type_parameter, name:type_identifier (try("extends" constraint:type_no_conditional if(no_cond, (), not("?"))))?)
|
|
420
|
+
production ts_function_type = modifier:"abstract"? kind:"new"? (type_parameter:type_parameters)? parameter:parameters "=>" return_type:return_type
|
|
421
|
+
production return_type = try(ts_type_predicate) | type_expression
|
|
422
|
+
production ts_type_predicate = (modifier:"asserts" same_line name:(ts_this | type_identifier) ("is" type:type_expression)?) | (name:(ts_this | type_identifier) same_line "is" type:type_expression)
|
|
423
|
+
production ts_type_query = "typeof" cut name:(ts_import_type | entity_query) (same_line type_argument:type_arguments)?
|
|
424
|
+
production ts_import_type = "import" cut "(" argument:type_expression ("," discard(goal(code, clear(no_in, assignment)))?)? ")" ("." qualifier:entity_name)? (same_line type_argument:type_arguments)?
|
|
425
|
+
production ts_literal_type = "-"? value:(ts_number | ts_bigint) | value:(ts_string | ts_boolean)
|
|
426
|
+
production ts_template_type = quasi:template | (quasi:template_head type:type_expression (goal(template_parts, quasi:template_middle) type:type_expression)* goal(template_parts, quasi:template_tail))
|
|
427
|
+
production ts_tuple_type = "[" (element:(emit(ts_rest, "..." @ts_parser_tuple_member) | ts_tuple_member) ("," element:(emit(ts_rest, "..." @ts_parser_tuple_member) | ts_tuple_member))* ","?)? "]"
|
|
428
|
+
production ts_tuple_member = @ts_parser_tuple_member
|
|
429
|
+
production ts_mapped_type = "{" (modifier:(text(/[-+]/ "readonly") | /readonly/))? "[" type_parameter:emit(ts_type_parameter, name:type_identifier "in" constraint:type_expression) ("as" name:type_expression)? "]" (optional:(text(/[-+]/ "?") | text("?")))? (":" type:type_expression)? (";" | ",")? "}"
|
|
430
|
+
production ts_type_literal = member:type_members
|
|
431
|
+
production type_members = "{" (type_member (";" | "," | terminator(";", before("}"), newline)))* "}"
|
|
432
|
+
production type_member = try(ts_call_signature) | try(ts_index_signature) | try(ts_method_signature) | ts_property_signature
|
|
433
|
+
production ts_call_signature = kind:"new"? @ts_parser_signature
|
|
434
|
+
production ts_index_signature = (modifier:"readonly" same_line peek("["))? "[" parameter:emit(ts_parameter, name:type_identifier optional:"?"? ":" type:type_expression) "]" (":" type:type_expression)?
|
|
435
|
+
production ts_method_signature = (modifier:"readonly" same_line peek(property_key))? (kind:/get|set/ same_line peek(property_key))? key:property_key optional:"?"? (type_parameter:type_parameters)? parameter:parameters (":" return_type:return_type)?
|
|
436
|
+
production ts_property_signature = (modifier:"readonly" same_line peek(property_key))? (discard(/get|set/) same_line peek(property_key))? key:property_key optional:"?"? (":" type:type_expression)?
|
|
437
|
+
|
|
438
|
+
production declaration = ts_function | ts_class | ts_interface | ts_type_alias | ts_enum | ts_namespace | ts_variable_declaration
|
|
439
|
+
production accessor_next = type_identifier | ts_string | ts_number | ts_bigint | ts_private_name | /\[|\*|\{|#/
|
|
440
|
+
production ts_class = decorator:ts_decorator* @ts_parser_class_header "{" (";" | member:class_member)* "}"
|
|
441
|
+
production decorated_export = emit(ts_export, scope(decorators, ts_decorator+,
|
|
442
|
+
"export" kind:"default"? declaration:emit(ts_class,
|
|
443
|
+
decorator:reuse(decorators) @ts_parser_class_header "{" (";" | member:class_member)* "}"
|
|
444
|
+
)
|
|
445
|
+
))
|
|
446
|
+
production class_member = try(ts_static_block) | try(class_index_signature) | try(class_method) | ts_class_property
|
|
447
|
+
production ts_static_block = discard(ts_decorator*) "static" body:clear(no_in, ts_block)
|
|
448
|
+
production class_index_signature = emit(ts_index_signature, decorator:ts_decorator* @ts_parser_class_modifiers "[" parameter:emit(ts_parameter, name:type_identifier optional:"?"? ":" type:goal(types, type_expression)) "]" (":" type:goal(types, type_expression))?) discard(@ts_parser_semi)
|
|
449
|
+
production class_method = emit(ts_method, decorator:ts_decorator* @ts_parser_class_modifiers (
|
|
450
|
+
modifier:"*" @ts_parser_method_header (body:clear(no_in, set(generator, ts_block)) | @ts_parser_semi) |
|
|
451
|
+
@ts_parser_method_header (body:clear(no_in, clear(generator, ts_block)) | @ts_parser_semi)
|
|
452
|
+
))
|
|
453
|
+
production object_method = emit(ts_method, (modifier:"async" same_line peek(accessor_next))? (
|
|
454
|
+
modifier:"*" @ts_parser_method_header (body:clear(no_in, set(generator, ts_block)) | @ts_parser_semi) |
|
|
455
|
+
@ts_parser_method_header (body:clear(no_in, clear(generator, ts_block)) | @ts_parser_semi)
|
|
456
|
+
))
|
|
457
|
+
production ts_class_property = decorator:ts_decorator* @ts_parser_class_modifiers modifier:"*"? (kind:/get|set/ peek(accessor_next))? key:property_key optional:"?"? "!"? (":" type:goal(types, type_expression))? ("=" init:clear(no_in, assignment))? @ts_parser_semi
|
|
458
|
+
production ts_interface = modifier:"declare"* "interface" same_line name:type_identifier (type_parameter:goal(types, type_parameters))? ("extends" extends:goal(types, type_expression) ("," extends:goal(types, type_expression))*)? member:goal(types, type_members)
|
|
459
|
+
production ts_type_alias = modifier:"declare"* "type" same_line name:type_identifier (type_parameter:goal(types, type_parameters))? "=" type:goal(types, type_expression) @ts_parser_semi
|
|
460
|
+
production ts_enum = modifier:"declare"* modifier:"const"? "enum" name:type_identifier "{" (member:ts_enum_member ("," member:ts_enum_member)* ","?)? "}"
|
|
461
|
+
production ts_enum_member = name:property_key ("=" init:clear(no_in, assignment))?
|
|
462
|
+
production namespace_name precedence (ts_string | type_identifier) {
|
|
463
|
+
suffix 1 ("." right:type_identifier) => ts_qualified_name(left)
|
|
464
|
+
}
|
|
465
|
+
production ts_namespace = modifier:"declare"* (
|
|
466
|
+
kind:"global" peek("{") | kind:/namespace|module/ same_line name:namespace_name
|
|
467
|
+
) (body:ts_block | @ts_parser_semi)
|
|
468
|
+
production ts_import_equals = "import" @ts_parser_import_kind name:type_identifier "=" value:lhs_expression @ts_parser_semi
|
|
469
|
+
production ts_import = "import" @ts_parser_import_kind (
|
|
470
|
+
from:ts_string import_attributes? |
|
|
471
|
+
default_import:type_identifier? ","? ("*" "as" namespace:type_identifier | "{" (specifier:ts_import_specifier ("," specifier:ts_import_specifier)* ","?)? "}")? "from" from:ts_string import_attributes?
|
|
472
|
+
) @ts_parser_semi
|
|
473
|
+
production ts_import_specifier = @ts_parser_specifier_kind imported:(ts_string | type_identifier) ("as" local:type_identifier)?
|
|
474
|
+
production import_attributes = discard(("with" | same_line "assert") attribute_braces)
|
|
475
|
+
production attribute_braces = "{" (attribute_braces | not("{" | "}") /[\s\S]+/)* "}"
|
|
476
|
+
production ts_export_assignment = "export" "=" expression:expression @ts_parser_semi
|
|
477
|
+
production ts_export = "export" (
|
|
478
|
+
"as" "namespace" namespace:type_identifier @ts_parser_semi |
|
|
479
|
+
kind:"default" (declaration:(try(ts_function) | try(ts_class) | try(ts_interface)) | expression:assignment @ts_parser_semi) |
|
|
480
|
+
declaration:(try(ts_import_equals) | ts_import) |
|
|
481
|
+
(kind:"type" peek("{" | "*"))? (
|
|
482
|
+
operator:"*" ("as" namespace:(ts_string | type_identifier))? "from" from:ts_string import_attributes? @ts_parser_semi |
|
|
483
|
+
"{" (specifier:ts_export_specifier ("," specifier:ts_export_specifier)* ","?)? "}" ("from" from:ts_string import_attributes?)? @ts_parser_semi
|
|
484
|
+
) |
|
|
485
|
+
declaration:declaration
|
|
486
|
+
)
|
|
487
|
+
production ts_export_specifier = @ts_parser_specifier_kind local:(ts_string | type_identifier) ("as" exported:(ts_string | type_identifier))?
|
|
488
|
+
}
|