node-source-walk
Advanced tools
Comparing version 4.2.2 to 4.3.0
43
index.js
@@ -19,14 +19,18 @@ const parser = require('@babel/parser'); | ||
'flow', | ||
'asyncGenerators', | ||
'classProperties', | ||
'doExpressions', | ||
'objectRestSpread', | ||
['decorators', {decoratorsBeforeExport: true}], | ||
'classProperties', | ||
'dynamicImport', | ||
'exportDefaultFrom', | ||
'exportNamespaceFrom', | ||
'asyncGenerators', | ||
'functionBind', | ||
'functionSent', | ||
'dynamicImport', | ||
'optionalChaining', | ||
'nullishCoalescingOperator' | ||
'nullishCoalescingOperator', | ||
'objectRestSpread', | ||
[ | ||
'decorators', { | ||
decoratorsBeforeExport: true | ||
} | ||
], | ||
'optionalChaining' | ||
], | ||
@@ -62,20 +66,19 @@ allowHashBang: true, | ||
module.exports.prototype.traverse = function(node, cb) { | ||
if (this.shouldStop) { return; } | ||
if (this.shouldStop) return; | ||
if (Array.isArray(node)) { | ||
for (let i = 0, l = node.length; i < l; i++) { | ||
const x = node[i]; | ||
if (x !== null) { | ||
for (const key of node) { | ||
if (key !== null) { | ||
// Mark that the node has been visited | ||
x.parent = node; | ||
this.traverse(x, cb); | ||
key.parent = node; | ||
this.traverse(key, cb); | ||
} | ||
} | ||
} else if (node && typeof node === 'object') { | ||
cb(node); | ||
for (let key in node) { | ||
// TODO switch to Object.entries | ||
for (const key of Object.keys(node)) { | ||
// Avoid visited nodes | ||
if (key === 'parent' || !node[key]) { continue; } | ||
if (key === 'parent' || !node[key]) continue; | ||
@@ -114,7 +117,7 @@ node[key].parent = node; | ||
function reverseTraverse(node, cb) { | ||
if (this.shouldStop || !node.parent) { return; } | ||
if (this.shouldStop || !node.parent) return; | ||
if (node.parent instanceof Array) { | ||
for (let i = 0, l = node.parent.length; i < l; i++) { | ||
cb(node.parent[i]); | ||
if (Array.isArray(node.parent)) { | ||
for (const parent of node.parent) { | ||
cb(parent); | ||
} | ||
@@ -121,0 +124,0 @@ } else { |
{ | ||
"name": "node-source-walk", | ||
"version": "4.2.2", | ||
"version": "4.3.0", | ||
"description": "Execute a callback on every node of a source code's AST and stop walking when you see fit", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
8194
4
112
0