source: trip-planner-front/node_modules/webpack/lib/runtime/RelativeUrlRuntimeModule.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3*/
4
5"use strict";
6
7const RuntimeGlobals = require("../RuntimeGlobals");
8const Template = require("../Template");
9const HelperRuntimeModule = require("./HelperRuntimeModule");
10
11class RelativeUrlRuntimeModule extends HelperRuntimeModule {
12 constructor() {
13 super("relative url");
14 }
15
16 /**
17 * @returns {string} runtime code
18 */
19 generate() {
20 const { runtimeTemplate } = this.compilation;
21 return Template.asString([
22 `${RuntimeGlobals.relativeUrl} = function RelativeURL(url) {`,
23 Template.indent([
24 'var realUrl = new URL(url, "x:/");',
25 "var values = {};",
26 "for (var key in realUrl) values[key] = realUrl[key];",
27 "values.href = url;",
28 'values.pathname = url.replace(/[?#].*/, "");',
29 'values.origin = values.protocol = "";',
30 `values.toString = values.toJSON = ${runtimeTemplate.returningFunction(
31 "url"
32 )};`,
33 "for (var key in values) Object.defineProperty(this, key, Object.assign({ enumerable: true, configurable: true, value: values[key] }));"
34 ]),
35 "};",
36 `${RuntimeGlobals.relativeUrl}.prototype = URL.prototype;`
37 ]);
38 }
39}
40
41module.exports = RelativeUrlRuntimeModule;
Note: See TracBrowser for help on using the repository browser.