microsoft / vscode-js-debug

A DAP-compatible JavaScript debugger. Used in VS Code, VS, + more
MIT License
1.67k stars 283 forks source link

fix: hover evaluation incorrectly showing undefined #2048

Closed connor4312 closed 3 months ago

connor4312 commented 3 months ago

I haven't been quite able to reproduce this, but this is the explaination I see for https://github.com/microsoft/vscode/issues/221503, plausibly caused by sourcemap funkiness.

The root cause is that a hover evaluation's scope is being misidentified as happening in a scope above the one it should actually run in. We then saw this and thought we should hoist a variable, but don't find a variable to hoist, and leave the replaced identifier in the expression. If the scope were not misidentified, then the behavior would have been identical because the variable would not be defined anyway.

In this PR we replace the identifier back to its original if we don't find a variable to hoist, and also add logging to help any future issues.