Skip to content

Commit

Permalink
Upgrade to Babel 6
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Apr 20, 2016
1 parent f67a187 commit ae98370
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 58 deletions.
17 changes: 12 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"stage": 0,
"loose": "all",
"plugins": [
"dev-expression"
]
"presets": ["stage-0", "react"],
"plugins": ["dev-expression"],

"env": {
"cjs": {
"presets": ["es2015-loose"],
"plugins": ["add-module-exports"]
},
"es": {
"presets": ["es2015-loose-native-modules"]
}
}
}
57 changes: 26 additions & 31 deletions modules/PatternUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,29 @@ export function matchPattern(pattern, pathname) {
}

const match = pathname.match(new RegExp(`^${regexpSource}`, 'i'))
if (match == null) {
return null
}

const matchedPath = match[0]
let remainingPathname = pathname.substr(matchedPath.length)

let remainingPathname, paramValues
if (match != null) {
const matchedPath = match[0]
remainingPathname = pathname.substr(matchedPath.length)

if (remainingPathname) {
// Require that the match ends at a path separator, if we didn't match
// the full path, so any remaining pathname is a new path segment.
if (matchedPath.charAt(matchedPath.length - 1) !== '/') {
return {
remainingPathname: null,
paramNames,
paramValues: null
}
}

// If there is a remaining pathname, treat the path separator as part of
// the remaining pathname for properly continuing the match.
remainingPathname = `/${remainingPathname}`
if (remainingPathname) {
// Require that the match ends at a path separator, if we didn't match
// the full path, so any remaining pathname is a new path segment.
if (matchedPath.charAt(matchedPath.length - 1) !== '/') {
return null
}

paramValues = match.slice(1).map(v => v && decodeURIComponent(v))
} else {
remainingPathname = paramValues = null
// If there is a remaining pathname, treat the path separator as part of
// the remaining pathname for properly continuing the match.
remainingPathname = `/${remainingPathname}`
}

return {
remainingPathname,
paramNames,
paramValues
paramValues: match.slice(1).map(v => v && decodeURIComponent(v))
}
}

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

export function getParams(pattern, pathname) {
const { paramNames, paramValues } = matchPattern(pattern, pathname)

if (paramValues != null) {
return paramNames.reduce(function (memo, paramName, index) {
memo[paramName] = paramValues[index]
return memo
}, {})
const match = matchPattern(pattern, pathname)
if (!match) {
return null
}

return null
const { paramNames, paramValues } = match
const params = {}

paramNames.forEach((paramName, index) => {
params[paramName] = paramValues[index]
})

return params
}

/**
Expand Down
10 changes: 7 additions & 3 deletions modules/isActive.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ function routeIsActive(pathname, routes, params) {

if (remainingPathname !== null && pattern) {
const matched = matchPattern(pattern, remainingPathname)
remainingPathname = matched.remainingPathname
paramNames = [ ...paramNames, ...matched.paramNames ]
paramValues = [ ...paramValues, ...matched.paramValues ]
if (matched) {
remainingPathname = matched.remainingPathname
paramNames = [ ...paramNames, ...matched.paramNames ]
paramValues = [ ...paramValues, ...matched.paramValues ]
} else {
remainingPathname = null
}

if (remainingPathname === '') {
// We have an exact match on the route. Just check that all the params
Expand Down
10 changes: 7 additions & 3 deletions modules/matchRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ function matchRouteDeep(
// we're not just searching for potential nested absolute paths.
if (remainingPathname !== null && pattern) {
const matched = matchPattern(pattern, remainingPathname)
remainingPathname = matched.remainingPathname
paramNames = [ ...paramNames, ...matched.paramNames ]
paramValues = [ ...paramValues, ...matched.paramValues ]
if (matched) {
remainingPathname = matched.remainingPathname
paramNames = [ ...paramNames, ...matched.paramNames ]
paramValues = [ ...paramValues, ...matched.paramValues ]
} else {
remainingPathname = null
}

// By assumption, pattern is non-empty here, which is the prerequisite for
// actually terminating a match.
Expand Down
39 changes: 23 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"homepage": "https://github.com/reactjs/react-router#readme",
"bugs": "https://github.com/reactjs/react-router/issues",
"scripts": {
"build": "npm run build-cjs && npm run build-es6",
"build-cjs": "rimraf lib && babel ./modules -d lib --ignore '__tests__'",
"build-es6": "rimraf es6 && babel ./modules -d es6 --blacklist=es6.modules --ignore '__tests__'",
"build-umd": "NODE_ENV=development webpack modules/index.js umd/ReactRouter.js",
"build-min": "NODE_ENV=production webpack -p modules/index.js umd/ReactRouter.min.js",
"build": "npm run build-cjs && npm run build-es",
"build-cjs": "rimraf lib && BABEL_ENV=cjs babel ./modules -d lib --ignore '__tests__'",
"build-es": "rimraf es6 && BABEL_ENV=es babel ./modules -d es6 --ignore '__tests__'",
"build-umd": "BABEL_ENV=cjs NODE_ENV=development webpack modules/index.js umd/ReactRouter.js",
"build-min": "BABEL_ENV=cjs NODE_ENV=production webpack -p modules/index.js umd/ReactRouter.min.js",
"lint": "eslint modules examples",
"start": "node examples/server.js",
"start": "BABEL_ENV=cjs node examples/server.js",
"test": "npm run lint && npm run test-node && npm run test-browser",
"test-browser": "karma start",
"test-node": "mocha --compilers js:babel-core/register tests.node.js"
"test-browser": "BABEL_ENV=cjs karma start",
"test-node": "BABEL_ENV=cjs mocha --compilers js:babel-register tests.node.js"
},
"authors": [
"Ryan Florence",
Expand All @@ -40,29 +40,36 @@
"react": "^0.14.0 || ^15.0.0"
},
"devDependencies": {
"babel": "^5.8.38",
"babel-core": "^5.8.38",
"babel-eslint": "^4.1.8",
"babel-loader": "^5.4.0",
"babel-plugin-dev-expression": "^0.1.0",
"babel-cli": "^6.7.5",
"babel-core": "^6.7.6",
"babel-eslint": "^5.0.4",
"babel-loader": "^6.2.4",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-dev-expression": "^0.2.1",
"babel-preset-es2015": "^6.6.0",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-es2015-loose-native-modules": "^1.0.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.7.2",
"bundle-loader": "^0.5.4",
"codecov.io": "^0.1.6",
"coveralls": "^2.11.9",
"css-loader": "^0.23.1",
"eslint": "^1.10.3",
"eslint-config-rackt": "^1.1.1",
"eslint-plugin-react": "^3.16.1",
"expect": "^1.16.0",
"expect": "^1.18.0",
"express": "^4.13.4",
"express-urlrewrite": "^1.2.0",
"gzip-size": "^3.0.0",
"isparta-loader": "^1.0.0",
"isparta-loader": "^2.0.0",
"karma": "^0.13.22",
"karma-browserstack-launcher": "^0.1.10",
"karma-chrome-launcher": "^0.2.3",
"karma-coverage": "^0.5.5",
"karma-mocha": "^0.2.2",
"karma-mocha-reporter": "^2.0.0",
"karma-mocha-reporter": "^2.0.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"mocha": "^2.4.5",
Expand Down

0 comments on commit ae98370

Please sign in to comment.