@suss/resolution 0.7.1 → 0.8.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
@@ -123,6 +123,26 @@ var FACT_CONTRACT_CASES = [
123
123
  return contained.some((row) => functions.has(row[2])) ? null : "what a class contains under a method name is not the node that declares the method";
124
124
  }
125
125
  },
126
+ {
127
+ name: "a class constructed with an argument",
128
+ requires: "a module-level class whose constructor takes one parameter, and a site that makes one of it, passing a name",
129
+ // However a language writes construction, it is a call of the class, and
130
+ // the constructor's parameters are the class's. Keying them on the
131
+ // constructor instead leaves the argument with nowhere to land.
132
+ check: (facts) => {
133
+ const classes = new Set(facts("objectValue").map((row) => row[0] ?? ""));
134
+ const parameters = facts("paramOf").filter(
135
+ (row) => classes.has(row[0] ?? "")
136
+ );
137
+ if (parameters.length === 0) {
138
+ return "a class lists none of its constructor's parameters, so an argument a construction site passes reaches nothing";
139
+ }
140
+ if (facts("call").length === 0) {
141
+ return "making one of a class is not written down as a call, so nothing says which class a construction arrives at";
142
+ }
143
+ return facts("callArg").length > 0 ? null : "a construction passes its argument nowhere, so the parameter it lands in has no value";
144
+ }
145
+ },
126
146
  {
127
147
  name: "a value another file declares",
128
148
  requires: "two files, one declaring a value and the other reading it by name",
@@ -276,6 +296,18 @@ var RESOLUTION_RULES = [
276
296
  (0, import_datalog.lit)("call", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("c"))
277
297
  ]
278
298
  ),
299
+ // The same, for a language whose adapter writes the import down as a
300
+ // declaration and the call's callee as the name referring to it.
301
+ (0, import_datalog.rule)(
302
+ "callsFunction",
303
+ [(0, import_datalog.variable)("r"), (0, import_datalog.variable)("f")],
304
+ [
305
+ (0, import_datalog.lit)("moduleExport", (0, import_datalog.variable)("m"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("f")),
306
+ (0, import_datalog.lit)("imports", (0, import_datalog.variable)("d"), (0, import_datalog.variable)("m"), (0, import_datalog.variable)("n")),
307
+ (0, import_datalog.lit)("binds", (0, import_datalog.variable)("c"), (0, import_datalog.variable)("d")),
308
+ (0, import_datalog.lit)("call", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("c"))
309
+ ]
310
+ ),
279
311
  // A function whose return is itself a call arrives at the same object
280
312
  // that call does, so a chain passing through two factories settles.
281
313
  (0, import_datalog.rule)(
package/dist/index.js CHANGED
@@ -93,6 +93,26 @@ var FACT_CONTRACT_CASES = [
93
93
  return contained.some((row) => functions.has(row[2])) ? null : "what a class contains under a method name is not the node that declares the method";
94
94
  }
95
95
  },
96
+ {
97
+ name: "a class constructed with an argument",
98
+ requires: "a module-level class whose constructor takes one parameter, and a site that makes one of it, passing a name",
99
+ // However a language writes construction, it is a call of the class, and
100
+ // the constructor's parameters are the class's. Keying them on the
101
+ // constructor instead leaves the argument with nowhere to land.
102
+ check: (facts) => {
103
+ const classes = new Set(facts("objectValue").map((row) => row[0] ?? ""));
104
+ const parameters = facts("paramOf").filter(
105
+ (row) => classes.has(row[0] ?? "")
106
+ );
107
+ if (parameters.length === 0) {
108
+ return "a class lists none of its constructor's parameters, so an argument a construction site passes reaches nothing";
109
+ }
110
+ if (facts("call").length === 0) {
111
+ return "making one of a class is not written down as a call, so nothing says which class a construction arrives at";
112
+ }
113
+ return facts("callArg").length > 0 ? null : "a construction passes its argument nowhere, so the parameter it lands in has no value";
114
+ }
115
+ },
96
116
  {
97
117
  name: "a value another file declares",
98
118
  requires: "two files, one declaring a value and the other reading it by name",
@@ -246,6 +266,18 @@ var RESOLUTION_RULES = [
246
266
  lit("call", v("r"), v("c"))
247
267
  ]
248
268
  ),
269
+ // The same, for a language whose adapter writes the import down as a
270
+ // declaration and the call's callee as the name referring to it.
271
+ rule(
272
+ "callsFunction",
273
+ [v("r"), v("f")],
274
+ [
275
+ lit("moduleExport", v("m"), v("n"), v("f")),
276
+ lit("imports", v("d"), v("m"), v("n")),
277
+ lit("binds", v("c"), v("d")),
278
+ lit("call", v("r"), v("c"))
279
+ ]
280
+ ),
249
281
  // A function whose return is itself a call arrives at the same object
250
282
  // that call does, so a chain passing through two factories settles.
251
283
  rule(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/resolution",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "description": "Language-neutral rules for following a value to the function it comes down to.",
6
6
  "keywords": [
@@ -53,6 +53,6 @@
53
53
  "access": "public"
54
54
  },
55
55
  "dependencies": {
56
- "@suss/datalog": "0.7.1"
56
+ "@suss/datalog": "0.8.0"
57
57
  }
58
58
  }