Open Bug 1894683 Opened 1 year ago Updated 1 year ago

In the Outline view, "Copy function" context menu is disabled for one-liner functions

Categories

(DevTools :: Debugger, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: nchevobbe, Unassigned)

Details

Steps to reproduce

  1. Open the console
  2. Evaluate the following
function x() { console.log("hello"); } 
function y() {
console.log("world")
}
debugger;
  1. Once the debugger pauses, select the Outline view
  2. Right-click on x

Expected results

The "Copy function" context menu is enabled

Actual results

The "Copy function" context menu is disabled


You can see that the context menu is enabled for y

The issue comes from https://searchfox.org/mozilla-central/rev/f1532761de0b60337e42c6c3f525288a523dabef/devtools/client/debugger/src/utils/ast.js#24,29-30,32-38,55-56

function findClosestofSymbol(declarations, location) {
...
  return declarations.reduce((found, currNode) => {
    if (
...
      !containsPosition(currNode.location, {
        line: location.line,
        column: location.column || 0,
      })
    ) {
      return found;
    }
...
  }, null);
}

we're returning found, which is always null, since it's the initial value passed into reduce

No longer blocks: 1894694

We should allow copying the function even if it's empty, so this should be easy to fix.

Severity: -- → S3
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.