mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
fix(javascript): preserve loader conditions across application evidence (#12023)
* fix(javascript): honor loader semantics for BOM hashbangs * fix(javascript): retain conditional BOM hashbang imports * fix(javascript): share conditional hashbang recovery * fix(javascript): recover suffix-only source imports * fix(javascript): retain conditional CommonJS hashbang imports * fix(javascript): preserve conditional hashbang dependency evidence * fix(javascript): preserve ambiguous dotfile and worker evidence * fix(javascript): qualify semantic evidence with source loader conditions * fix(javascript): qualify all source-backed application evidence * test(javascript): identify imports by their projected kind --------- Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
1 parent
919531c7c1
commit
34f7d2131c
22 files changed
+1053
-69
No files matched your search
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
qualifyJavaScriptLoaderEvidence,
|
||||
type ApplicationGraphEvidence,
|
||||
} from "../../domain/javascript/javascriptApplicationEvidenceSchemas.js";
|
||||
import {
|
||||
createJavaScriptApplicationEdge,
|
||||
createJavaScriptApplicationNode,
|
||||
@@ -17,9 +21,43 @@ export class JavaScriptArtifactGraphAccumulator {
|
||||
readonly #nodes = new Map<string, AccumulatedNode>();
|
||||
readonly #edges = new Map<string, ApplicationEdge>();
|
||||
|
||||
constructor(
|
||||
private readonly loaderConditions: ReadonlyMap<
|
||||
string,
|
||||
{ readonly sha256: string; readonly condition: string }
|
||||
> = new Map(),
|
||||
) {}
|
||||
|
||||
readonly #qualifyEvidence = (
|
||||
evidence: ApplicationGraphEvidence,
|
||||
): ApplicationGraphEvidence => {
|
||||
if (
|
||||
!evidence.artifact.available ||
|
||||
!evidence.location.available ||
|
||||
(evidence.authority !== "ast-static-analysis" &&
|
||||
evidence.authority !== "static-relationship-inference")
|
||||
)
|
||||
return evidence;
|
||||
const location = evidence.location.value;
|
||||
const path =
|
||||
location.kind === "source-range"
|
||||
? location.source
|
||||
: location.kind === "artifact-path"
|
||||
? location.path
|
||||
: undefined;
|
||||
const origin =
|
||||
path === undefined ? undefined : this.loaderConditions.get(path);
|
||||
return origin?.sha256 === evidence.artifact.sha256
|
||||
? qualifyJavaScriptLoaderEvidence(evidence, origin.condition)
|
||||
: evidence;
|
||||
};
|
||||
|
||||
/** Merge observations into a stable live node; order is finalized by nodes(). */
|
||||
addNode<Input extends DisplayableNodeInput>(input: Input): ApplicationNode {
|
||||
const created = createJavaScriptApplicationNode(displayableNode(input));
|
||||
const created = createJavaScriptApplicationNode(
|
||||
displayableNode(input),
|
||||
this.loaderConditions.size === 0 ? undefined : this.#qualifyEvidence,
|
||||
);
|
||||
const existing = this.#nodes.get(created.node_id);
|
||||
if (existing === undefined) {
|
||||
this.#nodes.set(created.node_id, {
|
||||
@@ -66,7 +104,10 @@ export class JavaScriptArtifactGraphAccumulator {
|
||||
|
||||
/** Create or replace one canonical edge by semantic identifier. */
|
||||
addEdge(input: unknown): ApplicationEdge {
|
||||
const edge = createJavaScriptApplicationEdge(input);
|
||||
const edge = createJavaScriptApplicationEdge(
|
||||
input,
|
||||
this.loaderConditions.size === 0 ? undefined : this.#qualifyEvidence,
|
||||
);
|
||||
this.#edges.set(edge.edge_id, edge);
|
||||
return edge;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user