Skip to content

Commit 67571bb

Browse files
committed
refactor: move types for webpack 4
1 parent 0cf54de commit 67571bb

File tree

4 files changed

+76
-70
lines changed

4 files changed

+76
-70
lines changed

build/configs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ module.exports = [
5555
},
5656
{
5757
input: resolve('src/composables/index.js'),
58-
file: resolve('./dist/composables.mjs'),
58+
file: resolve('./composables.mjs'),
5959
format: 'es'
6060
},
6161
{
6262
input: resolve('src/composables/index.js'),
63-
file: resolve('./dist/composables.js'),
63+
file: resolve('./composables.js'),
6464
format: 'cjs'
6565
}
6666
].map(genConfig)

dist/composables.js composables.js

+69-65
Original file line numberDiff line numberDiff line change
@@ -3,108 +3,108 @@
33
* (c) 2022 Evan You
44
* @license MIT
55
*/
6-
'use strict';
6+
'use strict'
77

8-
Object.defineProperty(exports, '__esModule', { value: true });
8+
Object.defineProperty(exports, '__esModule', { value: true })
99

10-
var vue = require('vue');
10+
var vue = require('vue')
1111

1212
// dev only warn if no current instance
1313

1414
function throwNoCurrentInstance (method) {
1515
if (!vue.getCurrentInstance()) {
1616
throw new Error(
17-
("[vue-router]: Missing current instance. " + method + "() must be called inside <script setup> or setup().")
17+
('[vue-router]: Missing current instance. ' + method + '() must be called inside <script setup> or setup().')
1818
)
1919
}
2020
}
2121

2222
function useRouter () {
2323
if (process.env.NODE_ENV !== 'production') {
24-
throwNoCurrentInstance('useRouter');
24+
throwNoCurrentInstance('useRouter')
2525
}
2626

2727
return vue.getCurrentInstance().proxy.$root.$router
2828
}
2929

3030
function useRoute () {
3131
if (process.env.NODE_ENV !== 'production') {
32-
throwNoCurrentInstance('useRoute');
32+
throwNoCurrentInstance('useRoute')
3333
}
3434

35-
var root = vue.getCurrentInstance().proxy.$root;
35+
var root = vue.getCurrentInstance().proxy.$root
3636
if (!root._$route) {
37-
var route = vue.effectScope(true).run(function () { return vue.shallowReactive(Object.assign({}, root.$router.currentRoute)); }
38-
);
39-
root._$route = route;
37+
var route = vue.effectScope(true).run(function () { return vue.shallowReactive(Object.assign({}, root.$router.currentRoute)) }
38+
)
39+
root._$route = route
4040

4141
root.$router.afterEach(function (to) {
42-
Object.assign(route, to);
43-
});
42+
Object.assign(route, to)
43+
})
4444
}
4545

4646
return root._$route
4747
}
4848

4949
function onBeforeRouteUpdate (guard) {
5050
if (process.env.NODE_ENV !== 'production') {
51-
throwNoCurrentInstance('onBeforeRouteUpdate');
51+
throwNoCurrentInstance('onBeforeRouteUpdate')
5252
}
5353

5454
return useFilteredGuard(guard, isUpdateNavigation)
5555
}
5656
function isUpdateNavigation (to, from, depth) {
57-
var toMatched = to.matched;
58-
var fromMatched = from.matched;
57+
var toMatched = to.matched
58+
var fromMatched = from.matched
5959
return (
6060
toMatched.length >= depth &&
6161
toMatched
6262
.slice(0, depth + 1)
63-
.every(function (record, i) { return record === fromMatched[i]; })
63+
.every(function (record, i) { return record === fromMatched[i] })
6464
)
6565
}
6666

6767
function isLeaveNavigation (to, from, depth) {
68-
var toMatched = to.matched;
69-
var fromMatched = from.matched;
68+
var toMatched = to.matched
69+
var fromMatched = from.matched
7070
return toMatched.length < depth || toMatched[depth] !== fromMatched[depth]
7171
}
7272

