Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203644,6 +203644,8 @@ var JS_FAMILY_QUERY = `
(function_declaration) @chunk
(class_declaration) @chunk
(method_definition) @chunk
(variable_declarator value: (arrow_function)) @chunk
(variable_declarator value: (function_expression)) @chunk
`;
var PYTHON_QUERY = `
(function_definition) @chunk
Expand Down Expand Up @@ -203686,11 +203688,16 @@ function findEnclosingClassName(node, classNodeType) {
return null;
}
function getChunkContainer(declNode) {
const parent = declNode.parent;
if (parent && parent.type === "export_statement") {
return parent;
let container = declNode;
const parent = container.parent;
if (parent && (parent.type === "lexical_declaration" || parent.type === "variable_declaration") && parent.namedChildCount === 1) {
container = parent;
}
return declNode;
const grandparent = container.parent;
if (grandparent && grandparent.type === "export_statement") {
container = grandparent;
}
return container;
}
function extractSignature(container) {
const text = container.text;
Expand Down Expand Up @@ -203734,7 +203741,7 @@ async function extractChunksFromSource(source, filePath, grammar) {
continue;
const declNode = capture.node;
const nameNode = declNode.childForFieldName("name");
if (!nameNode)
if (!nameNode || nameNode.type !== "identifier")
continue;
const kind = resolveKind(declNode, grammar);
const className = kind === "method" ? findEnclosingClassName(declNode, classNodeType) : null;
Expand Down
30 changes: 25 additions & 5 deletions packages/core/src/parsing/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,29 @@ function findEnclosingClassName(node: Node, classNodeType: string): string | nul
}

function getChunkContainer(declNode: Node): Node {
const parent = declNode.parent;
if (parent && parent.type === 'export_statement') {
return parent;
let container = declNode;

// `const foo = () => {}` captures the `variable_declarator`, but the
// declaration keyword (and any `export`) lives one or two levels up.
// Skip the widen when siblings share the statement (`const a = 1, b = () => {}`)
// - otherwise every declarator on the line would get an identical
// body/signature, causing false-positive staleness on unrelated siblings
// and indistinguishable embedding text.
const parent = container.parent;
if (
parent &&
(parent.type === 'lexical_declaration' || parent.type === 'variable_declaration') &&
parent.namedChildCount === 1
) {
container = parent;
}

const grandparent = container.parent;
if (grandparent && grandparent.type === 'export_statement') {
container = grandparent;
}
return declNode;

return container;
}

function extractSignature(container: Node): string {
Expand Down Expand Up @@ -97,7 +115,9 @@ export async function extractChunksFromSource(
if (capture.name !== 'chunk') continue;
const declNode = capture.node;
const nameNode = declNode.childForFieldName('name');
if (!nameNode) continue;
// `variable_declarator`'s name field can be a destructuring pattern
// (`const { a, b } = () => {}`) - not a real declaration name, skip it.
if (!nameNode || nameNode.type !== 'identifier') continue;

const kind = resolveKind(declNode, grammar);
const className = kind === 'method' ? findEnclosingClassName(declNode, classNodeType) : null;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/parsing/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const JS_FAMILY_QUERY = `
(function_declaration) @chunk
(class_declaration) @chunk
(method_definition) @chunk
(variable_declarator value: (arrow_function)) @chunk
(variable_declarator value: (function_expression)) @chunk
`;

export const PYTHON_QUERY = `
Expand Down
Loading