Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
/**
* Return the slot name with empty props, when the expression is a literal
* value.
*/
if (parsed.type === expressions.Literal) {
return [name.raw, null]
}
/**
* Make sure the sequence expression has only 2 arguments in it. Though it doesn't hurt
* the rendering of component, we must not run code with false expectations.
*/
if (parsed.expressions.length > 2) {
throw new EdgeError('maximum of 2 arguments are allowed for @slot tag', 'E_MAX_ARGUMENTS', {
line: parsed.loc.start.line,
col: parsed.loc.start.column,
filename: parser.options.filename,
})
}
allowExpressions(
parsed.expressions[1],
[expressions.Identifier],
parser.options.filename,
`{${parser.stringifyExpression(parsed.expressions[1])}} is not valid prop identifier for @slot tag`,
)
/**
* Returning the slot name and slot props name
*/
export function disAllowExpressions (
expression: any,
expressions: (keyof typeof expressionsList)[],
filename: string,
message: string,
) {
if (expressions.includes(expression.type)) {
throw new EdgeError(message, 'E_UNALLOWED_EXPRESSION', {
line: expression.loc.start.line,
col: expression.loc.start.column,
filename: filename,
})
}
}
compile (parser, _buffer, token) {
throw new EdgeError(
`@slot tag must appear as top level tag inside the @component tag`,
'E_ORPHAN_SLOT_TAG',
{
line: token.loc.start.line,
col: token.loc.start.col,
filename: parser.options.filename,
},
)
},
}
return
}
/**
* Collect set calls inside parent templates
*/
if (isBlockToken(node, 'set')) {
extendedSetCalls.push(node)
return
}
/**
* Everything else if not allowed as top level nodes
*/
const [line, col] = getLineAndColumnForToken(node)
throw new EdgeError(
`Template extending the layout can only define @sections as top level nodes`,
'E_UNALLOWED_EXPRESSION',
{ line, col, filename },
)
})
/**
* The set tag only accepts a sequence expression.
*/
allowExpressions(
parsed,
[expressions.SequenceExpression],
parser.options.filename,
`{${token.properties.jsArg}} is not a valid key-value pair for the @slot tag`,
)
/**
* Disallow more than 2 values for the sequence expression
*/
if (parsed.expressions.length > 2) {
throw new EdgeError(`maximum of 2 arguments are allowed for the @set tag`, 'E_MAX_ARGUMENTS', {
line: parsed.loc.start.line,
col: parsed.loc.start.column,
filename: parser.options.filename,
})
}
const [key, value] = parsed.expressions
/**
* The key has to be a literal value
*/
allowExpressions(
key,
[expressions.Literal],
parser.options.filename,
'The first argument for @set tag must be a string literal',
export function allowExpressions (
expression: any,
expressions: (keyof typeof expressionsList)[],
filename: string,
message: string,
) {
if (!expressions.includes(expression.type)) {
throw new EdgeError(message, 'E_UNALLOWED_EXPRESSION', {
line: expression.loc.start.line,
col: expression.loc.start.column,
filename: filename,
})
}
}