source: imaps-frontend/node_modules/webpack/lib/runtime/RelativeUrlRuntimeModule.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.3 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
11/** @typedef {import("../Compilation")} Compilation */
12
13class RelativeUrlRuntimeModule extends HelperRuntimeModule {
14 constructor() {
15 super("relative url");
16 }
17
18 /**
19 * @returns {string | null} runtime code
20 */
21 generate() {
22 const compilation = /** @type {Compilation} */ (this.compilation);
23 const { runtimeTemplate } = compilation;
24 return Template.asString([
25 `${RuntimeGlobals.relativeUrl} = function RelativeURL(url) {`,
26 Template.indent([
27 'var realUrl = new URL(url, "x:/");',
28 "var values = {};",
29 "for (var key in realUrl) values[key] = realUrl[key];",
30 "values.href = url;",
31 'values.pathname = url.replace(/[?#].*/, "");',
32 'values.origin = values.protocol = "";',
33 `values.toString = values.toJSON = ${runtimeTemplate.returningFunction(
34 "url"
35 )};`,
36 "for (var key in values) Object.defineProperty(this, key, { enumerable: true, configurable: true, value: values[key] });"
37 ]),
38 "};",
39 `${RuntimeGlobals.relativeUrl}.prototype = URL.prototype;`
40 ]);
41 }
42}
43
44module.exports = RelativeUrlRuntimeModule;
Note: See TracBrowser for help on using the repository browser.