@skastr0/quartz-engine 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/dist/index.js +66 -27
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -740,8 +740,7 @@ var isDefault = (node) => {
740
740
  const modifiers = node.modifierFlags;
741
741
  return modifiers !== undefined && (modifiers & ModifierFlags.Default) !== 0;
742
742
  };
743
- var exportMatchesFor = async (project, source) => {
744
- const moduleSymbol = await project.checker.getSymbolAtLocation(source);
743
+ var exportMatchesFor = async (project, moduleSymbol) => {
745
744
  if (moduleSymbol === undefined)
746
745
  return [];
747
746
  const exported = await project.checker.getExportsOfModule(moduleSymbol);
@@ -776,7 +775,8 @@ var exportMatchesFor = async (project, source) => {
776
775
  return matches;
777
776
  };
778
777
  var exportedMatches = async (project, sourceFiles) => {
779
- const all = await Promise.all(sourceFiles.map((source) => exportMatchesFor(project, source)));
778
+ const moduleSymbols = await project.checker.getSymbolOfSourceFile(sourceFiles.map((sourceFile) => sourceFile.fileName));
779
+ const all = await Promise.all(moduleSymbols.map((moduleSymbol) => exportMatchesFor(project, moduleSymbol)));
780
780
  return all.flat();
781
781
  };
782
782
  var exportedMatchesFor = (context, project, packageInfo, revision, sourceFiles) => context.cacheForRevision(`exported-matches:${packageInfo.tsconfigPath}`, revision, () => exportedMatches(project, sourceFiles));
@@ -900,7 +900,8 @@ var makeTypeInfo = async (match, project, packageInfo, root) => {
900
900
  return properties.length > 0 ? { ...result, properties } : result;
901
901
  };
902
902
  var metadataFor = async (project, source) => {
903
- const matches = await exportMatchesFor(project, source);
903
+ const moduleSymbol = await project.checker.getSymbolOfSourceFile(source.fileName);
904
+ const matches = await exportMatchesFor(project, moduleSymbol);
904
905
  const direct = declarationsIn(source).flatMap((node) => {
905
906
  const name = declarationName(node);
906
907
  if (name === undefined)
@@ -1221,7 +1222,7 @@ var createLeafOperations = (context) => {
1221
1222
  // src/reference-operations.ts
1222
1223
  import { relative as relative4, resolve as resolve6 } from "path";
1223
1224
  import { SyntaxKind as SyntaxKind2 } from "typescript/unstable/ast";
1224
- import { isTypeReferenceNode as isTypeReferenceNode2 } from "typescript/unstable/ast/is";
1225
+ import { isIdentifier as isIdentifier2, isTypeReferenceNode as isTypeReferenceNode2 } from "typescript/unstable/ast/is";
1225
1226
  var PRIMITIVE_NAMES = {
1226
1227
  string: true,
1227
1228
  number: true,
@@ -1271,12 +1272,12 @@ var createReferenceOperations = (context) => ({
1271
1272
  if (rootTarget === null)
1272
1273
  return null;
1273
1274
  const nodes = [symbolName];
1274
- const nodeIds = new Set([String(rootTarget.symbol.id)]);
1275
+ const nodeIds = new Set([await symbolIdentity(project, rootTarget.symbol)]);
1275
1276
  const edges = [];
1276
1277
  const edgeKeys = new Set;
1277
1278
  const visited = new Set;
1278
1279
  const visit = async (target, displayName, currentDepth) => {
1279
- const targetId = String(target.symbol.id);
1280
+ const targetId = await symbolIdentity(project, target.symbol);
1280
1281
  if (visited.has(targetId) || currentDepth > depth)
1281
1282
  return;
1282
1283
  visited.add(targetId);
@@ -1287,9 +1288,10 @@ var createReferenceOperations = (context) => ({
1287
1288
  const child = await targets.lookup(reference.symbol);
1288
1289
  if (child === null)
1289
1290
  continue;
1290
- const childId = String(child.symbol.id);
1291
+ const childId = await symbolIdentity(project, child.symbol);
1291
1292
  const childName = child.symbol.name;
1292
1293
  if (!nodeIds.has(childId)) {
1294
+ nodeIds.add(childId);
1293
1295
  nodes.push(childName);
1294
1296
  }
1295
1297
  const edgeKey = `${targetId}:${childId}:${reference.context}`;
@@ -1430,8 +1432,10 @@ var buildDeclarationTargetIndex = async (project, packagePath, rootPath) => {
1430
1432
  }
1431
1433
  }
1432
1434
  if (!byName.has("default")) {
1433
- for (const sourceFile of sourceFiles) {
1434
- const moduleSymbol = await project.checker.getSymbolAtLocation(sourceFile);
1435
+ const moduleSymbols = await project.checker.getSymbolOfSourceFile(sourceFiles.map((sourceFile) => sourceFile.fileName));
1436
+ for (let index = 0;index < sourceFiles.length; index += 1) {
1437
+ const sourceFile = sourceFiles[index];
1438
+ const moduleSymbol = moduleSymbols[index];
1435
1439
  if (moduleSymbol === undefined)
1436
1440
  continue;
1437
1441
  const exports = await project.checker.getExportsOfModule(moduleSymbol);
@@ -1494,8 +1498,10 @@ var findTargetByScan = async (project, packagePath, rootPath, requestedName) =>
1494
1498
  return { symbol: canonical, declaration, packagePath, rootPath };
1495
1499
  }
1496
1500
  if (requestedName === "default") {
1497
- for (const sourceFile of sourceFiles) {
1498
- const moduleSymbol = await project.checker.getSymbolAtLocation(sourceFile);
1501
+ const moduleSymbols = await project.checker.getSymbolOfSourceFile(sourceFiles.map((sourceFile) => sourceFile.fileName));
1502
+ for (let index = 0;index < sourceFiles.length; index += 1) {
1503
+ const sourceFile = sourceFiles[index];
1504
+ const moduleSymbol = moduleSymbols[index];
1499
1505
  if (moduleSymbol === undefined)
1500
1506
  continue;
1501
1507
  const exports = await project.checker.getExportsOfModule(moduleSymbol);
@@ -1557,11 +1563,11 @@ var findIncomingReferences = async (project, target) => {
1557
1563
  const declarationName2 = declarationNameNode(target.declaration) ?? target.declaration;
1558
1564
  const declarationPosition = declarationName2.getStart(declarationName2.getSourceFile());
1559
1565
  try {
1560
- const referenced = await project.checker.getReferencedSymbolsForNode(declarationName2, declarationPosition);
1566
+ const referenced = await project.languageService.getReferencedSymbolsForNode(declarationName2, declarationPosition);
1561
1567
  for (const entry of referenced) {
1562
1568
  const handles = [entry.definition, ...entry.references];
1563
1569
  for (const handle of handles) {
1564
- const node = await handle.resolve(project);
1570
+ const node = await resolveIdentifierHandle(project, handle);
1565
1571
  if (node !== undefined)
1566
1572
  await add(node, entry.symbol ?? target.symbol);
1567
1573
  }
@@ -1600,7 +1606,7 @@ var findOutgoingReferences = async (project, target) => {
1600
1606
  const resolved = await resolveSymbol(project, symbol);
1601
1607
  if (resolved.id === target.symbol.id || PRIMITIVE_NAMES[resolved.name] === true)
1602
1608
  return;
1603
- const key = `${resolved.id}:${context}`;
1609
+ const key = `${await symbolIdentity(project, resolved)}:${context}`;
1604
1610
  if (seen.has(key))
1605
1611
  return;
1606
1612
  seen.add(key);
@@ -1633,12 +1639,12 @@ var findRenameSites = async (project, target) => {
1633
1639
  const declarationName2 = declarationNameNode(target.declaration) ?? target.declaration;
1634
1640
  const position = declarationName2.getStart(declarationName2.getSourceFile());
1635
1641
  try {
1636
- const referenced = await project.checker.getReferencedSymbolsForNode(declarationName2, position);
1642
+ const referenced = await project.languageService.getReferencedSymbolsForNode(declarationName2, position);
1637
1643
  for (const entry of referenced) {
1638
1644
  const handles = [entry.definition, ...entry.references];
1639
1645
  for (const handle of handles) {
1640
- const node = await handle.resolve(project);
1641
- if (node === undefined || node.kind !== SyntaxKind2.Identifier)
1646
+ const node = await resolveIdentifierHandle(project, handle);
1647
+ if (node === undefined)
1642
1648
  continue;
1643
1649
  const sourceFile = node.getSourceFile();
1644
1650
  if (!isProjectSourceFile(sourceFile.fileName, target.packagePath))
@@ -1692,17 +1698,24 @@ var findContainingSymbol = async (project, start, target) => {
1692
1698
  current = current.parent;
1693
1699
  }
1694
1700
  const sourceFile = start.getSourceFile();
1695
- const moduleSymbol = await project.checker.getSymbolAtLocation(sourceFile);
1701
+ const moduleSymbol = await project.checker.getSymbolOfSourceFile(sourceFile.fileName);
1696
1702
  return moduleSymbol?.name ?? "anonymous";
1697
1703
  };
1698
1704
  var resolveSymbol = async (project, symbol) => {
1705
+ let resolved = symbol;
1699
1706
  try {
1700
- return await project.checker.getAliasedSymbol(symbol);
1701
- } catch {
1702
- return symbol;
1703
- }
1707
+ resolved = await project.checker.getAliasedSymbol(resolved);
1708
+ } catch {}
1709
+ return project.checker.getTargetSymbol(resolved);
1704
1710
  };
1705
1711
  var matchesCanonicalSymbol = async (project, candidate, target) => (await resolveSymbol(project, candidate)).id === target.id;
1712
+ var symbolIdentity = async (project, symbol) => project.checker.getFullyQualifiedName(await resolveSymbol(project, symbol));
1713
+ var resolveIdentifierHandle = async (project, handle) => {
1714
+ if (handle.kind !== SyntaxKind2.Identifier)
1715
+ return;
1716
+ const node = await handle.resolve(project);
1717
+ return node !== undefined && isIdentifier2(node) ? node : undefined;
1718
+ };
1706
1719
  var projectSourceFiles = async (project, packagePath) => {
1707
1720
  const names = await project.program.getSourceFileNames();
1708
1721
  const files = [];
@@ -1776,6 +1789,12 @@ var isTypeReferencePosition = (node) => {
1776
1789
  return parent !== undefined && (parent.kind === SyntaxKind2.TypeReference || parent.kind === SyntaxKind2.ExpressionWithTypeArguments || isTypeReferenceNode2(parent));
1777
1790
  };
1778
1791
  var classifyReferenceContext = (parent) => {
1792
+ let ancestor = parent;
1793
+ while (ancestor !== undefined && ancestor.kind !== SyntaxKind2.SourceFile) {
1794
+ if (ancestor.kind === SyntaxKind2.HeritageClause)
1795
+ return "extends";
1796
+ ancestor = ancestor.parent;
1797
+ }
1779
1798
  switch (parent.kind) {
1780
1799
  case SyntaxKind2.HeritageClause:
1781
1800
  return "extends";
@@ -2030,9 +2049,18 @@ var symbolsForSeeds = async (project, seeds) => {
2030
2049
  nodes.push(node);
2031
2050
  }
2032
2051
  const symbols = nodes.length === 0 ? [] : await project.checker.getSymbolAtLocation(nodes);
2052
+ const canonical = await Promise.all(symbols.map(async (symbol) => {
2053
+ if (symbol === undefined)
2054
+ return;
2055
+ const target = await project.checker.getTargetSymbol(symbol);
2056
+ return {
2057
+ symbol: target,
2058
+ identity: await project.checker.getFullyQualifiedName(target)
2059
+ };
2060
+ }));
2033
2061
  const bySeed = new Map;
2034
2062
  for (let index = 0;index < symbols.length; index += 1) {
2035
- const symbol = symbols[index];
2063
+ const symbol = canonical[index];
2036
2064
  if (symbol !== undefined)
2037
2065
  bySeed.set(indexes[index], symbol);
2038
2066
  }
@@ -2042,8 +2070,10 @@ var groupCandidateSeeds = (seeds, symbols) => {
2042
2070
  const groups = new Map;
2043
2071
  for (let index = 0;index < seeds.length; index += 1) {
2044
2072
  const seed = seeds[index];
2045
- const symbol = symbols.get(index) ?? null;
2046
- const callableId = symbol === null ? seed.callableId : `${symbol.id}:${seed.kind}`;
2073
+ const symbolInfo = symbols.get(index);
2074
+ const symbol = symbolInfo?.symbol ?? null;
2075
+ const symbolIdentity2 = symbolInfo?.identity ?? null;
2076
+ const callableId = symbolIdentity2 === null ? seed.callableId : `${symbolIdentity2}:${seed.kind}`;
2047
2077
  const existing = groups.get(callableId);
2048
2078
  groups.set(callableId, existing === undefined ? { seed, symbol, seedCount: 1 } : { ...existing, seedCount: existing.seedCount + 1 });
2049
2079
  }
@@ -2308,7 +2338,16 @@ var loadTransformIndex = async (project) => {
2308
2338
  const sourceFiles = [];
2309
2339
  for (let start = 0;start < sourceNames.length; start += SOURCE_FILE_BATCH_SIZE) {
2310
2340
  const batch = await Promise.all(sourceNames.slice(start, start + SOURCE_FILE_BATCH_SIZE).map((name) => project.program.getSourceFile(name)));
2311
- sourceFiles.push(...batch.filter((sourceFile) => sourceFile !== undefined && !sourceFile.isDeclarationFile && !sourceFile.fileName.includes("node_modules")));
2341
+ const eligible = await Promise.all(batch.map(async (sourceFile) => {
2342
+ if (sourceFile === undefined || sourceFile.isDeclarationFile)
2343
+ return;
2344
+ const [external, defaultLibrary] = await Promise.all([
2345
+ project.program.isSourceFileFromExternalLibrary(sourceFile),
2346
+ project.program.isSourceFileDefaultLibrary(sourceFile)
2347
+ ]);
2348
+ return external || defaultLibrary ? undefined : sourceFile;
2349
+ }));
2350
+ sourceFiles.push(...eligible.filter((sourceFile) => sourceFile !== undefined));
2312
2351
  }
2313
2352
  const allCandidates = await compilerCandidates(project, enumerate(sourceFiles));
2314
2353
  const availableNodes = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skastr0/quartz-engine",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "prepack": "bun run build"
21
21
  },
22
22
  "dependencies": {
23
- "typescript": "7.1.0-dev.20260723.1"
23
+ "typescript": "7.1.0-dev.20260905.1"
24
24
  },
25
25
  "license": "MIT",
26
26
  "description": "Persistent TypeScript 7 native workspace engine for Quartz.",