kjelsrud.dev/node_modules/astro/dist/runtime/server/astro-component.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-07-19 21:31:30 +02:00
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
function validateArgs(args) {
if (args.length !== 3)
return false;
if (!args[0] || typeof args[0] !== "object")
return false;
return true;
}
function baseCreateComponent(cb, moduleId) {
var _a;
const name = ((_a = moduleId == null ? void 0 : moduleId.split("/").pop()) == null ? void 0 : _a.replace(".astro", "")) ?? "";
const fn = (...args) => {
if (!validateArgs(args)) {
throw new AstroError({
...AstroErrorData.InvalidComponentArgs,
message: AstroErrorData.InvalidComponentArgs.message(name)
});
}
return cb(...args);
};
Object.defineProperty(fn, "name", { value: name, writable: false });
fn.isAstroComponentFactory = true;
fn.moduleId = moduleId;
return fn;
}
function createComponentWithOptions(opts) {
const cb = baseCreateComponent(opts.factory, opts.moduleId);
cb.propagation = opts.propagation;
return cb;
}
function createComponent(arg1, moduleId) {
if (typeof arg1 === "function") {
return baseCreateComponent(arg1, moduleId);
} else {
return createComponentWithOptions(arg1);
}
}
export {
createComponent
};