Skip to content

Commit 52c268d

Browse files
taiontimdorr
authored andcommitted
Upgrade to Babel 6 (#3362)
1 parent f67a187 commit 52c268d

File tree

5 files changed

+75
-58
lines changed

5 files changed

+75
-58
lines changed

.babelrc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
{
2-
"stage": 0,
3-
"loose": "all",
4-
"plugins": [
5-
"dev-expression"
6-
]
2+
"presets": ["stage-0", "react"],
3+
"plugins": ["dev-expression"],
4+
5+
"env": {
6+
"cjs": {
7+
"presets": ["es2015-loose"],
8+
"plugins": ["add-module-exports"]
9+
},
10+
"es": {
11+
"presets": ["es2015-loose-native-modules"]
12+
}
13+
}
714
}

modules/PatternUtils.js

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,29 @@ export function matchPattern(pattern, pathname) {
9494
}
9595

9696
const match = pathname.match(new RegExp(`^${regexpSource}`, 'i'))
97+
if (match == null) {
98+
return null
99+
}
100+
101+
const matchedPath = match[0]
102+
let remainingPathname = pathname.substr(matchedPath.length)
97103

98-
let remainingPathname, paramValues
99-
if (match != null) {
100-
const matchedPath = match[0]
101-
remainingPathname = pathname.substr(matchedPath.length)
102-
103-
if (remainingPathname) {
104-
// Require that the match ends at a path separator, if we didn't match
105-
// the full path, so any remaining pathname is a new path segment.
106-
if (matchedPath.charAt(matchedPath.length - 1) !== '/') {
107-
return {
108-
remainingPathname: null,
109-
paramNames,
110-
paramValues: null
111-
}
112-
}
113-
114-
// If there is a remaining pathname, treat the path separator as part of
115-
// the remaining pathname for properly continuing the match.
116-
remainingPathname = `/${remainingPathname}`
104+
if (remainingPathname) {
105+
// Require that the match ends at a path separator, if we didn't match
106+
// the full path, so any remaining pathname is a new path segment.
107+
if (matchedPath.charAt(matchedPath.length - 1) !== '/') {
108+
return null
117109
}
118110

119-
paramValues = match.slice(1).map(v => v && decodeURIComponent(v))
120-
} else {
121-
remainingPathname = paramValues = null
111+
// If there is a remaining pathname, treat the path separator as part of
112+
// the remaining pathname for properly continuing the match.
113+
remainingPathname = `/${remainingPathname}`
122114
}
123115

124116
return {
125117
remainingPathname,
126118
paramNames,
127-
paramValues
119+
paramValues: match.slice(1).map(v => v && decodeURIComponent(v))
128120
}
129121
}
130122

@@ -133,16 +125,19 @@ export function getParamNames(pattern) {
133125
}
134126

135127
export function getParams(pattern, pathname) {
136-
const { paramNames, paramValues } = matchPattern(pattern, pathname)
137-
138-
if (paramValues != null) {
139-
return paramNames.reduce(function (memo, paramName, index) {
140-
memo[paramName] = paramValues[index]
141-
return memo
142-
}, {})
128+
const match = matchPattern(pattern, pathname)
129+
if (!match) {
130+
return null
143131
}
144132

145-
return null
133+
const { paramNames, paramValues } = match
134+
const params = {}
135+
136+
paramNames.forEach((paramName, index) => {
137+
params[paramName] = paramValues[index]
138+
})
139+
140+
return params
146141
}
147142

148143
/**

modules/isActive.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ function routeIsActive(pathname, routes, params) {
8282

8383
if (remainingPathname !== null && pattern) {
8484
const matched = matchPattern(pattern, remainingPathname)
85-
remainingPathname = matched.remainingPathname
86-
paramNames = [ ...paramNames, ...matched.paramNames ]
87-
paramValues = [ ...paramValues, ...matched.paramValues ]
85+
if (matched) {
86+
remainingPathname = matched.remainingPathname
87+
paramNames = [ ...paramNames, ...matched.paramNames ]
88+
paramValues = [ ...paramValues, ...matched.paramValues ]
89+
} else {
90+
remainingPathname = null
91+
}
8892

8993
if (remainingPathname === '') {
9094
// We have an exact match on the route. Just check that all the params

modules/matchRoutes.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,13 @@ function matchRouteDeep(
8989
// we're not just searching for potential nested absolute paths.
9090
if (remainingPathname !== null && pattern) {
9191
const matched = matchPattern(pattern, remainingPathname)
92-
remainingPathname = matched.remainingPathname
93-
paramNames = [ ...paramNames, ...matched.paramNames ]
94-
paramValues = [ ...paramValues, ...matched.paramValues ]
92+
if (matched) {
93+
remainingPathname = matched.remainingPathname
94+
paramNames = [ ...paramNames, ...matched.paramNames ]
95+
paramValues = [ ...paramValues, ...matched.paramValues ]
96+
} else {
97+
remainingPathname = null
98+
}
9599

96100
// By assumption, pattern is non-empty here, which is the prerequisite for
97101
// actually terminating a match.

package.json

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
"homepage": "https://github.com/reactjs/react-router#readme",
1616
"bugs": "https://github.com/reactjs/react-router/issues",
1717
"scripts": {
18-
"build": "npm run build-cjs && npm run build-es6",
19-
"build-cjs": "rimraf lib && babel ./modules -d lib --ignore '__tests__'",
20-
"build-es6": "rimraf es6 && babel ./modules -d es6 --blacklist=es6.modules --ignore '__tests__'",
21-
"build-umd": "NODE_ENV=development webpack modules/index.js umd/ReactRouter.js",
22-
"build-min": "NODE_ENV=production webpack -p modules/index.js umd/ReactRouter.min.js",
18+
"build": "npm run build-cjs && npm run build-es",
19+
"build-cjs": "rimraf lib && BABEL_ENV=cjs babel ./modules -d lib --ignore '__tests__'",
20+
"build-es": "rimraf es6 && BABEL_ENV=es babel ./modules -d es6 --ignore '__tests__'",
21+
"build-umd": "BABEL_ENV=cjs NODE_ENV=development webpack modules/index.js umd/ReactRouter.js",
22+
"build-min": "BABEL_ENV=cjs NODE_ENV=production webpack -p modules/index.js umd/ReactRouter.min.js",
2323
"lint": "eslint modules examples",
24-
"start": "node examples/server.js",
24+
"start": "BABEL_ENV=cjs node examples/server.js",
2525
"test": "npm run lint && npm run test-node && npm run test-browser",
26-
"test-browser": "karma start",
27-
"test-node": "mocha --compilers js:babel-core/register tests.node.js"
26+
"test-browser": "BABEL_ENV=cjs karma start",
27+
"test-node": "BABEL_ENV=cjs mocha --compilers js:babel-register tests.node.js"
2828
},
2929
"authors": [
3030
"Ryan Florence",
@@ -40,29 +40,36 @@
4040
"react": "^0.14.0 || ^15.0.0"
4141
},
4242
"devDependencies": {
43-
"babel": "^5.8.38",
44-
"babel-core": "^5.8.38",
45-
"babel-eslint": "^4.1.8",
46-
"babel-loader": "^5.4.0",
47-
"babel-plugin-dev-expression": "^0.1.0",
43+
"babel-cli": "^6.7.5",
44+
"babel-core": "^6.7.6",
45+
"babel-eslint": "^5.0.4",
46+
"babel-loader": "^6.2.4",
47+
"babel-plugin-add-module-exports": "^0.1.2",
48+
"babel-plugin-dev-expression": "^0.2.1",
49+
"babel-preset-es2015": "^6.6.0",
50+
"babel-preset-es2015-loose": "^7.0.0",
51+
"babel-preset-es2015-loose-native-modules": "^1.0.0",
52+
"babel-preset-react": "^6.5.0",
53+
"babel-preset-stage-0": "^6.5.0",
54+
"babel-register": "^6.7.2",
4855
"bundle-loader": "^0.5.4",
4956
"codecov.io": "^0.1.6",
5057
"coveralls": "^2.11.9",
5158
"css-loader": "^0.23.1",
5259
"eslint": "^1.10.3",
5360
"eslint-config-rackt": "^1.1.1",
5461
"eslint-plugin-react": "^3.16.1",
55-
"expect": "^1.16.0",
62+
"expect": "^1.18.0",
5663
"express": "^4.13.4",
5764
"express-urlrewrite": "^1.2.0",
5865
"gzip-size": "^3.0.0",
59-
"isparta-loader": "^1.0.0",
66+
"isparta-loader": "^2.0.0",
6067
"karma": "^0.13.22",
6168
"karma-browserstack-launcher": "^0.1.10",
6269
"karma-chrome-launcher": "^0.2.3",
6370
"karma-coverage": "^0.5.5",
6471
"karma-mocha": "^0.2.2",
65-
"karma-mocha-reporter": "^2.0.0",
72+
"karma-mocha-reporter": "^2.0.1",
6673
"karma-sourcemap-loader": "^0.3.7",
6774
"karma-webpack": "^1.7.0",
6875
"mocha": "^2.4.5",

0 commit comments

Comments
 (0)