Skip to content

Commit

Permalink
Fix property mangling and implement ES5 compatibility properly (#442)
Browse files Browse the repository at this point in the history
* Remove custom Babel config

* Use method instead of property getter for internal `_location`

* Update Jest
  • Loading branch information
bakerkretzmar authored Jul 6, 2021
1 parent 13bed90 commit d8432a5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
3 changes: 0 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: 'defaults, not IE 11' }],
],
plugins: ['@babel/plugin-proposal-optional-chaining'],
env: {
test: {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"watch": "npm run build watch",
"build:npm": "microbundle --name route --format modern,es,umd --no-sourcemap",
"build:npm:vue": "microbundle --entry src/js/vue.js --output dist/vue.js --name ZiggyVue --format modern,es,umd --no-sourcemap",
"test": "jest",
"test": "jest --verbose",
"prepublishOnly": "npm run build:npm && npm run build:npm:vue"
},
"mangle": {
Expand All @@ -57,7 +57,7 @@
"devDependencies": {
"@babel/preset-env": "^7.11.0",
"babel-preset-power-assert": "^3.0.0",
"jest": "^26.2.2",
"jest": "^27.0.6",
"microbundle": "^0.12.3",
"power-assert": "^1.6.1"
}
Expand Down
12 changes: 6 additions & 6 deletions src/js/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default class Router extends String {
*/
current(name, params) {
const url = this._config.absolute
? this._location.host + this._location.pathname
: this._location.pathname.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '').replace(/^\/+/, '/');
? this._location().host + this._location().pathname
: this._location().pathname.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '').replace(/^\/+/, '/');

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

return {
Expand Down Expand Up @@ -239,7 +239,7 @@ export default class Router extends String {
* @return {Object} Parameters.
*/
_dehydrate(route) {
let pathname = this._location.pathname
let pathname = this._location().pathname
// If this Laravel app is in a subdirectory, trim the subdirectory from the path
.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '')
.replace(/^\/+/, '');
Expand All @@ -260,9 +260,9 @@ export default class Router extends String {
}

return {
...dehydrate(this._location.host, route.domain, '.'), // Domain parameters
...dehydrate(this._location().host, route.domain, '.'), // Domain parameters
...dehydrate(pathname, route.uri, '/'), // Path parameters
...parse(this._location.search?.replace(/^\?/, '')), // Query parameters
...parse(this._location().search?.replace(/^\?/, '')), // Query parameters
};
}

Expand Down
4 changes: 4 additions & 0 deletions tests/js/route.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @jest-environment jsdom
*/

import assert, { deepEqual, strictEqual as same, throws } from 'assert';
import route from '../../src/js';

Expand Down

0 comments on commit d8432a5

Please sign in to comment.