Skip to content

Commit 57543eb

Browse files
committed
Version 0.13.3
1 parent 04c8487 commit 57543eb

38 files changed

+1314
-1309
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v0.13.3 - Wed, 29 Apr 2015 01:47:08 GMT
2+
---------------------------------------
3+
4+
-
5+
6+
17
v0.13.2 - Tue, 24 Mar 2015 14:22:07 GMT
28
---------------------------------------
39

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-router",
3-
"version": "0.13.2",
3+
"version": "0.13.3",
44
"description": "A complete routing library for React.js",
55
"main": "build/umd/ReactRouter.js",
66
"homepage": "https://github.com/rackt/react-router",

build/lib/History.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"use strict";
1+
'use strict';
22

3-
var invariant = require("react/lib/invariant");
4-
var canUseDOM = require("react/lib/ExecutionEnvironment").canUseDOM;
3+
var invariant = require('react/lib/invariant');
4+
var canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM;
55

66
var History = {
77

@@ -16,7 +16,7 @@ var History = {
1616
* Sends the browser back one entry in the history.
1717
*/
1818
back: function back() {
19-
invariant(canUseDOM, "Cannot use History.back without a DOM");
19+
invariant(canUseDOM, 'Cannot use History.back without a DOM');
2020

2121
// Do this first so that History.length will
2222
// be accurate in location change listeners.

build/lib/Match.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
"use strict";
1+
'use strict';
22

3-
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
3+
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
44

5-
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
5+
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
66

77
/* jshint -W084 */
8-
var PathUtils = require("./PathUtils");
8+
var PathUtils = require('./PathUtils');
99

1010
function deepSearch(route, pathname, query) {
1111
// Check the subtree first to find the most deeply-nested match.
@@ -50,26 +50,24 @@ var Match = (function () {
5050
this.routes = routes;
5151
}
5252

53-
_createClass(Match, null, {
54-
findMatch: {
53+
_createClass(Match, null, [{
54+
key: 'findMatch',
5555

56-
/**
57-
* Attempts to match depth-first a route in the given route's
58-
* subtree against the given path and returns the match if it
59-
* succeeds, null if no match can be made.
60-
*/
56+
/**
57+
* Attempts to match depth-first a route in the given route's
58+
* subtree against the given path and returns the match if it
59+
* succeeds, null if no match can be made.
60+
*/
61+
value: function findMatch(routes, path) {
62+
var pathname = PathUtils.withoutQuery(path);
63+
var query = PathUtils.extractQuery(path);
64+
var match = null;
6165

62-
value: function findMatch(routes, path) {
63-
var pathname = PathUtils.withoutQuery(path);
64-
var query = PathUtils.extractQuery(path);
65-
var match = null;
66+
for (var i = 0, len = routes.length; match == null && i < len; ++i) match = deepSearch(routes[i], pathname, query);
6667

67-
for (var i = 0, len = routes.length; match == null && i < len; ++i) match = deepSearch(routes[i], pathname, query);
68-
69-
return match;
70-
}
68+
return match;
7169
}
72-
});
70+
}]);
7371

7472
return Match;
7573
})();

build/lib/Navigation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"use strict";
1+
'use strict';
22

3-
var PropTypes = require("./PropTypes");
3+
var PropTypes = require('./PropTypes');
44

55
/**
66
* A mixin for components that modify the URL.

build/lib/PathUtils.js

Lines changed: 51 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,36 @@
1-
/* jshint -W084 */
2-
"use strict";
1+
'use strict';
32

4-
var invariant = require("react/lib/invariant");
5-
var assign = require("object-assign");
6-
var qs = require("qs");
3+
var invariant = require('react/lib/invariant');
4+
var assign = require('object-assign');
5+
var qs = require('qs');
76

7+
var paramCompileMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|[*.()\[\]\\+|{}^$]/g;
8+
var paramInjectMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$?]*[?]?)|[*]/g;
9+
var paramInjectTrailingSlashMatcher = /\/\/\?|\/\?\/|\/\?/g;
810
var queryMatcher = /\?(.*)$/;
911

10-
function escapeRegExp(string) {
11-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
12-
}
13-
14-
function _compilePattern(pattern) {
15-
var escapedSource = "";
16-
var paramNames = [];
17-
var tokens = [];
18-
19-
var match,
20-
lastIndex = 0,
21-
matcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|\*|\(|\)/g;
22-
while (match = matcher.exec(pattern)) {
23-
if (match.index !== lastIndex) {
24-
tokens.push(pattern.slice(lastIndex, match.index));
25-
escapedSource += escapeRegExp(pattern.slice(lastIndex, match.index));
26-
}
27-
28-
if (match[1]) {
29-
escapedSource += "([^/?#]+)";
30-
paramNames.push(match[1]);
31-
} else if (match[0] === "*") {
32-
escapedSource += "(.*?)";
33-
paramNames.push("splat");
34-
} else if (match[0] === "(") {
35-
escapedSource += "(?:";
36-
} else if (match[0] === ")") {
37-
escapedSource += ")?";
38-
}
39-
40-
tokens.push(match[0]);
41-
42-
lastIndex = matcher.lastIndex;
43-
}
44-
45-
if (lastIndex !== pattern.length) {
46-
tokens.push(pattern.slice(lastIndex, pattern.length));
47-
escapedSource += escapeRegExp(pattern.slice(lastIndex, pattern.length));
48-
}
49-
50-
return {
51-
pattern: pattern,
52-
escapedSource: escapedSource,
53-
paramNames: paramNames,
54-
tokens: tokens
55-
};
56-
}
57-
5812
var _compiledPatterns = {};
5913

6014
function compilePattern(pattern) {
61-
if (!(pattern in _compiledPatterns)) _compiledPatterns[pattern] = _compilePattern(pattern);
15+
if (!(pattern in _compiledPatterns)) {
16+
var paramNames = [];
17+
var source = pattern.replace(paramCompileMatcher, function (match, paramName) {
18+
if (paramName) {
19+
paramNames.push(paramName);
20+
return '([^/?#]+)';
21+
} else if (match === '*') {
22+
paramNames.push('splat');
23+
return '(.*?)';
24+
} else {
25+
return '\\' + match;
26+
}
27+
});
28+
29+
_compiledPatterns[pattern] = {
30+
matcher: new RegExp('^' + source + '$', 'i'),
31+
paramNames: paramNames
32+
};
33+
}
6234

6335
return _compiledPatterns[pattern];
6436
}
@@ -69,14 +41,14 @@ var PathUtils = {
6941
* Returns true if the given path is absolute.
7042
*/
7143
isAbsolute: function isAbsolute(path) {
72-
return path.charAt(0) === "/";
44+
return path.charAt(0) === '/';
7345
},
7446

7547
/**
7648
* Joins two URL paths together.
7749
*/
7850
join: function join(a, b) {
79-
return a.replace(/\/*$/, "/") + b;
51+
return a.replace(/\/*$/, '/') + b;
8052
},
8153

8254
/**
@@ -92,12 +64,11 @@ var PathUtils = {
9264
* pattern does not match the given path.
9365
*/
9466
extractParams: function extractParams(pattern, path) {
95-
var _compilePattern2 = compilePattern(pattern);
67+
var _compilePattern = compilePattern(pattern);
9668

97-
var escapedSource = _compilePattern2.escapedSource;
98-
var paramNames = _compilePattern2.paramNames;
69+
var matcher = _compilePattern.matcher;
70+
var paramNames = _compilePattern.paramNames;
9971

100-
var matcher = new RegExp("^" + escapedSource + "$", "i");
10172
var match = path.match(matcher);
10273

10374
if (!match) {
@@ -118,41 +89,31 @@ var PathUtils = {
11889
injectParams: function injectParams(pattern, params) {
11990
params = params || {};
12091

121-
var _compilePattern2 = compilePattern(pattern);
122-
123-
var tokens = _compilePattern2.tokens;
92+
var splatIndex = 0;
12493

125-
var parenCount = 0,
126-
pathname = "",
127-
splatIndex = 0;
94+
return pattern.replace(paramInjectMatcher, function (match, paramName) {
95+
paramName = paramName || 'splat';
12896

129-
var token, paramName, paramValue;
130-
for (var i = 0, len = tokens.length; i < len; ++i) {
131-
token = tokens[i];
97+
// If param is optional don't check for existence
98+
if (paramName.slice(-1) === '?') {
99+
paramName = paramName.slice(0, -1);
132100

133-
if (token === "*") {
134-
paramValue = Array.isArray(params.splat) ? params.splat[splatIndex++] : params.splat;
135-
136-
invariant(paramValue != null || parenCount > 0, "Missing splat #%s for path \"%s\"", splatIndex, pattern);
137-
138-
if (paramValue != null) pathname += paramValue;
139-
} else if (token === "(") {
140-
parenCount += 1;
141-
} else if (token === ")") {
142-
parenCount -= 1;
143-
} else if (token.charAt(0) === ":") {
144-
paramName = token.substring(1);
145-
paramValue = params[paramName];
101+
if (params[paramName] == null) return '';
102+
} else {
103+
invariant(params[paramName] != null, 'Missing "%s" parameter for path "%s"', paramName, pattern);
104+
}
146105

147-
invariant(paramValue != null || parenCount > 0, "Missing \"%s\" parameter for path \"%s\"", paramName, pattern);
106+
var segment;
107+
if (paramName === 'splat' && Array.isArray(params[paramName])) {
108+
segment = params[paramName][splatIndex++];
148109

149-
if (paramValue != null) pathname += paramValue;
110+
invariant(segment != null, 'Missing splat # %s for path "%s"', splatIndex, pattern);
150111
} else {
151-
pathname += token;
112+
segment = params[paramName];
152113
}
153-
}
154114

155-
return pathname.replace(/\/+/g, "/");
115+
return segment;
116+
}).replace(paramInjectTrailingSlashMatcher, '/');
156117
},
157118

158119
/**
@@ -168,7 +129,7 @@ var PathUtils = {
168129
* Returns a version of the given path without the query string.
169130
*/
170131
withoutQuery: function withoutQuery(path) {
171-
return path.replace(queryMatcher, "");
132+
return path.replace(queryMatcher, '');
172133
},
173134

174135
/**
@@ -180,10 +141,10 @@ var PathUtils = {
180141

181142
if (existingQuery) query = query ? assign(existingQuery, query) : existingQuery;
182143

183-
var queryString = qs.stringify(query, { arrayFormat: "brackets" });
144+
var queryString = qs.stringify(query, { arrayFormat: 'brackets' });
184145

185146
if (queryString) {
186-
return PathUtils.withoutQuery(path) + "?" + queryString;
147+
return PathUtils.withoutQuery(path) + '?' + queryString;
187148
}return PathUtils.withoutQuery(path);
188149
}
189150

build/lib/PropTypes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"use strict";
1+
'use strict';
22

3-
var assign = require("react/lib/Object.assign");
4-
var ReactPropTypes = require("react").PropTypes;
5-
var Route = require("./Route");
3+
var assign = require('react/lib/Object.assign');
4+
var ReactPropTypes = require('react').PropTypes;
5+
var Route = require('./Route');
66

77
var PropTypes = assign({}, ReactPropTypes, {
88

@@ -11,7 +11,7 @@ var PropTypes = assign({}, ReactPropTypes, {
1111
*/
1212
falsy: function falsy(props, propName, componentName) {
1313
if (props[propName]) {
14-
return new Error("<" + componentName + "> should not have a \"" + propName + "\" prop");
14+
return new Error('<' + componentName + '> should not have a "' + propName + '" prop');
1515
}
1616
},
1717

0 commit comments

Comments
 (0)