fallow-type-aware 3.36.0 → 3.37.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fallow-type-aware",
3
- "version": "3.36.0",
3
+ "version": "3.37.0",
4
4
  "description": "Optional TypeScript-Go semantic refinement sidecar for Fallow",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,32 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+
4
+ /** Source extensions accepted by the semantic backend, including declaration-file suffixes. */
5
+ export const MODULE_SOURCE_EXTENSIONS = [
6
+ ".ts",
7
+ ".tsx",
8
+ ".mts",
9
+ ".cts",
10
+ ".js",
11
+ ".jsx",
12
+ ".mjs",
13
+ ".cjs",
14
+ ];
15
+
16
+ /** Whether the backend can parse the query's source without a component transform. */
17
+ export const isSupportedSemanticQuery = (query) =>
18
+ !query.symbol ||
19
+ MODULE_SOURCE_EXTENSIONS.includes(path.extname(query.symbol.absolutePath).toLowerCase());
20
+
21
+ /** Component files must stay out of openFiles because the backend cannot infer their script kind. */
22
+ export const semanticOpenFiles = (queries) =>
23
+ queries
24
+ .filter((query) => query.symbol && isSupportedSemanticQuery(query))
25
+ .map((query) => query.symbol.absolutePath);
26
+
27
+ /** Resolve explicit projects or the conventional root project. */
28
+ export const semanticOpenProjects = (root, projects) => {
29
+ if (projects.length > 0) return projects.map((project) => project.absolutePath);
30
+ const conventionalProject = path.join(root, "tsconfig.json");
31
+ return existsSync(conventionalProject) ? [conventionalProject] : [];
32
+ };
package/src/semantic.mjs CHANGED
@@ -48,6 +48,12 @@ import {
48
48
  targetName,
49
49
  } from "./symbol-targets.mjs";
50
50
  import { analyzeTypeCoupling } from "./type-coupling.mjs";
51
+ import {
52
+ MODULE_SOURCE_EXTENSIONS,
53
+ isSupportedSemanticQuery,
54
+ semanticOpenFiles,
55
+ semanticOpenProjects,
56
+ } from "./semantic-input.mjs";
51
57
 
52
58
  const { SignatureKind, SymbolFlags } = sync;
53
59
  const {
@@ -493,8 +499,6 @@ const importTypeSpecifier = (node) => {
493
499
  return literal && isStringLiteralLikeNode(literal) ? literal : undefined;
494
500
  };
495
501
 
496
- const MODULE_SOURCE_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
497
-
498
502
  const lexicalModuleIdentityForText = (project, sourceFile, specifierText) => {
499
503
  if (!specifierText?.startsWith(".")) return undefined;
500
504
  const resolved = path.resolve(path.dirname(sourceFile.fileName), specifierText);
@@ -748,11 +752,11 @@ const selectSymbolContext = (
748
752
  query,
749
753
  allowDefaultFallback,
750
754
  ) => {
751
- if (!DECLARATION_KINDS.has(query.symbol.declarationKind)) {
755
+ if (!isSupportedSemanticQuery(query) || !DECLARATION_KINDS.has(query.symbol.declarationKind)) {
752
756
  return symbolResolutionError(
753
757
  query,
754
758
  "unsupported-syntax",
755
- "Use a supported declaration kind or retain the syntactic finding.",
759
+ "Use a supported TypeScript or JavaScript declaration or retain the syntactic finding.",
756
760
  );
757
761
  }
758
762
  let owners = owningProjectContexts(statesByProject, query.symbol.absolutePath);
@@ -1403,16 +1407,16 @@ const signatureTypes = (project, type, anchor) =>
1403
1407
 
1404
1408
  const checkerTypeChildren = (project, type, anchor, hasNamedDeclaration) => {
1405
1409
  if (type.isTypeParameter()) {
1406
- const constraint = safeCheckerValue(
1407
- () => project.checker.getConstraintOfTypeParameter(type),
1408
- undefined,
1409
- );
1410
+ const constraint = safeCheckerValue(() => project.checker.getConstraintOfTypeParameter(type));
1410
1411
  return constraint ? [constraint] : [];
1411
1412
  }
1412
1413
  const structural = [
1413
1414
  ...(type.getTypes() ?? []),
1414
1415
  ...safeCheckerValue(() => type.getAliasTypeArguments(), []),
1415
- ...safeCheckerValue(() => project.checker.getTypeArguments(type), []),
1416
+ // On tsrs, this call panics to stderr for a type that is not a reference.
1417
+ ...(type.isTypeReference()
1418
+ ? safeCheckerValue(() => project.checker.getTypeArguments(type), [])
1419
+ : []),
1416
1420
  ].filter(Boolean);
1417
1421
  if (hasNamedDeclaration) return structural;
1418
1422
  const direct = [...structural, ...signatureTypes(project, type, anchor)];
@@ -1725,8 +1729,10 @@ const emptySemanticAnalysis = (queries) => ({
1725
1729
  results: queries.map((query) =>
1726
1730
  unavailable(
1727
1731
  query,
1728
- "no-project",
1729
- "Pass an explicit tsconfig with --type-aware-project and retry.",
1732
+ isSupportedSemanticQuery(query) ? "no-project" : "unsupported-syntax",
1733
+ isSupportedSemanticQuery(query)
1734
+ ? "Pass an explicit tsconfig with --type-aware-project and retry."
1735
+ : "Use a supported TypeScript or JavaScript declaration or retain the syntactic finding.",
1730
1736
  ),
1731
1737
  ),
1732
1738
  phaseTimings: { project_setup: 0, diagnostics: 0, semantic_queries: 0 },
@@ -1956,15 +1962,6 @@ const emptyRequestedAnalysis = () => ({
1956
1962
  warnings: [],
1957
1963
  });
1958
1964
 
1959
- const semanticOpenFiles = (queries) =>
1960
- queries.filter((query) => query.symbol).map((query) => query.symbol.absolutePath);
1961
-
1962
- const semanticOpenProjects = (root, projects) => {
1963
- if (projects.length > 0) return projects.map((project) => project.absolutePath);
1964
- const conventionalProject = path.join(root, "tsconfig.json");
1965
- return existsSync(conventionalProject) ? [conventionalProject] : [];
1966
- };
1967
-
1968
1965
  const semanticProjectSelection = (snapshot, openProjects, openFiles, allowDefaultFallback) => {
1969
1966
  const explicitProjects = openProjects
1970
1967
  .map((project) => snapshot.getProject(project))