mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
export function assertAllowedAttributes(path, allowed) {
|
|
const { node } = path;
|
|
node.attributes.forEach((attr, i) => {
|
|
if (!allowed.includes(attr.name)) {
|
|
throw path
|
|
.get(`attributes.${i}`)
|
|
.buildCodeFrameError(
|
|
`Invalid "${node.name.value}" tag attribute: "${attr.name}".`
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
export function assertNoAttributes(path) {
|
|
assertAllowedAttributes(path, []);
|
|
}
|
|
|
|
export function assertNoParams(path) {
|
|
const { hub } = path;
|
|
const params = path.get("params");
|
|
if (params.length) {
|
|
const start = params[0].node.loc.start;
|
|
const end = params[params.length - 1].node.loc.end;
|
|
throw hub.buildError(
|
|
{ loc: { start, end } },
|
|
"Tag does not support parameters."
|
|
);
|
|
}
|
|
}
|
|
|
|
export function assertNoAttributeTags(path) {
|
|
const exampleAttributeTag = path.get("exampleAttributeTag");
|
|
if (exampleAttributeTag.node) {
|
|
throw exampleAttributeTag
|
|
.get("name")
|
|
.buildCodeFrameError("@tags must be within a custom element.");
|
|
}
|
|
}
|
|
|
|
export function assertNoArgs(path) {
|
|
const { hub } = path;
|
|
const args = path.get("arguments");
|
|
if (args.length) {
|
|
const start = args[0].node.loc.start;
|
|
const end = args[args.length - 1].node.loc.end;
|
|
throw hub.buildError(
|
|
{ loc: { start, end } },
|
|
"Tag does not support arguments."
|
|
);
|
|
}
|
|
}
|