Socket
Socket
Sign inDemoInstall

es-info

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-info - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

13

index.js

@@ -12,3 +12,3 @@ const {walk} = require("estree-walker");

function analyze(ast) {
function analyze({ast, subtree = false}) {
const result = {

@@ -24,3 +24,5 @@ import: {},

ast._esInfoScope = attachScopes(ast, "_esInfoScope");
if (subtree) {
ast._esInfoScope = attachScopes(ast, "_esInfoScope");
}

@@ -49,3 +51,3 @@ const importRefs = new Map;

}
if (!node._esInfoScope && parent) {
if (!node._esInfoScope && parent && parent._esInfoScope) {
node._esInfoScope = parent._esInfoScope;

@@ -115,3 +117,3 @@ }

}
} else if (node.type === "Identifier" && isReference(node, parent)) {
} else if (node.type === "Identifier" && isReference(node, parent) && node._esInfoScope) {
if (!node._esInfoScope.contains(node.name) && importRefs.has(node.name)) {

@@ -127,2 +129,5 @@ let {id, name} = importRefs.get(node.name);

}
if (!subtree && node.type !== "Program") {
this.skip();
}
}

@@ -129,0 +134,0 @@

{
"name": "es-info",
"version": "0.2.1",
"version": "0.3.0",
"description": "Analyze ES module and extract information about imports, exports, and dynamic imports.",

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

@@ -35,3 +35,3 @@ es-info

const result = analyze(ast);
const result = analyze({ast, subtree: true});
```

@@ -92,7 +92,18 @@

dynamicImport: Array<String>
} = analyze(ast);
} = analyze({
ast,
subtree?: Boolean
});
```
`import` is an object map. The key is the module ID and the value is an info object with these members:
#### options
`ast` is an estree object.
If `subtree` is `true`, the analyzer will analyze the entire tree, otherwise only the top nodes (import/export declarations) are analyzed. **You have to set `subtree` to `true` if you want to collect the usage of imported names and to collect dynamic imports**. Default: `false`.
#### analyzeResult
`import` is an object map. The key is the module ID and the value is an information object with these properties:
```js

@@ -117,3 +128,3 @@ const importInfo = {

`exportInfo` has the following shape:
`exportInfo` has following properties:

@@ -139,2 +150,7 @@ ```js

* 0.3.0 (Jun 13, 2019)
- **Breaking: the signature of `analyze()` is changed.**
- Add: `subtree` option.
* 0.2.1 (Jun 6, 2019)

@@ -141,0 +157,0 @@

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