Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

acorn-globals

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acorn-globals - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

57

index.js

@@ -16,5 +16,2 @@ 'use strict';

}
function declaresThis(node) {
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
}

@@ -42,5 +39,10 @@ function reallyParse(source) {

var globals = [];
var ast = typeof source === 'string' ?
ast = reallyParse(source) :
source;
var ast;
// istanbul ignore else
if (typeof source === 'string') {
ast = reallyParse(source);
} else {
ast = source;
}
// istanbul ignore if
if (!(ast && typeof ast === 'object' && ast.type === 'Program')) {

@@ -80,2 +82,3 @@ throw new TypeError('Source must be either a string of JavaScript or an acorn AST');

break;
// istanbul ignore next
default:

@@ -85,2 +88,6 @@ throw new Error('Unrecognized pattern type: ' + node.type);

}
var declareModuleSpecifier = function (node, parents) {
ast.locals = ast.locals || {};
ast.locals[node.local.name] = true;
}
walk.ancestor(ast, {

@@ -126,20 +133,5 @@ 'VariableDeclaration': function (node, parents) {

},
'ImportDefaultSpecifier': function (node) {
if (node.local.type === 'Identifier') {
ast.locals = ast.locals || {};
ast.locals[node.local.name] = true;
}
},
'ImportSpecifier': function (node) {
if (node.local.type === 'Identifier') {
ast.locals = ast.locals || {};
ast.locals[node.local.name] = true;
}
},
'ImportNamespaceSpecifier': function (node) {
if (node.local.type === 'Identifier') {
ast.locals = ast.locals || {};
ast.locals[node.local.name] = true;
}
}
'ImportDefaultSpecifier': declareModuleSpecifier,
'ImportSpecifier': declareModuleSpecifier,
'ImportNamespaceSpecifier': declareModuleSpecifier
});

@@ -170,19 +162,8 @@ function identifier(node, parents) {

'VariablePattern': identifier,
'Identifier': identifier,
'ThisExpression': function (node, parents) {
for (var i = 0; i < parents.length; i++) {
if (declaresThis(parents[i])) {
return;
}
}
node.parents = parents;
globals.push(node);
}
'Identifier': identifier
});
var groupedGlobals = {};
globals.forEach(function (node) {
var name = node.name;
if (node.type === 'ThisExpression') name = 'this';
groupedGlobals[name] = (groupedGlobals[name] || []);
groupedGlobals[name].push(node);
groupedGlobals[node.name] = (groupedGlobals[node.name] || []);
groupedGlobals[node.name].push(node);
});

@@ -189,0 +170,0 @@ return Object.keys(groupedGlobals).sort().map(function (name) {

{
"name": "acorn-globals",
"version": "1.0.7",
"version": "1.0.8",
"description": "Detect global variables in JavaScript using acorn",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc