@digifi/acorn-globals
Advanced tools
Comparing version 1.0.1 to 1.0.2
37
index.js
@@ -34,6 +34,13 @@ 'use strict'; | ||
try { | ||
return acorn.parse(source, parseOptions); | ||
const acornParseResult = acorn.parse(source, parseOptions); | ||
return { | ||
ast: acornParseResult, | ||
}; | ||
} catch (err) { | ||
if (fallbackToLoose) { | ||
return acornLoose.parse(source, parseOptions); | ||
return { | ||
ast: acornLoose.parse(source, parseOptions), | ||
parsingError: err.message, | ||
}; | ||
} | ||
@@ -45,3 +52,3 @@ | ||
function findGlobals(source, options) { | ||
function parseWithGlobals(source, options, fallbackToLoose) { | ||
options = options || {}; | ||
@@ -52,8 +59,6 @@ | ||
// istanbul ignore else | ||
if (typeof source === 'string') { | ||
ast = reallyParse(source, options); | ||
} else { | ||
ast = source; | ||
} | ||
const { | ||
ast, | ||
parsingError, | ||
} = (typeof source === 'string') ? reallyParse(source, options, fallbackToLoose) : { ast: source }; | ||
@@ -227,9 +232,13 @@ // istanbul ignore if | ||
}); | ||
return Object.keys(groupedGlobals).sort().map(function (name) { | ||
return {name: name, nodes: groupedGlobals[name]}; | ||
}); | ||
return { | ||
ast, | ||
globals: Object.keys(groupedGlobals).sort().map((name) => ({ | ||
name, nodes: groupedGlobals[name], | ||
})), | ||
parsingError, | ||
}; | ||
} | ||
module.exports = findGlobals; | ||
module.exports = parseWithGlobals; | ||
module.exports.parse = reallyParse; |
{ | ||
"name": "@digifi/acorn-globals", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Detect global variables in JavaScript using acorn for DigiFi", | ||
@@ -22,4 +22,3 @@ "keywords": [ | ||
"acorn-loose": "^8.1.0", | ||
"acorn-walk": "^7.1.1", | ||
"esprima-fb": "^15001.1001.0-dev-harmony-fb" | ||
"acorn-walk": "^7.1.1" | ||
}, | ||
@@ -26,0 +25,0 @@ "devDependencies": { |
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
9642
3
195
- Removedesprima-fb@15001.1001.0-dev-harmony-fb(transitive)