@tanstack/router-generator
Version:
Modern and scalable routing for React applications
37 lines (36 loc) • 1.14 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const recast = require("recast");
const b = recast.types.builders;
function ensureStringArgument(callExpression, value, preferredQuote) {
const argument = callExpression.arguments[0];
if (!argument) {
let stringLiteral;
if (!preferredQuote) {
stringLiteral = b.stringLiteral.from({ value });
} else {
stringLiteral = b.stringLiteral.from({
value,
extra: {
rawValue: value,
raw: `${preferredQuote}${value}${preferredQuote}`
}
});
}
callExpression.arguments.push(stringLiteral);
return true;
} else if (argument.type === "StringLiteral") {
if (argument.value !== value) {
argument.value = value;
return true;
}
} else if (argument.type === "TemplateLiteral") {
if (argument.quasis.length === 1 && argument.quasis[0] && argument.quasis[0].value.raw !== value) {
argument.quasis[0].value.raw = value;
return true;
}
}
return false;
}
exports.ensureStringArgument = ensureStringArgument;
//# sourceMappingURL=utils.cjs.map
;