7373
function onBeforeRouteLeave (guard) {
7474
if (process.env.NODE_ENV !== 'production') {
75-
throwNoCurrentInstance('onBeforeRouteLeave');
75+
throwNoCurrentInstance('onBeforeRouteLeave')
7676
}
7777

7878
return useFilteredGuard(guard, isLeaveNavigation)
7979
}
8080

81-
var noop = function () {};
81+
var noop = function () {}
8282
function useFilteredGuard (guard, fn) {
83-
var instance = vue.getCurrentInstance();
84-
var router = useRouter();
83+
var instance = vue.getCurrentInstance()
84+
var router = useRouter()
8585

86-
var target = instance.proxy;
86+
var target = instance.proxy
8787
// find the nearest RouterView to know the depth
8888
while (
8989
target &&
9090
target.$vnode &&
9191
target.$vnode.data &&
9292
target.$vnode.data.routerViewDepth == null
9393
) {
94-
target = target.$parent;
94+
target = target.$parent
9595
}
9696

9797
var depth =
9898
target && target.$vnode && target.$vnode.data
9999
? target.$vnode.data.routerViewDepth
100-
: null;
100+
: null
101101

102102
if (depth != null) {
103103
var removeGuard = router.beforeEach(function (to, from, next) {
104104
return fn(to, from, depth) ? guard(to, from, next) : next()
105-
});
105+
})
106106

107-
vue.onUnmounted(removeGuard);
107+
vue.onUnmounted(removeGuard)
108108
return removeGuard
109109
}
110110

@@ -122,37 +122,37 @@ function guardEvent (e) {
122122
if (e.button !== undefined && e.button !== 0) { return }
123123
// don't redirect if `target="_blank"`
124124
if (e.currentTarget && e.currentTarget.getAttribute) {
125-
var target = e.currentTarget.getAttribute('target');
125+
var target = e.currentTarget.getAttribute('target')
126126
if (/\b_blank\b/i.test(target)) { return }
127127
}
128128
// this may be a Weex event which doesn't have this method
129129
if (e.preventDefault) {
130-
e.preventDefault();
130+
e.preventDefault()
131131
}
132132
return true
133133
}
134134

