esrefactor icon indicating copy to clipboard operation
esrefactor copied to clipboard

[Question] meaning of ctx.identify(4); in example code

Open ntrongkha opened this issue 10 years ago • 1 comments

Could you update or help me understand what is the meaning of ctx.identify(4); in example of this project ???

ntrongkha avatar Dec 09 '15 11:12 ntrongkha

If I'm not wrong, ctx.indefity(4) is the location of the variable 'x' in that example.

var [x] = 42; y = x * 2; z = x / 2'"; // x match with 4th position;

if you take a look inside of the code

 if (node.type === esprima.Syntax.Identifier) {
    if (node.range[0] <= pos && node.range[1] >= pos) {
        identifier = node;
        return estraverse.VisitorOption.Break;
     }
}

Once the position match with the range of some node, it breaks the iteration and return the Node. The number exact location it could come from some javascript editor or so on.

juanpicado avatar Mar 20 '16 18:03 juanpicado