@jefuriiij/synthra 0.1.6 → 0.1.7

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.
@@ -1013,7 +1013,7 @@ async function parseRust(f, source) {
1013
1013
  }
1014
1014
 
1015
1015
  // src/scanner/parsers/typescript.ts
1016
- var QUERY12 = `
1016
+ var TS_QUERY = `
1017
1017
  (function_declaration name: (identifier) @function.name) @function
1018
1018
  (class_declaration name: (type_identifier) @class.name) @class
1019
1019
  (interface_declaration name: (type_identifier) @interface.name) @interface
@@ -1023,11 +1023,22 @@ var QUERY12 = `
1023
1023
  (lexical_declaration (variable_declarator name: (identifier) @const-fn.name value: [(arrow_function) (function_expression)])) @const-fn
1024
1024
  (import_statement source: (string) @import)
1025
1025
  `;
1026
+ var JS_QUERY = `
1027
+ (function_declaration name: (identifier) @function.name) @function
1028
+ (class_declaration name: (identifier) @class.name) @class
1029
+ (method_definition name: (property_identifier) @method.name) @method
1030
+ (lexical_declaration (variable_declarator name: (identifier) @const-fn.name value: [(arrow_function) (function_expression)])) @const-fn
1031
+ (import_statement source: (string) @import)
1032
+ (call_expression function: (identifier) @_require_fn arguments: (arguments . (string) @require_source))
1033
+ `;
1026
1034
  function grammarFor(ext) {
1027
1035
  if (ext === ".tsx" || ext === ".jsx") return "tsx";
1028
1036
  if (ext === ".js" || ext === ".cjs" || ext === ".mjs") return "javascript";
1029
1037
  return "typescript";
1030
1038
  }
1039
+ function queryFor(grammar) {
1040
+ return grammar === "javascript" ? JS_QUERY : TS_QUERY;
1041
+ }
1031
1042
  function unquote(s) {
1032
1043
  return s.replace(/^["'`]|["'`]$/g, "");
1033
1044
  }
@@ -1051,7 +1062,7 @@ async function parseTypeScript(f, source) {
1051
1062
  const { parser, language } = await createParser(grammar);
1052
1063
  const tree = parser.parse(source);
1053
1064
  if (!tree) return { file: f, source, symbols, imports, calls: [] };
1054
- const query = language.query(QUERY12);
1065
+ const query = language.query(queryFor(grammar));
1055
1066
  const matches = query.matches(tree.rootNode);
1056
1067
  for (const match of matches) {
1057
1068
  const byName = /* @__PURE__ */ new Map();
@@ -1068,7 +1079,15 @@ async function parseTypeScript(f, source) {
1068
1079
  continue;
1069
1080
  }
1070
1081
  const importNode = byName.get("import");
1071
- if (importNode) imports.push(unquote(importNode.text));
1082
+ if (importNode) {
1083
+ imports.push(unquote(importNode.text));
1084
+ continue;
1085
+ }
1086
+ const requireFn = byName.get("_require_fn");
1087
+ const requireSource = byName.get("require_source");
1088
+ if (requireFn && requireSource && requireFn.text === "require") {
1089
+ imports.push(unquote(requireSource.text));
1090
+ }
1072
1091
  }
1073
1092
  const seen = /* @__PURE__ */ new Set();
1074
1093
  symbols = symbols.filter((s) => {