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

ast-module-types

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-module-types - npm Package Compare versions

Comparing version 2.2.2 to 2.3.0

22

index.js

@@ -161,10 +161,24 @@ // Whether or not the node represents an AMD define() call

// import 'mylib' or import {foo, bar} from 'mylib'
module.exports.isES6Import = function(node) {
return node.type === 'ImportDeclaration' && node.source && node.source.value;
switch(node.type) {
case 'ImportDeclaration':
case 'ImportDefaultSpecifier':
case 'ImportNamespaceSpecifier':
return true;
};
return false;
};
// Any form of es6 export
module.exports.isES6Export = function (node) {
return node.type === 'ExportDeclaration';
switch(node.type) {
case 'ExportDeclaration':
case 'ExportNamedDeclaration':
case 'ExportSpecifier':
case 'ExportDefaultDeclaration':
case 'ExportAllDeclaration':
return true;
};
return false;
};

2

package.json
{
"name": "ast-module-types",
"version": "2.2.2",
"version": "2.3.0",
"description": "Collection of useful helper functions when trying to determine module type (CommonJS or AMD) properties of an AST node.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -31,5 +31,7 @@ # ast-module-types [![travis](http://img.shields.io/travis/mrjoelkemp/ast-module-types.svg)](https://travis-ci.org/mrjoelkemp/node-ast-module-types/) [![npm](http://img.shields.io/npm/v/ast-module-types.svg)](https://npmjs.org/package/ast-module-types) [![npm](http://img.shields.io/npm/dm/ast-module-types.svg)](https://npmjs.org/package/ast-module-types)

* `isES6Import`: if the node is of the form: `import 'mylib'` or `import {something} from 'mylib'`
* `isES6Export`: if the node is of any es6 export form: ex: `export default 123;` or `export { D as default };`
*All types abide by the [EStree spec](https://github.com/estree/estree/blob/master/es6.md)*
* `isES6Import`: if the node is any of the es6 import forms
* `isES6Export`: if the node is of any es6 export forms
### Usage

@@ -36,0 +38,0 @@

@@ -94,3 +94,6 @@ var types = require('../');

it('detects es6 imports', function() {
assert(check('import {foo, bar} from "mylib";\nimport "mylib2"', types.isES6Import, true));
assert(check('import {foo, bar} from "mylib";', types.isES6Import, true));
assert(check('import * as foo from "mod.js";', types.isES6Import, true));
assert(check('import "mylib2";', types.isES6Import, true));
assert(check('import foo from "mod.js";', types.isES6Import, true));
});

@@ -100,6 +103,8 @@

assert(check('export default 123;', types.isES6Export, true));
assert(check('export {foo, bar};', types.isES6Export, true));
assert(check('export { D as default };', types.isES6Export, true));
assert(check('export function inc() { counter++; }', types.isES6Export, true));
assert(check('export * from "mod";', types.isES6Export, true));
});
});
});
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