acorn-globals
Advanced tools
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": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
8208
163