@suss/adapter-python 0.13.0 → 0.13.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.
package/dist/index.cjs CHANGED
@@ -642,18 +642,25 @@ function resolveObjectModule(name, scope) {
642
642
  }
643
643
  if (binding?.kind === "assignment" && binding.value?.type === "call") {
644
644
  const callee = field(binding.value, "function");
645
- if (callee?.type === "identifier") {
646
- const calleeBinding = resolveName(scope, callee.text);
647
- if (calleeBinding?.kind === "importFrom") {
648
- return {
649
- module: calleeBinding.module,
650
- relativeLevel: calleeBinding.relativeLevel
651
- };
652
- }
653
- }
645
+ return callee === null ? null : calleeModule(callee, scope);
654
646
  }
655
647
  return null;
656
648
  }
649
+ function calleeModule(callee, scope) {
650
+ if (callee.type === "identifier") {
651
+ const binding2 = resolveName(scope, callee.text);
652
+ return binding2?.kind === "importFrom" ? { module: binding2.module, relativeLevel: binding2.relativeLevel } : null;
653
+ }
654
+ if (callee.type !== "attribute") {
655
+ return null;
656
+ }
657
+ const object2 = field(callee, "object");
658
+ if (object2?.type !== "identifier") {
659
+ return null;
660
+ }
661
+ const binding = resolveName(scope, object2.text);
662
+ return binding?.kind === "import" ? { module: binding.module, relativeLevel: binding.relativeLevel } : null;
663
+ }
657
664
  function resolveCallee(expr, scope) {
658
665
  if (expr.type === "identifier") {
659
666
  const binding = resolveName(scope, expr.text);
@@ -18796,14 +18803,11 @@ function constructionOf(name, scope, importModule) {
18796
18803
  return null;
18797
18804
  }
18798
18805
  const callee = field(binding.value, "function");
18799
- if (callee?.type !== "identifier") {
18800
- return null;
18801
- }
18802
- const calleeBinding = resolveName(scope, callee.text);
18803
- if (calleeBinding?.kind !== "importFrom" || !importModule.includes(calleeBinding.module)) {
18806
+ if (callee === null) {
18804
18807
  return null;
18805
18808
  }
18806
- return { constructorName: calleeBinding.importedName, call: binding.value };
18809
+ const constructorName = importedConstructorName(callee, scope, importModule);
18810
+ return constructorName === null ? null : { constructorName, call: binding.value };
18807
18811
  }
18808
18812
  var PREFIX_TRAILING_SLASH_READERS = {
18809
18813
  kept: (prefix) => prefix,
@@ -18815,7 +18819,20 @@ var NO_VALUE_LITERALS = {
18815
18819
  boolean: (arg) => arg.kind === "boolean" && !arg.value,
18816
18820
  none: () => true
18817
18821
  };
18818
- function readPrefixKeyword(keywordArgs, keyword, composition) {
18822
+ function prefixStringOf(arg, scope) {
18823
+ if (arg.kind === "string") {
18824
+ return arg.value;
18825
+ }
18826
+ if (arg.kind !== "identifier" || scope === void 0) {
18827
+ return null;
18828
+ }
18829
+ const binding = resolveName(scope, arg.name);
18830
+ if (binding === null || binding.kind !== "assignment" || binding.value === null) {
18831
+ return null;
18832
+ }
18833
+ return stringLiteralValue(binding.value);
18834
+ }
18835
+ function readPrefixKeyword(keywordArgs, keyword, composition, scope) {
18819
18836
  const arg = keywordArgs[keyword];
18820
18837
  if (arg === void 0) {
18821
18838
  return UNSTATED_PREFIX;
@@ -18823,16 +18840,15 @@ function readPrefixKeyword(keywordArgs, keyword, composition) {
18823
18840
  if ((composition.noValuePrefix ?? "unreadable") === "unstated" && NO_VALUE_LITERALS[arg.kind]?.(arg) === true) {
18824
18841
  return UNSTATED_PREFIX;
18825
18842
  }
18826
- if (arg.kind === "string") {
18827
- return { kind: "stated", value: arg.value };
18828
- }
18829
- return UNREADABLE_PREFIX;
18843
+ const value = prefixStringOf(arg, scope);
18844
+ return value === null ? UNREADABLE_PREFIX : { kind: "stated", value };
18830
18845
  }
18831
- function constructorPrefix(keywordArgs, composition) {
18846
+ function constructorPrefix(keywordArgs, composition, scope) {
18832
18847
  const reading = readPrefixKeyword(
18833
18848
  keywordArgs,
18834
18849
  composition.prefixKeyword,
18835
- composition
18850
+ composition,
18851
+ scope
18836
18852
  );
18837
18853
  if (reading.kind !== "stated") {
18838
18854
  return reading;
@@ -18859,18 +18875,36 @@ function constructionStatement(stmt, scope, importModule) {
18859
18875
  return null;
18860
18876
  }
18861
18877
  const callee = field(right, "function");
18862
- if (callee?.type !== "identifier") {
18878
+ if (callee === null) {
18863
18879
  return null;
18864
18880
  }
18865
- const calleeBinding = resolveName(scope, callee.text);
18866
- if (calleeBinding?.kind !== "importFrom" || !importModule.includes(calleeBinding.module)) {
18881
+ const constructorName = importedConstructorName(callee, scope, importModule);
18882
+ if (constructorName === null) {
18867
18883
  return null;
18868
18884
  }
18869
- return {
18870
- name: left.text,
18871
- constructorName: calleeBinding.importedName,
18872
- call: right
18873
- };
18885
+ return { name: left.text, constructorName, call: right };
18886
+ }
18887
+ function importedConstructorName(callee, scope, importModule) {
18888
+ if (callee.type === "identifier") {
18889
+ const binding2 = resolveName(scope, callee.text);
18890
+ if (binding2?.kind !== "importFrom" || !importModule.includes(binding2.module)) {
18891
+ return null;
18892
+ }
18893
+ return binding2.importedName;
18894
+ }
18895
+ if (callee.type !== "attribute") {
18896
+ return null;
18897
+ }
18898
+ const object2 = field(callee, "object");
18899
+ const attribute = field(callee, "attribute");
18900
+ if (object2?.type !== "identifier" || attribute?.type !== "identifier") {
18901
+ return null;
18902
+ }
18903
+ const binding = resolveName(scope, object2.text);
18904
+ if (binding?.kind !== "import" || !importModule.includes(binding.module)) {
18905
+ return null;
18906
+ }
18907
+ return attribute.text;
18874
18908
  }
18875
18909
  function recordConstruction(construction, module2, file2, prefixOf, into, byValueKey) {
18876
18910
  const perModule = into.get(module2) ?? /* @__PURE__ */ new Map();
@@ -18906,7 +18940,7 @@ function collectConstructions(bound, importModule, composition, index) {
18906
18940
  construction,
18907
18941
  bound.module,
18908
18942
  bound.file,
18909
- (keywordArgs) => constructorPrefix(keywordArgs, composition),
18943
+ (keywordArgs) => constructorPrefix(keywordArgs, composition, bound.module.moduleScope),
18910
18944
  index.constructions,
18911
18945
  index.byValueKey
18912
18946
  );
@@ -18930,7 +18964,12 @@ function collectCarrierConstructions(carrier, composition, scan) {
18930
18964
  construction,
18931
18965
  scan.bound.module,
18932
18966
  scan.bound.file,
18933
- (keywordArgs) => readPrefixKeyword(keywordArgs, carrier.prefixKeyword, composition),
18967
+ (keywordArgs) => readPrefixKeyword(
18968
+ keywordArgs,
18969
+ carrier.prefixKeyword,
18970
+ composition,
18971
+ scan.bound.module.moduleScope
18972
+ ),
18934
18973
  scan.index.carriers,
18935
18974
  scan.index.byValueKey
18936
18975
  );
@@ -19249,14 +19288,15 @@ function recordMountStatement(stmt, position, scan) {
19249
19288
  keywordArgs,
19250
19289
  objectPrefix,
19251
19290
  scan.composition,
19252
- position.site
19291
+ position.site,
19292
+ position.scope
19253
19293
  );
19254
19294
  const mounted = args[0] ?? (scan.composition.routerKeyword === void 0 ? void 0 : keywordArgs[scan.composition.routerKeyword]);
19255
19295
  for (const target of mountedConstructions(mounted, position, scan)) {
19256
19296
  recordMount(scan.index, target, state);
19257
19297
  }
19258
19298
  }
19259
- function mountStateOf(includerConstructorName, keywordArgs, objectPrefix, composition, site) {
19299
+ function mountStateOf(includerConstructorName, keywordArgs, objectPrefix, composition, site, scope) {
19260
19300
  if (includerConstructorName === composition.routerConstructorName) {
19261
19301
  return {
19262
19302
  kind: "abstain",
@@ -19272,7 +19312,8 @@ function mountStateOf(includerConstructorName, keywordArgs, objectPrefix, compos
19272
19312
  const mountPrefix = readPrefixKeyword(
19273
19313
  keywordArgs,
19274
19314
  composition.prefixKeyword,
19275
- composition
19315
+ composition,
19316
+ scope
19276
19317
  );
19277
19318
  if (mountPrefix.kind === "unreadable") {
19278
19319
  return {
@@ -19428,7 +19469,12 @@ function readMountObjectPrefix(spec, objectName, constructionCall, scope, scan)
19428
19469
  const { args, keywordArgs } = readCallArguments(
19429
19470
  field(constructionCall, "arguments")
19430
19471
  );
19431
- const own = spec.prefixKeyword === void 0 ? UNSTATED_PREFIX : readPrefixKeyword(keywordArgs, spec.prefixKeyword, scan.composition);
19472
+ const own = spec.prefixKeyword === void 0 ? UNSTATED_PREFIX : readPrefixKeyword(
19473
+ keywordArgs,
19474
+ spec.prefixKeyword,
19475
+ scan.composition,
19476
+ scan.bound.module.moduleScope
19477
+ );
19432
19478
  if (own.kind === "unreadable") {
19433
19479
  return {
19434
19480
  kind: "abstain",
package/dist/index.js CHANGED
@@ -588,18 +588,25 @@ function resolveObjectModule(name, scope) {
588
588
  }
589
589
  if (binding?.kind === "assignment" && binding.value?.type === "call") {
590
590
  const callee = field(binding.value, "function");
591
- if (callee?.type === "identifier") {
592
- const calleeBinding = resolveName(scope, callee.text);
593
- if (calleeBinding?.kind === "importFrom") {
594
- return {
595
- module: calleeBinding.module,
596
- relativeLevel: calleeBinding.relativeLevel
597
- };
598
- }
599
- }
591
+ return callee === null ? null : calleeModule(callee, scope);
600
592
  }
601
593
  return null;
602
594
  }
595
+ function calleeModule(callee, scope) {
596
+ if (callee.type === "identifier") {
597
+ const binding2 = resolveName(scope, callee.text);
598
+ return binding2?.kind === "importFrom" ? { module: binding2.module, relativeLevel: binding2.relativeLevel } : null;
599
+ }
600
+ if (callee.type !== "attribute") {
601
+ return null;
602
+ }
603
+ const object2 = field(callee, "object");
604
+ if (object2?.type !== "identifier") {
605
+ return null;
606
+ }
607
+ const binding = resolveName(scope, object2.text);
608
+ return binding?.kind === "import" ? { module: binding.module, relativeLevel: binding.relativeLevel } : null;
609
+ }
603
610
  function resolveCallee(expr, scope) {
604
611
  if (expr.type === "identifier") {
605
612
  const binding = resolveName(scope, expr.text);
@@ -18752,14 +18759,11 @@ function constructionOf(name, scope, importModule) {
18752
18759
  return null;
18753
18760
  }
18754
18761
  const callee = field(binding.value, "function");
18755
- if (callee?.type !== "identifier") {
18756
- return null;
18757
- }
18758
- const calleeBinding = resolveName(scope, callee.text);
18759
- if (calleeBinding?.kind !== "importFrom" || !importModule.includes(calleeBinding.module)) {
18762
+ if (callee === null) {
18760
18763
  return null;
18761
18764
  }
18762
- return { constructorName: calleeBinding.importedName, call: binding.value };
18765
+ const constructorName = importedConstructorName(callee, scope, importModule);
18766
+ return constructorName === null ? null : { constructorName, call: binding.value };
18763
18767
  }
18764
18768
  var PREFIX_TRAILING_SLASH_READERS = {
18765
18769
  kept: (prefix) => prefix,
@@ -18771,7 +18775,20 @@ var NO_VALUE_LITERALS = {
18771
18775
  boolean: (arg) => arg.kind === "boolean" && !arg.value,
18772
18776
  none: () => true
18773
18777
  };
18774
- function readPrefixKeyword(keywordArgs, keyword, composition) {
18778
+ function prefixStringOf(arg, scope) {
18779
+ if (arg.kind === "string") {
18780
+ return arg.value;
18781
+ }
18782
+ if (arg.kind !== "identifier" || scope === void 0) {
18783
+ return null;
18784
+ }
18785
+ const binding = resolveName(scope, arg.name);
18786
+ if (binding === null || binding.kind !== "assignment" || binding.value === null) {
18787
+ return null;
18788
+ }
18789
+ return stringLiteralValue(binding.value);
18790
+ }
18791
+ function readPrefixKeyword(keywordArgs, keyword, composition, scope) {
18775
18792
  const arg = keywordArgs[keyword];
18776
18793
  if (arg === void 0) {
18777
18794
  return UNSTATED_PREFIX;
@@ -18779,16 +18796,15 @@ function readPrefixKeyword(keywordArgs, keyword, composition) {
18779
18796
  if ((composition.noValuePrefix ?? "unreadable") === "unstated" && NO_VALUE_LITERALS[arg.kind]?.(arg) === true) {
18780
18797
  return UNSTATED_PREFIX;
18781
18798
  }
18782
- if (arg.kind === "string") {
18783
- return { kind: "stated", value: arg.value };
18784
- }
18785
- return UNREADABLE_PREFIX;
18799
+ const value = prefixStringOf(arg, scope);
18800
+ return value === null ? UNREADABLE_PREFIX : { kind: "stated", value };
18786
18801
  }
18787
- function constructorPrefix(keywordArgs, composition) {
18802
+ function constructorPrefix(keywordArgs, composition, scope) {
18788
18803
  const reading = readPrefixKeyword(
18789
18804
  keywordArgs,
18790
18805
  composition.prefixKeyword,
18791
- composition
18806
+ composition,
18807
+ scope
18792
18808
  );
18793
18809
  if (reading.kind !== "stated") {
18794
18810
  return reading;
@@ -18815,18 +18831,36 @@ function constructionStatement(stmt, scope, importModule) {
18815
18831
  return null;
18816
18832
  }
18817
18833
  const callee = field(right, "function");
18818
- if (callee?.type !== "identifier") {
18834
+ if (callee === null) {
18819
18835
  return null;
18820
18836
  }
18821
- const calleeBinding = resolveName(scope, callee.text);
18822
- if (calleeBinding?.kind !== "importFrom" || !importModule.includes(calleeBinding.module)) {
18837
+ const constructorName = importedConstructorName(callee, scope, importModule);
18838
+ if (constructorName === null) {
18823
18839
  return null;
18824
18840
  }
18825
- return {
18826
- name: left.text,
18827
- constructorName: calleeBinding.importedName,
18828
- call: right
18829
- };
18841
+ return { name: left.text, constructorName, call: right };
18842
+ }
18843
+ function importedConstructorName(callee, scope, importModule) {
18844
+ if (callee.type === "identifier") {
18845
+ const binding2 = resolveName(scope, callee.text);
18846
+ if (binding2?.kind !== "importFrom" || !importModule.includes(binding2.module)) {
18847
+ return null;
18848
+ }
18849
+ return binding2.importedName;
18850
+ }
18851
+ if (callee.type !== "attribute") {
18852
+ return null;
18853
+ }
18854
+ const object2 = field(callee, "object");
18855
+ const attribute = field(callee, "attribute");
18856
+ if (object2?.type !== "identifier" || attribute?.type !== "identifier") {
18857
+ return null;
18858
+ }
18859
+ const binding = resolveName(scope, object2.text);
18860
+ if (binding?.kind !== "import" || !importModule.includes(binding.module)) {
18861
+ return null;
18862
+ }
18863
+ return attribute.text;
18830
18864
  }
18831
18865
  function recordConstruction(construction, module, file2, prefixOf, into, byValueKey) {
18832
18866
  const perModule = into.get(module) ?? /* @__PURE__ */ new Map();
@@ -18862,7 +18896,7 @@ function collectConstructions(bound, importModule, composition, index) {
18862
18896
  construction,
18863
18897
  bound.module,
18864
18898
  bound.file,
18865
- (keywordArgs) => constructorPrefix(keywordArgs, composition),
18899
+ (keywordArgs) => constructorPrefix(keywordArgs, composition, bound.module.moduleScope),
18866
18900
  index.constructions,
18867
18901
  index.byValueKey
18868
18902
  );
@@ -18886,7 +18920,12 @@ function collectCarrierConstructions(carrier, composition, scan) {
18886
18920
  construction,
18887
18921
  scan.bound.module,
18888
18922
  scan.bound.file,
18889
- (keywordArgs) => readPrefixKeyword(keywordArgs, carrier.prefixKeyword, composition),
18923
+ (keywordArgs) => readPrefixKeyword(
18924
+ keywordArgs,
18925
+ carrier.prefixKeyword,
18926
+ composition,
18927
+ scan.bound.module.moduleScope
18928
+ ),
18890
18929
  scan.index.carriers,
18891
18930
  scan.index.byValueKey
18892
18931
  );
@@ -19205,14 +19244,15 @@ function recordMountStatement(stmt, position, scan) {
19205
19244
  keywordArgs,
19206
19245
  objectPrefix,
19207
19246
  scan.composition,
19208
- position.site
19247
+ position.site,
19248
+ position.scope
19209
19249
  );
19210
19250
  const mounted = args[0] ?? (scan.composition.routerKeyword === void 0 ? void 0 : keywordArgs[scan.composition.routerKeyword]);
19211
19251
  for (const target of mountedConstructions(mounted, position, scan)) {
19212
19252
  recordMount(scan.index, target, state);
19213
19253
  }
19214
19254
  }
19215
- function mountStateOf(includerConstructorName, keywordArgs, objectPrefix, composition, site) {
19255
+ function mountStateOf(includerConstructorName, keywordArgs, objectPrefix, composition, site, scope) {
19216
19256
  if (includerConstructorName === composition.routerConstructorName) {
19217
19257
  return {
19218
19258
  kind: "abstain",
@@ -19228,7 +19268,8 @@ function mountStateOf(includerConstructorName, keywordArgs, objectPrefix, compos
19228
19268
  const mountPrefix = readPrefixKeyword(
19229
19269
  keywordArgs,
19230
19270
  composition.prefixKeyword,
19231
- composition
19271
+ composition,
19272
+ scope
19232
19273
  );
19233
19274
  if (mountPrefix.kind === "unreadable") {
19234
19275
  return {
@@ -19384,7 +19425,12 @@ function readMountObjectPrefix(spec, objectName, constructionCall, scope, scan)
19384
19425
  const { args, keywordArgs } = readCallArguments(
19385
19426
  field(constructionCall, "arguments")
19386
19427
  );
19387
- const own = spec.prefixKeyword === void 0 ? UNSTATED_PREFIX : readPrefixKeyword(keywordArgs, spec.prefixKeyword, scan.composition);
19428
+ const own = spec.prefixKeyword === void 0 ? UNSTATED_PREFIX : readPrefixKeyword(
19429
+ keywordArgs,
19430
+ spec.prefixKeyword,
19431
+ scan.composition,
19432
+ scan.bound.module.moduleScope
19433
+ );
19388
19434
  if (own.kind === "unreadable") {
19389
19435
  return {
19390
19436
  kind: "abstain",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/adapter-python",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "type": "module",
5
5
  "description": "Python language adapter for suss — parses source with tree-sitter (WASM), resolves names with a lexical binder, and emits raw extractions for the suss pipeline.",
6
6
  "keywords": [
@@ -47,10 +47,10 @@
47
47
  "typecheck": "tsc --noEmit"
48
48
  },
49
49
  "dependencies": {
50
- "@suss/behavioral-ir": "0.13.0",
51
- "@suss/datalog": "0.13.0",
52
- "@suss/extractor": "0.13.0",
53
- "@suss/sql": "0.13.0",
50
+ "@suss/behavioral-ir": "0.13.1",
51
+ "@suss/datalog": "0.13.1",
52
+ "@suss/extractor": "0.13.1",
53
+ "@suss/sql": "0.13.1",
54
54
  "web-tree-sitter": "^0.26.11"
55
55
  },
56
56
  "devDependencies": {