amdextract
Advanced tools
Comparing version 1.0.4 to 1.1.0
51
index.js
@@ -13,3 +13,3 @@ /* | ||
commentRegExp = /(?:\/\*[^]*?\*\/)|(?:\/\/[^]*?$)/gm, | ||
commaRegExp = /\s*,\s*/, | ||
commaRegExp = /(\s*),(\s*)/, | ||
@@ -67,2 +67,19 @@ getModuleBody = function (text) { | ||
}); | ||
}, | ||
splitByComma = function (str) { | ||
var result = [], | ||
parts = str.split(commaRegExp), | ||
tokensLength = (parts.length + 2) / 3; | ||
for (var i = 0; i < tokensLength; i++) { | ||
var index = 3 * i; | ||
result.push({ | ||
before: parts[index - 1], | ||
token: parts[index], | ||
after: parts[index + 1] | ||
}); | ||
} | ||
return result; | ||
}; | ||
@@ -90,3 +107,3 @@ | ||
if (exceptsPathsStr) { | ||
exceptsPaths = options.exceptsPaths.concat(exceptsPathsStr.split(commaRegExp)); | ||
exceptsPaths = options.exceptsPaths.concat(splitByComma(exceptsPathsStr).map(function (p) { return p.token; })); | ||
} | ||
@@ -97,10 +114,12 @@ | ||
paths = commentlessPathsStr ? commentlessPathsStr.split(commaRegExp).map(function (p) { | ||
paths = commentlessPathsStr ? splitByComma(commentlessPathsStr).map(function (p) { | ||
return { | ||
path: p.substr(1, p.length - 2), | ||
quote: p[0] | ||
path: p.token.substr(1, p.token.length - 2), | ||
quote: p.token[0], | ||
before: p.before, | ||
after: p.after | ||
}; | ||
}) : []; | ||
dependencies = commentlessDependenciesStr ? commentlessDependenciesStr.split(commaRegExp) : []; | ||
dependencies = commentlessDependenciesStr ? splitByComma(commentlessDependenciesStr) : []; | ||
@@ -117,5 +136,5 @@ if (text) { | ||
var index = dependencies.indexOf(dependency); | ||
return !isException(excepts, dependency) && | ||
return !isException(excepts, dependency.token) && | ||
(index >= paths.length || !isException(exceptsPaths, paths[index].path)) && | ||
!findUseage(dependency, source); | ||
!findUseage(dependency.token, source); | ||
}); | ||
@@ -134,4 +153,4 @@ | ||
unusedPaths: unusedPaths.map(function (p) { return p.path; }), | ||
dependencies: dependencies, | ||
unusedDependencies: unusedDependencies, | ||
dependencies: dependencies.map(function (d) { return d.token; }), | ||
unusedDependencies: unusedDependencies.map(function (d) { return d.token; }), | ||
bodyWithComments: body, | ||
@@ -153,4 +172,12 @@ bodyWithoutComments: source, | ||
match = match.replace(pathsStr, usedPaths.map(function (p) { return p.quote + p.path + p.quote; }).join(', ')) | ||
.replace(dependenciesStr, usedDependencies.join(', ')); | ||
match = match.replace(pathsStr, usedPaths.map(function (p, index, array) { | ||
var before = (index === 0 || !p.before) ? '' : p.before; | ||
var after = (index === array.length || !p.after) ? '' : p.after; | ||
return before + p.quote + p.path + p.quote + after; | ||
}).join(',')) | ||
.replace(dependenciesStr, usedDependencies.map(function (d, index, array) { | ||
var before = (index === 0 || !d.before) ? '' : d.before; | ||
var after = (index === array.length || !d.after) ? '' : d.after; | ||
return before + d.token + after; | ||
}).join(',')); | ||
} | ||
@@ -157,0 +184,0 @@ |
{ | ||
"name": "amdextract", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Extracts AMD modules and their parts.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -123,4 +123,5 @@ # amdextract [![Build Status](https://travis-ci.org/mehdishojaei/amdextract.png)](https://travis-ci.org/mehdishojaei/amdextract) | ||
## Release History | ||
* 2014-04-19 v1.1.0 Keeps the original separators of paths and dependencies. | ||
* 2014-04-09 v1.0.4 Fix a bug when dependencies length is grater than paths length. | ||
* 2014-03-29 v1.0.3 Fix a bug when specifying exceptsPaths in options only. | ||
* 2014-03-17 v1.0.0 First release. |
// General test for all cases. | ||
/* exceptsPaths: p3 */ | ||
define('name', ["p2", 'p3', "t5", 'm6', 'm7'], function (b, c) { | ||
define('name', ["p2" | ||
, 'p3', "t5" , 'm6' | ||
, | ||
'm7'], function (b | ||
, c) { | ||
/** | ||
@@ -6,0 +14,0 @@ * a.fetch() must not be encountered as code. |
// General test for all cases. | ||
/* exceptsPaths: p3 */ | ||
define('name', ["p1", "p2", 'p3', "p4", "t5", 'm6', 'm7'], function (a, b, c) { | ||
define('name', ["p1", | ||
"p2" | ||
, 'p3', | ||
"p4", "t5" , 'm6' | ||
, | ||
'm7'], function (a , b | ||
, c) { | ||
/** | ||
@@ -6,0 +16,0 @@ * a.fetch() must not be encountered as code. |
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
20389
331
127