Skip to content

Commit b33a645

Browse files
committed
Simplify location constructors
1 parent 708465c commit b33a645

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

src/core/location/location.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class Location {
4242
* @param {string} appBaseNoFile application base URL stripped of any filename
4343
*/
4444
constructor(appBase, appBaseNoFile) {
45+
const parsedUrl = urlResolve(appBase);
46+
4547
/** @type {string} */
4648
this.appBase = appBase;
4749

@@ -67,16 +69,17 @@ export class Location {
6769
this.$$replace = false;
6870

6971
/** @type {import('../url-utils/url-utils').HttpProtocol} */
70-
this.$$protocol = undefined;
72+
this.$$protocol = parsedUrl.protocol;
7173

7274
/** @type {string} */
73-
this.$$host = undefined;
75+
this.$$host = parsedUrl.hostname;
7476

7577
/**
7678
* The port, without ":"
7779
* @type {number}
7880
*/
79-
this.$$port = undefined;
81+
this.$$port =
82+
toInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
8083

8184
/**
8285
* The pathname, beginning with "/"
@@ -359,7 +362,6 @@ export class LocationHtml5Url extends Location {
359362
super(appBase, appBaseNoFile);
360363
this.$$html5 = true;
361364
this.basePrefix = basePrefix || "";
362-
parseAbsoluteUrl(appBase, this);
363365
}
364366

365367
/**
@@ -442,10 +444,7 @@ export class LocationHtml5Url extends Location {
442444
export class LocationHashbangUrl extends Location {
443445
constructor(appBase, appBaseNoFile, hashPrefix) {
444446
super(appBase, appBaseNoFile);
445-
this.appBase = appBase;
446-
this.appBaseNoFile = appBaseNoFile;
447447
this.hashPrefix = hashPrefix;
448-
parseAbsoluteUrl(appBase, this);
449448
}
450449

451450
/**
@@ -890,19 +889,6 @@ function normalizePath(pathValue, searchValue, hashValue) {
890889
return path + (search ? `?${search}` : "") + hash;
891890
}
892891

893-
/**
894-
* @param {string} absoluteUrl
895-
* @param {Location} locationObj
896-
*/
897-
function parseAbsoluteUrl(absoluteUrl, locationObj) {
898-
const parsedUrl = urlResolve(absoluteUrl);
899-
900-
locationObj.$$protocol = parsedUrl.protocol;
901-
locationObj.$$host = parsedUrl.hostname;
902-
locationObj.$$port =
903-
toInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
904-
}
905-
906892
function parseAppUrl(url, locationObj, html5Mode) {
907893
if (/^\s*[\\/]{2,}/.test(url)) {
908894
throw $locationMinErr("badpath", 'Invalid url "{0}".', url);

types/core/location/location.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,13 @@ export class LocationHtml5Url extends Location {
230230
*/
231231
export class LocationHashbangUrl extends Location {
232232
constructor(appBase: any, appBaseNoFile: any, hashPrefix: any);
233-
appBase: any;
234-
appBaseNoFile: any;
235233
hashPrefix: any;
236234
/**
237235
* Parse given hashbang URL into properties
238236
* @param {string} url Hashbang URL
239237
*/
240238
$$parse(url: string): void;
241-
$$normalizeUrl(url: any): any;
239+
$$normalizeUrl(url: any): string;
242240
/**
243241
* @param {string} url
244242
* @returns {boolean}

0 commit comments

Comments
 (0)