mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
refactor(javascript): share semantic callable node lookup (#16018)
This commit is contained in:
1 parent
185b1b12cd
commit
3abd5b25cd
8 files changed
+17
-62
No files matched your search
@@ -95,11 +95,7 @@ const addListenerNode = (
|
||||
: operation.eventName.length <= "listener".length
|
||||
? `${operation.method}:${operation.eventName}`
|
||||
: `${operation.method}:listener`,
|
||||
functionNodeId:
|
||||
operation.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(operation.ownerCallableId)?.node_id ??
|
||||
null),
|
||||
functionNodeId: context.callableNodeId(operation.ownerCallableId),
|
||||
properties: {
|
||||
emitter_key: operation.emitterKey,
|
||||
event_name: operation.eventName,
|
||||
@@ -155,16 +151,12 @@ export const projectSemanticTimers = (
|
||||
const timerNodes = new Map(
|
||||
context.ir.timerOperations.flatMap((operation) => {
|
||||
if (operation.kind !== "schedule") return [];
|
||||
const owner =
|
||||
operation.ownerCallableId === null
|
||||
? undefined
|
||||
: context.callableNodes.get(operation.ownerCallableId);
|
||||
const timer = retainSemanticGraphNode(context.state, context.file, {
|
||||
kind: "timer",
|
||||
roleKey: operation.timerId,
|
||||
location: operation.location,
|
||||
label: operation.method,
|
||||
functionNodeId: owner?.node_id ?? null,
|
||||
functionNodeId: context.callableNodeId(operation.ownerCallableId),
|
||||
...builtinSemanticNode(context.file, operation, {
|
||||
delay_milliseconds: operation.delayMilliseconds,
|
||||
method: operation.method,
|
||||
|
||||
@@ -704,6 +704,8 @@ function* projectFileWithEvidenceSteps(
|
||||
moduleNode,
|
||||
bindingNodes,
|
||||
callableNodes,
|
||||
callableNodeId: (id) =>
|
||||
id === null ? null : (callableNodes.get(id)?.node_id ?? null),
|
||||
callSiteNodes,
|
||||
returnSiteNodes,
|
||||
argumentNodes: new Map(),
|
||||
|
||||
@@ -62,10 +62,7 @@ const addChildProcessNode = (
|
||||
roleKey: spawn.processId,
|
||||
location: spawn.location,
|
||||
label: spawn.command ?? spawn.method,
|
||||
functionNodeId:
|
||||
spawn.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(spawn.ownerCallableId)?.node_id ?? null),
|
||||
functionNodeId: context.callableNodeId(spawn.ownerCallableId),
|
||||
...builtinSemanticNode(context.file, spawn, {
|
||||
argv_count: spawn.argvCount,
|
||||
command: spawn.command,
|
||||
@@ -237,11 +234,7 @@ const addChildListenerNode = (
|
||||
roleKey: interaction.interactionId,
|
||||
location: interaction.listenerLocation ?? interaction.location,
|
||||
label: interaction.eventName,
|
||||
functionNodeId:
|
||||
interaction.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(interaction.ownerCallableId)?.node_id ??
|
||||
null),
|
||||
functionNodeId: context.callableNodeId(interaction.ownerCallableId),
|
||||
...builtinSemanticNode(context.file, interaction, {
|
||||
event_name: interaction.eventName,
|
||||
method: interaction.method,
|
||||
@@ -257,11 +250,7 @@ const addSignalNode = (
|
||||
roleKey: interaction.interactionId,
|
||||
location: interaction.location,
|
||||
label: interaction.signalName,
|
||||
functionNodeId:
|
||||
interaction.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(interaction.ownerCallableId)?.node_id ??
|
||||
null),
|
||||
functionNodeId: context.callableNodeId(interaction.ownerCallableId),
|
||||
...builtinSemanticNode(context.file, interaction, {
|
||||
signal_name: interaction.signalName,
|
||||
}),
|
||||
|
||||
@@ -87,11 +87,7 @@ const addConfigurationNode = (
|
||||
roleKey: operation.configId,
|
||||
location: operation.location,
|
||||
label: operation.key ?? operation.kind,
|
||||
functionNodeId:
|
||||
operation.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(operation.ownerCallableId)?.node_id ??
|
||||
null),
|
||||
functionNodeId: context.callableNodeId(operation.ownerCallableId),
|
||||
...builtinSemanticNode(context.file, operation, {
|
||||
key: operation.key,
|
||||
source_kind: operation.kind,
|
||||
@@ -161,11 +157,7 @@ const addRequestNode = (
|
||||
operation.endpoint.length <= operation.method.length
|
||||
? operation.endpoint
|
||||
: operation.method,
|
||||
functionNodeId:
|
||||
operation.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(operation.ownerCallableId)?.node_id ??
|
||||
null),
|
||||
functionNodeId: context.callableNodeId(operation.ownerCallableId),
|
||||
...builtinSemanticNode(context.file, operation, {
|
||||
endpoint: operation.endpoint,
|
||||
method: operation.method,
|
||||
@@ -299,11 +291,7 @@ const addBoundaryNode = (
|
||||
roleKey: operation.boundaryId,
|
||||
location: operation.location,
|
||||
label: operation.method,
|
||||
functionNodeId:
|
||||
operation.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(operation.ownerCallableId)?.node_id ??
|
||||
null),
|
||||
functionNodeId: context.callableNodeId(operation.ownerCallableId),
|
||||
properties: {
|
||||
boundary_kind: operation.kind,
|
||||
field: operation.method,
|
||||
|
||||
@@ -156,10 +156,7 @@ export function* projectSemanticExpressionInfluence(
|
||||
);
|
||||
for (const [index, flow] of context.ir.expressionFlows.entries()) {
|
||||
if (index % 64 === 0) yield;
|
||||
const owner =
|
||||
flow.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(flow.ownerCallableId)?.node_id ?? null);
|
||||
const owner = context.callableNodeId(flow.ownerCallableId);
|
||||
const node = retainSemanticGraphNode(context.state, context.file, {
|
||||
kind: "expression",
|
||||
roleKey: `operator:${index}`,
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface SemanticFlowProjectionContext {
|
||||
readonly moduleNode: JavaScriptSemanticGraphNode;
|
||||
readonly bindingNodes: ReadonlyMap<string, JavaScriptSemanticGraphNode>;
|
||||
readonly callableNodes: ReadonlyMap<string, JavaScriptSemanticGraphNode>;
|
||||
readonly callableNodeId: (id: string | null) => string | null;
|
||||
readonly callSiteNodes: ReadonlyMap<string, JavaScriptSemanticGraphNode>;
|
||||
readonly returnSiteNodes: ReadonlyMap<string, JavaScriptSemanticGraphNode>;
|
||||
readonly readNodes: JavaScriptSemanticGraphNode[];
|
||||
@@ -73,16 +74,12 @@ export const projectSemanticPromises = (
|
||||
): void => {
|
||||
const promiseNodes = new Map(
|
||||
context.ir.promiseOperations.flatMap((operation) => {
|
||||
const owner =
|
||||
operation.ownerCallableId === null
|
||||
? undefined
|
||||
: context.callableNodes.get(operation.ownerCallableId);
|
||||
const node = retainSemanticGraphNode(context.state, context.file, {
|
||||
kind: operation.kind === "awaited-expression" ? "task" : "promise",
|
||||
roleKey: operation.promiseId,
|
||||
location: operation.location,
|
||||
label: promiseLabel(operation),
|
||||
functionNodeId: owner?.node_id ?? null,
|
||||
functionNodeId: context.callableNodeId(operation.ownerCallableId),
|
||||
properties: {
|
||||
method: operation.method,
|
||||
operation_kind: operation.kind,
|
||||
@@ -359,10 +356,8 @@ export function* projectSemanticFrontiers(
|
||||
: (["reads-property", "writes-property"] as const);
|
||||
addSemanticGraphUnknown(context.state, {
|
||||
node_id:
|
||||
frontier.callableId === null
|
||||
? context.moduleNode.node_id
|
||||
: (context.callableNodes.get(frontier.callableId)?.node_id ??
|
||||
context.moduleNode.node_id),
|
||||
context.callableNodeId(frontier.callableId) ??
|
||||
context.moduleNode.node_id,
|
||||
family,
|
||||
relation_kinds: [...relationKinds],
|
||||
reason: frontier.kind,
|
||||
|
||||
@@ -164,11 +164,7 @@ const addObjectOccurrence = (
|
||||
operation.propertyPath === null
|
||||
? operation.kind
|
||||
: `${operation.kind}:${semanticPropertyPointer(operation.propertyPath)}`,
|
||||
functionNodeId:
|
||||
operation.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(operation.ownerCallableId)?.node_id ??
|
||||
null),
|
||||
functionNodeId: context.callableNodeId(operation.ownerCallableId),
|
||||
properties: {
|
||||
operation_kind: operation.kind,
|
||||
property_path:
|
||||
|
||||
@@ -55,11 +55,7 @@ const addResourceNode = (
|
||||
roleKey: operation.resourceId,
|
||||
location: operation.location,
|
||||
label: operation.method,
|
||||
functionNodeId:
|
||||
operation.ownerCallableId === null
|
||||
? null
|
||||
: (context.callableNodes.get(operation.ownerCallableId)?.node_id ??
|
||||
null),
|
||||
functionNodeId: context.callableNodeId(operation.ownerCallableId),
|
||||
...builtinSemanticNode(context.file, operation, {
|
||||
method: operation.method,
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user