Comparing version 2.0.7 to 2.0.8
19
index.js
@@ -1,8 +0,4 @@ | ||
/** | ||
* Created by nuintun on 2015/4/29. | ||
*/ | ||
'use strict'; | ||
// import lib | ||
// Import lib | ||
var util = require('./lib/util'); | ||
@@ -12,3 +8,4 @@ var parser = require('./lib/parser'); | ||
/** | ||
* cmd-deps | ||
* Cmd deps | ||
* | ||
* @param src | ||
@@ -19,7 +16,7 @@ * @param replace | ||
*/ | ||
module.exports = function (src, replace, flags){ | ||
// is buffer | ||
module.exports = function(src, replace, flags) { | ||
// Is buffer | ||
if (Buffer.isBuffer(src)) src = src.toString(); | ||
// normalize arguments | ||
// Normalize arguments | ||
if (replace === true || Array.isArray(replace)) { | ||
@@ -30,3 +27,3 @@ flags = replace === true ? ['async'] : replace; | ||
// flags | ||
// Flags | ||
if (flags === true) { | ||
@@ -36,3 +33,3 @@ flags = ['async']; | ||
// is has require | ||
// Is has require | ||
if (!util.string(src) || !/\brequire\b/.test(src)) { | ||
@@ -39,0 +36,0 @@ return replace ? src : []; |
@@ -1,13 +0,9 @@ | ||
/** | ||
* Created by nuintun on 2015/5/4. | ||
*/ | ||
'use strict'; | ||
// import lib | ||
// Import lib | ||
var util = require('./util'); | ||
var acorn = require('acorn'); | ||
// the parse function | ||
function parse(src, options){ | ||
// The parse function | ||
function parse(src, options) { | ||
if (!options) options = {}; | ||
@@ -27,4 +23,4 @@ | ||
// executes visitor on the object and its children (recursively). | ||
function traverse(object, visitor){ | ||
// Executes visitor on the object and its children (recursively). | ||
function traverse(object, visitor) { | ||
var key; | ||
@@ -46,14 +42,14 @@ var child; | ||
// the tree walk function | ||
function walk(src, options, callback){ | ||
// The tree walk function | ||
function walk(src, options, callback) { | ||
var syntax; | ||
// parse ast | ||
// Parse ast | ||
try { | ||
syntax = parse(src, options); | ||
} catch (error) { | ||
// parse ast wrong, do nothing | ||
// Parse ast wrong, do nothing | ||
} | ||
// if parse success | ||
// If parse success | ||
if (syntax) { | ||
@@ -66,4 +62,4 @@ traverse(syntax, callback); | ||
// the is require function | ||
function isRequire(node, word, flags){ | ||
// The is require function | ||
function isRequire(node, word, flags) { | ||
if (node.type === 'CallExpression') { | ||
@@ -75,3 +71,3 @@ node = node.callee; | ||
&& ((node.property.type === 'Identifier' && flags.indexOf(node.property.name) !== -1) | ||
|| (node.property.type === 'Literal' && flags.indexOf(node.property.value) !== -1)); | ||
|| (node.property.type === 'Literal' && flags.indexOf(node.property.value) !== -1)); | ||
} else { | ||
@@ -84,5 +80,5 @@ return node.type === 'Identifier' && node.name === word; | ||
/** | ||
* exports module | ||
* Exports module | ||
*/ | ||
module.exports = function (src, replace, options){ | ||
module.exports = function(src, replace, options) { | ||
var deps = []; | ||
@@ -104,8 +100,8 @@ var offset = 0; | ||
// the handle function | ||
var handle = function (node, flag){ | ||
// The handle function | ||
var handle = function(node, flag) { | ||
var update; | ||
var value = node.value; | ||
// push deps in to array | ||
// Push deps in to array | ||
deps.push({ | ||
@@ -116,3 +112,3 @@ flag: flag, | ||
// replace code | ||
// Replace code | ||
if (replace) { | ||
@@ -128,4 +124,4 @@ update = replace(value, flag); | ||
// walk code | ||
walk(src, options.parse, function (node){ | ||
// Walk code | ||
walk(src, options.parse, function(node) { | ||
if (isRequire(node, options.word, options.flags)) { | ||
@@ -136,3 +132,3 @@ var args = node.arguments; | ||
// when arguments length > 0 | ||
// When arguments length > 0 | ||
if (args.length) { | ||
@@ -144,3 +140,3 @@ args = args[0]; | ||
} else if (args.type === 'ArrayExpression') { | ||
args.elements.forEach(function (args){ | ||
args.elements.forEach(function(args) { | ||
if (args.type === 'Literal') { | ||
@@ -147,0 +143,0 @@ handle(args, flag); |
@@ -1,18 +0,14 @@ | ||
/** | ||
* Created by nuintun on 2015/5/26. | ||
*/ | ||
'use strict'; | ||
// variable declaration | ||
// Variable declaration | ||
var toString = Object.prototype.toString; | ||
/** | ||
* exports module | ||
* Exports module | ||
*/ | ||
module.exports = { | ||
// the noop function | ||
noop: function (){}, | ||
// get the first argument that is not equal undefined | ||
defined: function (){ | ||
// The noop function | ||
noop: function() {}, | ||
// Get the first argument that is not equal undefined | ||
defined: function() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
@@ -22,14 +18,14 @@ if (arguments[i] !== undefined) return arguments[i]; | ||
}, | ||
// is string | ||
string: function (string){ | ||
// Is string | ||
string: function(string) { | ||
return toString.call(string) === '[object String]'; | ||
}, | ||
// is function | ||
fn: function (fn){ | ||
// Is function | ||
fn: function(fn) { | ||
return toString.call(fn) === '[object Function]'; | ||
}, | ||
// is object | ||
object: function (object){ | ||
// Is object | ||
object: function(object) { | ||
return toString.call(object) === '[object Object]'; | ||
} | ||
}; |
{ | ||
"name": "cmd-deps", | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"description": "Transform cmd and get cmd dependences", | ||
@@ -29,3 +29,3 @@ "author": { | ||
"dependencies": { | ||
"acorn": "^4.0.8" | ||
"acorn": "^4.0.11" | ||
}, | ||
@@ -32,0 +32,0 @@ "devDependencies": { |
9206
6
178
Updatedacorn@^4.0.11