feat(javascript): report observed export property presence (#1160)
* feat(javascript): report observed export property presence Extend compare_javascript_export_shapes so each retained return variant lists observed property names and each change reports presence independently of value resolution. Complete parent coverage classifies one-sided names as added or removed even when static values stay unknown. Fixes #725 * test(javascript): match unknown export-shape values by availability Nested availability objects include a reason when values stay unresolved. Assert availability through objectContaining so presence-only added and removed rows still verify unknown values. * fix(javascript): preserve uncertain export property presence and locations * fix(javascript): normalize presence and preserve local property coverage * fix(javascript): require present discriminants for return pairing * fix(javascript): normalize retained shapes before comparison * refactor(javascript): share return projection with executable examples * fix(javascript): localize uncertainty for missing mutated slots * fix(javascript): bind advertised export examples to exact artifacts * fix(javascript): keep uncertain property flow as candidates --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -8,7 +8,10 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/javascript/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { compareJavaScriptExportShapes } from "../../../src/domain/javascript/javascriptExportShapeComparison.js";
|
||||
import { javaScriptExportShapeComparisonResultSchema } from "../../../src/domain/javascript/javascriptExportShapeComparisonSchemas.js";
|
||||
import {
|
||||
javaScriptExportShapeComparisonResultSchema,
|
||||
projectedExportReturnShapesSchema,
|
||||
} from "../../../src/domain/javascript/javascriptExportShapeComparisonSchemas.js";
|
||||
import {
|
||||
createJavaScriptApplicationGraph,
|
||||
createJavaScriptApplicationNode,
|
||||
@@ -53,6 +56,7 @@ describe("JavaScript export return-shape comparison", () => {
|
||||
status: "added",
|
||||
path: "/depth",
|
||||
discriminant: { path: "/type", value: "heading" },
|
||||
presence: { left: "absent", right: "present" },
|
||||
left: { availability: "absent" },
|
||||
right: { availability: "literal", value: 1 },
|
||||
}),
|
||||
@@ -83,7 +87,11 @@ describe("JavaScript export return-shape comparison", () => {
|
||||
const result = compare(left, right);
|
||||
|
||||
expect(result.changes).toEqual([
|
||||
expect.objectContaining({ status: "unknown", path: "/depth" }),
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
path: "/depth",
|
||||
presence: { left: "unknown-coverage", right: "present" },
|
||||
}),
|
||||
]);
|
||||
expect(result.coverage.status).toBe("partial");
|
||||
});
|
||||
@@ -102,6 +110,81 @@ describe("JavaScript export return-shape comparison", () => {
|
||||
expect(first.changes).toEqual(second.changes);
|
||||
expect(first.comparison_id).toBe(second.comparison_id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("JavaScript export return-shape pairing limits", () => {
|
||||
it.each([
|
||||
{ presence: "absent", side: "left" },
|
||||
{ presence: "unknown-coverage", side: "left" },
|
||||
{ presence: "absent", side: "right" },
|
||||
{ presence: "unknown-coverage", side: "right" },
|
||||
] as const)(
|
||||
"does not pair an inline $side discriminant whose presence is $presence",
|
||||
async ({ presence, side }) => {
|
||||
const [left, right] = await analyzeSources({
|
||||
left: 'export default () => ({ kind: "result", count: 1 });',
|
||||
right: 'export default () => ({ kind: "result", total: 2 });',
|
||||
});
|
||||
const selected = side === "left" ? left : right;
|
||||
const graph = createJavaScriptApplicationGraph({
|
||||
schema: "JavaScriptApplicationGraph",
|
||||
root_node_ids: selected.graph.root_node_ids,
|
||||
edges: selected.graph.edges,
|
||||
coverage: selected.graph.coverage,
|
||||
limitations: selected.graph.limitations,
|
||||
nodes: selected.graph.nodes.map((node) =>
|
||||
createJavaScriptApplicationNode({
|
||||
kind: node.kind,
|
||||
identity: node.identity,
|
||||
observations: node.observations.map(
|
||||
({ label, properties, evidence }) => ({
|
||||
label,
|
||||
evidence,
|
||||
properties:
|
||||
properties.semantic_role !== "export-return-shapes"
|
||||
? properties
|
||||
: {
|
||||
...properties,
|
||||
static_return_shapes: projectedExportReturnShapesSchema
|
||||
.parse(properties)
|
||||
.static_return_shapes.map((shape) => ({
|
||||
...shape,
|
||||
fields: shape.fields.map((field) =>
|
||||
field.path === "/kind"
|
||||
? { ...field, presence }
|
||||
: field,
|
||||
),
|
||||
})),
|
||||
},
|
||||
}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
});
|
||||
const result =
|
||||
side === "left"
|
||||
? compare({ ...left, graph }, right)
|
||||
: compare(left, { ...right, graph });
|
||||
expect(result.coverage).toMatchObject({
|
||||
status: "partial",
|
||||
paired_variants: 0,
|
||||
unpaired_left_variants: 1,
|
||||
unpaired_right_variants: 1,
|
||||
});
|
||||
expect(result.changes).toHaveLength(2);
|
||||
expect(
|
||||
result.changes.every(
|
||||
({ status, discriminant }) =>
|
||||
status === "unknown" && discriminant === null,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
result.property_inventories.every(
|
||||
({ paired, discriminant }) => !paired && discriminant === null,
|
||||
),
|
||||
).toBe(true);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not pair discriminants that an unknown trailing spread can overwrite", async () => {
|
||||
const [left, right] = await analyzeSources({
|
||||
@@ -172,6 +255,432 @@ describe("JavaScript export return-shape comparison", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("JavaScript export return-shape uncertain presence", () => {
|
||||
it.each([false, true])(
|
||||
"keeps deleted property presence unknown (reversed: %s)",
|
||||
async (reversed) => {
|
||||
const plain = 'export default () => ({ kind: "result" });';
|
||||
const mutated = `export default function make() {
|
||||
const result = { kind: "result", count: 1 };
|
||||
delete result.count;
|
||||
return result;
|
||||
}`;
|
||||
const graphs = await analyzeSources({
|
||||
left: reversed ? mutated : plain,
|
||||
right: reversed ? plain : mutated,
|
||||
});
|
||||
const result = compare(...graphs);
|
||||
expect(result.changes).toContainEqual(
|
||||
expect.objectContaining({
|
||||
path: "/count",
|
||||
status: "unknown",
|
||||
presence: reversed
|
||||
? { left: "unknown-coverage", right: "absent" }
|
||||
: { left: "absent", right: "unknown-coverage" },
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
inventoryProperties(result, reversed ? "left" : "right", 0),
|
||||
).not.toContain("/count");
|
||||
expect(result.summary.added + result.summary.removed).toBe(0);
|
||||
expect(result.coverage.status).toBe("partial");
|
||||
},
|
||||
);
|
||||
|
||||
it("excludes array holes while preserving observed unknown elements", async () => {
|
||||
const holes = 'export default () => ({ kind: "result", items: [,] });';
|
||||
const empty = await analyzeSources({
|
||||
left: holes,
|
||||
right: 'export default () => ({ kind: "result", items: [] });',
|
||||
});
|
||||
const result = compare(...empty);
|
||||
expect(result.coverage.status).toBe("complete-within-inputs");
|
||||
expect(inventoryProperties(result, "left", 0)).not.toContain("/items/0");
|
||||
expect(result.changes.some(({ path }) => path === "/items/0")).toBe(false);
|
||||
const filled = await analyzeSources({
|
||||
left: holes,
|
||||
right: 'export default () => ({ kind: "result", items: [call()] });',
|
||||
});
|
||||
expect(compare(...filled).changes).toContainEqual(
|
||||
expect.objectContaining({
|
||||
path: "/items/0",
|
||||
status: "added",
|
||||
presence: { left: "absent", right: "present" },
|
||||
left: { availability: "absent" },
|
||||
right: expect.objectContaining({ availability: "unknown" }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("retains unpaired inventory locations when the opposite export has no return", async () => {
|
||||
const graphs = await analyzeSources({
|
||||
left: "export default function f() {}",
|
||||
right: `export default function f(flag) {
|
||||
if (flag) return { count: call() };
|
||||
return { total: call() };
|
||||
}`,
|
||||
});
|
||||
const result = compare(...graphs);
|
||||
expect(result.property_inventories).toEqual([
|
||||
expect.objectContaining({
|
||||
side: "right",
|
||||
paired: false,
|
||||
variant_index: 0,
|
||||
properties: expect.arrayContaining(["/count"]),
|
||||
source_range: expect.objectContaining({
|
||||
start: expect.objectContaining({ line: 2 }),
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
side: "right",
|
||||
paired: false,
|
||||
variant_index: 1,
|
||||
properties: expect.arrayContaining(["/total"]),
|
||||
source_range: expect.objectContaining({
|
||||
start: expect.objectContaining({ line: 3 }),
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
expect(() =>
|
||||
javaScriptExportShapeComparisonResultSchema.parse(result),
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("JavaScript export matching uncertain projections", () => {
|
||||
it.each(["delete result.count;", "result.count = query();"])(
|
||||
"omits matching uncertain projections after %s",
|
||||
async (mutation) => {
|
||||
const source = `export default function make() {
|
||||
const result = { kind: "result", count: 1 };
|
||||
${mutation}
|
||||
return result;
|
||||
}`;
|
||||
const graphs = await analyzeSources({ left: source, right: source });
|
||||
const result = compare(...graphs);
|
||||
expect(result.changes).toEqual([]);
|
||||
expect(result.summary).toEqual({
|
||||
added: 0,
|
||||
removed: 0,
|
||||
changed: 0,
|
||||
unknown: 0,
|
||||
});
|
||||
expect(result.coverage.status).toBe("partial");
|
||||
expect(
|
||||
result.property_inventories.every(
|
||||
({ properties }) => !properties.includes("/count"),
|
||||
),
|
||||
).toBe(true);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("JavaScript export localized mutation uncertainty", () => {
|
||||
it.each([
|
||||
{
|
||||
initializer: '{ kind: "result", count: 1 }',
|
||||
mutation: "delete result.count;",
|
||||
uncertain: "/count",
|
||||
right: '{ kind: "result", total: 1 }',
|
||||
added: "/total",
|
||||
},
|
||||
{
|
||||
initializer: '{ kind: "result" }',
|
||||
mutation: "result.count = query();",
|
||||
uncertain: "/count",
|
||||
right: '{ kind: "result", total: 1 }',
|
||||
added: "/total",
|
||||
},
|
||||
{
|
||||
initializer: '{ kind: "result" }',
|
||||
mutation: "delete result.count;",
|
||||
uncertain: "/count",
|
||||
right: '{ kind: "result", total: 1 }',
|
||||
added: "/total",
|
||||
},
|
||||
{
|
||||
initializer: '{ kind: "result", nested: {} }',
|
||||
mutation: "result.nested.count = query();",
|
||||
uncertain: "/nested/count",
|
||||
right: '{ kind: "result", nested: { total: 1 } }',
|
||||
added: "/nested/total",
|
||||
},
|
||||
{
|
||||
initializer: '{ kind: "result", items: [] }',
|
||||
mutation: "result.items[1] = query();",
|
||||
uncertain: "/items/1",
|
||||
right: '{ kind: "result", items: [,,1] }',
|
||||
added: "/items/2",
|
||||
},
|
||||
{
|
||||
initializer: '{ kind: "result", items: [] }',
|
||||
mutation: "delete result.items[1];",
|
||||
uncertain: "/items/1",
|
||||
right: '{ kind: "result", items: [,,1] }',
|
||||
added: "/items/2",
|
||||
},
|
||||
{
|
||||
initializer: '{ kind: "result", items: [] }',
|
||||
mutation: "result.items[1000000000] = query();",
|
||||
uncertain: "/items/1000000000",
|
||||
right: '{ kind: "result", items: [,,1] }',
|
||||
added: "/items/2",
|
||||
},
|
||||
])(
|
||||
"localizes $mutation without losing sibling absence",
|
||||
async ({ initializer, mutation, uncertain, right, added }) => {
|
||||
const graphs = await analyzeSources({
|
||||
left: `export default function make() {
|
||||
const result = ${initializer};
|
||||
${mutation}
|
||||
return result;
|
||||
}`,
|
||||
right: `export default () => (${right});`,
|
||||
});
|
||||
const result = compare(...graphs);
|
||||
expect(result.changes).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
path: uncertain,
|
||||
status: "unknown",
|
||||
presence: { left: "unknown-coverage", right: "absent" },
|
||||
}),
|
||||
expect.objectContaining({
|
||||
path: added,
|
||||
status: "added",
|
||||
presence: { left: "absent", right: "present" },
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(result.summary).toEqual({
|
||||
added: 1,
|
||||
removed: 0,
|
||||
changed: 0,
|
||||
unknown: 1,
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("JavaScript export property presence boundaries", () => {
|
||||
it("normalizes omitted legacy presence before comparing identical literals and unions", async () => {
|
||||
const source =
|
||||
'export default () => ({ kind: "result", count: flag ? 1 : 2, nested: { enabled: true } });';
|
||||
const [left, right] = await analyzeSources({ left: source, right: source });
|
||||
const graph = createJavaScriptApplicationGraph({
|
||||
schema: "JavaScriptApplicationGraph",
|
||||
root_node_ids: left.graph.root_node_ids,
|
||||
edges: left.graph.edges,
|
||||
coverage: left.graph.coverage,
|
||||
limitations: left.graph.limitations,
|
||||
nodes: left.graph.nodes.map((node) =>
|
||||
createJavaScriptApplicationNode({
|
||||
kind: node.kind,
|
||||
identity: node.identity,
|
||||
observations: node.observations.map(
|
||||
({ label, properties, evidence }) => {
|
||||
if (properties.semantic_role !== "export-return-shapes")
|
||||
return { label, properties, evidence };
|
||||
const projection =
|
||||
projectedExportReturnShapesSchema.parse(properties);
|
||||
return {
|
||||
label,
|
||||
evidence,
|
||||
properties: {
|
||||
...properties,
|
||||
static_return_shapes: projection.static_return_shapes.map(
|
||||
(shape) => ({
|
||||
...shape,
|
||||
fields: shape.fields.map(
|
||||
({ path, state, value, reason }) => ({
|
||||
path,
|
||||
state,
|
||||
value,
|
||||
reason,
|
||||
}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
},
|
||||
};
|
||||
},
|
||||
),
|
||||
}),
|
||||
),
|
||||
});
|
||||
for (const sides of [
|
||||
[{ ...left, graph }, right],
|
||||
[right, { ...left, graph }],
|
||||
] as const) {
|
||||
const result = compare(sides[0], sides[1]);
|
||||
expect(result.coverage.paired_variants).toBe(1);
|
||||
expect(result.changes).toEqual([]);
|
||||
expect(result.coverage.status).toBe("complete-within-inputs");
|
||||
}
|
||||
});
|
||||
|
||||
it("proves absence beyond literal holes while retaining unknown spread coverage", async () => {
|
||||
const right =
|
||||
'export default () => ({ kind: "result", items: [,, call()] });';
|
||||
const literal = await analyzeSources({
|
||||
left: 'export default () => ({ kind: "result", items: [,] });',
|
||||
right,
|
||||
});
|
||||
const result = compare(...literal);
|
||||
expect(result.changes).toEqual([
|
||||
expect.objectContaining({
|
||||
path: "/items/2",
|
||||
status: "added",
|
||||
presence: { left: "absent", right: "present" },
|
||||
}),
|
||||
]);
|
||||
expect(result.coverage.status).toBe("complete-within-inputs");
|
||||
const spread = await analyzeSources({
|
||||
left: 'export default () => ({ kind: "result", items: [, ...rest] });',
|
||||
right,
|
||||
});
|
||||
expect(compare(...spread).changes).toContainEqual(
|
||||
expect.objectContaining({
|
||||
path: "/items/2",
|
||||
status: "unknown",
|
||||
presence: { left: "unknown-coverage", right: "present" },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("excludes the return root but retains empty property names and nested containers", async () => {
|
||||
const source =
|
||||
'export default () => ({ kind: "result", "": call(), options: {} });';
|
||||
const graphs = await analyzeSources({ left: source, right: source });
|
||||
const result = compare(...graphs);
|
||||
expect(inventoryProperties(result, "left", 0)).toEqual([
|
||||
"/",
|
||||
"/kind",
|
||||
"/options",
|
||||
]);
|
||||
expect(result.property_inventories[0]?.property_coverage).toContainEqual({
|
||||
path: "",
|
||||
status: "complete",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("JavaScript export return-shape property presence", () => {
|
||||
it("lists observed names without pairing untagged search variants", async () => {
|
||||
const graphs = await analyzeSources(
|
||||
{
|
||||
left: untaggedSearchSource("count"),
|
||||
right: untaggedSearchSource("total"),
|
||||
},
|
||||
"search.js",
|
||||
);
|
||||
const first = compare(...graphs, {
|
||||
modulePath: "search.js",
|
||||
leftExportName: "search",
|
||||
rightExportName: "search",
|
||||
});
|
||||
const second = compare(...graphs, {
|
||||
modulePath: "search.js",
|
||||
leftExportName: "search",
|
||||
rightExportName: "search",
|
||||
});
|
||||
|
||||
expect(first.comparison_id).toBe(second.comparison_id);
|
||||
expect(first.coverage).toMatchObject({
|
||||
paired_variants: 0,
|
||||
unpaired_left_variants: 1,
|
||||
unpaired_right_variants: 1,
|
||||
});
|
||||
expect(first.summary).toEqual({
|
||||
added: 0,
|
||||
removed: 0,
|
||||
changed: 0,
|
||||
unknown: 2,
|
||||
});
|
||||
expect(
|
||||
first.changes.every(({ discriminant }) => discriminant === null),
|
||||
).toBe(true);
|
||||
expect(inventoryProperties(first, "left", 0)).toEqual(
|
||||
expect.arrayContaining(["/count", "/matches"]),
|
||||
);
|
||||
expect(inventoryProperties(first, "right", 0)).toEqual(
|
||||
expect.arrayContaining(["/matches", "/query", "/total"]),
|
||||
);
|
||||
expect(inventoryProperties(first, "left", 0)).not.toEqual(
|
||||
inventoryProperties(first, "right", 0),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports presence-only added and removed names for tagged search variants", async () => {
|
||||
const graphs = await analyzeSources(
|
||||
{
|
||||
left: taggedSearchSource({ count: true }),
|
||||
right: taggedSearchSource({ total: true, query: true }),
|
||||
},
|
||||
"search.js",
|
||||
);
|
||||
const first = compare(...graphs, {
|
||||
modulePath: "search.js",
|
||||
leftExportName: "search",
|
||||
rightExportName: "search",
|
||||
});
|
||||
const second = compare(...graphs, {
|
||||
modulePath: "search.js",
|
||||
leftExportName: "search",
|
||||
rightExportName: "search",
|
||||
});
|
||||
|
||||
expect(first.comparison_id).toBe(second.comparison_id);
|
||||
expect(() =>
|
||||
javaScriptExportShapeComparisonResultSchema.parse(first),
|
||||
).not.toThrow();
|
||||
expect(first.coverage.paired_variants).toBe(1);
|
||||
expect(first.summary.added).toBe(2);
|
||||
expect(first.summary.removed).toBe(1);
|
||||
expect(
|
||||
first.changes.filter(({ path }) =>
|
||||
["/count", "/total", "/query"].includes(path),
|
||||
),
|
||||
).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
status: "removed",
|
||||
path: "/count",
|
||||
presence: { left: "present", right: "absent" },
|
||||
left: expect.objectContaining({ availability: "unknown" }),
|
||||
right: { availability: "absent" },
|
||||
}),
|
||||
expect.objectContaining({
|
||||
status: "added",
|
||||
path: "/total",
|
||||
presence: { left: "absent", right: "present" },
|
||||
left: { availability: "absent" },
|
||||
right: expect.objectContaining({ availability: "unknown" }),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
status: "added",
|
||||
path: "/query",
|
||||
presence: { left: "absent", right: "present" },
|
||||
left: { availability: "absent" },
|
||||
right: expect.objectContaining({ availability: "unknown" }),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(
|
||||
first.changes.some(
|
||||
({ path, status }) =>
|
||||
["/count", "/total", "/query"].includes(path) && status === "unknown",
|
||||
),
|
||||
).toBe(false);
|
||||
expect(inventoryProperties(first, "left", 0)).toEqual(
|
||||
expect.arrayContaining(["/count", "/kind", "/matches"]),
|
||||
);
|
||||
expect(inventoryProperties(first, "right", 0)).toEqual(
|
||||
expect.arrayContaining(["/kind", "/matches", "/query", "/total"]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("JavaScript export return-shape container presence", () => {
|
||||
it.each(["{}", "[]", "{ nested: 1 }"])(
|
||||
"does not report a retained %s container property as removed",
|
||||
@@ -399,6 +908,7 @@ const compare = (
|
||||
left: GraphSource,
|
||||
right: GraphSource,
|
||||
options: {
|
||||
readonly modulePath?: string;
|
||||
readonly leftExportName?: string;
|
||||
readonly rightExportName?: string;
|
||||
} = {},
|
||||
@@ -407,13 +917,13 @@ const compare = (
|
||||
left: {
|
||||
evidenceId: left.evidence.evidence_id,
|
||||
graph: left.graph,
|
||||
modulePath: "parser.mjs",
|
||||
modulePath: options.modulePath ?? "parser.mjs",
|
||||
exportName: options.leftExportName ?? "default",
|
||||
},
|
||||
right: {
|
||||
evidenceId: right.evidence.evidence_id,
|
||||
graph: right.graph,
|
||||
modulePath: "parser.mjs",
|
||||
modulePath: options.modulePath ?? "parser.mjs",
|
||||
exportName: options.rightExportName ?? "default",
|
||||
},
|
||||
});
|
||||
@@ -426,21 +936,74 @@ const analyzeGraph = async (root: string) => {
|
||||
return parseApplicationGraphEvidence(result.value);
|
||||
};
|
||||
|
||||
const analyzeSources = async (sources: {
|
||||
readonly left: string;
|
||||
readonly right: string;
|
||||
}): Promise<[GraphSource, GraphSource]> => {
|
||||
const analyzeSources = async (
|
||||
sources: {
|
||||
readonly left: string;
|
||||
readonly right: string;
|
||||
},
|
||||
fileName = "parser.mjs",
|
||||
): Promise<[GraphSource, GraphSource]> => {
|
||||
const root = await temporaryRoot();
|
||||
const leftRoot = join(root, "left");
|
||||
const rightRoot = join(root, "right");
|
||||
await Promise.all([mkdir(leftRoot), mkdir(rightRoot)]);
|
||||
await Promise.all([
|
||||
writeFile(join(leftRoot, "parser.mjs"), sources.left),
|
||||
writeFile(join(rightRoot, "parser.mjs"), sources.right),
|
||||
writeFile(join(leftRoot, fileName), sources.left),
|
||||
writeFile(join(rightRoot, fileName), sources.right),
|
||||
]);
|
||||
return Promise.all([analyzeGraph(leftRoot), analyzeGraph(rightRoot)]);
|
||||
};
|
||||
|
||||
const inventoryProperties = (
|
||||
result: ReturnType<typeof compareJavaScriptExportShapes>,
|
||||
side: "left" | "right",
|
||||
variantIndex: number,
|
||||
): string[] => {
|
||||
const inventory = result.property_inventories.find(
|
||||
(entry) => entry.side === side && entry.variant_index === variantIndex,
|
||||
);
|
||||
if (inventory === undefined)
|
||||
throw new Error(
|
||||
`Missing ${side} property inventory ${String(variantIndex)}`,
|
||||
);
|
||||
return inventory.properties;
|
||||
};
|
||||
|
||||
const untaggedSearchSource = (countKey: "count" | "total"): string =>
|
||||
countKey === "count"
|
||||
? `
|
||||
export function search(items, q) {
|
||||
const matches = items.filter((item) => item.includes(q));
|
||||
return { matches, count: matches.length };
|
||||
}
|
||||
`
|
||||
: `
|
||||
export function search(items, q) {
|
||||
const matches = items.filter((item) => item.includes(q));
|
||||
return { matches, total: matches.length, query: String(q) };
|
||||
}
|
||||
`;
|
||||
|
||||
const taggedSearchSource = (fields: {
|
||||
readonly count?: boolean;
|
||||
readonly total?: boolean;
|
||||
readonly query?: boolean;
|
||||
}): string => {
|
||||
const extra = [
|
||||
fields.count === true ? "count: matches.length" : null,
|
||||
fields.total === true ? "total: matches.length" : null,
|
||||
fields.query === true ? "query: String(q)" : null,
|
||||
]
|
||||
.filter((field): field is string => field !== null)
|
||||
.join(", ");
|
||||
return `
|
||||
export function search(items, q) {
|
||||
const matches = items.filter((item) => item.includes(q));
|
||||
return { kind: "results", matches${extra.length > 0 ? `, ${extra}` : ""} };
|
||||
}
|
||||
`;
|
||||
};
|
||||
|
||||
const sourceOwnedParsers = async (): Promise<[GraphSource, GraphSource]> => {
|
||||
const root = await temporaryRoot();
|
||||
const leftRoot = join(root, "left");
|
||||
|
||||
Reference in New Issue
Block a user