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) {
/**
* Instead of using `parser.generateEdgeExpression`, we make use of
* `generateAcornExpression`, since we do not want to process
* `Indentifer` expressions as per the normal parsing logic
* and just want to extract it's name.
*/
const parsed = parser.generateAcornExpression(token.properties.jsArg, token.loc).expression
allowExpressions(
parsed,
[expressions.BinaryExpression],
parser.options.filename,
`{${token.properties.jsArg}} is not a valid binary expression for the @each tag`,
)
/**
* Finding if an else child exists inside the each tag
*/
const elseIndex = token.children.findIndex((child) => isBlockToken(child, 'else'))
const elseChild = elseIndex > -1 ? token.children.splice(elseIndex) : []
/**
* Fetching the item,index and list for the each loop
*/
const [item, index] = getLoopItemAndIndex(parsed.left, parser.options.filename)
const list = getLoopList(parsed.right, parser)