HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/shahnamag/back-end/node_modules/dedent/macro.js
const { MacroError, createMacro } = require("babel-plugin-macros");
const dedent = require("./dist/dedent.js").default;

module.exports = createMacro(prevalMacros);

function prevalMacros({ babel, references, state }) {
	references.default.forEach((referencePath) => {
		if (referencePath.parentPath.type === "TaggedTemplateExpression") {
			asTag(referencePath.parentPath.get("quasi"), state, babel);
		} else if (referencePath.parentPath.type === "CallExpression") {
			asFunction(referencePath.parentPath.get("arguments"), state, babel);
		} else {
			throw new MacroError(
				`dedent.macro can only be used as tagged template expression or function call. You tried ${referencePath.parentPath.type}.`,
			);
		}
	});
}

function asTag(quasiPath, _, babel) {
	const string = quasiPath.parentPath.get("quasi").evaluate().value;
	const { types: t } = babel;

	quasiPath.parentPath.replaceWith(t.stringLiteral(dedent(string)));
}

function asFunction(argumentsPaths, _, babel) {
	const string = argumentsPaths[0].evaluate().value;
	const { types: t } = babel;

	argumentsPaths[0].parentPath.replaceWith(t.stringLiteral(dedent(string)));
}