135135
function includesParams (outer, inner) {
136-
var loop = function ( key ) {
137-
var innerValue = inner[key];
138-
var outerValue = outer[key];
136+
var loop = function (key) {
137+
var innerValue = inner[key]
138+
var outerValue = outer[key]
139139
if (typeof innerValue === 'string') {
140140
if (innerValue !== outerValue) { return { v: false } }
141141
} else {
142142
if (
143143
!Array.isArray(outerValue) ||
144144
outerValue.length !== innerValue.length ||
145-
innerValue.some(function (value, i) { return value !== outerValue[i]; })
145+
innerValue.some(function (value, i) { return value !== outerValue[i] })
146146
) {
147147
return { v: false }
148148
}
149149
}
150-
};
150+
}
151151

152152
for (var key in inner) {
153-
var returned = loop( key );
153+
var returned = loop(key)
154154

155-
if ( returned ) return returned.v;
155+
if (returned) return returned.v
156156
}
157157

158158
return true
@@ -170,7 +170,7 @@ function isSameRouteLocationParamsValue (a, b) {
170170

171171
function isEquivalentArray (a, b) {
172172
return Array.isArray(b)
173-
? a.length === b.length && a.every(function (value, i) { return value === b[i]; })
173+
? a.length === b.length && a.every(function (value, i) { return value === b[i] })
174174
: a.length === 1 && a[0] === b
175175
}
176176

@@ -186,25 +186,25 @@ function isSameRouteLocationParams (a, b) {
186186

187187
function useLink (props) {
188188
if (process.env.NODE_ENV !== 'production') {
189-
throwNoCurrentInstance('useLink');
189+
throwNoCurrentInstance('useLink')
190190
}
191191

192-
var router = useRouter();
193-
var currentRoute = useRoute();
192+
var router = useRouter()
193+
var currentRoute = useRoute()
194194

195-
var resolvedRoute = vue.computed(function () { return router.resolve(vue.unref(props.to), currentRoute); });
195+
var resolvedRoute = vue.computed(function () { return router.resolve(vue.unref(props.to), currentRoute) })
196196

197197
var activeRecordIndex = vue.computed(function () {
198-
var route = resolvedRoute.value.route;
199-
var matched = route.matched;
200-
var length = matched.length;
201-
var routeMatched = matched[length - 1];
202-
var currentMatched = currentRoute.matched;
198+
var route = resolvedRoute.value.route
199+
var matched = route.matched
200+
var length = matched.length
201+
var routeMatched = matched[length - 1]
202+
var currentMatched = currentRoute.matched
203203
if (!routeMatched || !currentMatched.length) { return -1 }
204-
var index = currentMatched.indexOf(routeMatched);
204+
var index = currentMatched.indexOf(routeMatched)
205205
if (index > -1) { return index }
206206
// possible parent record
207-
var parentRecord = currentMatched[currentMatched.length - 2];
207+
var parentRecord = currentMatched[currentMatched.length - 2]
208208

209209
return (
210210
// we are dealing with nested routes
@@ -214,40 +214,44 @@ function useLink (props) {
214214
// child of the same parent
215215
parentRecord && parentRecord === routeMatched.parent
216216
)
217-
});
217+
})
218218

219219
var isActive = vue.computed(
220-
function () { return activeRecordIndex.value > -1 &&
221-
includesParams(currentRoute.params, resolvedRoute.value.route.params); }
222-
);
220+
function () {
221+
return activeRecordIndex.value > -1 &&
222+
includesParams(currentRoute.params, resolvedRoute.value.route.params)
223+
}
224+
)
223225
var isExactActive = vue.computed(
224-
function () { return activeRecordIndex.value > -1 &&
226+
function () {
227+
return activeRecordIndex.value > -1 &&
225228
activeRecordIndex.value === currentRoute.matched.length - 1 &&
226-
isSameRouteLocationParams(currentRoute.params, resolvedRoute.value.route.params); }
227-
);
229+
isSameRouteLocationParams(currentRoute.params, resolvedRoute.value.route.params)
230+
}
231+
)
228232

229233
var navigate = function (e) {
230-
var href = resolvedRoute.value.route;
234+
var href = resolvedRoute.value.route
231235
if (guardEvent(e)) {
232236
return props.replace
233237
? router.replace(href)
234238
: router.push(href)
235239
}
236240
return Promise.resolve()
237-
};
241+
}
238242

239243
return {
240-
href: vue.computed(function () { return resolvedRoute.value.href; }),
241-
route: vue.computed(function () { return resolvedRoute.value.route; }),
244+
href: vue.computed(function () { return resolvedRoute.value.href }),
245+
route: vue.computed(function () { return resolvedRoute.value.route }),
242246
isExactActive: isExactActive,
243247
isActive: isActive,
244248
navigate: navigate
245249
}
246250
}
247251

248-
exports.isSameRouteLocationParams = isSameRouteLocationParams;
249-
exports.onBeforeRouteLeave = onBeforeRouteLeave;
250-
exports.onBeforeRouteUpdate = onBeforeRouteUpdate;
251-
exports.useLink = useLink;
252-
exports.useRoute = useRoute;
253-
exports.useRouter = useRouter;
252+
exports.isSameRouteLocationParams = isSameRouteLocationParams
253+
exports.onBeforeRouteLeave = onBeforeRouteLeave
254+
exports.onBeforeRouteUpdate = onBeforeRouteUpdate
255+
exports.useLink = useLink
256+
exports.useRoute = useRoute
257+
exports.useRouter = useRouter
File renamed without changes.

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"dist/*.js",
2020
"dist/*.mjs",
2121
"types/*.d.ts",
22+
"composables.mjs",
23+
"composables.js",
2224
"composables.d.ts",
2325
"vetur/tags.json",
2426
"vetur/attributes.json"
@@ -33,9 +35,9 @@
3335
"types": "./types/index.d.ts"
3436
},
3537
"./composables": {
36-
"import": "./dist/composables.mjs",
37-
"require": "./dist/composables.js",
38-
"types": "./types/composables.d.ts"
38+
"import": "./composables.mjs",
39+
"require": "./composables.js",
40+
"types": "./composables.d.ts"
3941
},
4042
"./dist/*": "./dist/*",
4143
"./types/*": "./types/*",

0 commit comments

Comments
 (0)