user2879704
user2879704

Reputation:

Nodejs Debugger misses out some property names on autocompletion in repl mode

var express    = require('express'); 
Debugger;
var router = express.Router();

In node debugger, when the control stops at second line, i do this,

debug> repl
Press Ctrl + C to leave debug repl
> express
[Function]

> express.

here, after 'express.', pressing tab for autocomplete doesn't list out Router option but node builtin properties like hasOwnProperty, call, bind... are there.

express.Router

is defined in

`node_modules/express/lib/router/index.js`.

I see, no reason this property may not be part of the express object. In summary, node debugger autocompletion is not listing all the properties for express object.

Upvotes: 0

Views: 141

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161517

This is a side-effect of the fact that express exports a function rather than a standard object. e.g.

module.exports = function(){ ...}
module.exports.Router = Router;

It all comes down to this line in the Node source, which ends up basically saying "if autocompleting a function, treat it like a simple anonymous function", thus it doesn't have any extra properties.

The reason for the roundabout code is because when you run node debug ..., you are actually starting two node processes, with one running your code, and one running the debugger. That means that when you autocomplete, the debugger process must send a message to the process being debugged, asking for information, and then it has to translate that back into something that you can render for autocompletion.

Looking over the node core source, my educated guess would be that this was simply the easiest thing to do. The current architecture of the debugger tries to hide the debugger implementation as much as possible, but that means that the autocompleter doesn't know that it is working on a faked object copy and the debugger doesn't know that we are autocompleting. The downside of this is that it tries to recursively duplicate the whole object before processing the autocomplete, meaning it does a costly recursive operation to then simply discard the result. Unfortunately adding function property recursion makes the autocomplete quite slow from my quick test a minute ago.

Upvotes: 3

Related Questions