Skip to content
This repository was archived by the owner on Dec 28, 2019. It is now read-only.

Commit 807b8ef

Browse files
committed
Implemented babel
1 parent 7708025 commit 807b8ef

10 files changed

+960
-57
lines changed

.babelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"targets": {
7+
"browsers": ["last 2 versions", "safari >= 7"]
8+
},
9+
"modules": false
10+
}
11+
]
12+
]
13+
}

package-lock.json

Lines changed: 880 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"route-parser": "0.0.5"
2525
},
2626
"devDependencies": {
27+
"babel-core": "^6.26.0",
28+
"babel-preset-env": "^1.6.1",
2729
"rollup": "^0.50.0",
30+
"rollup-plugin-babel": "^3.0.3",
2831
"rollup-plugin-commonjs": "^8.2.6",
2932
"rollup-plugin-node-resolve": "^3.0.0",
3033
"rollup-plugin-uglify": "^3.0.0",

react/index.js

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@
22

33
Object.defineProperty(exports, '__esModule', { value: true });
44

5-
const sourceProperty = 'source';
6-
const separatorChar = '-';
5+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
6+
7+
var sourceProperty = 'source';
8+
var separatorChar = '-';
79

810
function Router(props) {
9-
let children = props.children;
10-
let childrens = Array.isArray(children) ? children : [children];
11-
let source = props[sourceProperty];
12-
for (let index = 0, total = childrens.length; index < total; ++index) {
13-
children = childrens[index];
14-
if (Check(children.props, source))
15-
return getChildrenOfChildren(children)
11+
var children = props.children;
12+
var childrens = Array.isArray(children) ? children : [children];
13+
var source = props[sourceProperty];
14+
for (var _index = 0, total = childrens.length; _index < total; ++_index) {
15+
children = childrens[_index];
16+
if (Check(children.props, source)) return getChildrenOfChildren(children);
1617
}
1718
}
1819

1920
function Route(props) {
20-
let { children } = props;
21-
let source = props[sourceProperty];
22-
if (Check(props, source)) return children
21+
var children = props.children;
22+
23+
var source = props[sourceProperty];
24+
if (Check(props, source)) return children;
2325
}
2426

25-
const Show = Route;
27+
var Show = Route;
2628

2729
// export function setSourceProperty(name) {
2830
// sourceProperty = name
@@ -34,50 +36,37 @@ const Show = Route;
3436

3537
function getChildrenOfChildren(children) {
3638
// react || preact
37-
const child = children.props.children || children.children;
38-
return Array.isArray(child) ? child[0] : child //[0] // We can remove [0] when preact supports array of childrens. react16 already does
39+
var child = children.props.children || children.children;
40+
return Array.isArray(child) ? child[0] : child; //[0] // We can remove [0] when preact supports array of childrens. react16 already does
3941
}
4042

4143
function Check(props, source) {
42-
if (props.hasOwnProperty('if')) if (!props.if) return false
44+
if (props.hasOwnProperty('if')) if (!props.if) return false;
4345

44-
let prop;
46+
var prop = void 0;
4547
for (prop in props) {
4648
if (prop !== 'children' && prop !== sourceProperty && prop !== 'if') {
47-
let value = source.hasOwnProperty(prop)
48-
? source[prop]
49-
: get(source, prop.split(separatorChar));
49+
var value = source.hasOwnProperty(prop) ? source[prop] : get(source, prop.split(separatorChar));
5050

5151
if (props[prop] instanceof RegExp) {
52-
if (!props[prop].test(value)) return false
53-
} else if (props[prop] !== value) return false
52+
if (!props[prop].test(value)) return false;
53+
} else if (props[prop] !== value) return false;
5454
}
5555
}
5656

57-
return true
57+
return true;
5858
}
5959

6060
function get(object, path) {
61-
if (path.length === 0) return object
62-
63-
for (
64-
let index = 0, total = path.length, tmpobject;
65-
index < total;
66-
index++
67-
) {
68-
tmpobject = object[path[index]];
69-
70-
if (
71-
index + 1 < total &&
72-
tmpobject !== null &&
73-
typeof tmpobject == 'object'
74-
)
75-
object = tmpobject;
76-
else if (object.hasOwnProperty(path[index])) return tmpobject
77-
else return undefined
61+
if (path.length === 0) return object;
62+
63+
for (var _index2 = 0, total = path.length, tmpobject; _index2 < total; _index2++) {
64+
tmpobject = object[path[_index2]];
65+
66+
if (_index2 + 1 < total && tmpobject !== null && (typeof tmpobject === 'undefined' ? 'undefined' : _typeof(tmpobject)) == 'object') object = tmpobject;else if (object.hasOwnProperty(path[_index2])) return tmpobject;else return undefined;
7867
}
7968

80-
return object[path[index]]
69+
return object[path[index]];
8170
}
8271

8372
exports.Router = Router;

react/index.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/index.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import uglify from 'rollup-plugin-uglify'
22
import resolve from 'rollup-plugin-node-resolve'
33
import commonjs from 'rollup-plugin-commonjs'
4+
import babel from 'rollup-plugin-babel'
45
// import pkg from './package.json'
56

67
export default [
@@ -13,16 +14,21 @@ export default [
1314
},
1415
sourcemap: true,
1516
plugins: [
17+
babel({
18+
exclude: ['node_modules/**']
19+
}),
1620
uglify(),
1721
resolve(), // so Rollup can find `ms`
1822
commonjs() // so Rollup can convert `ms` to an ES module
1923
]
2024
},
2125
{
2226
input: 'src/routes/index.js',
23-
output: [
24-
{ file: './routes/index.js', format: 'cjs' }
25-
// { file: './routes/index.js', format: 'es' }
27+
output: { file: './routes/index.js', format: 'cjs' },
28+
plugins: [
29+
babel({
30+
exclude: ['node_modules/**']
31+
})
2632
],
2733
external: ['ms']
2834
},
@@ -53,10 +59,20 @@ export default [
5359
format: 'umd'
5460
},
5561
sourcemap: true,
56-
plugins: [uglify()]
62+
plugins: [
63+
uglify(),
64+
babel({
65+
exclude: ['node_modules/**']
66+
})
67+
]
5768
},
5869
{
5970
input: 'src/react/index.js',
60-
output: { file: './react/index.js', format: 'cjs' }
71+
output: { file: './react/index.js', format: 'cjs' },
72+
plugins: [
73+
babel({
74+
exclude: ['node_modules/**']
75+
})
76+
]
6177
}
6278
]

routes/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
77
var Route = _interopDefault(require('route-parser'));
88

99
function createRoute(path_user) {
10-
const route = new Route(path_user);
11-
const f = params => route.reverse(params);
12-
f.match = route_built => route.match(getDefaultPathname(route_built));
13-
return f
10+
var route = new Route(path_user);
11+
var f = function f(params) {
12+
return route.reverse(params);
13+
};
14+
f.match = function (route_built) {
15+
return route.match(getDefaultPathname(route_built));
16+
};
17+
return f;
1418
}
1519

1620
function getDefaultPathname(route) {
17-
return typeof route != 'string' && typeof window != 'undefined'
18-
? window.location.href.slice(location.origin.length)
19-
: route
21+
return typeof route != 'string' && typeof window != 'undefined' ? window.location.href.slice(location.origin.length) : route;
2022
}
2123

2224
// https://github.com/rcs/route-parser

0 commit comments

Comments
 (0)