Skip to content

Commit

Permalink
fix (Analyzer): Resolves overzealous matching of define statements
Browse files Browse the repository at this point in the history
This resolves a problem with define() calls that did not declare a dependency
array, but had an array immediately defined at the top of their factory
function. In these cases, the array was being identified as dependencies. To
resolve this, the Inject reject for define() now scans for [^)] instead of
the prior [\w\W] pattern.
  • Loading branch information
jakobo committed Jun 27, 2014
1 parent 0efc73f commit a6c976b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dist/recent/inject.js
Expand Up @@ -230,7 +230,7 @@ var REQUIRE_REGEX = new RegExp(
var DEFINE_REGEX = new RegExp(
'(?:^|[\\s;,\\?\\}\\)\\(])' + // begins with start of string, and any symbol a function call() can follow
'define[\\s]*\\(' + // the "define" keyword, followed by optional whitespace and its opening paren
'[\\w\\W]*?\\[' + // anything (don't care) until we hit the first [
'[^\\)]*?\\[' + // anything (not a closing paren) until we hit the first [
'([\\w\\W]*?)' + // our match (contents of the array)
'\\]', // the closing bracket
'gim' // flags: global, case-insensitive, multiline
Expand Down Expand Up @@ -4569,5 +4569,5 @@ var TreeNode = Fiber.extend(function() {


// initialize
init('0.7.0-rc4-1-g80da8ae');
init('0.7.0-rc4-4-g0efc73f');
})(this);
4 changes: 2 additions & 2 deletions dist/recent/inject.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/includes/constants.js
Expand Up @@ -132,7 +132,7 @@ var REQUIRE_REGEX = new RegExp(
var DEFINE_REGEX = new RegExp(
'(?:^|[\\s;,\\?\\}\\)\\(])' + // begins with start of string, and any symbol a function call() can follow
'define[\\s]*\\(' + // the "define" keyword, followed by optional whitespace and its opening paren
'[\\w\\W]*?\\[' + // anything (don't care) until we hit the first [
'[^\\)]*?\\[' + // anything (not a closing paren) until we hit the first [
'([\\w\\W]*?)' + // our match (contents of the array)
'\\]', // the closing bracket
'gim' // flags: global, case-insensitive, multiline
Expand Down
4 changes: 2 additions & 2 deletions src/rulesengine.js
Expand Up @@ -648,7 +648,7 @@ var RulesEngine = Fiber.extend(function() {
if (ABSOLUTE_PATH_REGEX.test(id)) {
return id;
}

// begins with a /, path is relative to root
if (id.indexOf('/') === 0) {
base = '';
Expand All @@ -663,7 +663,7 @@ var RulesEngine = Fiber.extend(function() {
for (i = 0, frags = id.split('/'), len = frags.length; i < len; i++) {
blownApartURL.push(frags[i]);
}

for (i = 0, len = blownApartURL.length; i < len; i++) {
piece = blownApartURL[i];

Expand Down
12 changes: 12 additions & 0 deletions tests/src/analyzer.html
Expand Up @@ -55,6 +55,12 @@
'});',
'']).join("\n");

var requireSampleCode_303 = ([
'define(function() {',
' var someThings = [\'one\', \'two\', \'three\'];',
'});',
'']).join("\n");

var sampleFunction = "function foo(one, two, three) {};";

test("Scaffolding", function() {
Expand Down Expand Up @@ -91,6 +97,12 @@
var result = analyzer.extractRequires(requireSampleCode_177);
equal(result.length, 3, "only three modules identified");
});

test("#303 define syntax overmatching on array", function() {
var analyzer = new Analyzer({});
var result = analyzer.extractRequires(requireSampleCode_303);
equal(result.length, 0, "no matches found when define goes straight into an array");
});
</script>
</body>
</html>

0 comments on commit a6c976b

Please sign in to comment.