|
13 | 13 | _DEFINITION_NODE_TYPES = { |
14 | 14 | "python": {"function_definition", "class_definition", "decorated_definition"}, |
15 | 15 | "javascript": {"function_declaration", "class_declaration", "method_definition", "arrow_function", "variable_declarator"}, |
| 16 | + "jsx": {"function_declaration", "class_declaration", "method_definition", "arrow_function", "variable_declarator"}, |
16 | 17 | "typescript": { |
17 | 18 | "function_declaration", |
18 | 19 | "class_declaration", |
|
23 | 24 | "enum_declaration", |
24 | 25 | "variable_declarator", |
25 | 26 | }, |
| 27 | + "tsx": { |
| 28 | + "function_declaration", |
| 29 | + "class_declaration", |
| 30 | + "method_definition", |
| 31 | + "arrow_function", |
| 32 | + "interface_declaration", |
| 33 | + "type_alias_declaration", |
| 34 | + "enum_declaration", |
| 35 | + "variable_declarator", |
| 36 | + }, |
26 | 37 | "go": {"function_declaration", "method_declaration", "type_declaration"}, |
27 | 38 | "rust": {"function_item", "impl_item", "struct_item", "enum_item", "trait_item"}, |
28 | 39 | "java": {"method_declaration", "class_declaration", "interface_declaration", "enum_declaration"}, |
|
69 | 80 | _LANG_MODULES = { |
70 | 81 | "python": "tree_sitter_python", |
71 | 82 | "javascript": "tree_sitter_javascript", |
| 83 | + "jsx": "tree_sitter_javascript", |
72 | 84 | "typescript": "tree_sitter_typescript", |
| 85 | + "tsx": "tree_sitter_typescript", |
73 | 86 | "go": "tree_sitter_go", |
74 | 87 | "rust": "tree_sitter_rust", |
75 | 88 | "java": "tree_sitter_java", |
@@ -98,15 +111,20 @@ def _get_parser(self, lang: str) -> Parser: |
98 | 111 | module_name = _LANG_MODULES[lang] |
99 | 112 | ts_lang_module = importlib.import_module(module_name) |
100 | 113 |
|
101 | | - if lang == "typescript": |
| 114 | + if lang == "tsx": |
102 | 115 | ts_lang = ts_lang_module.language_tsx() |
| 116 | + elif lang == "typescript": |
| 117 | + ts_lang = ts_lang_module.language_typescript() |
103 | 118 | elif hasattr(ts_lang_module, "language"): |
104 | 119 | ts_lang = ts_lang_module.language() |
105 | 120 | else: |
106 | 121 | ts_lang = ts_lang_module |
107 | 122 |
|
108 | 123 | parser = Parser() |
109 | | - parser.language = Language(ts_lang) |
| 124 | + if isinstance(ts_lang, Language): |
| 125 | + parser.language = ts_lang |
| 126 | + else: |
| 127 | + parser.language = Language(ts_lang) |
110 | 128 | self._parsers[lang] = parser |
111 | 129 | return parser |
112 | 130 |
|
|
0 commit comments