Skip to content

Commit d8432a5

Browse files
Fix property mangling and implement ES5 compatibility properly (#442)
* Remove custom Babel config * Use method instead of property getter for internal `_location` * Update Jest
1 parent 13bed90 commit d8432a5

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

babel.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
module.exports = {
2-
presets: [
3-
['@babel/preset-env', { targets: 'defaults, not IE 11' }],
4-
],
52
plugins: ['@babel/plugin-proposal-optional-chaining'],
63
env: {
74
test: {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"watch": "npm run build watch",
4646
"build:npm": "microbundle --name route --format modern,es,umd --no-sourcemap",
4747
"build:npm:vue": "microbundle --entry src/js/vue.js --output dist/vue.js --name ZiggyVue --format modern,es,umd --no-sourcemap",
48-
"test": "jest",
48+
"test": "jest --verbose",
4949
"prepublishOnly": "npm run build:npm && npm run build:npm:vue"
5050
},
5151
"mangle": {
@@ -57,7 +57,7 @@
5757
"devDependencies": {
5858
"@babel/preset-env": "^7.11.0",
5959
"babel-preset-power-assert": "^3.0.0",
60-
"jest": "^26.2.2",
60+
"jest": "^27.0.6",
6161
"microbundle": "^0.12.3",
6262
"power-assert": "^1.6.1"
6363
}

src/js/Router.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export default class Router extends String {
7070
*/
7171
current(name, params) {
7272
const url = this._config.absolute
73-
? this._location.host + this._location.pathname
74-
: this._location.pathname.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '').replace(/^\/+/, '/');
73+
? this._location().host + this._location().pathname
74+
: this._location().pathname.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '').replace(/^\/+/, '/');
7575

7676
// Find the first route that matches the current URL
7777
const [current, route] = Object.entries(this._config.routes).find(
@@ -106,7 +106,7 @@ export default class Router extends String {
106106
*
107107
* @return {Object}
108108
*/
109-
get _location() {
109+
_location() {
110110
const { host = '', pathname = '', search = '' } = typeof window !== 'undefined' ? window.location : {};
111111

112112
return {
@@ -239,7 +239,7 @@ export default class Router extends String {
239239
* @return {Object} Parameters.
240240
*/
241241
_dehydrate(route) {
242-
let pathname = this._location.pathname
242+
let pathname = this._location().pathname
243243
// If this Laravel app is in a subdirectory, trim the subdirectory from the path
244244
.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '')
245245
.replace(/^\/+/, '');
@@ -260,9 +260,9 @@ export default class Router extends String {
260260
}
261261

262262
return {
263-
...dehydrate(this._location.host, route.domain, '.'), // Domain parameters
263+
...dehydrate(this._location().host, route.domain, '.'), // Domain parameters
264264
...dehydrate(pathname, route.uri, '/'), // Path parameters
265-
...parse(this._location.search?.replace(/^\?/, '')), // Query parameters
265+
...parse(this._location().search?.replace(/^\?/, '')), // Query parameters
266266
};
267267
}
268268

tests/js/route.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
15
import assert, { deepEqual, strictEqual as same, throws } from 'assert';
26
import route from '../../src/js';
37

0 commit comments

Comments
 (0)