Implement reusable interface conformance rules
This commit is contained in:
@@ -86,3 +86,21 @@ export const resolveQxSources = async (read: (name: string) => Promise<string>,
|
||||
};
|
||||
|
||||
export const loadQxSources = (root: string) => resolveQxSources((name) => readQxSource(root, name));
|
||||
|
||||
/** The same validated closure used by compilation, for installation and pinning. */
|
||||
export const qxSourceManifest = async (root: string) => {
|
||||
const resolved = await loadQxSources(root);
|
||||
const syntax = parseQx(resolved.source);
|
||||
const imports = [...walkSyntax(syntax.root)]
|
||||
.filter((node) => node.kind === "resourceImportDecl")
|
||||
.map((node) => {
|
||||
const name = node.children.find((child) => child.kind === "identifier")!;
|
||||
const kind = syntax.tokens.some(
|
||||
(token) => token.start >= node.start && token.end <= node.end && token.kind === "INTERFACE",
|
||||
)
|
||||
? ("interface" as const)
|
||||
: ("package" as const);
|
||||
return { kind, binding: resolved.source.slice(name.start, name.end) };
|
||||
});
|
||||
return { sourceFiles: resolved.sourceFiles, imports };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user