/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v5.108.4
lib/runtime/RelativeUrlRuntimeModule.js
46 строк
1 KB
Alexander Akait
feat: add output.environment.let option and emit let/const in generated code (#21010)
25 май 2026, 20:47
Не верифицирован
25 май 2026, 20:47
e42372c
Код
Авторство
О чём код?
/* MIT License http://www.opensource.org/licenses/mit-license.php */ "use strict"; const RuntimeGlobals = require("../RuntimeGlobals"); const Template = require("../Template"); const HelperRuntimeModule = require("./HelperRuntimeModule"); /** @typedef {import("../Compilation")} Compilation */ class RelativeUrlRuntimeModule extends HelperRuntimeModule { constructor() { super("relative url"); } /** * Generates runtime code for this runtime module. * @returns {string | null} runtime code */ generate() { const compilation = /** @type {Compilation} */ (this.compilation); const { runtimeTemplate } = compilation; const cst = runtimeTemplate.renderConst(); return Template.asString([ `${RuntimeGlobals.relativeUrl} = function RelativeURL(url) {`, Template.indent([ `${cst} realUrl = new URL(url, "x:/");`, `${cst} values = {};`, "for (var key in realUrl) values[key] = realUrl[key];", "values.href = url;", 'values.pathname = url.replace(/[?#].*/, "");', 'values.origin = values.protocol = "";', `values.toString = values.toJSON = ${runtimeTemplate.returningFunction( "url" )};`, "for (var key in values) Object.defineProperty(this, key, { enumerable: true, configurable: true, value: values[key] });" ]), "};", `${RuntimeGlobals.relativeUrl}.prototype = URL.prototype;` ]); } } module.exports = RelativeUrlRuntimeModule;