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.6.0 to 2.7.0

26

index.js

@@ -1,2 +0,5 @@

// Whether or not the node represents an AMD define() call
// Deprecated
// Whether or not the node represents a generic define() call
// Note: this should not be used as it will have false positives.
// It is mostly used to guide sniffs for other methods and will be made private eventually.
module.exports.isDefine = function (node) {

@@ -13,2 +16,13 @@ if (!node) return false;

// Whether or not the node represents any of the AMD define() forms
module.exports.isDefineAMD = function (node) {
if (!node) return false;
var e = module.exports;
return e.isNamedForm(node) || e.isDependencyForm(node) ||
e.isFactoryForm(node) || e.isNoDependencyForm(node) ||
e.isREMForm(node);
};
// Whether or not the node represents a require function call

@@ -128,3 +142,3 @@ module.exports.isRequire = function (node) {

return args && (args[0].type === 'Literal' || args[0].type === 'StringLiteral');
return args && args.length > 0 && (args[0].type === 'Literal' || args[0].type === 'StringLiteral');
};

@@ -138,3 +152,3 @@

return args && args[0].type === 'ArrayExpression';
return args && args.length > 0 && args[0].type === 'ArrayExpression';
};

@@ -150,3 +164,3 @@

// Node should have a function whose first param is 'require'
return args && args[0].type === 'FunctionExpression' &&
return args && args.length > 0 && args[0].type === 'FunctionExpression' &&
firstParamNode && firstParamNode.type === 'Identifier' && firstParamNode.name === 'require';

@@ -161,3 +175,3 @@ };

return args && args[0].type === 'ObjectExpression';
return args && args.length > 0 && args[0].type === 'ObjectExpression';
};

@@ -173,3 +187,3 @@

if (!args || args[0].type !== 'FunctionExpression' || params.length !== 3) {
if (!args || args.length == 0 || args[0].type !== 'FunctionExpression' || params.length !== 3) {
return false;

@@ -176,0 +190,0 @@ }

{
"name": "ast-module-types",
"version": "2.6.0",
"version": "2.7.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",

@@ -15,3 +15,3 @@ # 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)

* `isDefine`: if node matches an AMD `define` function call (defining a module)
* `isDefineAMD`: if node matches any form of an AMD `define` function call
* `isRequire`: if node matches a `require` function all (declaring a dependency)

@@ -45,3 +45,3 @@ * `isTopLevelRequire`: if node matches a `require` at the very top of the file.

console.log(types.isDefine(node));
console.log(types.isDefineAMD(node));
```

@@ -32,2 +32,22 @@ var types = require('../');

describe('isDefineAMD', function() {
it('does not detect a generic define function call', function() {
assert(!check('define();', types.isDefineAMD));
// Named form
assert(check('define("foobar", ["a"], function(a){});', types.isDefineAMD));
// Dependency form
assert(check('define(["a"], function(a){});', types.isDefineAMD));
// Factory form
assert(check('define(function(require){});', types.isDefineAMD));
// REM form
assert(check('define(function(require, exports, module){});', types.isDefineAMD));
// No-dependency form
assert(check('define({});', types.isDefineAMD));
});
it('detect a named form AMD define function call', function() {
assert(!check('define();', types.isDefineAMD));
});
});
describe('isRequire', function() {

@@ -34,0 +54,0 @@ it('detects require function calls', function() {

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