Socket
Socket
Sign inDemoInstall

dependents-editor-backend

Package Overview
Dependencies
109
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.16.1 to 1.17.0

lib/getClickedNode.js

88

lib/jumpToDefinition.js

@@ -0,4 +1,6 @@

var fs = require('fs');
var Walker = require('node-source-walk');
var cabinet = require('filing-cabinet');
var debug = require('./debug');
var Walker = require('node-source-walk');
var fs = require('fs');
var getClickedNode = require('./getClickedNode');

@@ -22,7 +24,8 @@ module.exports = function(options) {

var walker = new Walker();
var ast;
try {
var walker = new Walker();
ast = walker.parse(fs.readFileSync(filename, 'utf8'));
options.ast = ast;
} catch (e) {

@@ -35,3 +38,3 @@ debug('could not read ' + filename);

var clickedNode = findClickedNode(walker, ast, clickPosition);
var clickedNode = getClickedNode(ast, clickPosition);

@@ -61,41 +64,18 @@ if (!clickedNode) {

return jumpTo;
}
};
function findClickedNode(walker, ast, clickPosition) {
var clickedNode;
} else if (clickedNode.type === 'StringLiteral') {
// Note: not asserting that the string is part of an import
// to avoid identifying CJS and AMD imports
debug('clicked string is part of an import');
options.partial = clickedNode.value;
var resolvedPartial = cabinet(options);
walker.walk(ast, function(node) {
var location = node.loc;
debug('cabinet resolved partial: ' + resolvedPartial);
// We don't need to specify a location to jump to
return resolvedPartial;
}
if (!location || typeof node.type === 'object') { return; }
return '';
};
// Provides sane output devoid of parents and constructors
location = {
start: {
line: location.start.line,
column: location.start.column,
},
end: {
line: location.end.line,
column: location.end.column
}
};
debug('current node: ', node.type);
if (clickedWithinNodeLocation(clickPosition, location)) {
debug('click position is within this node: ' + node.type);
// The last node within the location should be the inner-most and represent the exact match
clickedNode = node;
} else if (nodeLocationBeyondClickPosition(clickPosition, location)) {
debug('current node is beyond the clicked node, so stopping the walk');
walker.stopWalking();
}
});
return clickedNode;
}
function findIdentifierWithinDeclarator(identifierNode) {

@@ -166,31 +146,1 @@ var declaratorChecks = {

}
function clickedWithinNodeLocation(clickPosition, location) {
var clickLine = clickPosition.line;
var clickColumn = clickPosition.column;
debug('clickWithinNodeLocation clickPosition: ', clickPosition);
debug('clickWithinNodeLocation location: ', location);
var linesIntersect = (location.start.line <= clickLine) && (clickLine <= location.end.line);
var columnsIntersect = (location.start.column <= clickColumn) && (clickColumn <= location.end.column);
debug('lines intersect? ', linesIntersect);
debug('columnsIntersect intersect? ', columnsIntersect);
return linesIntersect && columnsIntersect;
}
function nodeLocationBeyondClickPosition(clickPosition, location) {
var clickLine = clickPosition.line;
var clickColumn = clickPosition.column;
debug('nodeLocationBeyondClickPosition clickPosition: ', clickPosition);
debug('nodeLocationBeyondClickPosition location: ', location);
var isNodeLineBeyond = location.start.line > clickLine;
debug('isNodeLineBeyond? ', isNodeLineBeyond);
return isNodeLineBeyond;
}
{
"name": "dependents-editor-backend",
"version": "1.16.1",
"version": "1.17.0",
"description": "The brains behind Dependents editor plugins",

@@ -5,0 +5,0 @@ "main": "lib/cli.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc