@suss/adapter-typescript 0.5.11 → 0.6.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/dist/index.cjs CHANGED
@@ -2431,7 +2431,7 @@ function dispatchAccessRecognizers(root, recognizers, isStop, resolveWrittenValu
2431
2431
  traversal.skip();
2432
2432
  return;
2433
2433
  }
2434
- if (!import_ts_morph12.Node.isPropertyAccessExpression(node) && !import_ts_morph12.Node.isCallExpression(node)) {
2434
+ if (!import_ts_morph12.Node.isPropertyAccessExpression(node) && !import_ts_morph12.Node.isCallExpression(node) && !import_ts_morph12.Node.isTaggedTemplateExpression(node)) {
2435
2435
  return;
2436
2436
  }
2437
2437
  const ctx = {
@@ -4005,10 +4005,59 @@ function writesToBindingUncached(declaration) {
4005
4005
  }
4006
4006
  return { values, inOrder: writesRunInOrder(declaration, writes) };
4007
4007
  }
4008
+ function writesToField(declaration) {
4009
+ const remembered = byDeclaration.get(declaration);
4010
+ if (remembered !== void 0) {
4011
+ return remembered;
4012
+ }
4013
+ const answer = writesToFieldUncached(declaration);
4014
+ byDeclaration.set(declaration, answer);
4015
+ return answer;
4016
+ }
4017
+ function writesToFieldUncached(declaration) {
4018
+ const initializer = declaration.getInitializer();
4019
+ const assignments = assignmentsTo(declaration);
4020
+ if (assignments.length === 0) {
4021
+ return {
4022
+ values: initializer === void 0 ? [] : [initializer],
4023
+ inOrder: true
4024
+ };
4025
+ }
4026
+ const values = [];
4027
+ for (const write of assignments) {
4028
+ if (write.value === null) {
4029
+ return { values: [], inOrder: false };
4030
+ }
4031
+ values.push(write.value);
4032
+ }
4033
+ const withInitializer = initializer === void 0 ? values : [initializer, ...values];
4034
+ return {
4035
+ values: withInitializer,
4036
+ inOrder: assignments.every(
4037
+ (write) => writeRunsInConstructor(declaration, write)
4038
+ )
4039
+ };
4040
+ }
4041
+ function writeRunsInConstructor(declaration, write) {
4042
+ const statement = statementOf(write.node);
4043
+ if (statement === null) {
4044
+ return false;
4045
+ }
4046
+ const body = statement.getParent();
4047
+ if (body === void 0 || !import_ts_morph18.Node.isBlock(body)) {
4048
+ return false;
4049
+ }
4050
+ const owner = body.getParent();
4051
+ return owner !== void 0 && import_ts_morph18.Node.isConstructorDeclaration(owner) && owner.getParent() === declaration.getParent();
4052
+ }
4008
4053
  function isWrittenAgain(declaration) {
4009
4054
  return assignmentsTo(declaration).length > 0;
4010
4055
  }
4011
4056
  function assignmentsTo(declaration) {
4057
+ if (import_ts_morph18.Node.isPropertyDeclaration(declaration)) {
4058
+ const sourceFile2 = declaration.getSourceFile();
4059
+ return sourceFile2.isDeclarationFile() ? [] : assignmentsInFile(sourceFile2).get(declaration) ?? [];
4060
+ }
4012
4061
  if (declaration.getVariableStatement()?.getDeclarationKind() === import_ts_morph18.VariableDeclarationKind.Const) {
4013
4062
  return [];
4014
4063
  }
@@ -4048,7 +4097,7 @@ function writeAt(node) {
4048
4097
  if (import_ts_morph18.Node.isBinaryExpression(node)) {
4049
4098
  const operator = node.getOperatorToken().getKind();
4050
4099
  const target = node.getLeft();
4051
- if (!isAssignmentOperator(operator) || !import_ts_morph18.Node.isIdentifier(target)) {
4100
+ if (!isAssignmentOperator(operator) || !(import_ts_morph18.Node.isIdentifier(target) || import_ts_morph18.Node.isPropertyAccessExpression(target))) {
4052
4101
  return null;
4053
4102
  }
4054
4103
  const value = operator === import_ts_morph18.SyntaxKind.EqualsToken ? node.getRight() : null;
@@ -4065,13 +4114,14 @@ function writeAt(node) {
4065
4114
  return null;
4066
4115
  }
4067
4116
  function declarationsOf(name) {
4068
- const symbol = name.getSymbol();
4117
+ const nameNode = import_ts_morph18.Node.isPropertyAccessExpression(name) ? name.getNameNode() : name;
4118
+ const symbol = nameNode.getSymbol();
4069
4119
  if (symbol === void 0) {
4070
4120
  return [];
4071
4121
  }
4072
4122
  const declarations = [];
4073
4123
  for (const declaration of symbol.getDeclarations()) {
4074
- if (import_ts_morph18.Node.isVariableDeclaration(declaration)) {
4124
+ if (import_ts_morph18.Node.isVariableDeclaration(declaration) || import_ts_morph18.Node.isPropertyDeclaration(declaration)) {
4075
4125
  declarations.push(declaration);
4076
4126
  }
4077
4127
  }
@@ -6093,6 +6143,14 @@ function emitBindingValues(db, table, declaration) {
6093
6143
  }
6094
6144
  fact(db, "endsHolding", declarationId, emitValue(db, table, last));
6095
6145
  }
6146
+ function emitFieldValues(db, table, declaration) {
6147
+ const { values, inOrder } = writesToField(declaration);
6148
+ const last = values[values.length - 1];
6149
+ if (!inOrder || last === void 0) {
6150
+ return;
6151
+ }
6152
+ fact(db, "binds", nodeId(declaration), emitValue(db, table, last));
6153
+ }
6096
6154
  function emitBindingElementFacts(db, table, element) {
6097
6155
  const id = nodeId(element);
6098
6156
  table.byId.set(id, element);
@@ -6168,6 +6226,11 @@ function emitReferenceFacts(db, table, reference) {
6168
6226
  emitBindingValues(db, table, declaration);
6169
6227
  continue;
6170
6228
  }
6229
+ if (import_ts_morph28.Node.isPropertyDeclaration(declaration)) {
6230
+ fact(db, "binds", referenceId, declarationId);
6231
+ emitFieldValues(db, table, declaration);
6232
+ continue;
6233
+ }
6171
6234
  if (import_ts_morph28.Node.isParameterDeclaration(declaration)) {
6172
6235
  fact(db, "binds", referenceId, declarationId);
6173
6236
  continue;
@@ -8657,6 +8720,9 @@ function trackFactoryBindings(sourceFile, recognize) {
8657
8720
  }
8658
8721
 
8659
8722
  // src/discovery/packageImport.ts
8723
+ function isLanguageLib(file) {
8724
+ return /[\\/]typescript[\\/]lib[\\/]lib\..*\.d\.ts$/.test(file.getFilePath());
8725
+ }
8660
8726
  function splitPackageSpec(spec) {
8661
8727
  if (spec.startsWith("@")) {
8662
8728
  const parts2 = spec.split("/");
@@ -8774,6 +8840,9 @@ function discoverPackageImports(sourceFile, match, kind) {
8774
8840
  if (subjectProvenance === null) {
8775
8841
  return null;
8776
8842
  }
8843
+ if (!methodComesFromSource(callee)) {
8844
+ return subjectProvenance;
8845
+ }
8777
8846
  return {
8778
8847
  packageName: subjectProvenance.packageName,
8779
8848
  exportPath: [...subjectProvenance.exportPath, callee.getName()]
@@ -8781,6 +8850,15 @@ function discoverPackageImports(sourceFile, match, kind) {
8781
8850
  }
8782
8851
  return null;
8783
8852
  }
8853
+ function methodComesFromSource(callee) {
8854
+ const declarations = callee.getNameNode().getSymbol()?.getDeclarations();
8855
+ if (declarations === void 0 || declarations.length === 0) {
8856
+ return true;
8857
+ }
8858
+ return declarations.some(
8859
+ (declaration) => !isLanguageLib(declaration.getSourceFile())
8860
+ );
8861
+ }
8784
8862
  const results = [];
8785
8863
  const seen = /* @__PURE__ */ new Set();
8786
8864
  sourceFile.forEachDescendant((node) => {
@@ -10381,8 +10459,8 @@ function bindingLabel(binding) {
10381
10459
  if (semantics.name === "rest") {
10382
10460
  return `${semantics.method} ${semantics.path}`;
10383
10461
  }
10384
- if (semantics.name === "storage-relational") {
10385
- return `${semantics.storageSystem}:${semantics.table}`;
10462
+ if (semantics.name === "storage") {
10463
+ return `${semantics.storageSystem}:${semantics.container}`;
10386
10464
  }
10387
10465
  if (semantics.name === "message-bus") {
10388
10466
  return `${semantics.messageBus}:${semantics.channel}`;
@@ -10616,7 +10694,9 @@ function extractReachableSummary(candidate, options, recognizers) {
10616
10694
  unit,
10617
10695
  reachablePack,
10618
10696
  recognizers.invocation,
10619
- recognizers.access
10697
+ recognizers.access,
10698
+ void 0,
10699
+ recognizers.resolveWrittenValue
10620
10700
  );
10621
10701
  raw.boundaryBinding = (0, import_behavioral_ir4.functionCallBinding)({
10622
10702
  transport: "in-process",
@@ -13056,7 +13136,8 @@ function createTypeScriptAdapter(config) {
13056
13136
  config.frameworks,
13057
13137
  tallies
13058
13138
  ),
13059
- access: collectAccessRecognizers(config.frameworks, tallies)
13139
+ access: collectAccessRecognizers(config.frameworks, tallies),
13140
+ resolveWrittenValue: (value) => resolution.resolveWrittenValue(value)
13060
13141
  }
13061
13142
  )
13062
13143
  ) : withSubUnits;
package/dist/index.js CHANGED
@@ -2394,7 +2394,7 @@ function dispatchAccessRecognizers(root, recognizers, isStop, resolveWrittenValu
2394
2394
  traversal.skip();
2395
2395
  return;
2396
2396
  }
2397
- if (!Node11.isPropertyAccessExpression(node) && !Node11.isCallExpression(node)) {
2397
+ if (!Node11.isPropertyAccessExpression(node) && !Node11.isCallExpression(node) && !Node11.isTaggedTemplateExpression(node)) {
2398
2398
  return;
2399
2399
  }
2400
2400
  const ctx = {
@@ -3975,10 +3975,59 @@ function writesToBindingUncached(declaration) {
3975
3975
  }
3976
3976
  return { values, inOrder: writesRunInOrder(declaration, writes) };
3977
3977
  }
3978
+ function writesToField(declaration) {
3979
+ const remembered = byDeclaration.get(declaration);
3980
+ if (remembered !== void 0) {
3981
+ return remembered;
3982
+ }
3983
+ const answer = writesToFieldUncached(declaration);
3984
+ byDeclaration.set(declaration, answer);
3985
+ return answer;
3986
+ }
3987
+ function writesToFieldUncached(declaration) {
3988
+ const initializer = declaration.getInitializer();
3989
+ const assignments = assignmentsTo(declaration);
3990
+ if (assignments.length === 0) {
3991
+ return {
3992
+ values: initializer === void 0 ? [] : [initializer],
3993
+ inOrder: true
3994
+ };
3995
+ }
3996
+ const values = [];
3997
+ for (const write of assignments) {
3998
+ if (write.value === null) {
3999
+ return { values: [], inOrder: false };
4000
+ }
4001
+ values.push(write.value);
4002
+ }
4003
+ const withInitializer = initializer === void 0 ? values : [initializer, ...values];
4004
+ return {
4005
+ values: withInitializer,
4006
+ inOrder: assignments.every(
4007
+ (write) => writeRunsInConstructor(declaration, write)
4008
+ )
4009
+ };
4010
+ }
4011
+ function writeRunsInConstructor(declaration, write) {
4012
+ const statement = statementOf(write.node);
4013
+ if (statement === null) {
4014
+ return false;
4015
+ }
4016
+ const body = statement.getParent();
4017
+ if (body === void 0 || !Node17.isBlock(body)) {
4018
+ return false;
4019
+ }
4020
+ const owner = body.getParent();
4021
+ return owner !== void 0 && Node17.isConstructorDeclaration(owner) && owner.getParent() === declaration.getParent();
4022
+ }
3978
4023
  function isWrittenAgain(declaration) {
3979
4024
  return assignmentsTo(declaration).length > 0;
3980
4025
  }
3981
4026
  function assignmentsTo(declaration) {
4027
+ if (Node17.isPropertyDeclaration(declaration)) {
4028
+ const sourceFile2 = declaration.getSourceFile();
4029
+ return sourceFile2.isDeclarationFile() ? [] : assignmentsInFile(sourceFile2).get(declaration) ?? [];
4030
+ }
3982
4031
  if (declaration.getVariableStatement()?.getDeclarationKind() === VariableDeclarationKind.Const) {
3983
4032
  return [];
3984
4033
  }
@@ -4018,7 +4067,7 @@ function writeAt(node) {
4018
4067
  if (Node17.isBinaryExpression(node)) {
4019
4068
  const operator = node.getOperatorToken().getKind();
4020
4069
  const target = node.getLeft();
4021
- if (!isAssignmentOperator(operator) || !Node17.isIdentifier(target)) {
4070
+ if (!isAssignmentOperator(operator) || !(Node17.isIdentifier(target) || Node17.isPropertyAccessExpression(target))) {
4022
4071
  return null;
4023
4072
  }
4024
4073
  const value = operator === SyntaxKind5.EqualsToken ? node.getRight() : null;
@@ -4035,13 +4084,14 @@ function writeAt(node) {
4035
4084
  return null;
4036
4085
  }
4037
4086
  function declarationsOf(name) {
4038
- const symbol = name.getSymbol();
4087
+ const nameNode = Node17.isPropertyAccessExpression(name) ? name.getNameNode() : name;
4088
+ const symbol = nameNode.getSymbol();
4039
4089
  if (symbol === void 0) {
4040
4090
  return [];
4041
4091
  }
4042
4092
  const declarations = [];
4043
4093
  for (const declaration of symbol.getDeclarations()) {
4044
- if (Node17.isVariableDeclaration(declaration)) {
4094
+ if (Node17.isVariableDeclaration(declaration) || Node17.isPropertyDeclaration(declaration)) {
4045
4095
  declarations.push(declaration);
4046
4096
  }
4047
4097
  }
@@ -6070,6 +6120,14 @@ function emitBindingValues(db, table, declaration) {
6070
6120
  }
6071
6121
  fact(db, "endsHolding", declarationId, emitValue(db, table, last));
6072
6122
  }
6123
+ function emitFieldValues(db, table, declaration) {
6124
+ const { values, inOrder } = writesToField(declaration);
6125
+ const last = values[values.length - 1];
6126
+ if (!inOrder || last === void 0) {
6127
+ return;
6128
+ }
6129
+ fact(db, "binds", nodeId(declaration), emitValue(db, table, last));
6130
+ }
6073
6131
  function emitBindingElementFacts(db, table, element) {
6074
6132
  const id = nodeId(element);
6075
6133
  table.byId.set(id, element);
@@ -6145,6 +6203,11 @@ function emitReferenceFacts(db, table, reference) {
6145
6203
  emitBindingValues(db, table, declaration);
6146
6204
  continue;
6147
6205
  }
6206
+ if (Node26.isPropertyDeclaration(declaration)) {
6207
+ fact(db, "binds", referenceId, declarationId);
6208
+ emitFieldValues(db, table, declaration);
6209
+ continue;
6210
+ }
6148
6211
  if (Node26.isParameterDeclaration(declaration)) {
6149
6212
  fact(db, "binds", referenceId, declarationId);
6150
6213
  continue;
@@ -8640,6 +8703,9 @@ function trackFactoryBindings(sourceFile, recognize) {
8640
8703
  }
8641
8704
 
8642
8705
  // src/discovery/packageImport.ts
8706
+ function isLanguageLib(file) {
8707
+ return /[\\/]typescript[\\/]lib[\\/]lib\..*\.d\.ts$/.test(file.getFilePath());
8708
+ }
8643
8709
  function splitPackageSpec(spec) {
8644
8710
  if (spec.startsWith("@")) {
8645
8711
  const parts2 = spec.split("/");
@@ -8757,6 +8823,9 @@ function discoverPackageImports(sourceFile, match, kind) {
8757
8823
  if (subjectProvenance === null) {
8758
8824
  return null;
8759
8825
  }
8826
+ if (!methodComesFromSource(callee)) {
8827
+ return subjectProvenance;
8828
+ }
8760
8829
  return {
8761
8830
  packageName: subjectProvenance.packageName,
8762
8831
  exportPath: [...subjectProvenance.exportPath, callee.getName()]
@@ -8764,6 +8833,15 @@ function discoverPackageImports(sourceFile, match, kind) {
8764
8833
  }
8765
8834
  return null;
8766
8835
  }
8836
+ function methodComesFromSource(callee) {
8837
+ const declarations = callee.getNameNode().getSymbol()?.getDeclarations();
8838
+ if (declarations === void 0 || declarations.length === 0) {
8839
+ return true;
8840
+ }
8841
+ return declarations.some(
8842
+ (declaration) => !isLanguageLib(declaration.getSourceFile())
8843
+ );
8844
+ }
8767
8845
  const results = [];
8768
8846
  const seen = /* @__PURE__ */ new Set();
8769
8847
  sourceFile.forEachDescendant((node) => {
@@ -10381,8 +10459,8 @@ function bindingLabel(binding) {
10381
10459
  if (semantics.name === "rest") {
10382
10460
  return `${semantics.method} ${semantics.path}`;
10383
10461
  }
10384
- if (semantics.name === "storage-relational") {
10385
- return `${semantics.storageSystem}:${semantics.table}`;
10462
+ if (semantics.name === "storage") {
10463
+ return `${semantics.storageSystem}:${semantics.container}`;
10386
10464
  }
10387
10465
  if (semantics.name === "message-bus") {
10388
10466
  return `${semantics.messageBus}:${semantics.channel}`;
@@ -10616,7 +10694,9 @@ function extractReachableSummary(candidate, options, recognizers) {
10616
10694
  unit,
10617
10695
  reachablePack,
10618
10696
  recognizers.invocation,
10619
- recognizers.access
10697
+ recognizers.access,
10698
+ void 0,
10699
+ recognizers.resolveWrittenValue
10620
10700
  );
10621
10701
  raw.boundaryBinding = functionCallBinding({
10622
10702
  transport: "in-process",
@@ -13062,7 +13142,8 @@ function createTypeScriptAdapter(config) {
13062
13142
  config.frameworks,
13063
13143
  tallies
13064
13144
  ),
13065
- access: collectAccessRecognizers(config.frameworks, tallies)
13145
+ access: collectAccessRecognizers(config.frameworks, tallies),
13146
+ resolveWrittenValue: (value) => resolution.resolveWrittenValue(value)
13066
13147
  }
13067
13148
  )
13068
13149
  ) : withSubUnits;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/adapter-typescript",
3
- "version": "0.5.11",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "TypeScript adapter for suss — walks source files with ts-morph and emits raw extractions for the suss pipeline.",
6
6
  "keywords": [
@@ -46,10 +46,10 @@
46
46
  "typecheck": "tsc --noEmit"
47
47
  },
48
48
  "dependencies": {
49
- "@suss/behavioral-ir": "0.5.11",
50
- "@suss/datalog": "0.5.11",
51
- "@suss/extractor": "0.5.11",
52
- "@suss/resolution": "0.5.11",
49
+ "@suss/behavioral-ir": "0.6.0",
50
+ "@suss/datalog": "0.6.0",
51
+ "@suss/extractor": "0.6.0",
52
+ "@suss/resolution": "0.6.0",
53
53
  "graphql": "^16.8.0",
54
54
  "picomatch": "^4.0.4",
55
55
  "ts-morph": "^23.0.0"