module-definition
Advanced tools
Comparing version 1.0.2 to 1.0.3
57
index.js
@@ -20,2 +20,55 @@ var Walker = require('node-source-walk'), | ||
// Whether or not the node represents a require function call | ||
function isRequire(node) { | ||
var c = node.callee; | ||
return c && | ||
node.type === 'CallExpression' && | ||
c.type === 'Identifier' && | ||
c.name === 'require'; | ||
} | ||
function isCommonJS(node) { | ||
return isExports(node) || | ||
// there's a require with no define | ||
(hasRequire(node) && ! hasDefine(node)); | ||
} | ||
// Whether or not the node has a require call | ||
// somewhere in its ast | ||
function hasRequire(node) { | ||
var sawRequire = false; | ||
var walker = new Walker(); | ||
walker.traverse(node, function (node) { | ||
if (isRequire(node)) { | ||
sawRequire = true; | ||
walker.stopWalking(); | ||
} | ||
}); | ||
return sawRequire; | ||
} | ||
// Whether or not the node has a define call | ||
// somewhere in its ast | ||
function hasDefine(node) { | ||
var sawDefine = false; | ||
var walker = new Walker(); | ||
walker.traverse(node, function (node) { | ||
if (isDefine(node)) { | ||
sawDefine = true; | ||
walker.stopWalking(); | ||
} | ||
}); | ||
return sawDefine; | ||
} | ||
function isAMD(node) { | ||
return isDefine(node); | ||
} | ||
module.exports = function (file, cb) { | ||
@@ -38,7 +91,7 @@ if (! file) throw new Error('filename missing'); | ||
walker.walk(src, function (node) { | ||
if (isExports(node)) { | ||
if (isCommonJS(node)) { | ||
type = 'commonjs'; | ||
walker.stopWalking(); | ||
} else if (isDefine(node)) { | ||
} else if (isAMD(node)) { | ||
type = 'amd'; | ||
@@ -45,0 +98,0 @@ walker.stopWalking(); |
{ | ||
"name": "module-definition", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Determines if a file is using a CommonJS or AMD module definition", | ||
@@ -17,4 +17,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"node-source-walk": "^1.0.0" | ||
"node-source-walk": "^1.1.0" | ||
} | ||
} |
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
3535
9
99
Updatednode-source-walk@^1.1.0