Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
compile (parser, buffer, token) {
const parsed = parser.generateEdgeExpression(token.properties.jsArg, token.loc)
disAllowExpressions(
parsed,
[expressions.SequenceExpression],
parser.options.filename,
`{${token.properties.jsArg}} is not a valid argument type for the @elseif tag`,
)
/**
* Dedent block
*/
buffer.dedent()
/**
* Start else block
*/
buffer.writeStatement(`} else if(${parser.stringifyExpression(parsed)}) {`)
/**
* Indent block again
compile (parser, buffer, token) {
const parsed = parser.generateEdgeExpression(token.properties.jsArg, token.loc)
disAllowExpressions(
parsed,
[expressions.SequenceExpression],
parser.options.filename,
`{${token.properties.jsArg}} is not a valid argument type for the @yield tag`,
)
const parsedString = parser.stringifyExpression(parsed)
/**
* Write main content when it's truthy
*/
buffer.writeStatement(`if(${parsedString}) {`)
buffer.indent()
buffer.writeLine(parsedString)
buffer.dedent()
/**
* Else write fallback
function getLoopItemAndIndex (expression: any, filename: string): [string, string] {
allowExpressions(
expression,
[expressions.SequenceExpression, expressions.Identifier],
filename,
`invalid left hand side expression for the @each tag`,
)
/**
* Return list index from the sequence expression
*/
if (expression.type === 'SequenceExpression') {
allowExpressions(
expression.expressions[0],
[expressions.Identifier],
filename,
`invalid expression for {value} identifier for the @each tag`,
)
allowExpressions(
compile (parser, buffer, token) {
const parsed = parser.generateEdgeExpression(token.properties.jsArg, token.loc)
/**
* 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
compile (parser, buffer, token) {
const parsed = parser.generateEdgeExpression(token.properties.jsArg, token.loc)
/**
* Check component js props for allowed expressions
*/
allowExpressions(
parsed,
componentNameAllowedExpressions.concat(expressions.SequenceExpression),
parser.options.filename,
`{${token.properties.jsArg}} is not a valid argument type for the @component tag`,
)
/**
* Pulling the name and props for the component. The underlying method will
* ensure that the arguments passed to component tag are valid
*/
const [name, props] = getComponentNameAndProps(parsed, parser)
/**
* Loop over all the children and set them as part of slots. If no slot
* is defined, then the content will be part of the main slot
*/
const slots = {}
token.children.forEach((child, index) => {
compile (parser, buffer, token) {
const parsed = parser.generateEdgeExpression(token.properties.jsArg, token.loc)
disAllowExpressions(
parsed,
[expressions.SequenceExpression],
parser.options.filename,
`{${token.properties.jsArg}} is not a valid argument type for the @unless tag`,
)
/**
* Start if block
*/
buffer.writeStatement(`if(!${parser.stringifyExpression(parsed)}) {`)
/**
* Indent upcoming code
*/
buffer.indent()
/**
* Process of all kids recursively
* ast to edge statements for a `@slot` tag.
*/
const parsed = parser.generateAcornExpression(expression.properties.jsArg, expression.loc).expression
allowExpressions(
parsed,
[expressions.Literal, expressions.SequenceExpression],
parser.options.filename,
`{${expression.properties.jsArg}} is not a valid argument type for the @slot tag`,
)
/**
* Fetch the slot name
*/
let name
if (parsed.type === expressions.SequenceExpression) {
name = parsed.expressions[0]
} else {
name = parsed
}
/**
* Validating the slot name to be a literal value, since slot names cannot be dynamic
*/
allowExpressions(
name,
[expressions.Literal],
parser.options.filename,
'slot name must be a valid string literal',
)
/**
compile (parser, buffer, token) {
const parsed = parser.generateEdgeExpression(token.properties.jsArg, token.loc)
disAllowExpressions(
parsed,
[expressions.SequenceExpression],
parser.options.filename,
`{${token.properties.jsArg}} is not a valid argument type for the @if tag`,
)
/**
* Start if block
*/
buffer.writeStatement(`if(${parser.stringifyExpression(parsed)}) {`)
/**
* Indent upcoming code
*/
buffer.indent()
/**
* Process of all kids recursively